-
Notifications
You must be signed in to change notification settings - Fork 21
broadcast with arguments of different type #174
Comments
Do you mean to say that |
Sorry! I copied the same code twice, I've edited the post above. Running this:
gives the following error:
Of course this example is not useful in practice, but there are several use-cases where one would want to broadcast a function taking arguments of different types. EDIT: of course you're right, I've changed it again, this is what give the |
Well, the trouble there is that you have reversed the arguments to julia> NullableArray(ones(Int64, 100)) .+ NullableArray(ones(Float64, 100))
WARNING: Array{T,N}(::Type{T},d::NTuple{N,Int}) is deprecated, use Array{T,N}(d) instead.
Stacktrace:
[1] depwarn(::String, ::Symbol) at ./deprecated.jl:64
[2] Array{T,N}(::Type{Float64}, ::Tuple{Int64}) at ./deprecated.jl:50
[3] Type at /Users/David/.julia/v0.6/NullableArrays/src/constructors.jl:25 [inlined]
[4] Type at /Users/David/.julia/v0.6/NullableArrays/src/constructors.jl:35 [inlined]
[5] similar at ./abstractarray.jl:489 [inlined]
[6] broadcast(::Base.#+, ::NullableArrays.NullableArray{Int64,1}, ::NullableArrays.NullableArray{Float64,1}) at /Users/David/.julia/v0.6/NullableArrays/src/broadcast.jl:68
[7] eval(::Module, ::Any) at ./boot.jl:237
[8] eval(::Module, ::Any) at /Users/David/julia/usr/lib/julia/sys.dylib:?
[9] eval_user_input(::Any, ::Base.REPL.REPLBackend) at ./REPL.jl:66
[10] macro expansion at ./REPL.jl:97 [inlined]
[11] (::Base.REPL.##1#2{Base.REPL.REPLBackend})() at ./event.jl:71
while loading no file, in expression starting on line 0
ERROR: MethodError: no method matching lift(::Base.#+, ::Tuple{Nullable{Int64},Nullable{Float64}})
Closest candidates are:
lift(::Any) at /Users/David/.julia/v0.6/NullableArrays/src/lift.jl:37
lift{F,N,T}(::F, ::Tuple{Vararg{T,N}}) at /Users/David/.julia/v0.6/NullableArrays/src/lift.jl:17
Stacktrace:
[1] macro expansion at ./broadcast.jl:150 [inlined]
[2] macro expansion at ./simdloop.jl:72 [inlined]
[3] macro expansion at ./broadcast.jl:143 [inlined]
[4] _broadcast! at ./broadcast.jl:136 [inlined]
[5] broadcast_c! at ./broadcast.jl:207 [inlined]
[6] broadcast! at ./broadcast.jl:201 [inlined]
[7] invoke_broadcast!(::NullableArrays.#f2#17{Base.#+}, ::NullableArrays.NullableArray{Float64,1}, ::NullableArrays.NullableArray{Int64,1}, ::NullableArrays.NullableArray{Float64,1}) at /Users/David/.julia/v0.6/NullableArrays/src/broadcast.jl:41
[8] broadcast(::Base.#+, ::NullableArrays.NullableArray{Int64,1}, ::NullableArrays.NullableArray{Float64,1}) at /Users/David/.julia/v0.6/NullableArrays/src/broadcast.jl:69 It should be possible to widen the argument signature for |
Good catch! It's surprising we didn't actually test this at all. #175 should fix it. |
First of all, kudos for #166, I find it extremely useful.
I have one doubt: by looking at the implementation, it seems that it only works if all the arguments of the function have the same type, i.e. this works fine:
NullableArray(ones(100)) .+ NullableArray(ones(100))
whereas this throws an error:
NullableArray(ones(Int64, 100)) .+ NullableArray(ones(Float64,100))
which as far as I understand comes from this definition of lift.
Is there a way/plan to generalize lift to tuples with elements of different types, or is that unfeasible?
The text was updated successfully, but these errors were encountered: