struct MultiNumber{N, T <: Real} <: Real
data::NTuple{N, T}
end
Where all mathematical operations on a MultiNumber would just apply element-wise. I.e. it would mimic a regular number while actually being multiple numbers beneath. E.g. for a MultiNumber, x, it would allow calculating f(x) with full SIMD support on N inputs.
The Vec struct from SIMD.jl could be used but it has two drawbacks:
It only wraps primitive types so can’t e.g. nest Vecs of Vecs
It is not a <:Real and thus cannot be ForwardDiff’ed.
The StaticVector from StaticArrays.jl also comes quite close, except it is semantically an AbstractVector and not a Real. Hence all operations must be dotted.
Does something like this exist - or should I roll my own? And could it have broader applicability besides just my own narrow interests?
julia> x = StaticParticles([1.0, 2.0])
1.5 ± 0.707 StaticParticles{Float64, 2}
julia> x^2 + 0.1 |> Base.Fix2(getfield, :particles)
2-element StaticArraysCore.SVector{2, Float64} with indices SOneTo(2):
1.1
4.1
julia> x isa Real
true