Theoretica
A C++ numerical and automatic mathematical library
theoretica::mat< Type, N, K > Class Template Reference

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. More...
 
template<typename Matrix >
 mat (const Matrix &m)
 Copy constructor. More...
 
template<typename T = Type>
 mat (const std::initializer_list< std::initializer_list< T >> &rows)
 Constructs a matrix from an initializer list. More...
 
 mat (Type diagonal, unsigned int n=0, unsigned int k=0)
 Constructor that initializes a diagonal matrix with equal entries on the diagonal. More...
 
template<typename Matrix >
mat< Type, N, K > & operator= (const Matrix &other)
 Assignment operator to copy from another matrix. More...
 
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. More...
 
template<typename Matrix >
mat< Type, N, K > operator- (const Matrix &other) const
 Matrix subtraction. More...
 
mat< Type, N, K > operator* (Type scalar) const
 Scalar multiplication. More...
 
mat< Type, N, K > operator/ (Type scalar) const
 Scalar division. More...
 
template<typename Vector >
Vector transform (const Vector &v) const
 Transforms a vector by multiplying it with the matrix. More...
 
vec< Type, N > transform (const vec< Type, K > &v) const
 Transforms a fixed-size vector by multiplying it with the matrix. More...
 
vec< Type, N > operator* (const vec< Type, K > &v) const
 Overloads the * operator to transform a fixed-size vector by the matrix. More...
 
template<unsigned int M>
mat< Type, N, M > mul (const mat< Type, K, M > &B) const
 Matrix multiplication for matrices with different column counts. More...
 
template<typename Matrix >
Matrix mul (const Matrix &B) const
 Matrix multiplication for matrices with any type. More...
 
template<typename Matrix >
auto operator* (const Matrix &B) const
 Overloads the * operator for matrix multiplication. More...
 
template<typename Matrix >
mat< Type, N, K > & operator+= (const Matrix &other)
 Matrix addition. More...
 
template<typename Matrix >
mat< Type, N, K > & operator-= (const Matrix &other)
 Matrix subtraction. More...
 
mat< Type, N, K > & operator*= (Type scalar)
 Scalar multiplication. More...
 
mat< Type, N, K > & operator/= (Type scalar)
 Scalar division. More...
 
template<typename Matrix >
mat< Type, N, K > & operator*= (const Matrix &B)
 Matrix multiplication with an assignment operator. More...
 
mat< Type, N, K > & transpose ()
 Transposes the matrix in place. More...
 
mat< Type, K, N > transposed () const
 Returns a transposed version of the matrix. More...
 
Type & at (unsigned int i, unsigned int j)
 Accesses the element at the given row and column. More...
 
const Type & at (unsigned int i, unsigned int j) const
 Accesses the element at the given row and column. More...
 
Type & operator() (unsigned int i, unsigned int j)
 Overloads the () operator to access an element. More...
 
const Type & operator() (unsigned int i, unsigned int j) const
 Overloads the () operator to access an element. More...
 
Type get (unsigned int i, unsigned int j) const
 Gets the element at the specified row and column. More...
 
auto begin ()
 Returns an iterator to the first element of the matrix. More...
 
auto end ()
 Returns an iterator to one past the last element of the matrix. More...
 
auto begin () const
 Returns a const iterator to the first element of the matrix. More...
 
auto end () const
 Returns a const iterator to one past the last element of the matrix. More...
 
TH_CONSTEXPR unsigned int rows () const
 Returns the number of rows in the matrix. More...
 
TH_CONSTEXPR unsigned int cols () const
 Returns the number of columns in the matrix. More...
 
unsigned int size () const
 Returns the total number of elements in the matrix. More...
 
template<typename Matrix >
bool operator== (const Matrix &other) const
 Checks whether this matrix is equal to another matrix element-wise. More...
 
template<typename Matrix >
bool operator!= (const Matrix &other) const
 Checks whether this matrix is not equal to another matrix element-wise. More...
 
bool is_square () const
 Checks if the matrix is square. More...
 
bool is_diagonal () const
 Checks if the matrix is diagonal. More...
 
bool is_symmetric () const
 Checks if the matrix is symmetric. More...
 
real density (real tolerance=1E-12)
 Compute the density of the matrix, counting the proportion of non-zero (bigger in module than the given tolerance) elements with respect to the total number of elements. More...
 
real sparsity (real tolerance=1E-12)
 Compute the sparsity of the matrix, counting the proportion of zero (smaller in module than the given tolerance) elements with respect to the total number of elements. More...
 
Type trace ()
 Computes the trace of the matrix. More...
 
Type diagonal_product ()
 Computes the product of the diagonal elements. More...
 
Type det () const
 Computes the determinant of the matrix. More...
 
mat< Type, N, K > inverse () const
 Computes the inverse of the matrix. More...
 
mat< Type, N, K > & invert ()
 Inverts the matrix in place. More...
 
mat< Type, N, K > resize (unsigned int n, unsigned int k) const
 Compatibility function to allow for allocation or resizing of dynamic matrices. More...
 
std::string to_string (std::string separator=", ", bool parenthesis=true) const
 Converts the matrix to a string representation. More...
 
 operator std::string ()
 Convert the matrix to string representation.
 

Static Public Member Functions

static mat< Type, N, K > zeroes ()
 Returns a null matrix with all elements set to zero. More...
 
static mat< Type, N, K > identity ()
 Returns the identity matrix. More...
 
static mat< Type, N, K > diagonal (Type diag)
 Returns a diagonal matrix with the specified diagonal element. More...
 
template<typename Vector = vec<real, N - 1>>
static mat< Type, N, K > translation (Vector &&t)
 Returns a 4x4 matrix for translation by the vector {x, y, z}. More...
 
static mat< Type, N, K > rotation_2d (real theta)
 Returns a matrix for 2D rotation by theta radians. More...
 
static mat< Type, N, K > rotation_3d_xaxis (real theta)
 Returns a matrix for 3D rotation around the x-axis. More...
 
static mat< Type, N, K > rotation_3d_yaxis (real theta)
 Returns a matrix for 3D rotation around the y-axis. More...
 
static mat< Type, N, K > rotation_3d_zaxis (real theta)
 Returns a matrix for 3D rotation around the z-axis. More...
 
template<typename Vector = vec<real, 3>>
static mat< Type, N, K > rotation_3d (real theta, Vector &&axis)
 Returns a matrix for 3D rotation around an arbitrary axis. More...
 
static mat< Type, N, K > perspective (real left, real right, real bottom, real top, real near, real far)
 Returns a perspective projection matrix. More...
 
static mat< Type, N, K > perspective_fov (real fov, real aspect, real near, real far)
 Returns a perspective projection matrix based on field of view. More...
 
static mat< Type, N, K > ortho (real left, real right, real bottom, real top, real near, real far)
 Returns an orthographic projection matrix. More...
 
template<typename Vector1 , typename Vector2 , typename Vector3 >
static mat< Type, 4, 4 > look_at (const Vector1 &camera, const Vector2 &target, const Vector3 &up)
 Return a 4x4 transformation matrix that points the field of view towards a given point from the <camera> point. More...
 
static mat< Type, N, K > symplectic (unsigned int n=0, unsigned int k=0)
 A symplectic NxN matrix, where \(N = 2K\) for some natural K. More...
 

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). More...
 
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. More...
 
std::ostream & operator<< (std::ostream &out, const mat< Type, N, K > &obj)
 Outputs the matrix to an output stream in string format. More...
 

Detailed Description

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
class theoretica::mat< Type, N, K >

A generic matrix with a fixed number of rows and columns.

Parameters
TypeThe type of the elements
NThe number of rows
KThe number of columns

Constructor & Destructor Documentation

◆ mat() [1/4]

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
theoretica::mat< Type, N, K >::mat ( )
inline

Default constructor.

Initializes the matrix with all elements set to zero.

◆ mat() [2/4]

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
template<typename Matrix >
theoretica::mat< Type, N, K >::mat ( const Matrix &  m)
inline

Copy constructor.

Template Parameters
MatrixThe type of the matrix to copy from.
Parameters
mThe matrix to copy.

Copies all elements from the given matrix m into this matrix.

◆ mat() [3/4]

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
template<typename T = Type>
theoretica::mat< Type, N, K >::mat ( const std::initializer_list< std::initializer_list< T >> &  rows)
inline

Constructs a matrix from an initializer list.

Template Parameters
TThe type of elements in the initializer list (default is Type).
Parameters
rowsAn 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).

◆ mat() [4/4]

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
theoretica::mat< Type, N, K >::mat ( Type  diagonal,
unsigned int  n = 0,
unsigned int  k = 0 
)
inline

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.

Parameters
diagonalThe value for the diagonal entries.
nNumber of rows.
kNumber of columns.

Member Function Documentation

◆ at() [1/2]

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
Type& theoretica::mat< Type, N, K >::at ( unsigned int  i,
unsigned int  j 
)
inline

Accesses the element at the given row and column.

Parameters
iThe row index.
jThe column index.
Returns
A reference to the element at position (i, j).

◆ at() [2/2]

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
const Type& theoretica::mat< Type, N, K >::at ( unsigned int  i,
unsigned int  j 
) const
inline

Accesses the element at the given row and column.

Parameters
iThe row index.
jThe column index.
Returns
A constant reference to the element at position (i, j).

◆ begin() [1/2]

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
auto theoretica::mat< Type, N, K >::begin ( )
inline

Returns an iterator to the first element of the matrix.

Returns
An iterator to the beginning of the matrix.

◆ begin() [2/2]

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
auto theoretica::mat< Type, N, K >::begin ( ) const
inline

Returns a const iterator to the first element of the matrix.

Returns
A const iterator to the beginning of the matrix.

◆ cols()

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
TH_CONSTEXPR unsigned int theoretica::mat< Type, N, K >::cols ( ) const
inline

Returns the number of columns in the matrix.

Returns
The number of columns.

◆ density()

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
real theoretica::mat< Type, N, K >::density ( real  tolerance = 1E-12)
inline

Compute the density of the matrix, counting the proportion of non-zero (bigger in module than the given tolerance) elements with respect to the total number of elements.

Parameters
toleranceThe minimum tolerance in absolute value to consider an element non-zero.
Returns
A real number between 0 and 1 representing the proportion of non-zero elements of the matrix.

◆ det()

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
Type theoretica::mat< Type, N, K >::det ( ) const
inline

Computes the determinant of the matrix.

Returns
The determinant.

This function is only valid for square matrices.

◆ diagonal()

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
static mat<Type, N, K> theoretica::mat< Type, N, K >::diagonal ( Type  diag)
inlinestatic

Returns a diagonal matrix with the specified diagonal element.

Parameters
diagThe value for the diagonal elements.
Returns
A diagonal matrix with the given diagonal value.

◆ diagonal_product()

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
Type theoretica::mat< Type, N, K >::diagonal_product ( )
inline

Computes the product of the diagonal elements.

Returns
The product of diagonal elements.

◆ end() [1/2]

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
auto theoretica::mat< Type, N, K >::end ( )
inline

Returns an iterator to one past the last element of the matrix.

Returns
An iterator to the end of the matrix.

◆ end() [2/2]

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
auto theoretica::mat< Type, N, K >::end ( ) const
inline

Returns a const iterator to one past the last element of the matrix.

Returns
A const iterator to the end of the matrix.

◆ get()

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
Type theoretica::mat< Type, N, K >::get ( unsigned int  i,
unsigned int  j 
) const
inline

Gets the element at the specified row and column.

Parameters
iThe row index.
jThe column index.
Returns
A copy of the element at position (i, j).

◆ identity()

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
static mat<Type, N, K> theoretica::mat< Type, N, K >::identity ( )
inlinestatic

Returns the identity matrix.

Returns
An identity matrix of the current dimensions.

◆ inverse()

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
mat<Type, N, K> theoretica::mat< Type, N, K >::inverse ( ) const
inline

Computes the inverse of the matrix.

Returns
The inverse matrix.

This function is only valid for square matrices.

◆ invert()

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
mat<Type, N, K>& theoretica::mat< Type, N, K >::invert ( )
inline

Inverts the matrix in place.

Returns
Reference to the inverted matrix.

This function is only valid for square matrices.

◆ is_diagonal()

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
bool theoretica::mat< Type, N, K >::is_diagonal ( ) const
inline

Checks if the matrix is diagonal.

Returns
true if the matrix is diagonal, false otherwise.

◆ is_square()

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
bool theoretica::mat< Type, N, K >::is_square ( ) const
inline

Checks if the matrix is square.

Returns
true if the matrix is square (N == K), false otherwise.

◆ is_symmetric()

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
bool theoretica::mat< Type, N, K >::is_symmetric ( ) const
inline

Checks if the matrix is symmetric.

Returns
true if the matrix is symmetric, false otherwise.

◆ look_at()

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
template<typename Vector1 , typename Vector2 , typename Vector3 >
static mat<Type, 4, 4> theoretica::mat< Type, N, K >::look_at ( const Vector1 &  camera,
const Vector2 &  target,
const Vector3 &  up 
)
inlinestatic

Return a 4x4 transformation matrix that points the field of view towards a given point from the <camera> point.

Template Parameters
Vector1,Vector2,Vector3Types for the camera, target, and up vectors.
Parameters
cameraThe camera position.
targetThe target point to look at.
upThe up direction vector.
Returns
A 4x4 look-at transformation matrix.

◆ mul() [1/2]

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
template<unsigned int M>
mat<Type, N, M> theoretica::mat< Type, N, K >::mul ( const mat< Type, K, M > &  B) const
inline

Matrix multiplication for matrices with different column counts.

Template Parameters
MThe number of columns in matrix B.
Parameters
BThe matrix to multiply with.
Returns
A new matrix resulting from the multiplication.

◆ mul() [2/2]

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
template<typename Matrix >
Matrix theoretica::mat< Type, N, K >::mul ( const Matrix &  B) const
inline

Matrix multiplication for matrices with any type.

Template Parameters
MatrixThe type of the matrix to multiply with.
Parameters
BThe matrix to multiply with.
Returns
The resulting matrix.

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.

◆ operator!=()

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
template<typename Matrix >
bool theoretica::mat< Type, N, K >::operator!= ( const Matrix &  other) const
inline

Checks whether this matrix is not equal to another matrix element-wise.

Template Parameters
MatrixThe type of the other matrix.
Parameters
otherThe matrix to compare with.
Returns
true if any elements are unequal, false otherwise.

◆ operator()() [1/2]

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
Type& theoretica::mat< Type, N, K >::operator() ( unsigned int  i,
unsigned int  j 
)
inline

Overloads the () operator to access an element.

Parameters
iThe row index.
jThe column index.
Returns
A reference to the element at position (i, j).

◆ operator()() [2/2]

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
const Type& theoretica::mat< Type, N, K >::operator() ( unsigned int  i,
unsigned int  j 
) const
inline

Overloads the () operator to access an element.

Parameters
iThe row index.
jThe column index.
Returns
A constant reference to the element at position (i, j).

◆ operator*() [1/3]

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
template<typename Matrix >
auto theoretica::mat< Type, N, K >::operator* ( const Matrix &  B) const
inline

Overloads the * operator for matrix multiplication.

Template Parameters
MatrixThe type of the matrix to multiply with.
Parameters
BThe matrix to multiply with.
Returns
The resulting matrix.

◆ operator*() [2/3]

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
vec<Type, N> theoretica::mat< Type, N, K >::operator* ( const vec< Type, K > &  v) const
inline

Overloads the * operator to transform a fixed-size vector by the matrix.

Parameters
vThe vector to transform.
Returns
The transformed vector.

◆ operator*() [3/3]

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
mat<Type, N, K> theoretica::mat< Type, N, K >::operator* ( Type  scalar) const
inline

Scalar multiplication.

Parameters
scalarThe scalar value to multiply.
Returns
A new matrix that is the result of multiplying this matrix by scalar.

◆ operator*=() [1/2]

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
template<typename Matrix >
mat<Type, N, K>& theoretica::mat< Type, N, K >::operator*= ( const Matrix &  B)
inline

Matrix multiplication with an assignment operator.

Template Parameters
MatrixThe type of the matrix to multiply with.
Parameters
BThe matrix to multiply with.
Returns
Reference to this matrix after multiplication.

◆ operator*=() [2/2]

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
mat<Type, N, K>& theoretica::mat< Type, N, K >::operator*= ( Type  scalar)
inline

Scalar multiplication.

Parameters
scalarThe scalar value to multiply with.
Returns
Reference to this matrix after multiplication.

◆ operator+()

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
template<typename Matrix >
mat<Type, N, K> theoretica::mat< Type, N, K >::operator+ ( const Matrix &  other) const
inline

Matrix addition.

Template Parameters
MatrixThe type of the matrix to add.
Parameters
otherThe matrix to add.
Returns
A new matrix that is the result of adding other to this matrix.

◆ operator+=()

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
template<typename Matrix >
mat<Type, N, K>& theoretica::mat< Type, N, K >::operator+= ( const Matrix &  other)
inline

Matrix addition.

Template Parameters
MatrixThe type of the matrix to add.
Parameters
otherThe matrix to add to this matrix.
Returns
Reference to this matrix after addition.

◆ operator-()

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
template<typename Matrix >
mat<Type, N, K> theoretica::mat< Type, N, K >::operator- ( const Matrix &  other) const
inline

Matrix subtraction.

Template Parameters
MatrixThe type of the matrix to subtract.
Parameters
otherThe matrix to subtract.
Returns
A new matrix that is the result of subtracting other from this matrix.

◆ operator-=()

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
template<typename Matrix >
mat<Type, N, K>& theoretica::mat< Type, N, K >::operator-= ( const Matrix &  other)
inline

Matrix subtraction.

Template Parameters
MatrixThe type of the matrix to subtract.
Parameters
otherThe matrix to subtract from this matrix.
Returns
Reference to this matrix after subtraction.

◆ operator/()

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
mat<Type, N, K> theoretica::mat< Type, N, K >::operator/ ( Type  scalar) const
inline

Scalar division.

Parameters
scalarThe scalar divisor.
Returns
A new matrix that is the result of dividing this matrix by scalar.

If scalar is close to zero, an error is raised.

◆ operator/=()

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
mat<Type, N, K>& theoretica::mat< Type, N, K >::operator/= ( Type  scalar)
inline

Scalar division.

Parameters
scalarThe scalar value to divide by.
Returns
Reference to this matrix after division.

If the scalar value is close to zero, this function raises a division by zero error.

◆ operator=()

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
template<typename Matrix >
mat<Type, N, K>& theoretica::mat< Type, N, K >::operator= ( const Matrix &  other)
inline

Assignment operator to copy from another matrix.

Template Parameters
MatrixThe type of the matrix to copy from.
Parameters
otherThe matrix to copy.
Returns
Reference to this matrix after assignment.

◆ operator==()

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
template<typename Matrix >
bool theoretica::mat< Type, N, K >::operator== ( const Matrix &  other) const
inline

Checks whether this matrix is equal to another matrix element-wise.

Template Parameters
MatrixThe type of the other matrix.
Parameters
otherThe matrix to compare with.
Returns
true if all elements are equal, false otherwise.

◆ ortho()

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
static mat<Type, N, K> theoretica::mat< Type, N, K >::ortho ( real  left,
real  right,
real  bottom,
real  top,
real  near,
real  far 
)
inlinestatic

Returns an orthographic projection matrix.

Parameters
leftThe left boundary.
rightThe right boundary.
bottomThe bottom boundary.
topThe top boundary.
nearThe near boundary.
farThe far boundary.
Returns
A 4x4 orthographic projection matrix.

◆ perspective()

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
static mat<Type, N, K> theoretica::mat< Type, N, K >::perspective ( real  left,
real  right,
real  bottom,
real  top,
real  near,
real  far 
)
inlinestatic

Returns a perspective projection matrix.

Parameters
leftThe left boundary.
rightThe right boundary.
bottomThe bottom boundary.
topThe top boundary.
nearThe near boundary.
farThe far boundary.
Returns
A 4x4 perspective projection matrix.

◆ perspective_fov()

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
static mat<Type, N, K> theoretica::mat< Type, N, K >::perspective_fov ( real  fov,
real  aspect,
real  near,
real  far 
)
inlinestatic

Returns a perspective projection matrix based on field of view.

Parameters
fovThe field of view angle in radians.
aspectThe aspect ratio.
nearThe near boundary.
farThe far boundary.
Returns
A 4x4 perspective projection matrix.

◆ resize()

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
mat<Type, N, K> theoretica::mat< Type, N, K >::resize ( unsigned int  n,
unsigned int  k 
) const
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.

◆ rotation_2d()

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
static mat<Type, N, K> theoretica::mat< Type, N, K >::rotation_2d ( real  theta)
inlinestatic

Returns a matrix for 2D rotation by theta radians.

Parameters
thetaThe angle of rotation in radians.
Returns
A 2x2 rotation matrix.

◆ rotation_3d()

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
template<typename Vector = vec<real, 3>>
static mat<Type, N, K> theoretica::mat< Type, N, K >::rotation_3d ( real  theta,
Vector &&  axis 
)
inlinestatic

Returns a matrix for 3D rotation around an arbitrary axis.

Template Parameters
VectorThe type of the rotation axis vector.
Parameters
thetaThe angle of rotation in radians.
axisThe axis vector to rotate around.
Returns
A 3x3 rotation matrix for the given axis.

◆ rotation_3d_xaxis()

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
static mat<Type, N, K> theoretica::mat< Type, N, K >::rotation_3d_xaxis ( real  theta)
inlinestatic

Returns a matrix for 3D rotation around the x-axis.

Parameters
thetaThe angle of rotation in radians.
Returns
A 3x3 rotation matrix for the x-axis.

◆ rotation_3d_yaxis()

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
static mat<Type, N, K> theoretica::mat< Type, N, K >::rotation_3d_yaxis ( real  theta)
inlinestatic

Returns a matrix for 3D rotation around the y-axis.

Parameters
thetaThe angle of rotation in radians.
Returns
A 3x3 rotation matrix for the y-axis.

◆ rotation_3d_zaxis()

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
static mat<Type, N, K> theoretica::mat< Type, N, K >::rotation_3d_zaxis ( real  theta)
inlinestatic

Returns a matrix for 3D rotation around the z-axis.

Parameters
thetaThe angle of rotation in radians.
Returns
A 3x3 rotation matrix for the z-axis.

◆ rows()

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
TH_CONSTEXPR unsigned int theoretica::mat< Type, N, K >::rows ( ) const
inline

Returns the number of rows in the matrix.

Returns
The number of rows.

◆ size()

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
unsigned int theoretica::mat< Type, N, K >::size ( ) const
inline

Returns the total number of elements in the matrix.

Returns
The total number of elements (rows * columns).

◆ sparsity()

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
real theoretica::mat< Type, N, K >::sparsity ( real  tolerance = 1E-12)
inline

Compute the sparsity of the matrix, counting the proportion of zero (smaller in module than the given tolerance) elements with respect to the total number of elements.

Parameters
toleranceThe minimum tolerance in absolute value to consider an element non-zero.
Returns
A real number between 0 and 1 representing the proportion of zero elements of the matrix.

◆ symplectic()

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
static mat<Type, N, K> theoretica::mat< Type, N, K >::symplectic ( unsigned int  n = 0,
unsigned int  k = 0 
)
inlinestatic

A symplectic NxN matrix, where \(N = 2K\) for some natural K.

Parameters
nOptional parameter for number of rows.
kOptional parameter for number of columns.
Returns
A symplectic matrix with given dimensions.

◆ to_string()

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
std::string theoretica::mat< Type, N, K >::to_string ( std::string  separator = ", ",
bool  parenthesis = true 
) const
inline

Converts the matrix to a string representation.

Parameters
separatorSeparator between elements (default is ", ").
parenthesisWhether to enclose each row in parentheses (default is true).
Returns
The matrix as a formatted string.

◆ trace()

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
Type theoretica::mat< Type, N, K >::trace ( )
inline

Computes the trace of the matrix.

Returns
The trace (sum of diagonal elements).

◆ transform() [1/2]

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
vec<Type, N> theoretica::mat< Type, N, K >::transform ( const vec< Type, K > &  v) const
inline

Transforms a fixed-size vector by multiplying it with the matrix.

Parameters
vThe vector to transform.
Returns
The transformed vector as a new vec<Type, N>.

◆ transform() [2/2]

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
template<typename Vector >
Vector theoretica::mat< Type, N, K >::transform ( const Vector &  v) const
inline

Transforms a vector by multiplying it with the matrix.

Template Parameters
VectorThe type of the vector to transform.
Parameters
vThe vector to transform.
Returns
The transformed vector.

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.

◆ translation()

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
template<typename Vector = vec<real, N - 1>>
static mat<Type, N, K> theoretica::mat< Type, N, K >::translation ( Vector &&  t)
inlinestatic

Returns a 4x4 matrix for translation by the vector {x, y, z}.

Template Parameters
VectorThe type of the translation vector.
Parameters
tThe translation vector.
Returns
A 4x4 translation matrix.

◆ transpose()

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
mat<Type, N, K>& theoretica::mat< Type, N, K >::transpose ( )
inline

Transposes the matrix in place.

Returns
Reference to this matrix after transposition.

This function only works if the matrix is square. An assertion will trigger if the matrix is not square.

◆ transposed()

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
mat<Type, K, N> theoretica::mat< Type, N, K >::transposed ( ) const
inline

Returns a transposed version of the matrix.

Returns
A new matrix that is the transposed version of this matrix.

◆ zeroes()

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
static mat<Type, N, K> theoretica::mat< Type, N, K >::zeroes ( )
inlinestatic

Returns a null matrix with all elements set to zero.

Returns
A new matrix with zero values.

Friends And Related Function Documentation

◆ operator* [1/2]

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
template<typename VecType , unsigned int M>
vec<VecType, K> operator* ( const vec< VecType, M > &  a,
const mat< Type, N, K > &  B 
)
friend

Friend operator for vector-matrix multiplication.

Template Parameters
VecTypeThe type of vector elements.
MThe number of elements in the vector.
Parameters
aThe vector to multiply.
BThe matrix to be multiplied by.
Returns
The resulting vector after multiplication.

◆ operator* [2/2]

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
mat<Type, N, K> operator* ( Type  a,
const mat< Type, N, K > &  B 
)
friend

Friend operator for scalar multiplication (T * mat).

Parameters
aThe scalar multiplier.
BThe matrix to be multiplied.
Returns
A new matrix that is the result of multiplying B by a.

◆ operator<<

template<typename Type = real, unsigned int N = 0, unsigned int K = 0>
std::ostream& operator<< ( std::ostream &  out,
const mat< Type, N, K > &  obj 
)
friend

Outputs the matrix to an output stream in string format.

Parameters
outThe output stream.
objThe matrix to output.
Returns
The modified output stream.

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