MikeInnes / Lazy.jl

I was gonna maintain this package, but then I got high
Other
470 stars 54 forks source link

Threading macros and dot operations with julia v0.6 #64

Closed eslgastal closed 7 years ago

eslgastal commented 7 years ago

When threading over an array, julia v0.6 complains that we should use the new "dot operations" syntax:

julia> using Lazy

julia> x = randn(100);

julia> y = @> x clamp(0.0,1.0);
WARNING: clamp(A::AbstractArray, lo, hi) is deprecated, use clamp.(A, lo, hi) instead.
Stacktrace:
 [1] depwarn(::String, ::Symbol) at ./deprecated.jl:70
 [2] clamp(::Array{Float64,1}, ::Float64, ::Float64) at ./deprecated.jl:57
 [3] eval(::Module, ::Any) at ./boot.jl:235
 [4] eval_user_input(::Any, ::Base.REPL.REPLBackend) at ./REPL.jl:66
 [5] macro expansion at ./REPL.jl:97 [inlined]
 [6] (::Base.REPL.##1#2{Base.REPL.REPLBackend})() at ./event.jl:73
while loading no file, in expression starting on line 0

However julia seems to parse the dot syntax before the @> macro gets to it:

julia> y = @> x clamp.(0.0,1.0);
ERROR: MethodError: no method matching clamp(::Float64, ::Float64)
Closest candidates are:
  clamp(::X, ::L, ::H) where {X, L, H} at math.jl:56
  clamp(::AbstractArray, ::Any, ::Any) at deprecated.jl:56
Stacktrace:
 [1] broadcast(::##1#2) at ./sysimg.jl:83

Any way to work around this issue? Thanks!

MikeInnes commented 7 years ago

I fixed this with https://github.com/MikeInnes/Lazy.jl/commit/6805c8adf332f6086ddaad25f3291773b7b69321 – you can try it with Pkg.checkout("Lazy")

eslgastal commented 7 years ago

Working. Thanks for the fix.

Now it's also possible to use the @. macro (but functions require empty parens () ):

julia> using Lazy

julia> x = rand(1000,1000);

julia> y = @. @> x clamp(0,1) exp();