From 7befb5892431da67ccee44b9951c8c3e3d85f392 Mon Sep 17 00:00:00 2001 From: Matt Bauman Date: Wed, 26 Aug 2015 10:12:29 -0400 Subject: [PATCH] Yet another checkbounds code churn Update the index checkbounds API to the latest incarnation from https://github.com/JuliaLang/julia/pull/11895. --- src/indexing.jl | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/indexing.jl b/src/indexing.jl index 0d3f94f..4e2e716 100644 --- a/src/indexing.jl +++ b/src/indexing.jl @@ -87,7 +87,8 @@ function Base.to_index(A::DataArray) end # Fast implementation of checkbounds for DataArray input -# This overrides an internal API that changed after #10525 +# This overrides an internal API that changed after JuliaLang/julia#10525, +# and which was finally stabilized and documented with JuliaLang/julia#11895. if VERSION < v"0.4-dev+5194" Base.checkbounds(sz::Int, I::AbstractDataVector{Bool}) = length(I) == sz || throw(BoundsError()) @@ -99,7 +100,7 @@ if VERSION < v"0.4-dev+5194" checkbounds(sz, v) end end -else +elseif VERSION < v"0.4-dev+6993" Base._checkbounds(sz::Int, I::AbstractDataVector{Bool}) = length(I) == sz function Base._checkbounds{T<:Real}(sz::Int, I::AbstractDataArray{T}) anyna(I) && throw(NAException("cannot index into an array with a DataArray containing NAs")) @@ -111,6 +112,18 @@ else end b end +else + Base.checkbounds(::Type{Bool}, sz::Int, I::AbstractDataVector{Bool}) = length(I) == sz + function Base.checkbounds{T<:Real}(::Type{Bool}, sz::Int, I::AbstractDataArray{T}) + anyna(I) && throw(NAException("cannot index into an array with a DataArray containing NAs")) + extr = daextract(I) + b = true + for i = 1:length(I) + @inbounds v = unsafe_getindex_notna(I, extr, i) + b &= Base.checkbounds(Bool, sz, v) + end + b + end end # Indexing uses undocumented APIs to determine the resulting shape. These APIs