JuliaStats / NullableArrays.jl

DEPRECATED Prototype of the new JuliaStats NullableArrays package
Other
35 stars 21 forks source link

Broadcast not working on type constructors with NullableArrays (on master) #176

Closed piever closed 7 years ago

piever commented 7 years ago

After #175 I can pass nullable arrays with different eltype to broadcast but it still doesn't seem to work on type constructors.

Example:

type SurvEvent
    time
    censored
end
t = NullableArray(rand(3))
c = NullableArray(rand(Bool,3))
SurvEvent.(t,c)

UndefRefError: access to undefined reference

 in lift(...) at /Users/pietro/.julia/v0.5/NullableArrays/src/lift.jl:20
 in macro expansion at ./broadcast.jl:129 [inlined]
 in macro expansion at ./simdloop.jl:73 [inlined]
 in macro expansion at ./broadcast.jl:123 [inlined]
 in _broadcast!(::NullableArrays.#f2#17{DataType}, ::NullableArrays.NullableArray{Any,1}, ::Tuple{Tuple{Bool},Tuple{Bool}}, ::Tuple{Tuple{Int64},Tuple{Int64}}, ::Tuple{NullableArrays.NullableArray{Float64,1},NullableArrays.NullableArray{Bool,1}}, ::Type{Val{2}}) at ./broadcast.jl:117
 in broadcast!(::Function, ::NullableArrays.NullableArray{Any,1}, ::NullableArrays.NullableArray{Float64,1}, ::NullableArrays.NullableArray{Bool,1}) at ./broadcast.jl:172
 in broadcast(::Type{SurvEvent}, ::NullableArrays.NullableArray{Float64,1}, ::NullableArrays.NullableArray{Bool,1}) at /Users/pietro/.julia/v0.5/NullableArrays/src/broadcast.jl:69

On the other hand, this works (but it fails the inference part as the output should be of type NullableArrays.NullableArray{SurvEvent,1} ):

g(x,y) = SurvEvent(x,y)
g.(t,c)

3-element NullableArrays.NullableArray{Any,1}:
 SurvEvent(0.914069,true) 
 SurvEvent(0.702524,false)
 SurvEvent(0.840124,true) 
nalimilan commented 7 years ago

Indeed, the f.instance on that line wasn't a very clean approach. I guess that's what happens when you do something without knowing why it works...

I have a simple fix, but I need to check that performance doesn't suffer first.

nalimilan commented 7 years ago

See https://github.com/JuliaStats/NullableArrays.jl/pull/177. Unfortunately, inference fails on Julia 0.5 and I couldn't find a workaround (at least it works on 0.6).