Skip to content

Instantly share code, notes, and snippets.

View timholy's full-sized avatar

Tim Holy timholy

View GitHub Profile
@timholy
timholy / options_demo.jl
Created April 16, 2012 09:58
Demo/test file for options.
function simplefun(x,funcopts::Options)
@defaults funcopts a=3 b=2 c=2*b
println(a)
println(b)
println(c)
@check_used funcopts
end
function complexfun(x,opts::Options)
@timholy
timholy / fsaiter.jl
Created April 26, 2012 14:44
Testing Julia array timing
step(i::Int) = 1
type ForwardSubarrayIterator
sub_min::Vector{Int}
sub_max::Vector{Int}
inc::Vector{Int}
pos::Vector{Int}
index::Int # the current linear index
end
function ForwardSubarrayIterator(dims::Dims,ind::RangeIndex...)
@timholy
timholy / thread.jl
Created July 2, 2012 12:51
Julia function for calling threads
v = zeros(10) # the "output" of the thread computation
index1 = [1,2,4,8] # the elements handled by thread 1
index2 = [3,5,6] # the elements handled by thread 2
indexwarmup = [7,10] # elements handled on warmup
# The function run by each thread
function fillvals(out, index, val)
out[index] = val
return nothing
end
@timholy
timholy / bounds_check_profile.jl
Created July 11, 2012 09:38
Code for profiling bounds checking
function arrayref_boundscheck_inloop(A::Matrix, I::AbstractVector{Int}, J::AbstractVector{Int})
X = similar(A, ref_shape(I, J))
storeind = 1
for j = J
for i = I
if i < 1 || i > size(A,1) || j < 1 || j > size(A,2)
throw(BoundsError())
end
X[storeind] = A[i,j]
end
@timholy
timholy / image.jl
Created December 5, 2012 10:50
Some musings on a revamped image package
require("color.jl")
require("options.jl")
import OptionsMod.*
require("setutils.jl")
# Plain arrays can be treated as images. Other types will have
# metadata associated, make yours a child of one of the following:
abstract ImageMeta # image with metadata
abstract ImageDirect <: ImageMeta # each pixel has own value/color
abstract ImageIndexed <: ImageMeta # indexed images (i.e., lookup table)
@timholy
timholy / iterator_test.jl
Last active December 14, 2015 15:29
Test file for Iterator2D
function test(m, n, k)
A = randn(m, n)
@time begin
s = 0.0
for j = 1:k
for i = 1:length(A)
s += A[i]
end
end
end
@timholy
timholy / threelibs.jl
Last active December 14, 2015 17:48
Clang/libav
import Clang.wrap_c
if (!has(ENV, "JULIAHOME"))
error("Please set JULIAHOME variable to the root of your julia install")
end
clang_includes = map(x->joinpath(ENV["JULIAHOME"], x), [
"deps/llvm-3.2/build/Release/lib/clang/3.2/include",
"deps/llvm-3.2/include",
"deps/llvm-3.2/include",
@timholy
timholy / plot_transpose_tests.jl
Created May 27, 2013 21:22
Cache-friendly transpose comparison
using Winston
n = [ntuple(length(sizes), i->prod(sizes[i]))...]
for i = 1:length(Ts)
p = FramedPlot()
setattr(p.x1, "log", true)
r = results[:,2,i] ./ results[:,:,i]
r = r[:,[1,3,4]]
ccopy = Curve(n, r[:,1], "color", "green")
setattr(ccopy, "label", "copy")
@timholy
timholy / newspawn.jl
Created June 14, 2013 14:46
Test spawn and sprofile
function new_jl_spawn(cmd::Ptr{Uint8}, argv::Ptr{Ptr{Uint8}}, loop::Ptr{Void}, pp::Base.Process,
in, out, err)
proc = Base.c_malloc(int(ccall(:jl_sizeof_uv_process_t,Csize_t,())))
@show proc
error = ccall(:jl_spawn, Int32,
(Ptr{Uint8}, Ptr{Ptr{Uint8}}, Ptr{Void}, Ptr{Void}, Any, Int32,
Ptr{Void}, Int32, Ptr{Void}, Int32, Ptr{Void},
Int32),
cmd, argv, loop, proc, pp, Base.uvtype(in),
Base.uvhandle(in), Base.uvtype(out), Base.uvhandle(out), Base.uvtype(err), Base.uvhandle(err),
@timholy
timholy / Makefile
Created June 23, 2013 13:48
Calling libunwind on Linux This is modified from https://gist.github.com/blakejohnson/5831456 Only "make test3" was tested (the rest may require extra things to be installed) You need an installation of Julia. The Makefile assumes this is in /home/yourusername/src/.
all: test test2 test3
JULIADIR = $(HOME)/src/julia
JULIALIB = $(JULIADIR)/usr/lib
OPENBLASDIR = $(JULIADIR)/deps/openblas-develop
UNWINDDIR = $(JULIADIR)/deps/libunwind-1.1
# LDFLAGS = -Wl,-no_compact_unwind
LDFLAGS =
CC = gcc