I have tried to use a Vector of StaticArrays inside an ArrayPartition. This led to a non-trivial problem with DifferentialEquations.jl, when I tried to use such an ArrayPartition as the state vector for an ODE: the resulting element type of ArrayPartition happened to be Any and it broke recursive_unitless_bottom_eltype function which is used somewhere inside DifferentialEquations.jl.
In order to illustrate this, consider the following example:
using RecursiveArrayTools, StaticArrays
a = ArrayPartition((zeros(Float64, 10), zeros(SVector{3,Float64}, 10)))
The output of typeof(a) is
ArrayPartition{Any,Tuple{Array{Float64,1},Array{SArray{Tuple{3},Float64,1,3},1}}}
And if you try to do recursive_unitless_bottom_eltype(a), you get a never-ending recursion:
ERROR: StackOverflowError:
Stacktrace:
[1] recursive_unitless_bottom_eltype(::Type{Any}) at ~/.julia/packages/RecursiveArrayTools/BVS4M/src/utils.jl:86 (repeats 79984 times)
In the example I provided, it would be logical if the element type of ArrayPartition is Float64. It seems that we can get such behaviour if we slightly change the constructor for ArrayPartition:
function ArrayPartition(x::S, ::Type{Val{copy_x}}=Val{false}) where {S<:Tuple,copy_x}
T = promote_type(recursive_bottom_eltype.(x)...)
if copy_x
return ArrayPartition{T,S}(copy.(x))
else
return ArrayPartition{T,S}(x)
end
end
The only change I propose to make is to replace eltype with recursive_bottom_eltype in the type promotion. Potentially, this solution can deal with any kind of crazy nesting of arrays.
I have tried to use a
VectorofStaticArrays inside anArrayPartition. This led to a non-trivial problem with DifferentialEquations.jl, when I tried to use such anArrayPartitionas the state vector for an ODE: the resulting element type ofArrayPartitionhappened to beAnyand it brokerecursive_unitless_bottom_eltypefunction which is used somewhere inside DifferentialEquations.jl.In order to illustrate this, consider the following example:
The output of
typeof(a)isAnd if you try to do
recursive_unitless_bottom_eltype(a), you get a never-ending recursion:In the example I provided, it would be logical if the element type of
ArrayPartitionisFloat64. It seems that we can get such behaviour if we slightly change the constructor forArrayPartition:The only change I propose to make is to replace
eltypewithrecursive_bottom_eltypein the type promotion. Potentially, this solution can deal with any kind of crazy nesting of arrays.