Qualpal
Repositories

qualpal::FixedMatrix

C++ · cpp · 4.1.0

template<typename T, std::size_t rows, std::size_t cols> class qualpal::FixedMatrix

Fixed-size matrix class with compile-time dimensions.

Template parameters

T

Element type (typically double or float).

rows

Number of rows (compile-time constant).

cols

Number of columns (compile-time constant).

Stores elements in row-major order (C-style). Provides constexpr element access, arithmetic, and multiplication.

Example:

FixedMatrix<double, 2, 3> mat = { {1.0, 2.0, 3.0}, {4.0, 5.0, 6.0} };
double v = mat(1, 2); // Access element at row 1, column 2

See also

Matrix for dynamic-sized matrices

Methods

FixedMatrix

FixedMatrix

constexpr inline constexpr FixedMatrix()

Default constructor - elements are zero-initialized.

FixedMatrix

constexpr inline constexpr FixedMatrix(std::initializer_list<std::initializer_list<T>> list)

Construct from nested initializer list.

Parameters

list

Nested initializer list of matrix elements

fill

constexpr inline void fill(const T & value)

Fill all elements with specified value.

operator()

operator()

constexpr inline T & operator()(std::size_t row, std::size_t col)

Access matrix element (mutable).

Parameters

row

Row index (0-based).

col

Column index (0-based).

Returns

Reference to element at (row, col).

Note

Elements are stored in row-major order: data[row * cols + col].

Throws

std::out_of_range

if indices are out of bounds (in debug builds).

operator()

constexpr inline const T & operator()(std::size_t row, std::size_t col) const

Access matrix element (const).

Parameters

row

Row index (0-based).

col

Column index (0-based).

Returns

Const reference to element at (row, col).

Note

Elements are stored in row-major order: data[row * cols + col].

Throws

std::out_of_range

if indices are out of bounds (in debug builds).

operator*

operator*

constexpr inline Matrix<T> operator*(const Matrix<T> & other) const

Matrix-matrix multiplication (FixedMatrix * dynamic Matrix).

Parameters

other

Dynamic matrix to multiply with

Returns

Result as dynamic Matrix

operator*

constexpr inline FixedMatrix<T, rows, cols> operator*(const T & scalar) const

Scalar multiplication.

Parameters

scalar

Value to multiply all elements by

Returns

New matrix with all elements multiplied by scalar

operator*

constexpr inline std::array<T, rows> operator*(const std::array<T, cols> & vec) const

Matrix-vector multiplication.

Parameters

vec

Vector to multiply with (must have 'cols' elements)

Returns

Result vector with 'rows' elements

operator*

template<std::size_t other_cols> constexpr inline FixedMatrix<T, rows, other_cols> operator*(const FixedMatrix<T, cols, other_cols> & other) const

Matrix-matrix multiplication (FixedMatrix * FixedMatrix).

Template parameters

other_cols

Number of columns in the other matrix.

Parameters

other

The matrix to multiply with (must have 'cols' rows).

Returns

Result matrix with dimensions (rows × other_cols).

operator+

constexpr inline FixedMatrix<T, rows, cols> operator+(const FixedMatrix<T, rows, cols> & other) const

Matrix addition.

Parameters

other

Matrix to add (must have same dimensions)

Returns

New matrix containing element-wise sum

operator-

constexpr inline FixedMatrix<T, rows, cols> operator-(const FixedMatrix<T, rows, cols> & other) const

Matrix subtraction.

Parameters

other

Matrix to subtract (must have same dimensions)

Returns

New matrix containing element-wise difference

t

constexpr inline FixedMatrix<T, cols, rows> t() const

Create transpose of this matrix.

Returns

New FixedMatrix that is the transpose of this matrix

zeros

constexpr inline void zeros()

Set all elements to zero.