Skip to content

Instantly share code, notes, and snippets.

Avatar
🐢

Simon Byrne simonbyrne

🐢
View GitHub Profile
View cunion.jl
# To ensure correct alignment (e.g. for an 80-bit type)
struct StrWrap{T}
value::T
end
function unsafe_reinterpret(T, a::A) where {A}
if sizeof(T) <= sizeof(A)
r = Ref(a)
Base.@gc_preserve r begin
u = convert(Ptr{T}, Base.unsafe_convert(Ptr{A}, r))
@simonbyrne
simonbyrne / normalize.jl
Last active Dec 8, 2017
column/row normalization of sparse matrices
View normalize.jl
"""
normalizecols!(X, p)
Normalize the non-empty columns of `X` using a `p`-norm.
Overwrites the contents of `X`.
"""
function normalizecols!(X::SparseMatrixCSC, p=2)
for col = 1:X.n
rr = X.colptr[col]:X.colptr[col+1]-1
View intrinsics.jl
module Intrinsics
tname(::Type{Float64}) = "double"
tname(::Type{Float32}) = "float"
fname(::Type{Float64}) = "f64"
fname(::Type{Float32}) = "f32"
for f in [:add, :sub, :mul, :div, :rem]
View sparse_matvec.jl
n = 2_500_000
p = 1.9e-5
X = sprand(n,n,p)
v = sprand(n,8/n)
function fast_A_mul_B(X::SparseMatrixCSC{TX,IX},v::SparseVector{TV,IV}) where {TX,IX,TV,IV}
X.n == v.n || throw(DimensionMismatch())
ind_out = promote_type(IX,IV)[]
val_out = promote_type(TX,TV)[]
@simonbyrne
simonbyrne / gitprob.sh
Created Oct 4, 2017
Create a bad git repository
View gitprob.sh
git init --bare gitprob
git clone gitprob gitprobwork
cd gitprobwork
echo "good" > aaaa
GOOD=$(git hash-object -w aaaa)
git add aaaa
git commit -m "1"
rm aaaa
@simonbyrne
simonbyrne / fisher.jl
Created Oct 4, 2017
Computing Fisher information via forward-mode automatic differentiation
View fisher.jl
using Distributions
import ForwardDiff: Dual, value, partials
@generated function get_values(a::NTuple{N}) where {N}
return ForwardDiff.tupexpr(i -> :(value(a[$i])),N)
end
ForwardDiff.value(p::ForwardDiff.Partials) =
ForwardDiff.Partials(get_values(p.values))
View mpfr_test.c
#include <stdio.h>
#include <gmp.h>
#include <mpfr.h>
int main (void)
{
unsigned int i;
mpfr_t u;
View snake.jl
using SenseHat
function newblob(snake)
while true
x = rand(1:8)
y = rand(1:8)
if (x,y) snake
return (x,y)
end
end
View test.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View Hands on intro to Julia.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.