Skip to content

Instantly share code, notes, and snippets.

@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
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: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
flatten_dot(s::Symbol) = (s,)
flatten_dot(ex::Expr) = tuple(flatten_dot(ex.args[1])..., ex.args[2].args[1])
macro reexport(syms...)
if length(syms) == 1 && isa(syms[1], Expr) && syms[1].head != :.
syms[1].head == :tuple || error("@reexport: invalid syntax")
syms = syms[1].args
end
modules = (Symbol...)[begin
if isa(arg, Symbol) || (isa(arg, Expr) && arg.head == :.)
@simonster
simonster / gist:8908354
Last active August 29, 2015 13:56
Benchmarks of prototypes of different Enum options
import Base.length
immutable MyOrdinalValue12
index::Uint8
pool::Vector{ASCIIString}
end
immutable MyPooledDataArray1
index::Vector{Uint8}
pool::Vector{ASCIIString}
@simonster
simonster / pathological_unique.jl
Created February 14, 2014 02:16
Strange error message
import Base: unique, hash
immutable Prehashed
hash::Uint
end
hash(x::Prehashed) = x.hash
function unique{T}(A::AbstractArray{T,2}, dim::Int)
hashes = zeros(Uint, size(A, 1))
@simonster
simonster / gist:0d397d36f1183dcd5965
Created May 23, 2014 02:14
sum_seq code comparison

With master:

julia> code_native(Base.sum_seq, (Vector{Float64}, Int, Int))
	.text
Filename: reduce.jl
Source line: 226
	push	RBP
	mov	RBP, RSP
Source line: 226
julia> (+)(A::AbstractArray{Bool},x::Bool) = A .+ x
Warning: New definition
+(AbstractArray{Bool,N},Bool) at none:1
is ambiguous with:
+(Range{T},Real) at range.jl:428.
To fix, define
+(Range{Bool},Bool)
before the new definition.
Warning: New definition
+(AbstractArray{Bool,N},Bool) at none:1
using DSP
N=1024*32;
x0=rand(N);
nn=div(N,8);
mm=div(N,16);
println("welch_pgram")
f(x0, nn, mm) = for i = 1:1000; power(Periodogramt(x0,n=nn,noverlap=mm,twosided=true,window=false)); end
f(x0, nn, mm);
@time f(x0, nn, mm);
function test(n)
a = 0
b = 0
aulpdiff = Array(Float64, n)
bulpdiff = Array(Float64, n)
for i = 1:n
x = rand()
r1 = (x*x)*(x*x)
r2 = x^4
bigres = big(x)^4