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-
91function recursivecopy (a)
102 deepcopy (a)
113end
12-
13- recursivecopy (a:: Number ) = copy (a)
14-
4+ recursivecopy (a:: Union{SVector,SMatrix,SArray,Number} ) = copy (a)
155function recursivecopy (a:: AbstractArray{T,N} ) where {T<: Number ,N}
166 copy (a)
177end
6656
6757function copyat_or_push! (a:: AbstractVector{T} ,i:: Int ,x,nc:: Type{Val{perform_copy}} = Val{true }) where {T,perform_copy}
6858 @inbounds if length (a) >= i
69- if T <: Number || T <: SArray || (T <: FieldVector && ! is_mutable_type (T) ) || ! perform_copy
59+ if ! ismutable (T ) || ! perform_copy
7060 # TODO : Check for `setindex!`` if T <: StaticArray and use `copy!(b[i],a[i])`
7161 # or `b[i] = a[i]`, see https://github.com/JuliaDiffEq/RecursiveArrayTools.jl/issues/19
7262 a[i] = x
@@ -75,16 +65,7 @@ function copyat_or_push!(a::AbstractVector{T},i::Int,x,nc::Type{Val{perform_copy
7565 end
7666 else
7767 if perform_copy
78- if typeof (x) <: Array && ! (eltype (x) <: Number )
79- push! (a,recursivecopy (x))
80- elseif typeof (x) <: Array || typeof (x) <: ArrayPartition ||
81- typeof (x) <: AbstractVectorOfArray
82- push! (a,copy (x))
83- elseif typeof (x) <: Union{SVector,SMatrix,SArray,Number} # Only immutable
84- push! (a,x)
85- else
86- push! (a,deepcopy (x))
87- end
68+ push! (a,recursivecopy (x))
8869 else
8970 push! (a,x)
9071 end
0 commit comments