Skip to content

Instantly share code, notes, and snippets.

View nalimilan's full-sized avatar

Milan Bouchet-Valat nalimilan

View GitHub Profile
# Array consisting of an element-wise transformation of another array
# Equivalent of vectorized functions
immutable LazyArray{T, N, A} <: AbstractArray{T, N}
a::A
fn::Function
args
end
LazyArray(a::AbstractArray, fn::Function, args) = LazyArray{eltype(fn(a[1], args...)), ndims(a), typeof(a)}(a, fn, args)
LazyArray(a::AbstractArray, fn::Function) = LazyArray(a, fn, ())
@nalimilan
nalimilan / sumsq_sparse.jl
Last active August 29, 2015 14:09
Sum of squares for sparse matrix
# These two functions are defined only in Julia 0.4
rowvals(S::SparseMatrixCSC) = S.rowval
nzrange(S::SparseMatrixCSC, col::Integer) = S.colptr[col]:(S.colptr[col+1]-1)
# Based on the example from http://julia.readthedocs.org/en/latest/stdlib/sparse/#Base.nzrange
function sumsq(A::SparseMatrixCSC)
vals = nonzeros(A)
m, n = size(A)
count = zero(eltype(A))
for i = 1:n
@nalimilan
nalimilan / puzzle.jl
Last active January 2, 2016 06:08
A small puzzle...
function test1(x::AbstractVector)
dims = [10]
a = zeros(Int, dims...)
for i in 1:length(x)
a[1] += 1
end
a
@nalimilan
nalimilan / table.jl
Last active January 1, 2016 10:29
Draft implementation of table() for PooledDataVectors
using DataArrays
using NamedArrays
function table(x::PooledDataVector...; usena::Bool = false)
n = length(x)
l = [length(y) for y in x]
for i in 1:n
if l[1] != l[i]
error("arguments are not of the same length: $l")
end
--- a/deps/Makefile 2013-11-30 15:23:26.387689253 +0100
+++ b/deps/Makefile 2013-12-06 17:58:34.800112867 +0100
@@ -439,14 +439,11 @@
UV_OBJ_TARGET = $(BUILD)/$(JL_LIBDIR)/libuv.a
endif
-libuv/configure:
- (cd .. && git submodule init && git submodule update)
-ifeq (exists, $(shell [ -d libuv/.git ] && echo exists ))
-libuv/config.status: libuv/.git/HEAD
$ LD_DEBUG=files BUILDROOT/julia-0.2.0-1.fc19.x86_64/usr/bin/julia
23065:
23065: file=libreadline.so.6 [0]; needed by BUILDROOT/julia-0.2.0-1.fc19.x86_64/usr/bin/julia [0]
23065: file=libreadline.so.6 [0]; generating link map
23065: dynamic: 0x000000356123c6d0 base: 0x0000000000000000 size: 0x00000000002443c8
23065: entry: 0x0000003561014f50 phdr: 0x0000003561000040 phnum: 7
23065:
23065:
23065: file=libncurses.so.5 [0]; needed by BUILDROOT/julia-0.2.0-1.fc19.x86_64/usr/bin/julia [0]
23065: file=libncurses.so.5 [0]; generating link map
@nalimilan
nalimilan / NamedArray.jl
Created November 24, 2013 13:38
"else if" error reproducer
## NamedArray.jl
## (c) 2013 David A. van Leeuwen
## Julia type that implements a drop-in replacement of Array with named dimensions.
## This code is licensed under the GNU General Public License, version 2
## See the file LICENSE in this distribution
## type definition
require("src/namedarraytypes.jl")