Skip to content

Commit d74fac9

Browse files
authored
implement copy (JuliaArrays#9)
1 parent 3783f6d commit d74fac9

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/structarray.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,5 @@ for op in [:hcat, :vcat]
9999
end
100100
end
101101
end
102+
103+
Base.copy(s::StructArray{T,N,C}) where {T,N,C} = StructArray{T,N,C}(C(copy(x) for x in columns(s)))

test/runtests.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ end
1818
@test view(t, 2, 1:2) == StructArray{ComplexF64}(view(a, 2, 1:2), view(b, 2, 1:2))
1919
end
2020

21+
@testset "copy" begin
22+
a, b = [1 2; 3 4], [4 5; 6 7]
23+
t = StructArray{ComplexF64}(a, b)
24+
t2 = @inferred copy(t)
25+
@test t2[1,1] == 1.0 + im*4.0
26+
t2[1,1] = 2.0 + im*4.0
27+
# Test we actually did a copy
28+
@test t[1,1] == 1.0 + im*4.0
29+
end
30+
2131
@testset "undef initializer" begin
2232
t = @inferred StructArray{ComplexF64}(undef, 5, 5)
2333
@test eltype(t) == ComplexF64

0 commit comments

Comments
 (0)