My goal is to create a new type, let’s say MultiVector
which contains an MVector{2^N,T}
with 2^N
elements, but I am going to define an unusual type of indexing on MultiVector
using multivector blades.
With standard arrays, this would look like this
mutable struct MultiVector{T}
N::UInt8
v::Vector{T}
end
function Base.getindex(m::MultiVector, i::Int)
0 <= i <= m.N || throw(BoundsError(m, i))
r = sum([binomial(Int(m.N),k) for k ∈ 0:i-1])
return @view m.v[r+1:r+binomial(Int(m.N),i)]
end
with the expected behavior like this
julia> g = MultiVector{Int}(2,[3,4,5,6])
MultiVector{Int64}(0x02, [3, 4, 5, 6])
julia> g[0]
1-element view(::Array{Int64,1}, 1:1) with eltype Int64:
3
julia> g[1]
2-element view(::Array{Int64,1}, 2:3) with eltype Int64:
4
5
julia> g[2]
1-element view(::Array{Int64,1}, 4:4) with eltype Int64:
6
However, now I would like to use StaticArrays
instead of the standard Array
, so I could do
mutable struct MultiVector
N::UInt8
v::MVector
end
However, what if I also want to include the parametric type T
and also specify the size 2^N
, since I am going to be dealing with MVector{2^N,T}
essentially. Note that the behavior of MultiVector
is going to be different because the indexing is based on a completely different concept.
This is going to be part of my Multivectors
package
So basically this is a question about parametric types, what is the best way to specify T
and N
in the type?