Skip to content

Commit d92f0b4

Browse files
committed
Add copy (#60)
1 parent 0273fed commit d92f0b4

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

src/BlockArrays.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import Base: @propagate_inbounds, Array, to_indices, to_index,
2121
broadcast, eltype, convert, broadcast,
2222
@_inline_meta, _maybetail, tail, @_propagate_inbounds_meta, reindex,
2323
RangeIndex, Int, Integer, Number,
24-
+, -, min, max, *, isless, in, copyto!, axes, @deprecate
24+
+, -, min, max, *, isless, in, copy, copyto!, axes, @deprecate
2525

2626

2727

src/blockarray.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ convert(::Type{BlockArray{T1}}, A::AbstractArray{T2, N}) where {T1,T2,N} =
211211
convert(::Type{BlockArray}, A::AbstractArray{T, N}) where {T,N} =
212212
convert(BlockArray{T, N}, A)
213213

214+
copy(A::BlockArray) = _BlockArray(copy.(A.blocks), copy(A.block_sizes))
214215

215216
################################
216217
# AbstractBlockArray Interface #

src/pseudo_blockarray.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ convert(::Type{PseudoBlockArray{T1}}, A::AbstractArray{T2, N}) where {T1,T2,N} =
105105
convert(::Type{PseudoBlockArray}, A::AbstractArray{T, N}) where {T,N} =
106106
convert(PseudoBlockArray{T, N}, A)
107107

108-
108+
copy(A::PseudoBlockArray) = PseudoBlockArray(copy(A.blocks), copy(A.block_sizes))
109109

110110
###########################
111111
# AbstractArray Interface #

test/test_blockarrays.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,3 +330,23 @@ end
330330
@test rmul!(A, 0.0) === A
331331
@test Array(A) == zeros(6)
332332
end
333+
334+
@testset "copy" begin
335+
A = PseudoBlockArray(randn(6), 1:3)
336+
B = copy(A)
337+
@test typeof(A) == typeof(B)
338+
@test blocksizes(A) == blocksizes(B)
339+
@test A == B
340+
B[1] = 2
341+
@test B[1] == 2
342+
@test A[1]  2
343+
344+
A = BlockArray(randn(6), 1:3)
345+
B = copy(A)
346+
@test typeof(A) == typeof(B)
347+
@test blocksizes(A) == blocksizes(B)
348+
@test A == B
349+
B[1] = 2
350+
@test B[1] == 2
351+
@test A[1]  2
352+
end

0 commit comments

Comments
 (0)