Skip to content

Commit b167ede

Browse files
authored
Define copy(::BlockIndexRange) (#460)
1 parent 4059149 commit b167ede

File tree

4 files changed

+10
-1
lines changed

4 files changed

+10
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "BlockArrays"
22
uuid = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
3-
version = "1.6.2"
3+
version = "1.6.3"
44

55
[deps]
66
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"

src/blockindices.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ BlockIndexRange(block::Block{N}, inds::Vararg{AbstractUnitRange{<:Integer},N}) w
203203

204204
block(R::BlockIndexRange) = R.block
205205

206+
copy(R::BlockIndexRange) = BlockIndexRange(R.block, map(copy, R.indices))
207+
206208
getindex(::Block{0}) = BlockIndex()
207209
getindex(B::Block{N}, inds::Vararg{Integer,N}) where N = BlockIndex(B,inds)
208210
getindex(B::Block{N}, inds::Vararg{AbstractUnitRange{<:Integer},N}) where N = BlockIndexRange(B,inds)

test/test_blockarrays.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,12 @@ end
861861
@test A[Block(1)[1], Block(1)[1:1]] == BlockArray(A)[Block(1)[1], Block(1)[1:1]] == A[1,1:1]
862862
end
863863

864+
@testset "BlockIndexRange blocks" begin
865+
a = mortar([Block(1)[1:2], Block(3)[2:3]])
866+
@test a[Block(1)] === Block(1)[1:2]
867+
@test a[Block(2)] === Block(3)[2:3]
868+
end
869+
864870
@testset "permutedims" begin
865871
for a in (BlockArray(randn(3), [1,2]), BlockedArray(randn(3), [1,2]))
866872
@test permutedims(a) == permutedims(Vector(a))

test/test_blockindices.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ import BlockArrays: BlockIndex, BlockIndexRange, BlockSlice
9595
@test BlockIndex(UInt(2),(2,)) === BlockIndex((UInt(2),),(2,))
9696
@test BlockIndex(Block(2),2) === BlockIndex(Block(2),(2,))
9797
@test BlockIndex(Block(2),UInt(2)) === BlockIndex(Block(2),(UInt(2),))
98+
@test copy(Block(1)[1:2]) === BlockIndexRange(Block(1),1:2)
9899
end
99100

100101
@testset "BlockRange" begin

0 commit comments

Comments
 (0)