Skip to content

Commit 1a7fb51

Browse files
authored
Use oneto in CartesianIndices when given sizes (#50534)
1 parent cdec4c2 commit 1a7fb51

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

base/multidimensional.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ module IteratorsMD
267267
CartesianIndices(A::AbstractArray) = CartesianIndices(axes(A))
268268

269269
_convert2ind(sz::Bool) = Base.OneTo(Int8(sz))
270-
_convert2ind(sz::Integer) = Base.OneTo(sz)
270+
_convert2ind(sz::Integer) = Base.oneto(sz)
271271
_convert2ind(sz::AbstractUnitRange) = first(sz):last(sz)
272272
_convert2ind(sz::OrdinalRange) = first(sz):step(sz):last(sz)
273273

test/abstractarray.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
using Random, LinearAlgebra
44

5+
isdefined(Main, :InfiniteArrays) || @eval Main include("testhelpers/InfiniteArrays.jl")
6+
using .Main.InfiniteArrays
7+
58
A = rand(5,4,3)
69
@testset "Bounds checking" begin
710
@test checkbounds(Bool, A, 1, 1, 1) == true
@@ -56,6 +59,13 @@ end
5659
@test checkbounds(Bool, A, CartesianIndex((5,)), CartesianIndex((4,)), CartesianIndex((4,))) == false
5760
end
5861

62+
@testset "Infinite CartesianIndices" begin
63+
r = OneToInf()
64+
C = CartesianIndices(size(r))
65+
ax = to_indices(r, (C,))[1]
66+
@test ax === r
67+
end
68+
5969
@testset "vector indices" begin
6070
@test checkbounds(Bool, A, 1:5, 1:4, 1:3) == true
6171
@test checkbounds(Bool, A, 0:5, 1:4, 1:3) == false

0 commit comments

Comments
 (0)