Skip to content

Instantly share code, notes, and snippets.

View carlobaldassi's full-sized avatar

Carlo Baldassi carlobaldassi

View GitHub Profile
@carlobaldassi
carlobaldassi / CBModules.diff
Created November 15, 2019 16:54
CBModules customizations diff
diff -r CBModules/ga/cbga.c CBModules.orig/ga/cbga.c
42c42
< #define MaxGenerations 1000
---
> #define MaxGenerations 100
154,155c154
< long watch,
< double errorscale)
---
> long watch)
@carlobaldassi
carlobaldassi / jld_alignment_issue.jl
Created July 24, 2018 11:39
scripts to reproduce JLD issues on julia 0.7
module Tst
using JLD
GC.gc()
Aarray = Vector{Float64}[[1.2,3.4],[1.1]]
str = "abc"
stringsA = ["x","y","z"]
strings16 = convert(Vector{JLD.UTF16String}, stringsA)
bigdata = [1:10000;]
@carlobaldassi
carlobaldassi / bitinitbug.jl
Last active January 20, 2017 22:50
Code to reproduce julia bug 20065
module BitBug
function copy_to_bitarray_chunks_simplified!(Bc::Vector{UInt64}, C::Array{Bool}, numbits::Int)
ld1 = numbits - 1
u = Base._msk64
msk_d1 = (u << (ld1+1))
ind = 1
@show C
@carlobaldassi
carlobaldassi / intvec_abstractsmart.txt
Last active August 29, 2015 14:20
abstractsmart benchmarking
abstractvector getindex A[I]
---------------------
A::BitArray I::Vector{Int}
elapsed time: 0.271078954 seconds (4 MB allocated)
A::Array{Bool} I::Vector{Int}
elapsed time: 0.096585028 seconds (35 MB allocated)
A::Array{Float64} I::Vector{Int}
elapsed time: 0.267021423 seconds (286 MB allocated)
abstractvector setindex! A[I]=X
@carlobaldassi
carlobaldassi / PartSort.jl
Last active August 29, 2015 14:18
partial select
module PartSort
using Base.Order
import Base: sort!, Sort.Algorithm
export PartialQuickSort
immutable PartialQuickSort <: Algorithm
k::Int
@carlobaldassi
carlobaldassi / nullablerand.jl
Last active August 29, 2015 14:13
NullableVector performance with random access
module NV
immutable NullableVector{T}
isnull::BitVector
values::Vector{T}
end
@inline Base.length(nv::NullableVector) = length(nv.isnull)
@inline function Base.getindex(nv::NullableVector{Float64}, i::Integer)
@carlobaldassi
carlobaldassi / bitlogicalbench.jl
Created January 7, 2015 09:50
logical indexing benchmark
function bench()
b = bitrand(500, 500, 300)
i = bitrand(500, 500, 300)
t = vec(bitrand(sum(i)))
c = bitunpack(b)
j = bitunpack(i)
y = bitunpack(t)
println("logical getindex A[I]")
@carlobaldassi
carlobaldassi / slowremote.jl
Created April 29, 2014 09:43
Slowdown of a function executed remotely (Julia issue #6686)
module SlowRemoteExecution
type W
J::Vector{BitVector}
W(N::Int, K::Int) = new([randbool(N) for k=1:K])
end
function inner(ws::Vector{W}, X::Vector{BitVector})
r = 0
@time begin
@carlobaldassi
carlobaldassi / regex_rsearch.jl
Created April 9, 2014 23:30
Naïve reverse rsearch
function Base.rsearch(str::Union(ByteString,SubString), re::Regex, idx::Integer = endof(str))
sidx = 1
lastr = 0:-1
while sidx <= endof(str)
r = search(str, re, sidx)
isempty(r) && return lastr
last(r) > last(lastr) && (lastr = r)
sidx = nextind(str, first(r))
end
return lastr
@carlobaldassi
carlobaldassi / glpkblog1.jl
Created April 9, 2014 20:37
Demo code for Stéphan Laurent blog post comment
import GLPK # NOTE: it's better to use 'import' with GLPK,
# rather than 'using'
μ = [1/7, 2/7, 4/7]
ν = [1/4, 1/4, 1/2]
n = length(μ)
D = 1 .- eye(n) # NOTE: starting from julia v0.3, you won't be
# allowed to use '-' here, you need to
# use '.-'