From 27e2b4c57cac3aadbdfd9dcb938d06d564936036 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Mon, 28 Apr 2025 09:37:44 -0400 Subject: [PATCH 1/3] Define copy of BlockIndexRange --- Project.toml | 2 +- src/blockindices.jl | 2 ++ test/test_blockarrays.jl | 5 +++++ test/test_blockindices.jl | 1 + 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index bd608f58..edf66627 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "BlockArrays" uuid = "8e7c35d0-a365-5155-bbbb-fb81a777f24e" -version = "1.6.2" +version = "1.6.3" [deps] ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a" diff --git a/src/blockindices.jl b/src/blockindices.jl index f924cb63..554e2608 100644 --- a/src/blockindices.jl +++ b/src/blockindices.jl @@ -203,6 +203,8 @@ BlockIndexRange(block::Block{N}, inds::Vararg{AbstractUnitRange{<:Integer},N}) w block(R::BlockIndexRange) = R.block +copy(R::BlockIndexRange) = BlockIndexRange(R.block, copy.(R.indices)) + getindex(::Block{0}) = BlockIndex() getindex(B::Block{N}, inds::Vararg{Integer,N}) where N = BlockIndex(B,inds) getindex(B::Block{N}, inds::Vararg{AbstractUnitRange{<:Integer},N}) where N = BlockIndexRange(B,inds) diff --git a/test/test_blockarrays.jl b/test/test_blockarrays.jl index 70b7d66e..db3d8048 100644 --- a/test/test_blockarrays.jl +++ b/test/test_blockarrays.jl @@ -861,6 +861,11 @@ end @test A[Block(1)[1], Block(1)[1:1]] == BlockArray(A)[Block(1)[1], Block(1)[1:1]] == A[1,1:1] end + @testset "BlockIndexRange blocks" begin + a = mortar([Block(1)[1:2], Block(2)[2:3]]) + @test a[Block(1)] === Block(1)[1:2] + @test a[Block(2)] === Block(2)[2:3] + end @testset "permutedims" begin for a in (BlockArray(randn(3), [1,2]), BlockedArray(randn(3), [1,2])) @test permutedims(a) == permutedims(Vector(a)) diff --git a/test/test_blockindices.jl b/test/test_blockindices.jl index 3e980332..b57512be 100644 --- a/test/test_blockindices.jl +++ b/test/test_blockindices.jl @@ -95,6 +95,7 @@ import BlockArrays: BlockIndex, BlockIndexRange, BlockSlice @test BlockIndex(UInt(2),(2,)) === BlockIndex((UInt(2),),(2,)) @test BlockIndex(Block(2),2) === BlockIndex(Block(2),(2,)) @test BlockIndex(Block(2),UInt(2)) === BlockIndex(Block(2),(UInt(2),)) + @test copy(Block(1)[1:2]) === BlockIndexRange(Block(1),1:2) end @testset "BlockRange" begin From 07112c38ce96c994621c913d7b6294608f047bd8 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Mon, 28 Apr 2025 09:41:46 -0400 Subject: [PATCH 2/3] Formatting and more robust test --- test/test_blockarrays.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/test_blockarrays.jl b/test/test_blockarrays.jl index db3d8048..30457f2b 100644 --- a/test/test_blockarrays.jl +++ b/test/test_blockarrays.jl @@ -862,10 +862,11 @@ end end @testset "BlockIndexRange blocks" begin - a = mortar([Block(1)[1:2], Block(2)[2:3]]) + a = mortar([Block(1)[1:2], Block(3)[2:3]]) @test a[Block(1)] === Block(1)[1:2] - @test a[Block(2)] === Block(2)[2:3] + @test a[Block(2)] === Block(3)[2:3] end + @testset "permutedims" begin for a in (BlockArray(randn(3), [1,2]), BlockedArray(randn(3), [1,2])) @test permutedims(a) == permutedims(Vector(a)) From 2db567158f9eddbec85bff075ac8d0bdbe0d825b Mon Sep 17 00:00:00 2001 From: Matt Fishman Date: Mon, 28 Apr 2025 11:15:03 -0400 Subject: [PATCH 3/3] Change broadcast to map --- src/blockindices.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/blockindices.jl b/src/blockindices.jl index 554e2608..1226e8af 100644 --- a/src/blockindices.jl +++ b/src/blockindices.jl @@ -203,7 +203,7 @@ BlockIndexRange(block::Block{N}, inds::Vararg{AbstractUnitRange{<:Integer},N}) w block(R::BlockIndexRange) = R.block -copy(R::BlockIndexRange) = BlockIndexRange(R.block, copy.(R.indices)) +copy(R::BlockIndexRange) = BlockIndexRange(R.block, map(copy, R.indices)) getindex(::Block{0}) = BlockIndex() getindex(B::Block{N}, inds::Vararg{Integer,N}) where N = BlockIndex(B,inds)