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

Fix breakage related to introduction of Base.OneTo #131

Merged
merged 2 commits into from
Jul 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/broadcast.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
using Base.Broadcast: check_broadcast_shape
using Base: promote_eltype
using Base.Broadcast: check_broadcast_shape, broadcast_shape
using Base.Cartesian

if VERSION >= v"0.5.0-dev+5189"
_to_shape(dims::Base.DimsOrInds) = map(_to_shape, dims)
_to_shape(r::Base.OneTo) = Int(last(r))
else
_to_shape(x) = x
end

if VERSION < v"0.5.0-dev+4724"
function gen_nullcheck(narrays::Int, nd::Int)
e_nullcheck = macroexpand(:( @nref $nd isnull_1 d->j_d_1 ))
Expand All @@ -24,7 +32,7 @@ if VERSION < v"0.5.0-dev+4724"
@nexprs $narrays k->(isnull_k = A_k.isnull)
# check size
@assert ndims(B) == $nd
@ncall $narrays Base.Broadcast.check_broadcast_shape size(B) k->A_k
@ncall $narrays check_broadcast_shape size(B) k->A_k
# main loops
@nloops($nd, i, B,
d->(@nexprs $narrays k->(j_d_k = size(A_k, d) == 1 ? 1 : i_d)), # pre
Expand Down Expand Up @@ -155,8 +163,8 @@ else
@inline function Base.broadcast!(f, Z::NullableArray, Xs::NullableArray...;
lift=false)
nargs = length(Xs)
check_broadcast_shape(indices(Z), Xs...)
sz = size(Z)
check_broadcast_shape(sz, Xs...)
mapindex = map(x->newindexer(sz, x), Xs)
Base.Broadcast._broadcast!(f, Z, mapindex, Xs, Val{nargs}; lift=lift)
Z
Expand All @@ -176,8 +184,8 @@ arguments consisting of both `Array`s and `NullableArray`s will fall back to the
implementation of `broadcast` in `base/broadcast.jl`.
""" ->
@inline function Base.broadcast(f, Xs::NullableArray...;lift::Bool=false)
return broadcast!(f, NullableArray(eltype(Base.promote_eltype(Xs...)),
Base.Broadcast.broadcast_shape(Xs...)),
return broadcast!(f, NullableArray(eltype(promote_eltype(Xs...)),
_to_shape(broadcast_shape(Xs...))),
Xs...; lift=lift)
end

Expand Down
6 changes: 3 additions & 3 deletions src/indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,16 @@ function unsafe_getvalue_notnull(X::NullableArray, I::Int...)
end

if VERSION >= v"0.5.0-dev+4697"
function Base.checkindex(::Type{Bool}, inds::UnitRange, i::Nullable)
function Base.checkindex(::Type{Bool}, inds::AbstractUnitRange, i::Nullable)
isnull(i) ? throw(NullException()) : checkindex(Bool, inds, get(i))
end

function Base.checkindex{N}(::Type{Bool}, inds::UnitRange, I::NullableArray{Bool, N})
function Base.checkindex{N}(::Type{Bool}, inds::AbstractUnitRange, I::NullableArray{Bool, N})
anynull(I) && throw(NullException())
checkindex(Bool, inds, I.values)
end

function Base.checkindex{T<:Real}(::Type{Bool}, inds::UnitRange, I::NullableArray{T})
function Base.checkindex{T<:Real}(::Type{Bool}, inds::AbstractUnitRange, I::NullableArray{T})
anynull(I) && throw(NullException())
b = true
for i in 1:length(I)
Expand Down