Skip to content

Instantly share code, notes, and snippets.

@simonster
simonster / gist:7792245
Created December 4, 2013 17:53
gtindex w/sizes as arguments
julia> function gtindex{T}(parent::Array{T,2}, sz1::Int, sz2::Int, first_index::Int, strd1::Int, strd2::Int, ind::Int)
ind -= 1
i2 = div(ind,sz1)
i1 = ind-i2*sz1
@inbounds ret = parent[first_index + i1*strd1 + i2*strd2]
ret
end;
julia> code_native(gtindex, (Array{Int, 2}, Int, Int, Int, Int, Int, Int))
.text
13 -0.2214 -0.0097 0.0554 -0.0184 0.0453 0.9501 66.73 46.66 0.951
14 -0.1920 -0.0266 0.0510 -0.0213 0.0456 0.6865 56.65 44.9 0.688
15 -0.2029 -0.0415 0.0558 -0.0250 0.0403 0.6010 53.6 43.76 0.603
16 -0.2030 -0.0196 0.0498 -0.0262 0.0417 0.6029 52.8 42.64 0.605
17 -0.2046 -0.0319 0.0479 -0.0251 0.0396 0.5895 51.7 41.8 0.591
@simonster
simonster / gist:6191203
Created August 9, 2013 04:30
IJulia error
2013-08-09 00:29:39.856 [NotebookApp] Using existing profile dir: u'/Users/simon/.ipython/profile_julia'
2013-08-09 00:29:39.883 [NotebookApp] Using MathJax from CDN: http://cdn.mathjax.org/mathjax/latest/MathJax.js
2013-08-09 00:29:39.898 [NotebookApp] Serving notebooks from local directory: /Users/simon
2013-08-09 00:29:39.899 [NotebookApp] The IPython Notebook is running at: http://127.0.0.1:8888/
2013-08-09 00:29:39.899 [NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
2013-08-09 00:29:51.461 [NotebookApp] Connecting to: tcp://127.0.0.1:62750
2013-08-09 00:29:51.462 [NotebookApp] Kernel started: 94e986c1-1aec-41f1-8251-bbada5073d53
2013-08-09 00:29:51.811 [NotebookApp] Connecting to: tcp://127.0.0.1:62747
2013-08-09 00:29:51.818 [NotebookApp] Connecting to: tcp://127.0.0.1:62749
2013-08-09 00:29:51.819 [NotebookApp] Connecting to: tcp://127.0.0.1:62748
@simonster
simonster / gist:6157543
Created August 5, 2013 17:01
Loop vectorizer benchmarks
Commit 5d05a4876df53257c7fde518ab3598cf9adeb6f9
➜ perf>make
fib 0.103 0.105 0.104 0.001
parse_int 0.332 0.344 0.338 0.005
mandel 0.332 0.338 0.334 0.003
quicksort 0.495 0.512 0.503 0.007
pi_sum 48.416 56.452 51.751 3.129
rand_mat_stat 48.037 70.606 59.050 9.001
rand_mat_mul 79.485 129.067 98.886 20.258
printfd 47.455 73.397 54.434 10.801
define void @julia_f(%jl_value_t*, i64) #2 {
top:
%2 = icmp slt i64 %1, 1, !dbg !3364
br i1 %2, label %L2, label %if.lr.ph, !dbg !3364
if.lr.ph: ; preds = %top
%3 = getelementptr inbounds %jl_value_t* %0, i64 1, i32 0, !dbg !3369
%4 = load %jl_value_t** %3, align 8, !dbg !3369
br label %if, !dbg !3364
@simonster
simonster / gist:6147959
Created August 3, 2013 21:00
IR with jl_value_t -> i8*
define void @julia_f(i8**, i64) #2 {
top:
%2 = icmp slt i64 %1, 1, !dbg !3364
br i1 %2, label %L2, label %if.lr.ph, !dbg !3364
if.lr.ph: ; preds = %top
%3 = getelementptr i8** %0, i64 1, !dbg !3369
%4 = load i8** %3, align 8, !dbg !3369
%5 = bitcast i8* %4 to double*, !dbg !3370
br label %if, !dbg !3364
@simonster
simonster / gist:6147815
Created August 3, 2013 20:08
Julia vectorization
julia> f(x) = for i = 1:length(x); @inbounds x[i] *= 2; end
# methods for generic function f
f(x) at none:1
julia> disassemble(f, (Matrix{Float64},))
define void @julia_f(i8**) {
top:
%1 = getelementptr i8** %0, i64 2, !dbg !3364
%2 = load i8** %1, align 8, !dbg !3364
@simonster
simonster / gist:5864205
Last active December 18, 2015 23:49
JLD mmap benchmark
using HDF5, JLD
const MATRIX_SIZE = 1000
# Write test file
x = rand(MATRIX_SIZE, MATRIX_SIZE)
jld = jldopen("test.jld", "w")
write(jld, "x", x)
close(jld)
macro s()
@simonster
simonster / gist:4712293
Created February 5, 2013 05:05
Modified RDF attachment export example
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:res="http://purl.org/vocab/resourcelist/schema#"
xmlns:z="http://www.zotero.org/namespaces/export#"
xmlns:dcterms="http://purl.org/dc/terms/"
xmlns:address="http://schemas.talis.com/2005/address/schema#"
xmlns:foaf="http://xmlns.com/foaf/0.1/"
xmlns:bibo="http://purl.org/ontology/bibo/"
xmlns:link="http://purl.org/rss/1.0/modules/link/">
<z:UserItem rdf:about="http://zotero.org/users/67180/items/4BUASI6R">
@simonster
simonster / gist:2920373
Created June 12, 2012 21:56
Asynchronous bottom-up merge sort in JavaScript
var AsyncComparator = function(list) {
this.listsAtCurrentLevel = [];
this.listsAtNextLevel = [];
this.listMerged = [];
for(var i=0; i<list.length; i++) {
this.listsAtCurrentLevel[i] = [list[i]];
}
};
AsyncComparator.prototype.getA = function() {