Skip to content

Instantly share code, notes, and snippets.

View JeffBezanson's full-sized avatar

Jeff Bezanson JeffBezanson

View GitHub Profile
import Base: endof, sizeof, pointer, next
using Base: UTF_ERR_INVALID_INDEX, is_valid_continuation, utf8_trailing, utf8_offset
type Str <: AbstractString
len::Int
function Str(p::Union{Ptr{Int8},Ptr{UInt8}}, n::Integer)
s = ccall(:jl_gc_allocobj, Any, (Csize_t,), n+sizeof(Int))
ps = pointer_from_objref(s)
unsafe_store!(convert(Ptr{Ptr{Void}}, ps), pointer_from_objref(Str), 0)
unsafe_store!(convert(Ptr{Int}, ps), n)

An array is a structure mapping indices to data values, where the indices have a particular structure.

An array can be thought of as a pair of an index set and a data set.

Two arrays are equal if they map the same indices to the same values.

The data

An array is iterable, and when iterated generates exactly the values of

Faster version:
julia> code_llvm(STDOUT, Base._unsafe_getindex, Tuple{typeof(Base.linearindexing(a)), typeof(a), typeof(r), typeof(1)}, false, true)
; ModuleID = '_unsafe_getindex'
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"
%jl_value_t = type { %jl_value_t* }
%OneTo = type { i64 }
@JeffBezanson
JeffBezanson / inlining.md
Last active January 14, 2016 22:03
how to invoke julia inlining passes

Here is a description and demo of the relevant functions.

StaticVarInfo is the state object used to track local variable and other context information during inference and other passes.

inlining_pass

Runs inlining in-place on an expression.

Arguments:

function rd(f)
nr = countlines(f)::Int
fh = open(f)
nc = length(split(readline(fh),','))
seekstart(fh)
d = Array(Float64, nr, nc)
temp = [0.0]
for i = 1:nr
l = readline(fh)::ASCIIString
idx = 1
@JeffBezanson
JeffBezanson / gist:ea224aa45e2242ca3ee9
Last active August 29, 2015 14:14
simple Dict benchmarks
function stress1(keys::Array{Int,1})
x = Dict{Int,Float64}()
for i in keys
x[i] = 0.0
end
return x
end
function stress_strings(n::Int)
d = Dict{String,Int}()
function factor{T<:Integer}(n::T)
0 < n || error("number to be factored must be positive")
h = Dict{T,Int}()
n == 1 && return h
local s::T, p::T
s = isqrt(n)
p = 2
while p <= s
if n % p == 0
while n % p == 0
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by arpack-ng configure 3.2.0, which was
generated by GNU Autoconf 2.69. Invocation command line was
$ ./configure --prefix=/home/bezanson/src/julia/usr --build=x86_64-linux-gnu --libdir=/home/bezanson/src/julia/usr/lib F77=gfortran -m64 CC=gcc -m64 CXX=g++ -m64 --with-blas=-L/home/bezanson/src/julia/usr/lib -lopenblas --with-lapack=-L/home/bezanson/src/julia/usr/lib -lopenblas --disable-mpi --enable-shared FFLAGS= -fdefault-integer-8 -cpp -ffixed-line-length-none -Dsaxpy=saxpy_64 -Ddaxpy=daxpy_64 -Dscopy=scopy_64 -Ddcopy=dcopy_64 -Dsgemv=sgemv_64 -Ddgemv=dgemv_64 -Dsgeqr2=sgeqr2_64 -Ddgeqr2=dgeqr2_64 -Dslacpy=slacpy_64 -Ddlacpy=dlacpy_64 -Dslahqr=slahqr_64 -Ddlahqr=dlahqr_64 -Dslanhs=slanhs_64 -Ddlanhs=dlanhs_64 -Dslarnv=slarnv_64 -Ddlarnv=dlarnv_64 -Dslartg=slartg_64 -Ddlartg=dlartg_64 -Dslascl=slascl_64 -Ddlascl=dlascl_64 -Dslaset=slaset_64 -Ddlaset=dla
(define (string.rpad s n c) (string s (string.rep c (- n (string.count s)))))
(define (string.rep s k)
(cond ((< k 4)
(cond ((<= k 0) "")
((= k 1) (string s))
((= k 2) (string s s))
(else (string s s s))))
((odd? k) (string s (string.rep s (- k 1))))
(else (string.rep (string s s) (/ k 2)))))
@JeffBezanson
JeffBezanson / escaped-symbols
Last active August 29, 2015 14:03
escaped symbols patch
diff --git a/src/julia-parser.scm b/src/julia-parser.scm
index 549b02f..8949495 100644
--- a/src/julia-parser.scm
+++ b/src/julia-parser.scm
@@ -1677,9 +1677,14 @@
;; symbol/expression quote
((eq? t ':)
(take-token s)
- (if (closing-token? (peek-token s))
- ':