diff --git a/Project.toml b/Project.toml index 1935c38a..9b9fde7d 100644 --- a/Project.toml +++ b/Project.toml @@ -2,6 +2,7 @@ name = "BlockArrays" uuid = "8e7c35d0-a365-5155-bbbb-fb81a777f24e" version = "1.7.0" + [deps] ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a" BandedMatrices = "aae01518-5342-5314-be14-df237901396f" diff --git a/src/blockindices.jl b/src/blockindices.jl index 4aa4b8a1..8090b98a 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 93542d23..57c50efb 100644 --- a/test/test_blockindices.jl +++ b/test/test_blockindices.jl @@ -90,6 +90,8 @@ import BlockArrays: BlockIndex, BlockIndexRange, BlockSlice, BlockedSlice @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 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,))