Skip to content

Commit 4999bca

Browse files
committed
check for mutable FieldVector
1 parent 9065539 commit 4999bca

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/utils.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
"""
2+
is_mutable_type(x::DataType)
3+
4+
Query whether a type is mutable or not, see
5+
https://github.com/JuliaDiffEq/RecursiveArrayTools.jl/issues/19.
6+
"""
7+
Base.@pure is_mutable_type(x::DataType) = x.mutable
8+
9+
110
function recursivecopy{T<:Number,N}(a::AbstractArray{T,N})
211
copy(a)
312
end
@@ -52,9 +61,9 @@ end
5261

5362
@inline function copyat_or_push!{T,perform_copy}(a::AbstractVector{T},i::Int,x,nc::Type{Val{perform_copy}}=Val{true})
5463
@inbounds if length(a) >= i
55-
if T <: Number || T <: StaticArray || !perform_copy
64+
if T <: Number || T <: SArray || (T <: FieldVector && !is_mutable_type(T)) || !perform_copy
5665
# TODO: Check for `setindex!`` if T <: StaticArray and use `copy!(b[i],a[i])`
57-
# or `b[i] = a[i]`, see #19
66+
# or `b[i] = a[i]`, see https://github.com/JuliaDiffEq/RecursiveArrayTools.jl/issues/19
5867
a[i] = x
5968
else
6069
recursivecopy!(a[i],x)

test/copy_static_array_test.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ a[1][1] *= 5
3232
@test a[1] != b[1]
3333
copyat_or_push!(a, 2, b[1])
3434
@test a[2] == b[1]
35+
a[2][1] *= 5
36+
@test a[2] != b[1]
3537
b[1] = 2*b[1]
3638
copyat_or_push!(a, 2, b[1])
3739
@test a[2] == b[1]
@@ -57,6 +59,8 @@ a[1][1] *= 5
5759
@test a[1] != b[1]
5860
copyat_or_push!(a, 2, b[1])
5961
@test a[2] == b[1]
62+
a[2][1] *= 5
63+
@test a[2] != b[1]
6064
b[1] = 2*b[1]
6165
copyat_or_push!(a, 2, b[1])
6266
@test a[2] == b[1]

0 commit comments

Comments
 (0)