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 Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
NLsolve = "2774e3e8-f4cf-5e23-947b-6d7e65073b56"
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
StructArrays = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"

[targets]
test = ["ForwardDiff", "NLsolve", "OrdinaryDiffEq", "Test", "Unitful", "Random", "Zygote"]
test = ["ForwardDiff", "NLsolve", "OrdinaryDiffEq", "Test", "Unitful", "Random", "StructArrays", "Zygote"]
7 changes: 6 additions & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ function recursivecopy(a::AbstractArray{T,N}) where {T<:Number,N}
end

function recursivecopy(a::AbstractArray{T,N}) where {T<:AbstractArray,N}
map(recursivecopy,a)
if ArrayInterface.ismutable(a)
b = similar(a)
map!(recursivecopy, b, a)
else
ArrayInterface.restructure(a, map(recursivecopy, a))
end
end

function recursivecopy!(b::AbstractArray{T,N},a::AbstractArray{T2,N}) where {T<:StaticArray,T2<:StaticArray,N}
Expand Down
18 changes: 17 additions & 1 deletion test/copy_static_array_test.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Test, RecursiveArrayTools, StaticArrays
using Test, RecursiveArrayTools, StaticArrays, StructArrays

struct ImmutableFV <: FieldVector{2,Float64}
a::Float64
Expand Down Expand Up @@ -64,3 +64,19 @@ a[2][1] *= 5
b[1] = 2*b[1]
copyat_or_push!(a, 2, b[1])
@test a[2] == b[1]

# StructArray of Immutable FieldVector
a = StructArray([ImmutableFV(1., 2.)])
b = recursivecopy(a)
@test typeof(a) == typeof(b)
@test a[1] == b[1]
a[1] *= 2
@test a[1] != b[1]

# StructArray of Mutable FieldVector
a = StructArray([MutableFV(1., 2.)])
b = recursivecopy(a)
@test typeof(a) == typeof(b)
@test a[1] == b[1]
a[1] *= 2
@test a[1] != b[1]