LoopVectorization.jl icon indicating copy to clipboard operation
LoopVectorization.jl copied to clipboard

@turbo with passmissing?

Open alfaromartino opened this issue 2 years ago • 1 comments

I've been using FastBroadcast and @turbo to speed up broadcasting operations in DataFrames. However, missing values are quite common when you work with a DataFrame, and @turbo throws an error in that case.

Is it possible to have something similar to passmissing for @turbo? This would be consistent with Base broadcast and as FastBroadcast works, which passes missing values when you broadcast.

using LoopVectorization, FastBroadcast

df = DataFrame(a = [1,missing,3])

@.. df.a .* df.a 		# this works
@turbo df.a .* df.a	# this throws error

The error is:

ERROR: MethodError: no method matching vmaterialize!(::Vector{Union{Missing, Int64}}, 
::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{1}, Nothing, typeof(*), 
Tuple{Vector{Union{Missing, Int64}}, Vector{Union{Missing, Int64}}}}, 
::Val{:Main}, ::Val{(true, 0, 0, 0, true, 0, 32, 15, 64, 0x0000000000000001, 1, true)}, ::Val{((true,), (true,))})

The problem persists if you create a view dropping missings, since the vector is still Union{Missing,T} and is not allowed.

Many thanks!!! Great package!!!

alfaromartino avatar Feb 20 '23 21:02 alfaromartino

Yes, this is fixable. If someone wants to make a PR, I could explain the approach and answer any questions.

chriselrod avatar Feb 20 '23 22:02 chriselrod