I am trying to come up with a function that gives me a recursive type without a single element. So, for example, to shorten it, call him ruet, I would like:
A = zeros(5,5)
reut(A) == Float64
using Unitful
A = zeros(5,5)*1u"kg"
reut(A) == Float64
AA = [zeros(5,5) for i in 1:5]
reut(AA) == Array{Float64,2}
AofA = [copy(A) for i in 1:5]
reut(AofA) == Array{Float64,2}
using StaticArrays
AofSA = [@SVector [2.0,3.0] for i in 1:5]
reut(AofSA) == SVector{2,Float64}
AofuSA = [@SVector [2.0u"kg",3.0u"kg"] for i in 1:5]
reut(AofuSA) == SVector{2,Float64}
So basically separate the blocks, but return the correct element type, which could be an array. This is an array that is heavy. I can recurs:
recursive_eltype(a) = recursive_eltype(eltype(a))
recursive_eltype{T<:Number}(a::Type{T}) = eltype(a)
and then get the type without a single element:
uEltype = recursive_eltype(u)
uEltypeNoUnits = typeof(one(uEltype))
but then it is always a type of number, and I cannot find a good way to return array types when it is an array of arrays, i.e. this method returns Float64in all the examples above. I am wondering if sending to static arrays is required and using similar_typehere.
, , , , Unitful.jl. one(u), , .
( : https://github.com/JuliaLang/julia/issues/22216)