Skip to content

Commit

Permalink
Use oneto in CartesianIndices when given sizes (#50534)
Browse files Browse the repository at this point in the history
  • Loading branch information
jishnub authored Jul 13, 2023
1 parent cdec4c2 commit 1a7fb51
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/multidimensional.jl
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ module IteratorsMD
CartesianIndices(A::AbstractArray) = CartesianIndices(axes(A))

_convert2ind(sz::Bool) = Base.OneTo(Int8(sz))
_convert2ind(sz::Integer) = Base.OneTo(sz)
_convert2ind(sz::Integer) = Base.oneto(sz)
_convert2ind(sz::AbstractUnitRange) = first(sz):last(sz)
_convert2ind(sz::OrdinalRange) = first(sz):step(sz):last(sz)

Expand Down
10 changes: 10 additions & 0 deletions test/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

using Random, LinearAlgebra

isdefined(Main, :InfiniteArrays) || @eval Main include("testhelpers/InfiniteArrays.jl")
using .Main.InfiniteArrays

A = rand(5,4,3)
@testset "Bounds checking" begin
@test checkbounds(Bool, A, 1, 1, 1) == true
Expand Down Expand Up @@ -56,6 +59,13 @@ end
@test checkbounds(Bool, A, CartesianIndex((5,)), CartesianIndex((4,)), CartesianIndex((4,))) == false
end

@testset "Infinite CartesianIndices" begin
r = OneToInf()
C = CartesianIndices(size(r))
ax = to_indices(r, (C,))[1]
@test ax === r
end

@testset "vector indices" begin
@test checkbounds(Bool, A, 1:5, 1:4, 1:3) == true
@test checkbounds(Bool, A, 0:5, 1:4, 1:3) == false
Expand Down

0 comments on commit 1a7fb51

Please sign in to comment.