Skip to content

Instantly share code, notes, and snippets.

@carlobaldassi
carlobaldassi / CBModules.diff
Created Nov 15, 2019
CBModules customizations diff
View CBModules.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 Jul 24, 2018
scripts to reproduce JLD issues on julia 0.7
View jld_alignment_issue.jl
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 Jan 20, 2017
Code to reproduce julia bug 20065
View bitinitbug.jl
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 Aug 29, 2015
abstractsmart benchmarking
View intvec_abstractsmart.txt
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 Aug 29, 2015
partial select
View PartSort.jl
module PartSort
using Base.Order
import Base: sort!, Sort.Algorithm
export PartialQuickSort
immutable PartialQuickSort <: Algorithm
k::Int
@carlobaldassi
carlobaldassi / nullablerand.jl
Last active Aug 29, 2015
NullableVector performance with random access
View nullablerand.jl
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 Jan 7, 2015
logical indexing benchmark
View bitlogicalbench.jl
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 Apr 29, 2014
Slowdown of a function executed remotely (Julia issue #6686)
View slowremote.jl
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
View regex_rsearch.jl
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 Apr 9, 2014
Demo code for Stéphan Laurent blog post comment
View glpkblog1.jl
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 '.-'