This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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])") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = 3 | |
const b = 3 | |
immutable Parameters | |
val::Int64 | |
end | |
g(f, N) = f(N) | |
function f_glob(N) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Interpolation | |
# by Andras Niedermayer | |
# afniedermayer@gmail.com | |
export interpolation, interpolation_regular, pchip, | |
CubicHermiteInterp, getindex, inverse | |
using Grid | |
#using Debug |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |