MMatrix in struct

I wish to define a struct, containing a square MMatrix. The number of rows / columns is N. I tried to do this as

mutable struct my_struct{N, T <: AbstractFloat}
    a::MVector{N, T}
    b::MMatrix{N, N, T, N * N}
end

but this does not work as N * N is not defined in general. How can I specify that N is a integer value? Thanks.

One approach could be to add another parameter.

mutable struct my_struct{N, T <: AbstractFloat, L}
    a::MVector{N, T}
    b::MMatrix{N, N, T, L}
end

my_struct(@MVector([1.0,2]), @MMatrix( [1.0 2; 2 3]))

This works since the parameter L can be determined at construction: API · StaticArrays.jl

1 Like