Skip to content

Commit

Permalink
Add copy (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
dlfivefifty committed Oct 3, 2018
1 parent 0273fed commit d92f0b4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/BlockArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import Base: @propagate_inbounds, Array, to_indices, to_index,
broadcast, eltype, convert, broadcast,
@_inline_meta, _maybetail, tail, @_propagate_inbounds_meta, reindex,
RangeIndex, Int, Integer, Number,
+, -, min, max, *, isless, in, copyto!, axes, @deprecate
+, -, min, max, *, isless, in, copy, copyto!, axes, @deprecate



Expand Down
1 change: 1 addition & 0 deletions src/blockarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ convert(::Type{BlockArray{T1}}, A::AbstractArray{T2, N}) where {T1,T2,N} =
convert(::Type{BlockArray}, A::AbstractArray{T, N}) where {T,N} =
convert(BlockArray{T, N}, A)

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

################################
# AbstractBlockArray Interface #
Expand Down
2 changes: 1 addition & 1 deletion src/pseudo_blockarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ convert(::Type{PseudoBlockArray{T1}}, A::AbstractArray{T2, N}) where {T1,T2,N} =
convert(::Type{PseudoBlockArray}, A::AbstractArray{T, N}) where {T,N} =
convert(PseudoBlockArray{T, N}, A)


copy(A::PseudoBlockArray) = PseudoBlockArray(copy(A.blocks), copy(A.block_sizes))

###########################
# AbstractArray Interface #
Expand Down
20 changes: 20 additions & 0 deletions test/test_blockarrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -330,3 +330,23 @@ end
@test rmul!(A, 0.0) === A
@test Array(A) == zeros(6)
end

@testset "copy" begin
A = PseudoBlockArray(randn(6), 1:3)
B = copy(A)
@test typeof(A) == typeof(B)
@test blocksizes(A) == blocksizes(B)
@test A == B
B[1] = 2
@test B[1] == 2
@test A[1]  2

A = BlockArray(randn(6), 1:3)
B = copy(A)
@test typeof(A) == typeof(B)
@test blocksizes(A) == blocksizes(B)
@test A == B
B[1] = 2
@test B[1] == 2
@test A[1]  2
end

0 comments on commit d92f0b4

Please sign in to comment.