From a2e873ae164fc4e23c04761aac28f0bb9d27b239 Mon Sep 17 00:00:00 2001 From: Milan Bouchet-Valat Date: Sun, 4 Dec 2016 22:37:18 +0100 Subject: [PATCH] Review comments --- src/broadcast.jl | 8 ++------ src/lift.jl | 6 +++--- src/map.jl | 8 ++------ 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/broadcast.jl b/src/broadcast.jl index 2b48dfc..f45f7b2 100644 --- a/src/broadcast.jl +++ b/src/broadcast.jl @@ -32,7 +32,7 @@ else end invoke_broadcast!{F, N}(f::F, dest, As::Vararg{NullableArray, N}) = - invoke(broadcast!, Tuple{Function, AbstractArray, Vararg{AbstractArray, N}}, f, dest, As...) + invoke(broadcast!, Tuple{F, AbstractArray, Vararg{AbstractArray, N}}, f, dest, As...) """ broadcast(f, As::NullableArray...) @@ -58,11 +58,7 @@ function Base.broadcast{F, N}(f::F, As::Vararg{NullableArray, N}) f2(x...) = lift(f, x...) T = _default_eltype(Base.Generator{ziptype(As...), ftype(f2, As...)}) - if isleaftype(T) && !(T <: Nullable) - dest = similar(Array{eltype(T)}, broadcast_indices(As...)) - else - dest = similar(NullableArray{eltype(T)}, broadcast_indices(As...)) - end + dest = similar(NullableArray{eltype(T)}, broadcast_indices(As...)) invoke_broadcast!(f2, dest, As...) end diff --git a/src/lift.jl b/src/lift.jl index b6843bd..554296f 100644 --- a/src/lift.jl +++ b/src/lift.jl @@ -4,7 +4,7 @@ else U = Core.Inference.return_type(f, Tuple{eltype(x)}) if isnull(x) - return Nullable{U}() + return isleaftype(U) ? Nullable{U}() : Nullable() else return Nullable(f(unsafe_get(x))) end @@ -18,7 +18,7 @@ end else U = Core.Inference.return_type(f, Tuple{eltype(x1), eltype(x2)}) if isnull(x1) | isnull(x2) - return Nullable{U}() + return isleaftype(U) ? Nullable{U}() : Nullable() else return Nullable(f(unsafe_get(x1), unsafe_get(x2))) end @@ -53,7 +53,7 @@ return `f` applied to values of `xs`. else U = Core.Inference.return_type(f, eltypes(xs...)) if hasnulls(xs...) - return Nullable{U}() + return isleaftype(U) ? Nullable{U}() : Nullable() else return Nullable(f(_unsafe_get(xs...)...)) end diff --git a/src/map.jl b/src/map.jl index 66fb29a..5389715 100644 --- a/src/map.jl +++ b/src/map.jl @@ -1,7 +1,7 @@ using Base: collect_similar, Generator invoke_map!{F, N}(f::F, dest, As::Vararg{NullableArray, N}) = - invoke(map!, Tuple{Function, AbstractArray, Vararg{AbstractArray, N}}, f, dest, As...) + invoke(map!, Tuple{F, AbstractArray, Vararg{AbstractArray, N}}, f, dest, As...) """ map(f, As::NullableArray...) @@ -27,11 +27,7 @@ function Base.map{F, N}(f::F, As::Vararg{NullableArray, N}) f2(x...) = lift(f, x...) T = _default_eltype(Base.Generator{ziptype(As...), ftype(f2, As...)}) - if isleaftype(T) && !(T <: Nullable) - dest = similar(Array{eltype(T)}, size(As[1])) - else - dest = similar(NullableArray{eltype(T)}, size(As[1])) - end + dest = similar(NullableArray{eltype(T)}, size(As[1])) invoke_map!(f2, dest, As...) end