Skip to content

Instantly share code, notes, and snippets.

View carlobaldassi's full-sized avatar

Carlo Baldassi carlobaldassi

View GitHub Profile
@carlobaldassi
carlobaldassi / deps.txt
Created January 22, 2013 02:08
R-grow generated dependencies example file (500 epochs)
abind 0.1.3 R
abind 0.1.4 R 0.1.0
abind 0.1.5 R 0.1.0
abind 0.1.6 R 0.1.0
abind 0.1.7 R 0.3.0
AcceptanceSampling 1.2.0 R 0.1.0 1.0.0
AcceptanceSampling 1.3.0 R 0.1.0 1.0.0
aCGH.Spline 1.1.0 rJava
aCGH.Spline 1.1.1 rJava
aCGH.Spline 1.1.2 rJava 0.1.0
@carlobaldassi
carlobaldassi / myresolvetst.jl
Created January 8, 2013 10:56
Test mixintprog-based resolve(). The function is just Pkg.update() up to the call to Metadata.resolve(), with the resolve() code inlined.
require("pkg")
myresolve() = Pkg.cd_pkgdir() do
have = (String=>ASCIIString)[]
reqs = Metadata.parse_requires("REQUIRE")
Git.each_submodule(false) do pkg, path, sha1
if pkg != "METADATA"
have[pkg] = sha1
end
end
@carlobaldassi
carlobaldassi / argparse_example6.jl
Created September 13, 2012 23:30
ArgParse examples #2
# example 6: commands & subtables
require("argparse.jl")
import ArgParse.*
function main(args)
s = ArgParseSettings("argparse_example_6.jl",
"Example 6 for argparse.jl: " *
"commands and their associated subtables.")
@carlobaldassi
carlobaldassi / lapackfail.jl
Created September 11, 2012 10:17
Lapack test failure example
dl = [-0.654981, -0.93716 , -0.459534, -0.0961306]
d = [1.03823, 1.00984, 1.30874 , 1.23003 , 1.98585]
v = [0.878788, 0.550649, 1.32675, -0.0301826, -0.48512]
# lines 174-178 of test/lapack.jl
Ts = Tridiagonal(dl,d,dl)
Fs = full(Ts)
invFsv = Fs\v
Tldlt = ldlt(Ts)
x = Tldlt\v
@carlobaldassi
carlobaldassi / syntaxes_comparisons.md
Created September 6, 2012 13:56
ArgParse syntaxes

@add_arg_table (macro version)

Uses an internal parser to read settings in the cleanest possible way.

Example:

s = ArgParseSettings()
                                                        
@carlobaldassi
carlobaldassi / argparse_example1.jl
Created September 4, 2012 08:52
ArgParse examples
# example 1: minimal options/arguments, auto-generated help/version
require("argparse.jl")
import ArgParse.*
function main(args)
s = ArgParseSettings()
s.prog = "argparse_example_1.jl" # program name (for usage & help screen)
@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)
@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 / 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 / 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