Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ end

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

Expand Down
42 changes: 42 additions & 0 deletions test/copy_static_array_test.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Base.Test, RecursiveArrayTools, StaticArrays

struct ImmutableFV <: FieldVector{2,Float64}
a::Float64
b::Float64
end

mutable struct MutableFV <: FieldVector{2,Float64}
a::Float64
b::Float64
end

# Immutable FieldVector
vec = ImmutableFV(1.,2.)
a = [vec]
b = zeros(a)
recursivecopy!(b, a)
@test a[1] == b[1]

# Mutable FieldVector
vec = MutableFV(1.,2.)
a = [vec]
b = zeros(a)
recursivecopy!(b, a)
@test a[1] == b[1]
a[1][1] *= 5
@test a[1] != b[1]

# SArray
vec = @SArray [1., 2.]
a = [vec]
b = zeros(a)
recursivecopy!(b, a)
@test a[1] == b[1]

# MArray
vec = @MArray [1., 2.]
a = [vec]
b = zeros(a)
recursivecopy!(b, a)
a[1][1] *= 5
@test a[1] != b[1]
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ tic()
@time @testset "Partitions Tests" begin include("partitions_test.jl") end
@time @testset "VecOfArr Indexing Tests" begin include("basic_indexing.jl") end
@time @testset "VecOfArr Interface Tests" begin include("interface_tests.jl") end
@time @testset "StaticArrays (recursivecopy!) Tests" begin include("copy_static_array_test.jl") end
toc()
# Test the VectorOfArray code