I have the struct
below that I am trying to make more flexible:
struct PolyFit
x::Vector{Float64}
y::Vector{Float64}
knots::Vector{Int64}
segmentlengths::Vector{Float64}
polys::Vector{Polynomial{Float64, :x}}
RMSE::Float64
end
The performance tips indicate that one way to allow this would be:
struct PolyFit{T1<:AbstractVector,T2<:AbstractVector,T3<:AbstractVector,T4<:AbstractVector,T5<:AbstractVector}
x::T1
y::T2
knots::T3
segmentlenghts::T4
polys::T5
RMSE::Float64
end
but that makes for a pretty ugly composite type signature.
Is there a clean way to promote the element and container types at the same time without too much overhead, so I can use something like the first version? I can’t guarantee that any of the element types or container types will match, but they should promote fine. Vectors might be Ranges and Floats might be Ints. Would the overhead of converting the types be worth it for the faster type performance?
I was going to try:
PolyFit(x::AbstractVector, y::AbstractVector, knots::AbstractVector, segmentlengths::AbstractVector, polys::AbstractVector, RMSE) = PolyFit(collect.((x, y, knots, segmentlengths, polys))..., RMSE)
but that seems like a bad idea for performance and it doesn’t help with the element types.