Skip to content

Instantly share code, notes, and snippets.

Avatar

Andras Niedermayer afniedermayer

View GitHub Profile
@afniedermayer
afniedermayer / isinferred.jl
Created Aug 25, 2017
`@isinferred` without evaluating function
View isinferred.jl
module Foo
_args_and_call(args...; kwargs...) = (args[1:end-1], kwargs, args[end](args[1:end-1]...; kwargs...))
_args(args...; kwargs...) = (args[1:end-1], kwargs)
_call(args...; kwargs...) = args[end](args[1:end-1]...; kwargs...)
macro inferred(ex)
inference = inferred_impl(ex, true, __module__)
quote
let (inftypes, result) = $inference
rettype = isa(result, Type) ? Type{result} : typeof(result)
rettype == inftypes[1] || error("return type $rettype does not match inferred return type $(inftypes[1])")
View infer.jl
import Base.Test: @inferred
macro inferred(ex)
if Meta.isexpr(ex, :ref)
ex = Expr(:call, :getindex, ex.args...)
end
Meta.isexpr(ex, :call)|| error("@inferred requires a call expression")
if isdefined(Main, :Base) && isdefined(Main.Base, :string) && applicable(Main.Base.string, ex)
string_ex = Main.Base.string(ex)
View methods_for_iterating_over_dataframe.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View mixed_vcat_test.jl
@generated function mixed_vcat(x...)
mixed_vcat_impl(x...)
end
function mixed_vcat_impl(x...)
T = Base.promote_eltype(x...)
result = [:(counter = 1),
:(totallength = 0)]
for i = 1:length(x)
@afniedermayer
afniedermayer / bench.jl
Created Sep 29, 2015
Globals vs Const Globals vs Closures vs Call Overloading
View bench.jl
a = 3
const b = 3
immutable Parameters
val::Int64
end
g(f, N) = f(N)
function f_glob(N)
@afniedermayer
afniedermayer / Interpolation.jl
Created Feb 2, 2015
cubic hermite interpolation (needs to be sped up, cleaned up, documented...)
View Interpolation.jl
module Interpolation
# by Andras Niedermayer
# afniedermayer@gmail.com
export interpolation, interpolation_regular, pchip,
CubicHermiteInterp, getindex, inverse
using Grid
#using Debug
@afniedermayer
afniedermayer / sort_pairs.py
Last active Aug 29, 2015
sorting of tuple/pairs
View sort_pairs.py
import numpy as np
import copy, time, gc
temp=np.random.rand(500000)
temp2=zip(temp,range(len(temp)))
gc.collect()
t0=time.time()
temp2.sort()
t1=time.time()
print('elapsed time: {} seconds'.format(t1-t0))