Theoretica
A C++ numerical and automatic mathematical library
|
A generic matrix with a fixed number of rows and columns. More...
#include <mat.h>
Public Types | |
using | iterator = mat_iterator< mat< Type, N, K >, Type & > |
Iterator for statically allocated matrices. | |
using | const_iterator = mat_iterator< const mat< Type, N, K >, const Type & > |
Const iterator for statically allocated matrices. | |
Public Member Functions | |
mat () | |
Default constructor. | |
template<typename Matrix > | |
mat (const Matrix &m) | |
Copy constructor. | |
template<typename T = Type> | |
mat (const std::initializer_list< std::initializer_list< T > > &rows) | |
Constructs a matrix from an initializer list. | |
mat (Type diagonal, unsigned int n=0, unsigned int k=0) | |
Constructor that initializes a diagonal matrix with equal entries on the diagonal. | |
template<typename Matrix > | |
mat< Type, N, K > & | operator= (const Matrix &other) |
Assignment operator to copy from another matrix. | |
void | make_zeroes () |
Sets all elements of the matrix to zero. | |
template<typename Matrix > | |
mat< Type, N, K > | operator+ (const Matrix &other) const |
Matrix addition. | |
template<typename Matrix > | |
mat< Type, N, K > | operator- (const Matrix &other) const |
Matrix subtraction. | |
mat< Type, N, K > | operator* (Type scalar) const |
Scalar multiplication. | |
mat< Type, N, K > | operator/ (Type scalar) const |
Scalar division. | |
template<typename Vector > | |
Vector | transform (const Vector &v) const |
Transforms a vector by multiplying it with the matrix. | |
vec< Type, N > | transform (const vec< Type, K > &v) const |
Transforms a fixed-size vector by multiplying it with the matrix. | |
vec< Type, N > | operator* (const vec< Type, K > &v) const |
Overloads the * operator to transform a fixed-size vector by the matrix. | |
template<unsigned int M> | |
mat< Type, N, M > | mul (const mat< Type, K, M > &B) const |
Matrix multiplication for matrices with different column counts. | |
template<typename Matrix > | |
Matrix | mul (const Matrix &B) const |
Matrix multiplication for matrices with any type. | |
template<typename Matrix > | |
auto | operator* (const Matrix &B) const |
Overloads the * operator for matrix multiplication. | |
template<typename Matrix > | |
mat< Type, N, K > & | operator+= (const Matrix &other) |
Matrix addition. | |
template<typename Matrix > | |
mat< Type, N, K > & | operator-= (const Matrix &other) |
Matrix subtraction. | |
mat< Type, N, K > & | operator*= (Type scalar) |
Scalar multiplication. | |
mat< Type, N, K > & | operator/= (Type scalar) |
Scalar division. | |
template<typename Matrix > | |
mat< Type, N, K > & | operator*= (const Matrix &B) |
Matrix multiplication with an assignment operator. | |
mat< Type, N, K > & | transpose () |
Transposes the matrix in place. | |
Type & | at (unsigned int i, unsigned int j) |
Accesses the element at the given row and column. | |
const Type & | at (unsigned int i, unsigned int j) const |
Accesses the element at the given row and column. | |
Type & | operator() (unsigned int i, unsigned int j) |
Overloads the () operator to access an element. | |
const Type & | operator() (unsigned int i, unsigned int j) const |
Overloads the () operator to access an element. | |
Type | get (unsigned int i, unsigned int j) const |
Gets the element at the specified row and column. | |
auto | begin () |
Returns an iterator to the first element of the matrix. | |
auto | end () |
Returns an iterator to one past the last element of the matrix. | |
auto | begin () const |
Returns a const iterator to the first element of the matrix. | |
auto | end () const |
Returns a const iterator to one past the last element of the matrix. | |
TH_CONSTEXPR unsigned int | rows () const |
Returns the number of rows in the matrix. | |
TH_CONSTEXPR unsigned int | cols () const |
Returns the number of columns in the matrix. | |
unsigned int | size () const |
Returns the total number of elements in the matrix. | |
template<typename Matrix > | |
bool | operator== (const Matrix &other) const |
Checks whether this matrix is equal to another matrix element-wise. | |
template<typename Matrix > | |
bool | operator!= (const Matrix &other) const |
Checks whether this matrix is not equal to another matrix element-wise. | |
mat< Type, N, K > & | invert () |
Inverts the matrix in place. | |
mat< Type, N, K > | resize (unsigned int n, unsigned int k) const |
Compatibility function to allow for allocation or resizing of dynamic matrices. | |
std::string | to_string (std::string separator=", ", bool parenthesis=true) const |
Converts the matrix to a string representation. | |
operator std::string () | |
Convert the matrix to string representation. | |
Public Attributes | |
Type | data [K][N] |
Friends | |
mat< Type, N, K > | operator* (Type a, const mat< Type, N, K > &B) |
Friend operator for scalar multiplication (T * mat). | |
template<typename VecType , unsigned int M> | |
vec< VecType, K > | operator* (const vec< VecType, M > &a, const mat< Type, N, K > &B) |
Friend operator for vector-matrix multiplication. | |
std::ostream & | operator<< (std::ostream &out, const mat< Type, N, K > &obj) |
Outputs the matrix to an output stream in string format. | |
A generic matrix with a fixed number of rows and columns.
Type | The type of the elements |
N | The number of rows |
K | The number of columns |
|
inline |
Default constructor.
Initializes the matrix with all elements set to zero.
|
inline |
Copy constructor.
Matrix | The type of the matrix to copy from. |
m | The matrix to copy. |
Copies all elements from the given matrix m
into this matrix.
|
inline |
Constructs a matrix from an initializer list.
T | The type of elements in the initializer list (default is Type ). |
rows | An initializer list representing the rows of the matrix. |
Initializes the matrix with values from the initializer list. Ensures that the initializer list matches the size of the matrix (i.e., N
rows and K
columns).
Constructor that initializes a diagonal matrix with equal entries on the diagonal.
The size parameters are required for compatibility with mat<T, 0> and may be used for additional error prevention.
diagonal | The value for the diagonal entries. |
n | Number of rows. |
k | Number of columns. |
Accesses the element at the given row and column.
i | The row index. |
j | The column index. |
Accesses the element at the given row and column.
i | The row index. |
j | The column index. |
|
inline |
Returns an iterator to the first element of the matrix.
|
inline |
Returns a const iterator to the first element of the matrix.
|
inline |
Returns the number of columns in the matrix.
|
inline |
Returns an iterator to one past the last element of the matrix.
|
inline |
Returns a const iterator to one past the last element of the matrix.
Gets the element at the specified row and column.
i | The row index. |
j | The column index. |
Inverts the matrix in place.
This function is only valid for square matrices.
Matrix multiplication for matrices with different column counts.
M | The number of columns in matrix B . |
B | The matrix to multiply with. |
Matrix multiplication for matrices with any type.
Matrix | The type of the matrix to multiply with. |
B | The matrix to multiply with. |
This function multiplies this matrix with another matrix B
. It checks if the number of rows in B
matches the number of columns in this matrix.
|
inline |
Checks whether this matrix is not equal to another matrix element-wise.
Matrix | The type of the other matrix. |
other | The matrix to compare with. |
true
if any elements are unequal, false
otherwise.
|
inline |
Overloads the ()
operator to access an element.
i | The row index. |
j | The column index. |
|
inline |
Overloads the ()
operator to access an element.
i | The row index. |
j | The column index. |
|
inline |
Overloads the *
operator for matrix multiplication.
Matrix | The type of the matrix to multiply with. |
B | The matrix to multiply with. |
|
inline |
Overloads the *
operator to transform a fixed-size vector by the matrix.
v | The vector to transform. |
|
inline |
Scalar multiplication.
scalar | The scalar value to multiply. |
scalar
.
|
inline |
Matrix multiplication with an assignment operator.
Matrix | The type of the matrix to multiply with. |
B | The matrix to multiply with. |
|
inline |
Scalar multiplication.
scalar | The scalar value to multiply with. |
|
inline |
Matrix addition.
Matrix | The type of the matrix to add. |
other | The matrix to add. |
other
to this matrix.
|
inline |
Matrix addition.
Matrix | The type of the matrix to add. |
other | The matrix to add to this matrix. |
|
inline |
Matrix subtraction.
Matrix | The type of the matrix to subtract. |
other | The matrix to subtract. |
other
from this matrix.
|
inline |
Matrix subtraction.
Matrix | The type of the matrix to subtract. |
other | The matrix to subtract from this matrix. |
|
inline |
Scalar division.
scalar | The scalar divisor. |
scalar
.If scalar
is close to zero, an error is raised.
|
inline |
Scalar division.
scalar | The scalar value to divide by. |
If the scalar value is close to zero, this function raises a division by zero error.
|
inline |
Assignment operator to copy from another matrix.
Matrix | The type of the matrix to copy from. |
other | The matrix to copy. |
|
inline |
Checks whether this matrix is equal to another matrix element-wise.
Matrix | The type of the other matrix. |
other | The matrix to compare with. |
true
if all elements are equal, false
otherwise.
|
inline |
Compatibility function to allow for allocation or resizing of dynamic matrices.
Since statically allocated matrices cannot change size, this function only checks whether the target size is the same as the matrix's.
|
inline |
Returns the number of rows in the matrix.
|
inline |
Returns the total number of elements in the matrix.
|
inline |
Converts the matrix to a string representation.
separator | Separator between elements (default is ", "). |
parenthesis | Whether to enclose each row in parentheses (default is true). |
Transforms a fixed-size vector by multiplying it with the matrix.
v | The vector to transform. |
vec<Type, N>
. Transforms a vector by multiplying it with the matrix.
Vector | The type of the vector to transform. |
v | The vector to transform. |
This function multiplies the given vector v
by the matrix. It checks if the size of v
matches the number of columns in the matrix.
Transposes the matrix in place.
This function only works if the matrix is square. An assertion will trigger if the matrix is not square.
Friend operator for vector-matrix multiplication.
VecType | The type of vector elements. |
M | The number of elements in the vector. |
a | The vector to multiply. |
B | The matrix to be multiplied by. |
Friend operator for scalar multiplication (T * mat).
a | The scalar multiplier. |
B | The matrix to be multiplied. |
B
by a
. Outputs the matrix to an output stream in string format.
out | The output stream. |
obj | The matrix to output. |