From 30c04c83b96188ef4c79b5bf2f78440816e4e08d Mon Sep 17 00:00:00 2001 From: mtfishman Date: Wed, 25 Jun 2025 11:18:12 -0400 Subject: [PATCH 1/2] Improve n-dimensional slicing of BlockIndexRange --- Project.toml | 2 +- src/blockindices.jl | 3 ++- test/test_blockindices.jl | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index edf66627..e455ea42 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "BlockArrays" uuid = "8e7c35d0-a365-5155-bbbb-fb81a777f24e" -version = "1.6.3" +version = "1.6.4" [deps] ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a" diff --git a/src/blockindices.jl b/src/blockindices.jl index 1226e8af..04770e9f 100644 --- a/src/blockindices.jl +++ b/src/blockindices.jl @@ -211,7 +211,8 @@ getindex(B::Block{N}, inds::Vararg{AbstractUnitRange{<:Integer},N}) where N = Bl getindex(B::Block{1}, inds::Colon) = B getindex(B::Block{1}, inds::Base.Slice) = B -@propagate_inbounds getindex(B::BlockIndexRange{1}, kr::AbstractUnitRange{<:Integer}) = BlockIndexRange(B.block, B.indices[1][kr]) +getindex(B::BlockIndexRange{0}) = B.block[] +@propagate_inbounds getindex(B::BlockIndexRange{N}, kr::Vararg{AbstractUnitRange{<:Integer},N}) where {N} = BlockIndexRange(B.block, map(getindex, B.indices, kr)) @propagate_inbounds getindex(B::BlockIndexRange{N}, inds::Vararg{Int,N}) where N = B.block[Base.reindex(B.indices, inds)...] eltype(R::BlockIndexRange) = eltype(typeof(R)) diff --git a/test/test_blockindices.jl b/test/test_blockindices.jl index b57512be..cb89483c 100644 --- a/test/test_blockindices.jl +++ b/test/test_blockindices.jl @@ -90,6 +90,7 @@ import BlockArrays: BlockIndex, BlockIndexRange, BlockSlice @test Block(1,1)[1,1] == BlockIndex((1,1),(1,1)) == BlockIndex((1,1),(1,)) @test Block(1,1)[1:2,1:2] == BlockIndexRange(Block(1,1),(1:2,1:2)) @test Block(1)[1:3][1:2] == BlockIndexRange(Block(1),1:2) + @test Block(1,1)[2:4,2:4][2:3,2:3] == BlockIndexRange(Block(1,1),(3:4,3:4)) @test BlockIndex((2,2,2),(2,)) == BlockIndex((2,2,2),(2,1,)) == BlockIndex((2,2,2),(2,1,1)) @test BlockIndex(2,(2,)) === BlockIndex((2,),(2,)) @test BlockIndex(UInt(2),(2,)) === BlockIndex((UInt(2),),(2,)) From bbb54f7e14a654ff028afb0def720ec8f515a011 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Wed, 25 Jun 2025 11:53:47 -0400 Subject: [PATCH 2/2] Improve coverage --- test/test_blockindices.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_blockindices.jl b/test/test_blockindices.jl index cb89483c..467a566e 100644 --- a/test/test_blockindices.jl +++ b/test/test_blockindices.jl @@ -91,6 +91,7 @@ import BlockArrays: BlockIndex, BlockIndexRange, BlockSlice @test Block(1,1)[1:2,1:2] == BlockIndexRange(Block(1,1),(1:2,1:2)) @test Block(1)[1:3][1:2] == BlockIndexRange(Block(1),1:2) @test Block(1,1)[2:4,2:4][2:3,2:3] == BlockIndexRange(Block(1,1),(3:4,3:4)) + @test BlockIndexRange(Block(),())[] == BlockIndex() @test BlockIndex((2,2,2),(2,)) == BlockIndex((2,2,2),(2,1,)) == BlockIndex((2,2,2),(2,1,1)) @test BlockIndex(2,(2,)) === BlockIndex((2,),(2,)) @test BlockIndex(UInt(2),(2,)) === BlockIndex((UInt(2),),(2,))