anpcpp 0.1.0
Analytic Network Process computational library
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Friends | List of all members
anpcpp::Matrix Class Reference

Dense row-major matrix stored in a flat buffer. More...

#include <matrix.hpp>

Public Member Functions

 Matrix ()=default
 Default-constructs a 0x0 matrix.
 
 Matrix (std::size_t rows, std::size_t cols, double fill=0.0)
 Constructs an rows by cols matrix filled with fill.
 
 Matrix (const Matrix &)=default
 Copy constructor.
 
 Matrix (Matrix &&) noexcept=default
 Move constructor.
 
Matrixoperator= (const Matrix &)=default
 Copy assignment.
 
Matrixoperator= (Matrix &&) noexcept=default
 Move assignment.
 
std::size_t rows () const noexcept
 
std::size_t cols () const noexcept
 
bool empty () const noexcept
 
double & operator() (std::size_t i, std::size_t j)
 Mutable element access.
 
const double & operator() (std::size_t i, std::size_t j) const
 Const element access.
 
double * data () noexcept
 
const double * data () const noexcept
 
Matrix operator+ (const Matrix &other) const
 Element-wise addition.
 
Matrix operator- (const Matrix &other) const
 Element-wise subtraction.
 
Matrix operator* (double scalar) const
 Scalar multiplication.
 
Matrix operator* (const Matrix &other) const
 Matrix product (this * other).
 
Vector operator* (const Vector &v) const
 Matrix-vector product.
 
Matrixoperator+= (const Matrix &other)
 In-place element-wise addition.
 
Matrixoperator-= (const Matrix &other)
 In-place element-wise subtraction.
 
Matrixoperator*= (double scalar)
 In-place scalar multiplication.
 
Matrix transposed () const
 
Vector row_sums () const
 
Vector col_sums () const
 
void normalize_rows ()
 Divides each row by its sum; zero-sum rows are unchanged.
 
void normalize_cols ()
 Divides each column by its sum; zero-sum columns are unchanged.
 
Matrix rows_normalized () const
 
Matrix cols_normalized () const
 
bool is_equal (const Matrix &other, double abs_tol=1e-12) const
 Per-element absolute tolerance equality.
 
bool is_near (const Matrix &other, double abs_tol=1e-9, double rel_tol=1e-9) const
 Absolute and relative tolerance equality.
 

Static Public Member Functions

static Matrix identity (std::size_t n)
 
static Matrix zeros (std::size_t rows, std::size_t cols)
 
static Matrix ones (std::size_t rows, std::size_t cols)
 

Friends

Matrix operator* (double scalar, const Matrix &m)
 Scalar multiplication from the left.
 

Detailed Description

Dense row-major matrix stored in a flat buffer.

Element (i, j) is at index i * cols() + j.

Constructor & Destructor Documentation

◆ Matrix()

anpcpp::Matrix::Matrix ( std::size_t  rows,
std::size_t  cols,
double  fill = 0.0 
)

Constructs an rows by cols matrix filled with fill.

Exceptions
DimensionErrorif exactly one of rows or cols is zero.

Member Function Documentation

◆ col_sums()

Vector anpcpp::Matrix::col_sums ( ) const
Returns
Vector of column sums.

◆ cols()

std::size_t anpcpp::Matrix::cols ( ) const
inlinenoexcept
Returns
Column count.

◆ cols_normalized()

Matrix anpcpp::Matrix::cols_normalized ( ) const
Returns
Copy with columns L1-normalized.

◆ data() [1/2]

const double * anpcpp::Matrix::data ( ) const
inlinenoexcept
Returns
Pointer to row-major contiguous storage (const).

◆ data() [2/2]

double * anpcpp::Matrix::data ( )
inlinenoexcept
Returns
Pointer to row-major contiguous storage (mutable).

◆ empty()

bool anpcpp::Matrix::empty ( ) const
inlinenoexcept
Returns
True if either dimension is zero.

◆ identity()

static Matrix anpcpp::Matrix::identity ( std::size_t  n)
static
Returns
n x n identity matrix.

◆ ones()

static Matrix anpcpp::Matrix::ones ( std::size_t  rows,
std::size_t  cols 
)
static
Returns
Matrix filled with ones.

◆ operator()() [1/2]

double & anpcpp::Matrix::operator() ( std::size_t  i,
std::size_t  j 
)

Mutable element access.

Parameters
iRow index (0-based).
jColumn index (0-based).
Exceptions
DimensionErrorif out of range.

◆ operator()() [2/2]

const double & anpcpp::Matrix::operator() ( std::size_t  i,
std::size_t  j 
) const

Const element access.

Parameters
iRow index (0-based).
jColumn index (0-based).
Exceptions
DimensionErrorif out of range.

◆ operator*() [1/2]

Matrix anpcpp::Matrix::operator* ( const Matrix other) const

Matrix product (this * other).

Exceptions
DimensionErrorif cols() != other.rows().

◆ operator*() [2/2]

Vector anpcpp::Matrix::operator* ( const Vector v) const

Matrix-vector product.

Exceptions
DimensionErrorif cols() != v.size().

◆ operator+()

Matrix anpcpp::Matrix::operator+ ( const Matrix other) const

Element-wise addition.

Exceptions
DimensionErroron shape mismatch.

◆ operator-()

Matrix anpcpp::Matrix::operator- ( const Matrix other) const

Element-wise subtraction.

Exceptions
DimensionErroron shape mismatch.

◆ row_sums()

Vector anpcpp::Matrix::row_sums ( ) const
Returns
Vector of row sums.

◆ rows()

std::size_t anpcpp::Matrix::rows ( ) const
inlinenoexcept
Returns
Row count.

◆ rows_normalized()

Matrix anpcpp::Matrix::rows_normalized ( ) const
Returns
Copy with rows L1-normalized.

◆ transposed()

Matrix anpcpp::Matrix::transposed ( ) const
Returns
Transpose (cols x rows).

◆ zeros()

static Matrix anpcpp::Matrix::zeros ( std::size_t  rows,
std::size_t  cols 
)
static
Returns
Matrix filled with zeros.

The documentation for this class was generated from the following file: