Skip to content

Instantly share code, notes, and snippets.

View carlobaldassi's full-sized avatar

Carlo Baldassi carlobaldassi

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / bitarray_perf_comparison.txt
Created June 1, 2013 19:22
BitArray performance comparisons
b = BitArray(10_000_017); fill!(b, true)
2x4 DataFrame:
Function Elapsed Relative Replications
[1,] "oldfill" 0.703632 3.394 1000
[2,] "newfill" 0.207316 1.0 1000
b1 = randbool(10_000_117); b2 = randbool(10_000_017); copy!(b1, b2)
2x4 DataFrame:
Function Elapsed Relative Replications
[1,] "oldcopy" 0.834918 2.37655 1000
@carlobaldassi
carlobaldassi / enumperf.jl
Last active December 18, 2015 03:29
Faster Enumerate and Zip, benchmarks code
# note: Enumerate2 and new_enumerate are `Enumerate` and `enumerate` in the pull request.
dosomething(x::Float64, i::Int) = x+i
function perf()
n = 1_000_000
const a = rand(n)
olden() = for (i, x) in enumerate(a) dosomething(x,i) end
function oldeninline()
@carlobaldassi
carlobaldassi / nzipperf.jl
Last active December 18, 2015 04:29
Alternative Zip iterator, with better performance than the one in base, but whose performance degrades if calls to start,next,done are inlined.
module NZipTest
import Base.start, Base.next, Base.done, Base.length
using Benchmark
immutable NZip0
end
immutable NZip1{I1}
i1::I1
# systematically compare return types of scalar vs array operations
# (also div vs mod)
# prints out only mismatching cases
module ScalarArrayComp
using DataFrames
realtypes = [Bool, Uint8, Uint16, Uint32, Uint64, Uint128,