From 0da26a35a70ba6018b8e93f4cf7cc5ae4997d815 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Wed, 29 Oct 2025 20:08:04 -0400 Subject: [PATCH] Fix axes and size of BlockIndices --- Project.toml | 2 +- src/blockindices.jl | 8 ++++---- test/test_blockindices.jl | 7 +++++++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Project.toml b/Project.toml index 28ffe14b..ceaf537b 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "BlockArrays" uuid = "8e7c35d0-a365-5155-bbbb-fb81a777f24e" -version = "1.9" +version = "1.9.1" [deps] diff --git a/src/blockindices.jl b/src/blockindices.jl index 05cb92cb..bc538a06 100644 --- a/src/blockindices.jl +++ b/src/blockindices.jl @@ -202,7 +202,7 @@ BlockIndex(indcs::Tuple{Vararg{BlockIndex{1},N}}) where N = BlockIndex(block.(in bl = block(I) checkbounds(Bool, A, bl) || return false # TODO: Replace with `eachblockaxes(A)[bl]` once that is defined. - binds = map(Base.axes1 ∘ getindex, axes(A), Tuple(bl)) + binds = map(axes1 ∘ getindex, axes(A), Tuple(bl)) Base.checkbounds_indices(Bool, binds, (blockindex(I),)) end checkbounds(::Type{Bool}, A::AbstractArray{<:Any,N}, I::AbstractArray{<:BlockIndex{N}}) where N = @@ -374,8 +374,8 @@ end nextstate, nextstate end -size(iter::BlockIndices) = map(dimlength, first(iter).α, last(iter).α) -length(iter::BlockIndices) = prod(size(iter)) +axes(iter::BlockIndices) = map(axes1, iter.indices) +size(iter::BlockIndices) = map(length, iter.indices) Block(bs::BlockIndices) = bs.block @@ -388,7 +388,7 @@ function checkbounds(::Type{Bool}, A::AbstractArray{<:Any,N}, I::BlockIndices{N} bl = block(I) checkbounds(Bool, A, bl) || return false # TODO: Replace with `eachblockaxes(A)[bl]` once that is defined. - binds = map(Base.axes1 ∘ getindex, axes(A), Tuple(bl)) + binds = map(axes1 ∘ getindex, axes(A), Tuple(bl)) Base.checkbounds_indices(Bool, binds, I.indices) end diff --git a/test/test_blockindices.jl b/test/test_blockindices.jl index 4041cac8..02c87dfc 100644 --- a/test/test_blockindices.jl +++ b/test/test_blockindices.jl @@ -119,6 +119,13 @@ import BlockArrays: split_index, merge_indices @test eltype(BlockIndices{3}) ≡ BlockIndex{3} @test Base.IteratorSize(BlockIndices{3}) ≡ Base.HasShape{1}() @test isnothing(iterate(Block(3,3)[[1,3],[3,1]])) + + I1 = BlockVector([2,4,7,2,3], (blockedrange([2,3]),)) + I2 = blockedrange(2, [4,3]) + b = Block(1,2)[I1,I2] + @test blockisequal(axes(b), (blockedrange([2,3]),blockedrange([4,3]))) + @test size(b) == (5,7) + @test length(b) == 35 end @testset "BlockRange" begin