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

Commit

Permalink
Review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nalimilan committed Dec 4, 2016
1 parent dc34174 commit a2e873a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
8 changes: 2 additions & 6 deletions src/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand All @@ -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

Expand Down
6 changes: 3 additions & 3 deletions src/lift.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions src/map.jl
Original file line number Diff line number Diff line change
@@ -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...)
Expand All @@ -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

Expand Down

0 comments on commit a2e873a

Please sign in to comment.