Git Product home page Git Product logo

fastanonymous.jl's Introduction

FastAnonymous

Creating efficient "anonymous functions" in Julia.

Build Status

Note: this package is deprecated

FastAnonymous provoked/inspired the creation of fast anonymous functions as a native feature for Julia 0.5. Hence this package is not necessary (and not supported) for Julia 0.5 and higher. Starting with Julia 0.7, this package will not be installable by the package manager.

FastAnonymous versions

There are two implementations, one that runs on julia 0.3 and the other for julia 0.4. If you're running julia 0.3, see the relevant README.

Installation

Install this package within Julia using

Pkg.add("FastAnonymous")

Usage

In Julia, you can create an anonymous function this way:

offset = 1.2
f = x->(x+offset)^2

At present, this function is not very efficient, as will be shown below. You can make it more performant by adding the @anon macro:

using FastAnonymous

offset = 1.2
f = @anon x->(x+offset)^2

You can use f like an ordinary function.

Here's a concrete example and speed comparison:

using FastAnonymous

function testn(f, n)
    s = 0.0
    for i = 1:n
        s += f(i/n)
    end
    s
end

function test_inlined(n)
    s = 0.0
    for i = 1:n
        s += (i/n+1.2)^2
    end
    s
end

# Conventional anonymous function
offset = 1.2
f = x->(x+offset)^2
@time testn(f, 1)
julia> @time testn(f, 10^7)
elapsed time: 1.344960759 seconds (610 MB allocated, 4.13% gc time in 28 pauses with 0 full sweep)
2.973333503333424e7

# Hard-wired generic function
sqroffset(x) = (x+1.2)^2
@time testn(sqroffset, 1)
julia> @time testn(sqroffset, 10^7)
elapsed time: 0.627085369 seconds (457 MB allocated, 5.99% gc time in 21 pauses with 0 full sweep)
2.973333503333424e7

# @anon-ized function
g = @anon x->(x+offset)^2
@time testn(g, 1)
julia> @time testn(g, 10^7)
elapsed time: 0.07966527 seconds (112 bytes allocated)
2.973333503333424e7

# Full manual inlining
@time test_inlined(1)
julia> @time test_inlined(10^7)
elapsed time: 0.078703981 seconds (112 bytes allocated)
2.973333503333424e7

You can see that it's more than 20-fold faster than the anonymous-function version, and more than tenfold faster than the generic function version. Indeed, it's as fast as if we had manually inlined this function. Relatedly, it also exhibits no unnecessary memory allocation.

Changing parameter values

With the previous definition of f, the display at the REPL is informative:

julia> f = @anon x->(x+offset)^2
(x) -> quote  # none, line 1:
    Main.^(Main.+(x,offset),2)
end
with:
  offset: 1.2

Main. is a necessary addition for specifying the module scope; without them, you can see the function definition as ^(+(x,offset),2) which is equivalent to (x+offset)^2. At the end, you see the "environment," which consists of stored values, in this case offset: 1.2. After creating f, you can change environmental variables:

julia> f.offset = -7
-7.0

julia> f(7)
0.0

julia> f(9)
4.0

Any symbols that are not arguments end up in environmental variables. As a second example:

julia> x = linspace(0,pi);

julia> f = @anon (A,θ) -> A*sin(x+θ)
(A,θ) -> quote  # none, line 1:
    Main.*(A,Main.sin(Main.+(x,θ)))
end
with:
  x: [0.0,0.0317333,0.0634665,0.0951998,0.126933,0.158666,0.1904,0.222133,0.253866,0.285599    2.85599,2.88773,2.91946,2.95119,2.98293,3.01466,3.04639,3.07813,3.10986,3.14159]

julia> f(10,pi/4)
100-element Array{Float64,1}:
  7.07107
  7.29186
  7.50531
  
 -6.60836
 -6.84316
 -7.07107

julia> f.x[2] = 15
15

julia> f
(A,θ) -> quote  # none, line 1:
    Main.*(A,Main.sin(Main.+(x,θ)))
end
with:
  x: [0.0,15.0,0.0634665,0.0951998,0.126933,0.158666,0.1904,0.222133,0.253866,0.285599    2.85599,2.88773,2.91946,2.95119,2.98293,3.01466,3.04639,3.07813,3.10986,3.14159]

Inner workings

This package uses shameless hacks to implement closures that behave much like a likely native solution. One major difference is that the native closure environment is likely to be immutable, but here it is mutable.

Acknowledgments

This package can be viewed in part as an alternative syntax to the excellent NumericFuns, which was split out from NumericExtensions.

fastanonymous.jl's People

Contributors

timholy avatar cstjean avatar malmaud avatar

Stargazers

Greg Werbin avatar  avatar  avatar Siva Swaminathan avatar Konstantinos avatar David Rapisarda avatar  avatar Chi Po Choi avatar  avatar Rafael C.P. avatar Adrian Salceanu avatar John Travers avatar Chris Timperley avatar Nicu Stiurca avatar Matthieu Gomez avatar Alexander Samoilov avatar  avatar Markus John avatar Alexey Brazhe avatar  avatar Chris Binz avatar Jack Peterson avatar Arets Paeglis avatar Brad Pillow avatar Jason Knight avatar Diego Javier Zea avatar Ariel Keselman avatar Theodore Papamarkou avatar  avatar Shashi Gowda avatar

Watchers

James Cloos avatar  avatar Arets Paeglis avatar  avatar  avatar  avatar

fastanonymous.jl's Issues

Type inference fails on nested anon functions

Consider:


julia> f = @anon () -> 5.0
() -> quote  # none, line 1:
    5.0
end

julia> g = @anon () -> f()
() -> quote  # none, line 1:
    Main.f()
end

julia> @code_warntype f()
Variables:
  f::FastAnonymous.Fun{Ptr{Void} @0x00007fcb81b12150,0x79c3814622fcabc4,()}
  __X__::Tuple{}

Body:
  begin  # /home/mauro/.julia/v0.4/FastAnonymous/src/FastAnonymous.jl, line 32:
      $(Expr(:meta, :inline)) # none, line 1:
      return 5.0
  end::Float64

julia> @code_warntype g()
Variables:
  f::FastAnonymous.Fun{Ptr{Void} @0x00007fcb81c87350,0xf7a3ff9717292be4,()}
  __X__::Tuple{}

Body:
  begin  # /home/mauro/.julia/v0.4/FastAnonymous/src/FastAnonymous.jl, line 32:
      $(Expr(:meta, :inline)) # none, line 1:
      return ((top(getfield))(Main,:f)::Any)()::Any
  end::Any

on Julia 0.4.6

Probably nothing that can be done, but I thought I report it here for others to find.

Info about upcoming removal of packages in the General registry

As described in https://discourse.julialang.org/t/ann-plans-for-removing-packages-that-do-not-yet-support-1-0-from-the-general-registry/ we are planning on removing packages that do not support 1.0 from the General registry. This package has been detected to not support 1.0 and is thus slated to be removed. The removal of packages from the registry will happen approximately a month after this issue is open.

To transition to the new Pkg system using Project.toml, see https://github.com/JuliaRegistries/Registrator.jl#transitioning-from-require-to-projecttoml.
To then tag a new version of the package, see https://github.com/JuliaRegistries/Registrator.jl#via-the-github-app.

If you believe this package has erroneously been detected as not supporting 1.0 or have any other questions, don't hesitate to discuss it here or in the thread linked at the top of this post.

Ambiguity warnings from conflict with DataArray

I am not sure who if any one is at fault here, but when I use FastAnonymous with Distributions.jl (which uses DataArray) I get a slew of ambiguity errors

Warning: New definition 
    map!(Union(DataType,Function),DataArray{T,N},Union(Array{T,N},Number,BitArray{N})...) at /home/zenna/.julia/v0.3/DataArrays/src/broadcast.jl:185
is ambiguous with: 
    map!(Type{f},AbstractArray{S,1},AbstractArray{T,1}) at /home/zenna/.julia/v0.3/FastAnonymous/src/FastAnonymous.jl:95.
To fix, define 
    map!(Type{f},DataArray{S,1},Union(Array{Bool,1},BitArray{1}))
before the new definition.
Warning: New definition 
    map!(Union(DataType,Function),DataArray{T,N},Union(Array{T,N},Number,BitArray{N})...) at /home/zenna/.julia/v0.3/DataArrays/src/broadcast.jl:185
is ambiguous with: 
    map!(Type{f},AbstractArray{S,2},AbstractArray{T,2}) at /home/zenna/.julia/v0.3/FastAnonymous/src/FastAnonymous.jl:95.
To fix, define 
    map!(Type{f},DataArray{S,2},Union(BitArray{2},Array{Bool,2}))
before the new definition.
Warning: New definition 
    map!(Union(DataType,Function),DataArray{T,N},Union(Array{T,N},Number,BitArray{N})...) at /home/zenna/.julia/v0.3/DataArrays/src/broadcast.jl:185
is ambiguous with: 
    map!(Type{f},AbstractArray{S,3},AbstractArray{T,3}) at /home/zenna/.julia/v0.3/FastAnonymous/src/FastAnonymous.jl:95.
To fix, define 
    map!(Type{f},DataArray{S,3},Union(Array{Bool,3},BitArray{3}))
before the new definition.
Warning: New definition 
    map!(Union(DataType,Function),DataArray{T,N},Union(Array{T,N},Number,BitArray{N})...) at /home/zenna/.julia/v0.3/DataArrays/src/broadcast.jl:185
is ambiguous with: 
    map!(Type{f},AbstractArray{S,4},AbstractArray{T,4}) at /home/zenna/.julia/v0.3/FastAnonymous/src/FastAnonymous.jl:95.
To fix, define 
    map!(Type{f},DataArray{S,4},Union(Array{Bool,4},BitArray{4}))
before the new definition.
Warning: New definition 
    map!(Union(DataType,Function),DataArray{T,N},Union(Array{T,N},Number,BitArray{N})...) at /home/zenna/.julia/v0.3/DataArrays/src/broadcast.jl:185
is ambiguous with: 
    map!(Type{f},AbstractArray{T,N},AbstractArray{T,1}) at /home/zenna/.julia/v0.3/FastAnonymous/src/FastAnonymous.jl:105.
To fix, define 
    map!(Type{f},DataArray{T,N},Union(Array{Bool,1},BitArray{1}))
before the new definition.
Warning: New definition 
    map!(Union(DataType,Function),DataArray{T,N},Union(Array{T,N},Number,BitArray{N})...) at /home/zenna/.julia/v0.3/DataArrays/src/broadcast.jl:185
is ambiguous with: 
    map!(Type{f},AbstractArray{T,N},AbstractArray{T,2}) at /home/zenna/.julia/v0.3/FastAnonymous/src/FastAnonymous.jl:105.
To fix, define 
    map!(Type{f},DataArray{T,N},Union(BitArray{2},Array{Bool,2}))
before the new definition.
Warning: New definition 
    map!(Union(DataType,Function),DataArray{T,N},Union(Array{T,N},Number,BitArray{N})...) at /home/zenna/.julia/v0.3/DataArrays/src/broadcast.jl:185
is ambiguous with: 
    map!(Type{f},AbstractArray{T,N},AbstractArray{T,3}) at /home/zenna/.julia/v0.3/FastAnonymous/src/FastAnonymous.jl:105.
To fix, define 
    map!(Type{f},DataArray{T,N},Union(Array{Bool,3},BitArray{3}))
before the new definition.
Warning: New definition 
    map!(Union(DataType,Function),DataArray{T,N},Union(Array{T,N},Number,BitArray{N})...) at /home/zenna/.julia/v0.3/DataArrays/src/broadcast.jl:185
is ambiguous with: 
    map!(Type{f},AbstractArray{T,N},AbstractArray{T,4}) at /home/zenna/.julia/v0.3/FastAnonymous/src/FastAnonymous.jl:105.
To fix, define 
    map!(Type{f},DataArray{T,N},Union(Array{Bool,4},BitArray{4}))
before the new definition.
Warning: New definition 
    map!(Union(DataType,Function),DataArray{T,N},Union(Array{T,N},Number,BitArray{N})...) at /home/zenna/.julia/v0.3/DataArrays/src/broadcast.jl:185
is ambiguous with: 
    map!(Type{f},AbstractArray{S,N},AbstractArray{T,N}) at cartesian.jl:100.
To fix, define 
    map!(Type{f},DataArray{S,N},Union(Array{Bool,N},BitArray{N}))
before the new definition.
Warning: New definition 
    map!(Union(DataType,Function),DataArray{T,N},Union(Array{T,N},Number,BitArray{N})...) at /home/zenna/.julia/v0.3/DataArrays/src/broadcast.jl:185
is ambiguous with: 
    map!(Type{f},AbstractArray{T,N},AbstractArray{T,N}) at cartesian.jl:100.
To fix, define 
    map!(Type{f},DataArray{T,N},Union(Array{Bool,N},BitArray{N}))
before the new definition.
Warning: New definition 
    map!(Union(DataType,Function),DataArray{T,N},Any...) at /home/zenna/.julia/v0.3/DataArrays/src/broadcast.jl:185
is ambiguous with: 
    map!(Type{f},AbstractArray{T,1},Range{T}) at /home/zenna/.julia/v0.3/FastAnonymous/src/FastAnonymous.jl:82.
To fix, define 
    map!(Type{f},DataArray{T,1},Range{T})
before the new definition.
Warning: New definition 
    map!(Union(DataType,Function),DataArray{T,N},Any...) at /home/zenna/.julia/v0.3/DataArrays/src/broadcast.jl:185
is ambiguous with: 
    map!(Type{f},AbstractArray{T,N},Range{T}) at /home/zenna/.julia/v0.3/FastAnonymous/src/FastAnonymous.jl:83.
To fix, define 
    map!(Type{f},DataArray{T,N},Range{T})
before the new definition.
Warning: New definition 
    map!(Union(DataType,Function),DataArray{T,N},Any...) at /home/zenna/.julia/v0.3/DataArrays/src/broadcast.jl:185
is ambiguous with: 
    map!(Type{f},AbstractArray{S,1},AbstractArray{T,1}) at /home/zenna/.julia/v0.3/FastAnonymous/src/FastAnonymous.jl:95.
To fix, define 
    map!(Type{f},DataArray{S,1},AbstractArray{T,1})
before the new definition.
Warning: New definition 
    map!(Union(DataType,Function),DataArray{T,N},Any...) at /home/zenna/.julia/v0.3/DataArrays/src/broadcast.jl:185
is ambiguous with: 
    map!(Type{f},AbstractArray{S,2},AbstractArray{T,2}) at /home/zenna/.julia/v0.3/FastAnonymous/src/FastAnonymous.jl:95.
To fix, define 
    map!(Type{f},DataArray{S,2},AbstractArray{T,2})
before the new definition.
Warning: New definition 
    map!(Union(DataType,Function),DataArray{T,N},Any...) at /home/zenna/.julia/v0.3/DataArrays/src/broadcast.jl:185
is ambiguous with: 
    map!(Type{f},AbstractArray{S,3},AbstractArray{T,3}) at /home/zenna/.julia/v0.3/FastAnonymous/src/FastAnonymous.jl:95.
To fix, define 
    map!(Type{f},DataArray{S,3},AbstractArray{T,3})
before the new definition.
Warning: New definition 
    map!(Union(DataType,Function),DataArray{T,N},Any...) at /home/zenna/.julia/v0.3/DataArrays/src/broadcast.jl:185
is ambiguous with: 
    map!(Type{f},AbstractArray{S,4},AbstractArray{T,4}) at /home/zenna/.julia/v0.3/FastAnonymous/src/FastAnonymous.jl:95.
To fix, define 
    map!(Type{f},DataArray{S,4},AbstractArray{T,4})
before the new definition.
Warning: New definition 
    map!(Union(DataType,Function),DataArray{T,N},Any...) at /home/zenna/.julia/v0.3/DataArrays/src/broadcast.jl:185
is ambiguous with: 
    map!(Type{f},AbstractArray{T,N},AbstractArray{T,1}) at /home/zenna/.julia/v0.3/FastAnonymous/src/FastAnonymous.jl:105.
To fix, define 
    map!(Type{f},DataArray{T,N},AbstractArray{T,1})
before the new definition.
Warning: New definition 
    map!(Union(DataType,Function),DataArray{T,N},Any...) at /home/zenna/.julia/v0.3/DataArrays/src/broadcast.jl:185
is ambiguous with: 
    map!(Type{f},AbstractArray{T,N},AbstractArray{T,2}) at /home/zenna/.julia/v0.3/FastAnonymous/src/FastAnonymous.jl:105.
To fix, define 
    map!(Type{f},DataArray{T,N},AbstractArray{T,2})
before the new definition.
Warning: New definition 
    map!(Union(DataType,Function),DataArray{T,N},Any...) at /home/zenna/.julia/v0.3/DataArrays/src/broadcast.jl:185
is ambiguous with: 
    map!(Type{f},AbstractArray{T,N},AbstractArray{T,3}) at /home/zenna/.julia/v0.3/FastAnonymous/src/FastAnonymous.jl:105.
To fix, define 
    map!(Type{f},DataArray{T,N},AbstractArray{T,3})
before the new definition.
Warning: New definition 
    map!(Union(DataType,Function),DataArray{T,N},Any...) at /home/zenna/.julia/v0.3/DataArrays/src/broadcast.jl:185
is ambiguous with: 
    map!(Type{f},AbstractArray{T,N},AbstractArray{T,4}) at /home/zenna/.julia/v0.3/FastAnonymous/src/FastAnonymous.jl:105.
To fix, define 
    map!(Type{f},DataArray{T,N},AbstractArray{T,4})
before the new definition.
Warning: New definition 
    map!(Union(DataType,Function),DataArray{T,N},Any...) at /home/zenna/.julia/v0.3/DataArrays/src/broadcast.jl:185
is ambiguous with: 
    map!(Type{f},AbstractArray{S,N},AbstractArray{T,N}) at cartesian.jl:100.
To fix, define 
    map!(Type{f},DataArray{S,N},AbstractArray{T,N})
before the new definition.
Warning: New definition 
    map!(Union(DataType,Function),DataArray{T,N},Any...) at /home/zenna/.julia/v0.3/DataArrays/src/broadcast.jl:185
is ambiguous with: 
    map!(Type{f},AbstractArray{T,N},AbstractArray{T,N}) at cartesian.jl:100.
To fix, define 
    map!(Type{f},DataArray{T,N},AbstractArray{T,N})
before the new definition.
Warning: New definition 
    map!(Union(DataType,Function),PooledDataArray{T,R<:Integer,N},Union(Array{T,N},Number,BitArray{N})...) at /home/zenna/.julia/v0.3/DataArrays/src/broadcast.jl:185
is ambiguous with: 
    map!(Type{f},AbstractArray{S,1},AbstractArray{T,1}) at /home/zenna/.julia/v0.3/FastAnonymous/src/FastAnonymous.jl:95.
To fix, define 
    map!(Type{f},PooledDataArray{S,R<:Integer,1},Union(Array{Bool,1},BitArray{1}))
before the new definition.
Warning: New definition 
    map!(Union(DataType,Function),PooledDataArray{T,R<:Integer,N},Union(Array{T,N},Number,BitArray{N})...) at /home/zenna/.julia/v0.3/DataArrays/src/broadcast.jl:185
is ambiguous with: 
    map!(Type{f},AbstractArray{S,2},AbstractArray{T,2}) at /home/zenna/.julia/v0.3/FastAnonymous/src/FastAnonymous.jl:95.
To fix, define 
    map!(Type{f},PooledDataArray{S,R<:Integer,2},Union(BitArray{2},Array{Bool,2}))
before the new definition.
Warning: New definition 
    map!(Union(DataType,Function),PooledDataArray{T,R<:Integer,N},Union(Array{T,N},Number,BitArray{N})...) at /home/zenna/.julia/v0.3/DataArrays/src/broadcast.jl:185
is ambiguous with: 
    map!(Type{f},AbstractArray{S,3},AbstractArray{T,3}) at /home/zenna/.julia/v0.3/FastAnonymous/src/FastAnonymous.jl:95.
To fix, define 
    map!(Type{f},PooledDataArray{S,R<:Integer,3},Union(Array{Bool,3},BitArray{3}))
before the new definition.
Warning: New definition 
    map!(Union(DataType,Function),PooledDataArray{T,R<:Integer,N},Union(Array{T,N},Number,BitArray{N})...) at /home/zenna/.julia/v0.3/DataArrays/src/broadcast.jl:185
is ambiguous with: 
    map!(Type{f},AbstractArray{S,4},AbstractArray{T,4}) at /home/zenna/.julia/v0.3/FastAnonymous/src/FastAnonymous.jl:95.
To fix, define 
    map!(Type{f},PooledDataArray{S,R<:Integer,4},Union(Array{Bool,4},BitArray{4}))
before the new definition.
Warning: New definition 
    map!(Union(DataType,Function),PooledDataArray{T,R<:Integer,N},Union(Array{T,N},Number,BitArray{N})...) at /home/zenna/.julia/v0.3/DataArrays/src/broadcast.jl:185
is ambiguous with: 
    map!(Type{f},AbstractArray{T,N},AbstractArray{T,1}) at /home/zenna/.julia/v0.3/FastAnonymous/src/FastAnonymous.jl:105.
To fix, define 
    map!(Type{f},PooledDataArray{T,R<:Integer,N},Union(Array{Bool,1},BitArray{1}))
before the new definition.
Warning: New definition 
    map!(Union(DataType,Function),PooledDataArray{T,R<:Integer,N},Union(Array{T,N},Number,BitArray{N})...) at /home/zenna/.julia/v0.3/DataArrays/src/broadcast.jl:185
is ambiguous with: 
    map!(Type{f},AbstractArray{T,N},AbstractArray{T,2}) at /home/zenna/.julia/v0.3/FastAnonymous/src/FastAnonymous.jl:105.
To fix, define 
    map!(Type{f},PooledDataArray{T,R<:Integer,N},Union(BitArray{2},Array{Bool,2}))
before the new definition.
Warning: New definition 
    map!(Union(DataType,Function),PooledDataArray{T,R<:Integer,N},Union(Array{T,N},Number,BitArray{N})...) at /home/zenna/.julia/v0.3/DataArrays/src/broadcast.jl:185
is ambiguous with: 
    map!(Type{f},AbstractArray{T,N},AbstractArray{T,3}) at /home/zenna/.julia/v0.3/FastAnonymous/src/FastAnonymous.jl:105.
To fix, define 
    map!(Type{f},PooledDataArray{T,R<:Integer,N},Union(Array{Bool,3},BitArray{3}))
before the new definition.
Warning: New definition 
    map!(Union(DataType,Function),PooledDataArray{T,R<:Integer,N},Union(Array{T,N},Number,BitArray{N})...) at /home/zenna/.julia/v0.3/DataArrays/src/broadcast.jl:185
is ambiguous with: 
    map!(Type{f},AbstractArray{T,N},AbstractArray{T,4}) at /home/zenna/.julia/v0.3/FastAnonymous/src/FastAnonymous.jl:105.
To fix, define 
    map!(Type{f},PooledDataArray{T,R<:Integer,N},Union(Array{Bool,4},BitArray{4}))
before the new definition.
Warning: New definition 
    map!(Union(DataType,Function),PooledDataArray{T,R<:Integer,N},Union(Array{T,N},Number,BitArray{N})...) at /home/zenna/.julia/v0.3/DataArrays/src/broadcast.jl:185
is ambiguous with: 
    map!(Type{f},AbstractArray{S,N},AbstractArray{T,N}) at cartesian.jl:100.
To fix, define 
    map!(Type{f},PooledDataArray{S,R<:Integer,N},Union(Array{Bool,N},BitArray{N}))
before the new definition.
Warning: New definition 
    map!(Union(DataType,Function),PooledDataArray{T,R<:Integer,N},Union(Array{T,N},Number,BitArray{N})...) at /home/zenna/.julia/v0.3/DataArrays/src/broadcast.jl:185
is ambiguous with: 
    map!(Type{f},AbstractArray{T,N},AbstractArray{T,N}) at cartesian.jl:100.
To fix, define 
    map!(Type{f},PooledDataArray{T,R<:Integer,N},Union(Array{Bool,N},BitArray{N}))
before the new definition.
Warning: New definition 
    map!(Union(DataType,Function),PooledDataArray{T,R<:Integer,N},Any...) at /home/zenna/.julia/v0.3/DataArrays/src/broadcast.jl:185
is ambiguous with: 
    map!(Type{f},AbstractArray{T,1},Range{T}) at /home/zenna/.julia/v0.3/FastAnonymous/src/FastAnonymous.jl:82.
To fix, define 
    map!(Type{f},PooledDataArray{T,R<:Integer,1},Range{T})
before the new definition.
Warning: New definition 
    map!(Union(DataType,Function),PooledDataArray{T,R<:Integer,N},Any...) at /home/zenna/.julia/v0.3/DataArrays/src/broadcast.jl:185
is ambiguous with: 
    map!(Type{f},AbstractArray{T,N},Range{T}) at /home/zenna/.julia/v0.3/FastAnonymous/src/FastAnonymous.jl:83.
To fix, define 
    map!(Type{f},PooledDataArray{T,R<:Integer,N},Range{T})
before the new definition.
Warning: New definition 
    map!(Union(DataType,Function),PooledDataArray{T,R<:Integer,N},Any...) at /home/zenna/.julia/v0.3/DataArrays/src/broadcast.jl:185
is ambiguous with: 
    map!(Type{f},AbstractArray{S,1},AbstractArray{T,1}) at /home/zenna/.julia/v0.3/FastAnonymous/src/FastAnonymous.jl:95.
To fix, define 
    map!(Type{f},PooledDataArray{S,R<:Integer,1},AbstractArray{T,1})
before the new definition.
Warning: New definition 
    map!(Union(DataType,Function),PooledDataArray{T,R<:Integer,N},Any...) at /home/zenna/.julia/v0.3/DataArrays/src/broadcast.jl:185
is ambiguous with: 
    map!(Type{f},AbstractArray{S,2},AbstractArray{T,2}) at /home/zenna/.julia/v0.3/FastAnonymous/src/FastAnonymous.jl:95.
To fix, define 
    map!(Type{f},PooledDataArray{S,R<:Integer,2},AbstractArray{T,2})
before the new definition.
Warning: New definition 
    map!(Union(DataType,Function),PooledDataArray{T,R<:Integer,N},Any...) at /home/zenna/.julia/v0.3/DataArrays/src/broadcast.jl:185
is ambiguous with: 
    map!(Type{f},AbstractArray{S,3},AbstractArray{T,3}) at /home/zenna/.julia/v0.3/FastAnonymous/src/FastAnonymous.jl:95.
To fix, define 
    map!(Type{f},PooledDataArray{S,R<:Integer,3},AbstractArray{T,3})
before the new definition.
Warning: New definition 
    map!(Union(DataType,Function),PooledDataArray{T,R<:Integer,N},Any...) at /home/zenna/.julia/v0.3/DataArrays/src/broadcast.jl:185
is ambiguous with: 
    map!(Type{f},AbstractArray{S,4},AbstractArray{T,4}) at /home/zenna/.julia/v0.3/FastAnonymous/src/FastAnonymous.jl:95.
To fix, define 
    map!(Type{f},PooledDataArray{S,R<:Integer,4},AbstractArray{T,4})
before the new definition.
Warning: New definition 
    map!(Union(DataType,Function),PooledDataArray{T,R<:Integer,N},Any...) at /home/zenna/.julia/v0.3/DataArrays/src/broadcast.jl:185
is ambiguous with: 
    map!(Type{f},AbstractArray{T,N},AbstractArray{T,1}) at /home/zenna/.julia/v0.3/FastAnonymous/src/FastAnonymous.jl:105.
To fix, define 
    map!(Type{f},PooledDataArray{T,R<:Integer,N},AbstractArray{T,1})
before the new definition.
Warning: New definition 
    map!(Union(DataType,Function),PooledDataArray{T,R<:Integer,N},Any...) at /home/zenna/.julia/v0.3/DataArrays/src/broadcast.jl:185
is ambiguous with: 
    map!(Type{f},AbstractArray{T,N},AbstractArray{T,2}) at /home/zenna/.julia/v0.3/FastAnonymous/src/FastAnonymous.jl:105.
To fix, define 
    map!(Type{f},PooledDataArray{T,R<:Integer,N},AbstractArray{T,2})
before the new definition.
Warning: New definition 
    map!(Union(DataType,Function),PooledDataArray{T,R<:Integer,N},Any...) at /home/zenna/.julia/v0.3/DataArrays/src/broadcast.jl:185
is ambiguous with: 
    map!(Type{f},AbstractArray{T,N},AbstractArray{T,3}) at /home/zenna/.julia/v0.3/FastAnonymous/src/FastAnonymous.jl:105.
To fix, define 
    map!(Type{f},PooledDataArray{T,R<:Integer,N},AbstractArray{T,3})
before the new definition.
Warning: New definition 
    map!(Union(DataType,Function),PooledDataArray{T,R<:Integer,N},Any...) at /home/zenna/.julia/v0.3/DataArrays/src/broadcast.jl:185
is ambiguous with: 
    map!(Type{f},AbstractArray{T,N},AbstractArray{T,4}) at /home/zenna/.julia/v0.3/FastAnonymous/src/FastAnonymous.jl:105.
To fix, define 
    map!(Type{f},PooledDataArray{T,R<:Integer,N},AbstractArray{T,4})
before the new definition.
Warning: New definition 
    map!(Union(DataType,Function),PooledDataArray{T,R<:Integer,N},Any...) at /home/zenna/.julia/v0.3/DataArrays/src/broadcast.jl:185
is ambiguous with: 
    map!(Type{f},AbstractArray{S,N},AbstractArray{T,N}) at cartesian.jl:100.
To fix, define 
    map!(Type{f},PooledDataArray{S,R<:Integer,N},AbstractArray{T,N})
before the new definition.
Warning: New definition 
    map!(Union(DataType,Function),PooledDataArray{T,R<:Integer,N},Any...) at /home/zenna/.julia/v0.3/DataArrays/src/broadcast.jl:185
is ambiguous with: 
    map!(Type{f},AbstractArray{T,N},AbstractArray{T,N}) at cartesian.jl:100.
To fix, define 
    map!(Type{f},PooledDataArray{T,R<:Integer,N},AbstractArray{T,N})
before the new definition.

Resolving inlining?

My understanding was that by using the @inline keyword on the function definition I could instruct the compiler (if inlining is enabled) to inject the code from the inlined function into the calling function. The thought being that the compiler would be able to see the entire composite function for optimization as well as experiencing a performance boost due to not needing to visit the stack for the function call. I've built functions using @anon where the sub-functions are defined with the @inline macro in the hopes of evaluating my constants (per compilation [an interesting concept with JiT]) at compile time and not at every call.
To my surprise when I accidentally had an error in the call to the fast anonymous function I see quotes to the function calls and not to the inlined code. Is this just an effect of the error reporting or is it in fact indication that the @anon macro is only going one level deep?
If doing this inlining is tractable I would be glad to contribute updates, but I am wondering now if I'm really seeing an issue.

let within (fast) anonymous function do not work

I'm not sure whether you intend to support let, but assuming the goal is for fast anonymous should work interchangeably with normal anonymous functions, the following is broken

@anon ω->begin
  let x = 3
    x
  end
end

julia>x not defined

[PkgEval] FastAnonymous may have a testing issue on Julia 0.4 (2015-02-09)

PackageEvaluator.jl is a script that runs nightly. It attempts to load all Julia packages and run their tests (if available) on both the stable version of Julia (0.3) and the nightly build of the unstable version (0.4). The results of this script are used to generate a package listing enhanced with testing results.

On Julia 0.4

  • On 2015-02-07 the testing status was Tests fail, but package loads.
  • On 2015-02-09 the testing status changed to Package doesn't load.

Tests fail, but package loads. means that PackageEvaluator found the tests for your package, executed them, and they didn't pass. However, trying to load your package with using worked.

Package doesn't load. means that PackageEvaluator did not find tests for your package. Additionally, trying to load your package with using failed.

This issue was filed because your testing status became worse. No additional issues will be filed if your package remains in this state, and no issue will be filed if it improves. If you'd like to opt-out of these status-change messages, reply to this message saying you'd like to and @IainNZ will add an exception. If you'd like to discuss PackageEvaluator.jl please file an issue at the repository. For example, your package may be untestable on the test machine due to a dependency - an exception can be added.

Test log:

>>> 'Pkg.add("FastAnonymous")' log
INFO: Installing FastAnonymous v0.0.1
INFO: Package database updated

>>> 'using FastAnonymous' log
Julia Version 0.4.0-dev+3225
Commit 6558327 (2015-02-09 04:52 UTC)
Platform Info:
  System: Linux (x86_64-unknown-linux-gnu)
  CPU: Intel(R) Xeon(R) CPU E5-2650 0 @ 2.00GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
  LAPACK: libopenblas
  LIBM: libopenlibm
  LLVM: libLLVM-3.3

ERROR: LoadError: LoadError: UndefVarError: @ngenerate not defined
 in include at ./boot.jl:249
 in include_from_node1 at ./loading.jl:128
 in reload_path at ./loading.jl:152
 in _require at ./loading.jl:67
 in require at ./loading.jl:52
 in include at ./boot.jl:249
 in include_from_node1 at loading.jl:128
 in process_options at ./client.jl:319
 in _start at ./client.jl:403
while loading /home/idunning/pkgtest/.julia/v0.4/FastAnonymous/src/FastAnonymous.jl, in expression starting on line 94
while loading /home/idunning/pkgtest/.julia/v0.4/FastAnonymous/testusing.jl, in expression starting on line 2

>>> test log
no tests to run
>>> end of log

Bad performance on multivariable functions.

Have a look:
a=randn(5000000);

@time(reduce((x,y) -> x,a))
elapsed time: 0.250185444 seconds (60000812 bytes allocated, 51.42% gc time)
0.5564212271634134

@time(reduce(@anon((x,y) -> x),a))
elapsed time: 0.815615445 seconds (120012708 bytes allocated, 35.23% gc time)
0.5564212271634134

Enhancement: using @anon with Task()?

julia> using FastAnonymous

julia> Task(() -> 6)
Task (runnable) @0x0000000113a56cb0

julia> Task(@anon(() -> 8))
ERROR: TypeError: call: in typeassert, expected Function, got FastAnonymous.Fun{Ptr{Void} @0x000000011065d2b0,0xc22def3c77661774,()}
 in call at /usr/local/julia-latest/lib/julia/sys.dylib

Any way to use FastAnonymous with Task()?

LoadError in 0.4

julia> VERSION
v"0.4.0-dev+4559"

julia> using FastAnonymous

WARNING: deprecated syntax "stagedfunction" at /Users/dpo/.julia/v0.4/FastAnonymous/src/FastAnonymous.jl:27.
Use "@generated function" instead.

WARNING: deprecated syntax "stagedfunction" at /Users/dpo/.julia/v0.4/FastAnonymous/src/FastAnonymous.jl:76.
Use "@generated function" instead.

WARNING: deprecated syntax "stagedfunction" at /Users/dpo/.julia/v0.4/FastAnonymous/src/FastAnonymous.jl:110.
Use "@generated function" instead.
ERROR: LoadError: MethodError: `start` has no method matching start(::Type{Symbol})
 in append_any at base.jl:198
 in include at /Applications/Julia-0.4.0-dev-060e5090e7.app/Contents/Resources/julia/lib/julia/sys.dylib
 in include_from_node1 at /Applications/Julia-0.4.0-dev-060e5090e7.app/Contents/Resources/julia/lib/julia/sys.dylib
 in reload_path at /Applications/Julia-0.4.0-dev-060e5090e7.app/Contents/Resources/julia/lib/julia/sys.dylib
 in _require at /Applications/Julia-0.4.0-dev-060e5090e7.app/Contents/Resources/julia/lib/julia/sys.dylib
 in require at /Applications/Julia-0.4.0-dev-060e5090e7.app/Contents/Resources/julia/lib/julia/sys.dylib
while loading /Users/dpo/.julia/v0.4/FastAnonymous/src/FastAnonymous.jl, in expression starting on line 25

Using with `Nullable{Function}`

How can I create a Nullable{Function} anon-ized anonymous function?

julia> VERSION
v"0.3.6"

julia> using Compat

julia> using FastAnonymous

julia> f = @anon x -> 2*x;

julia> Nullable{Function}(f)
ERROR: `Nullable{Function}` has no method matching Nullable{Function}(::Type{##23149})

Error with current Julia v0.4 master

I see this problem:

using FastAnonymous
offset = 1.2
f = @anon x->(x+offset)^2
ERROR: TypeError: apply_type: in Vararg, expected Type{T<:Top}, got (Expr,)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.