Skip to content

Commit 7346d2c

Browse files
Merge pull request #20 from ranocha/pull-request/51ccc062
recursivecopy! for StaticArrays
2 parents 6d304a5 + 51ccc06 commit 7346d2c

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

src/utils.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ end
88

99
function recursivecopy!{T<:StaticArray,N}(b::AbstractArray{T,N},a::AbstractArray{T,N})
1010
@inbounds for i in eachindex(a)
11-
b[i] = a[i]
11+
# TODO: Check for `setindex!`` and use `copy!(b[i],a[i])` or `b[i] = a[i]`, see #19
12+
b[i] = copy(a[i])
1213
end
1314
end
1415

test/copy_static_array_test.jl

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using Base.Test, RecursiveArrayTools, StaticArrays
2+
3+
struct ImmutableFV <: FieldVector{2,Float64}
4+
a::Float64
5+
b::Float64
6+
end
7+
8+
mutable struct MutableFV <: FieldVector{2,Float64}
9+
a::Float64
10+
b::Float64
11+
end
12+
13+
# Immutable FieldVector
14+
vec = ImmutableFV(1.,2.)
15+
a = [vec]
16+
b = zeros(a)
17+
recursivecopy!(b, a)
18+
@test a[1] == b[1]
19+
20+
# Mutable FieldVector
21+
vec = MutableFV(1.,2.)
22+
a = [vec]
23+
b = zeros(a)
24+
recursivecopy!(b, a)
25+
@test a[1] == b[1]
26+
a[1][1] *= 5
27+
@test a[1] != b[1]
28+
29+
# SArray
30+
vec = @SArray [1., 2.]
31+
a = [vec]
32+
b = zeros(a)
33+
recursivecopy!(b, a)
34+
@test a[1] == b[1]
35+
36+
# MArray
37+
vec = @MArray [1., 2.]
38+
a = [vec]
39+
b = zeros(a)
40+
recursivecopy!(b, a)
41+
a[1][1] *= 5
42+
@test a[1] != b[1]

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ tic()
77
@time @testset "Partitions Tests" begin include("partitions_test.jl") end
88
@time @testset "VecOfArr Indexing Tests" begin include("basic_indexing.jl") end
99
@time @testset "VecOfArr Interface Tests" begin include("interface_tests.jl") end
10+
@time @testset "StaticArrays (recursivecopy!) Tests" begin include("copy_static_array_test.jl") end
1011
toc()
1112
# Test the VectorOfArray code

0 commit comments

Comments
 (0)