Skip to content

Instantly share code, notes, and snippets.

View carlobaldassi's full-sized avatar

Carlo Baldassi carlobaldassi

View GitHub Profile
@carlobaldassi
carlobaldassi / conversion_trouble.jl
Created March 21, 2012 00:17
julia: problematic convesion to Vector{Tuple}
typealias MyTuple (ASCIIString, BitsKind)
type MyType
some_field::Int
function MyType(vec::Vector{MyTuple})
println("INNER")
new(0)
end
end
@carlobaldassi
carlobaldassi / silly_bug_annotated.jl
Created March 22, 2012 15:58
A very silly Julia bug [NOW FIXED]
# Annotated version
function calc{T<:Float}(X::Matrix{T}, N...) # change the name of the second argument -> the bug goes away
# (type of second argument doesn't matter)
# we might even use a single argument N::Matrix{T}
# it doesn't matter what's left of the T, it might be
# T<:Float64 or T<:Any or even just T
#function calc(X::Matrix{Float64}, N::Int) # use this form -> the bug goes away
# except where noted
@carlobaldassi
carlobaldassi / lambda_error_message.txt
Created March 24, 2012 01:20
julia: error message with lambda instead of type
julia> a(i) = a(i::x->1)
(type-error car cons ())
unexpected error: #0 (goto-form/lambda/lambda
#0=#fn("7000r1|i10Ko102i11awo11;" [] #1=[#0#
#2=#fn("8000r0i12ai12wo122;" [] #1# make-label)
#3=#fn("8000r1~c0|L241;" [label] #1# mark-label)
#4=#fn("7000r0i10F16G02i10MF16=02e0i1031c1<680i10M\x84;c2q\x7f3041;" [caar
label #fn("7000r1i02|312|;" [])] #1# make&mark-label)
#5=#fn("7000r3|F@17702|c0>6>0|C670~|41;^;c1q|M41;" [(null)
#fn(":000r1|c0=6=0i10e1~3141;|c2=6L0c3qe4e5~\x84i023217502c63141;|c7=6^0c8qc9e1~\x8431c:L3c;c:L2e<~31F16<02e<~31Mc=<43;|c>=6<0e?c@q~N42;|cA=6B0cBqi1330i113042;|cC=6=0cDqi113041;|cE=6?0cFqcG~\x84\x7f3241;|c==6Y0eHi23`326A0i10cIi23L231530]2i10e1~3141;|cJ=6B0cKqi1130i113042;|cL=640^;i10e1~3141;" [call
@carlobaldassi
carlobaldassi / glpk_error_message.txt
Created April 9, 2012 22:31
glpk test error message
(type-error car cons ())
unexpected error: #0 (caddr ((call dlsym _jl_libglpk ($ f))
($ (... args))))
#1 (parse-resword/lambda/lambda/lambda/lambda/lambda/lambda
((call dlsym _jl_libglpk ($ f))
($ (... args))))
#2 (parse-resword/lambda/lambda/lambda
#fn("6000r0~k02\x7fk12i02k2;" [ops-by-prec range-colon-enabled space-sensitive] [[(=
:= += -= *= /= //= .//= .*= ./= |\\=| |.\\=| ^= .^= %= |\|=| &= $= => <<= >>=
>>>=) (?) (|\|\||) (&&) (<- -- -->) (> < >= <= == != .> .< .>= .<= .== .!= .=
@carlobaldassi
carlobaldassi / wctst.jl
Created April 13, 2012 15:14
greedy wc test
function reallygreedylinecounter(fname::String)
f = open(fname)
return reallygreedylinecounter(f)
end
function reallygreedylinecounter(f::IOStream)
try
seek(f, 0)
end
ln = 0
eof = int(typemax(Uint32)) #argh
100x100 matrices, averages over 250000 tests:
A'*A gemm : 0.00022529661750793456 ± 1.3165374929527648e-6
A'*A syrk : 0.0004116961793899536 ± 2.2544687273938097e-6
A*A' gemm : 0.00020168535614013673 ± 9.12395962546235e-7
A*A' syrk : 0.0004128545732498169 ± 2.236023626830784e-6
200x200 matrices, averages over 31250 tests:
A'*A gemm : 0.0016472916564941407 ± 1.1819936441612635e-5
A'*A syrk : 0.0019588019256591795 ± 1.173932771520073e-5
A*A' gemm : 0.0012420702819824219 ± 2.3948308461046164e-6
@carlobaldassi
carlobaldassi / unionbug1.jl
Created May 7, 2012 22:10
Union type dispatch bug
typealias MatOrNothing{T} Union(AbstractMatrix{T}, Vector{None}, Nothing)
my_func{T}(A::MatOrNothing{T}) = println("my_func ok")
M = [1. 2. ; 3. 4.]
my_func(M) # works
my_func([]) # works
my_func(nothing) # fails
@carlobaldassi
carlobaldassi / demo.txt
Created June 19, 2012 11:12
flatten nested Arrays in a plain Vector
julia> load("flatten1d.jl")
julia> a = [[randi(3) for k=1:3] for i=1:3, j=1:2]
3x2 Array{Int64,1} Array:
[3, 1, 2] [1, 3, 3]
[1, 1, 3] [2, 3, 3]
[3, 1, 3] [3, 2, 2]
julia> flatten1d(a)
18-element Int64 Array:
@carlobaldassi
carlobaldassi / fft_benchmarks.jl
Created June 28, 2012 15:50
fft_powers tests
load("fft_powers.jl")
@assert fft_powers_approx([2,3,5], 37) == 40
@assert nextprod([2,3,5], 37) == 40
function bench_nextprod(ps, x)
tm = 1000
t = Array(Float64, tm)
for i = 1:tm
t[i] = @elapsed nextprod(ps, x)
end
@carlobaldassi
carlobaldassi / tw_example.jl
Created August 29, 2012 14:10
TextWrap example
require("textwrap.jl")
import TextWrap.*
import OptionsMod.*
text = "Julia is a high-level, high-performance dynamic programming language for technical computing, with syntax that is familiar to users of other technical computing environments. It provides a sophisticated compiler, distributed parallel execution, numerical accuracy, and an extensive mathematical function library."
println("DEFAULT OPTIONS")
println("-"^70)
println_wrapped(text)