|
146 | 146 | return LogicalIndex{Int}(arg) |
147 | 147 | end |
148 | 148 | @propagate_inbounds function to_index(::IndexLinear, x, arg::AbstractArray{<:AbstractCartesianIndex}) |
149 | | - @boundscheck _multi_check_index(axes(x), arg) || throw(BoundsError(x, arg)) |
| 149 | + @boundscheck Base.checkindex(Bool, axes(x), arg) || throw(BoundsError(x, arg)) |
150 | 150 | return arg |
151 | 151 | end |
152 | 152 | @propagate_inbounds function to_index(::IndexLinear, x, arg::LogicalIndex) |
@@ -175,27 +175,18 @@ to_index(::IndexCartesian, x, arg::Colon) = CartesianIndices(x) |
175 | 175 | to_index(::IndexCartesian, x, arg::CartesianIndices{0}) = arg |
176 | 176 | to_index(::IndexCartesian, x, arg::AbstractCartesianIndex) = arg |
177 | 177 | function to_index(::IndexCartesian, x, arg) |
178 | | - @boundscheck _multi_check_index(axes(x), arg) || throw(BoundsError(x, arg)) |
| 178 | + @boundscheck Base.checkindex(Bool, axes(x), arg) || throw(BoundsError(x, arg)) |
179 | 179 | return arg |
180 | 180 | end |
181 | | -@propagate_inbounds function to_index(::IndexCartesian, x, arg::AbstractArray{<:AbstractCartesianIndex}) |
182 | | - @boundscheck _multi_check_index(axes(x), arg) || throw(BoundsError(x, arg)) |
| 181 | +function to_index(::IndexCartesian, x, arg::AbstractArray{<:AbstractCartesianIndex}) |
| 182 | + @boundscheck Base.checkindex(Bool, axes(x), arg) || throw(BoundsError(x, arg)) |
183 | 183 | return arg |
184 | 184 | end |
185 | | -@propagate_inbounds function to_index(::IndexCartesian, x, arg::AbstractArray{Bool}) |
| 185 | +function to_index(::IndexCartesian, x, arg::AbstractArray{Bool}) |
186 | 186 | @boundscheck checkbounds(x, arg) |
187 | 187 | return LogicalIndex(arg) |
188 | 188 | end |
189 | | - |
190 | | -function _multi_check_index(axs::Tuple, arg::AbstractArray{T}) where {T<:AbstractCartesianIndex} |
191 | | - b = true |
192 | | - for i in arg |
193 | | - b &= Base.checkbounds_indices(Bool, axs, (i,)) |
194 | | - end |
195 | | - return b |
196 | | -end |
197 | | - |
198 | | -@propagate_inbounds function to_index(::IndexCartesian, x, arg::Union{Array{Bool}, BitArray}) |
| 189 | +function to_index(::IndexCartesian, x, arg::Union{Array{Bool}, BitArray}) |
199 | 190 | @boundscheck checkbounds(x, arg) |
200 | 191 | return LogicalIndex{Int}(arg) |
201 | 192 | end |
@@ -370,33 +361,12 @@ function unsafe_get_collection(A, inds) |
370 | 361 | axs = to_axes(A, inds) |
371 | 362 | dest = similar(A, axs) |
372 | 363 | if map(Base.unsafe_length, axes(dest)) == map(Base.unsafe_length, axs) |
373 | | - _unsafe_get_index!(dest, A, inds...) # usually a generated function, don't allow it to impact inference result |
| 364 | + Base._unsafe_getindex!(dest, A, inds...) |
374 | 365 | else |
375 | 366 | Base.throw_checksize_error(dest, axs) |
376 | 367 | end |
377 | 368 | return dest |
378 | 369 | end |
379 | | - |
380 | | -function _generate_unsafe_get_index!_body(N::Int) |
381 | | - quote |
382 | | - Compat.@inline() |
383 | | - D = eachindex(dest) |
384 | | - Dy = iterate(D) |
385 | | - @inbounds Base.Cartesian.@nloops $N j d -> I[d] begin |
386 | | - # This condition is never hit, but at the moment |
387 | | - # the optimizer is not clever enough to split the union without it |
388 | | - Dy === nothing && return dest |
389 | | - (idx, state) = Dy |
390 | | - dest[idx] = unsafe_getindex(src, NDIndex(Base.Cartesian.@ntuple($N, j))) |
391 | | - Dy = iterate(D, state) |
392 | | - end |
393 | | - return dest |
394 | | - end |
395 | | -end |
396 | | -@generated function _unsafe_get_index!(dest, src, I::Vararg{Any,N}) where {N} |
397 | | - return _generate_unsafe_get_index!_body(N) |
398 | | -end |
399 | | - |
400 | 370 | _ints2range(x::Integer) = x:x |
401 | 371 | _ints2range(x::AbstractRange) = x |
402 | 372 | @inline function unsafe_get_collection(A::CartesianIndices{N}, inds) where {N} |
@@ -476,28 +446,5 @@ unsafe_setindex!(a, v, i::Vararg{Any}) = unsafe_set_collection!(a, v, i) |
476 | 446 |
|
477 | 447 | Sets `inds` of `A` to `val`. `inds` is assumed to have been bounds-checked. |
478 | 448 | =# |
479 | | -@inline unsafe_set_collection!(A, v, i) = _unsafe_setindex!(A, v, i...) |
480 | | - |
481 | | -function _generate_unsafe_setindex!_body(N::Int) |
482 | | - quote |
483 | | - x′ = Base.unalias(A, x) |
484 | | - Base.Cartesian.@nexprs $N d -> (I_d = Base.unalias(A, I[d])) |
485 | | - idxlens = Base.Cartesian.@ncall $N Base.index_lengths I |
486 | | - Base.Cartesian.@ncall $N Base.setindex_shape_check x′ (d -> idxlens[d]) |
487 | | - Xy = iterate(x′) |
488 | | - @inbounds Base.Cartesian.@nloops $N i d->I_d begin |
489 | | - # This is never reached, but serves as an assumption for |
490 | | - # the optimizer that it does not need to emit error paths |
491 | | - Xy === nothing && break |
492 | | - (val, state) = Xy |
493 | | - unsafe_setindex!(A, val, NDIndex(Base.Cartesian.@ntuple($N, i))) |
494 | | - Xy = iterate(x′, state) |
495 | | - end |
496 | | - A |
497 | | - end |
498 | | -end |
499 | | - |
500 | | -@generated function _unsafe_setindex!(A, x, I::Vararg{Any,N}) where {N} |
501 | | - return _generate_unsafe_setindex!_body(N) |
502 | | -end |
| 449 | +unsafe_set_collection!(A, v, i) = Base._unsafe_setindex!(IndexStyle(A), A, v, i...) |
503 | 450 |
|
0 commit comments