Qualpal
Repositories

qualpal::Matrix

C++ · cpp · 4.1.0

template<typename T> class qualpal::Matrix

Dynamic matrix class with runtime-determined dimensions.

Template parameters

T

Element type (typically double or float).

Stores elements in column-major order (Fortran-style). Provides element access, transposition, and dimension queries.

Example:

Matrix<double> mat(2, 3); // 2 rows, 3 columns
mat(0, 1) = 5.0;          // Set element at row 0, column 1
double v = mat(1, 2);     // Get element at row 1, column 2

See also

FixedMatrix for compile-time sized matrices

Methods

Matrix

Matrix

inline Matrix()

Default constructor creates an empty matrix (0x0).

Matrix

inline Matrix(std::size_t rows, std::size_t cols)

Construct matrix with specified dimensions.

Parameters

rows

Number of rows

cols

Number of columns

Matrix

inline Matrix(std::size_t rows, std::size_t cols, const std::vector<T> & data)

Construct matrix with specified dimensions and data.

Parameters

rows

Number of rows

cols

Number of columns

data

Vector containing matrix elements in column-major order

ncol

inline std::size_t ncol() const

Get number of columns.

nrow

inline std::size_t nrow() const

Get number of rows.

operator()

operator()

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 column-major order: data[col * nrow + row].

Throws

std::out_of_range

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

operator()

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 column-major order: data[col * nrow + row].

Throws

std::out_of_range

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

transpose

inline Matrix<T> transpose() const

Create transpose of this matrix.

Returns

New matrix that is the transpose of this matrix