Skip to content
This repository has been archived by the owner on May 4, 2019. It is now read-only.

Commit

Permalink
Improve efficiency of null checking for generic case
Browse files Browse the repository at this point in the history
In my benchmarks, this approach is just as fast as manually repeating
isnull(x) | isnull(y)...
  • Loading branch information
nalimilan committed Nov 26, 2016
1 parent ebca424 commit 17688ce
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ eltypes() = Tuple{}
eltypes(x) = Tuple{eltype(x)}
eltypes(x, xs...) = Tuple{eltype(x), eltypes(xs...).parameters...}

hasnulls() = false
hasnulls(x) = isnull(x)
hasnulls(x, xs...) = hasnulls(x) | hasnulls(xs...)

"""
broadcast_lift(f, xs...)
Expand All @@ -71,14 +75,10 @@ return `f` applied to values of `xs`.
"""
@inline function broadcast_lift(f, xs...)
if null_safe_op(f, eltypes(xs).parameters...)
# TODO: find a more efficient approach than mapreduce
# (i.e. one which gets lowered to just isnull(x1) | isnull(x2) | ...)
return @compat Nullable(f(unsafe_get.(xs)...), !mapreduce(isnull, |, xs))
return @compat Nullable(f(unsafe_get.(xs)...), !hasnulls(xs...))
else
U = Core.Inference.return_type(f, eltypes(xs...))
# TODO: find a more efficient approach than mapreduce
# (i.e. one which gets lowered to just isnull(x1) | isnull(x2) | ...)
if mapreduce(isnull, |, xs)
U = Core.Inference.return_type(f, eltypes(xs))
if hasnulls(xs...)
return Nullable{U}()
else
return Nullable(f(map(unsafe_get, xs)...))
Expand Down

0 comments on commit 17688ce

Please sign in to comment.