GSI_Toolbox 1.0.0
A toolbox for Gas-Surface Interaction simulations
|
This class implements a matrix object used for linear algebra and vectorized operations. More...
#include <Matrix.h>
Public Member Functions | |
Matrix () | |
Default constructor. Initializes an empty matrix. | |
Matrix (long dim_x, long dim_y) | |
Constructor that initializes the matrix with the specified dimensions. | |
Matrix (long dim_x, long dim_y, std::initializer_list< T > l) | |
Constructor that initializes the matrix with the specified dimensions and data. | |
~Matrix () | |
Destructor. Cleans up the allocated memory. | |
Matrix (const Matrix &other) | |
Copy constructor. Creates a copy of an existing Matrix object. | |
Matrix (Matrix &&other) | |
Move constructor. Moves the data from a given Matrix object to the new one. | |
T * | getData () |
long | get_rows () const |
long | get_cols () const |
Matrix & | operator= (const Matrix &other) |
Copy assignment operator. Copies the data from the given Matrix object. | |
Matrix & | operator= (Matrix &&other) |
Move assignment operator. Moves the data from the given Matrix object. | |
Matrix & | operator= (T constant) |
Constant assignment operator. Assigns all Matrix values to one constant. | |
Matrix & | operator+= (const Matrix &other) |
Compound assignment operator (addition). Adds another Matrix to this Matrix. | |
Matrix & | operator-= (const Matrix &other) |
Compound assignment operator (subtraction). Subtracts another Matrix from this Matrix. | |
Matrix & | operator*= (const Matrix &other) |
Compound assignment operator (multiplication). Multiplies this Matrix with another Matrix. | |
Matrix & | operator/= (const Matrix &other) |
Compound assignment operator (division). Divides this Matrix by another Matrix. | |
Matrix & | operator+= (T other) |
Compound assignment operator (addition). Adds a scalar to this Matrix. | |
Matrix & | operator-= (T other) |
Compound assignment operator (subtraction). Subtracts a scalar from this Matrix. | |
Matrix & | operator*= (T other) |
Compound assignment operator (multiplication). Multiplies this Matrix by a scalar. | |
Matrix & | operator/= (T other) |
Compound assignment operator (division). Divides this Matrix by a scalar. | |
T & | operator() (const long i, const long j) |
Subscript operator for element access (read/write). | |
const T & | operator() (const long i, const long j) const |
Subscript operator for element access (read-only). | |
T & | operator() (const long n) |
Subscript operator for element access in a single row (read/write). | |
const T & | operator() (const long n) const |
Subscript operator for element access in a single row (read-only). | |
Matrix | operator+ (const Matrix &other) |
Matrix | operator- (const Matrix &other) |
Matrix | operator* (const Matrix &other) |
Matrix | operator/ (const Matrix &other) |
Matrix | operator* (T constant) |
Matrix | operator/ (T constant) |
Matrix | operator^ (T constant) |
Matrix | operator+ (T constant) |
Matrix | operator- (T constant) |
Matrix | dot (const Matrix &other) |
Calculates the dot product of two matrices. | |
Matrix | cross (const Matrix &other) |
Calculates the cross product of two matrices. | |
Matrix | outer (const Matrix &other) |
Calculates the outer product of two matrices. | |
std::tuple< Matrix< T >, Matrix< T > > | meshgrid (const Matrix &other) |
Calculates the meshgrid of 2 1D matrices. | |
Matrix | tr () |
Transposes the matrix. | |
T | norm () |
Calculates the Frobenius norm of the matrix. | |
T | max () |
Finds the maximum element in the matrix. | |
T | min () |
Finds the minimum element in the matrix. | |
void | print () |
Prints the matrix to the console. | |
This class implements a matrix object used for linear algebra and vectorized operations.
The Matrix class provides a range of operations that can be performed on matrix objects, including addition, subtraction, multiplication, division, dot product, cross product, and various other operations common in linear algebra.
Constructor that initializes the matrix with the specified dimensions.
The created matrix has the specified number of rows and columns, all set to zero.
dim_x | Number of rows. |
dim_y | Number of columns. |
Constructor that initializes the matrix with the specified dimensions and data.
The created matrix has the specified number of rows and columns. The data for the matrix is provided by an initializer list. If the size of the list does not match the expected size of the matrix (rows * columns), an error message is displayed.
dim_x | Number of rows. |
dim_y | Number of columns. |
l | Initializer list containing data to populate the matrix. |
Move constructor. Moves the data from a given Matrix object to the new one.
This constructor "steals" the internal data from the original object and leaves it in an empty state. This is more efficient than copying when the original object is no longer needed.
other | The Matrix object whose data is to be moved. |
Calculates the cross product of two matrices.
This function calculates the cross product, or vector product, of two matrices. Both matrices must be 3x1 (three rows, one column), otherwise, an exception is thrown.
other | The matrix with which to calculate the cross product. |
Calculates the dot product of two matrices.
This function calculates the dot product, or scalar product, of two matrices. Both matrices must have the same dimensions, otherwise, an exception is thrown.
other | The matrix with which to calculate the dot product. |
T Matrix< T >::max | ( | ) |
Finds the maximum element in the matrix.
This function searches for the largest element in the matrix.
std::tuple< Matrix< T >, Matrix< T > > Matrix< T >::meshgrid | ( | const Matrix< T > & | other | ) |
Calculates the meshgrid of 2 1D matrices.
This function calculates the meshgrid matrix of two 1D vectors. Both vectors must be column vectors, otherwise, an exception is thrown.
other | The matrix with which to calculate the meshgrid. |
T Matrix< T >::min | ( | ) |
Finds the minimum element in the matrix.
This function searches for the smallest element in the matrix.
T Matrix< T >::norm | ( | ) |
Calculates the Frobenius norm of the matrix.
This function calculates the square root of the sum of the absolute squares of its elements.
|
inline |
Subscript operator for element access (read/write).
This operator provides direct access to the matrix data using a two-dimensional index. It performs boundary checks and throws an exception if the indices are out of range.
i | The row index. |
j | The column index. |
|
inline |
Subscript operator for element access (read-only).
This operator provides direct access to the matrix data using a two-dimensional index. It performs boundary checks and throws an exception if the indices are out of range.
i | The row index. |
j | The column index. |
|
inline |
Subscript operator for element access in a single row (read/write).
This operator provides direct access to the matrix data considering it as a single row. It performs boundary checks and throws an exception if the index is out of range.
n | The index in the matrix considering it as a single row. |
|
inline |
Subscript operator for element access in a single row (read-only).
This operator provides direct access to the matrix data considering it as a single row. It performs boundary checks and throws an exception if the index is out of range.
n | The index in the matrix considering it as a single row. |
Compound assignment operator (multiplication). Multiplies this Matrix with another Matrix.
This operator performs matrix multiplication between this Matrix and the 'other' Matrix. The number of columns in this Matrix must be equal to the number of rows in the 'other' matrix, otherwise, an exception is thrown.
other | The Matrix object to be multiplied with this one. |
Compound assignment operator (multiplication). Multiplies this Matrix by a scalar.
This operator performs element-wise multiplication of this Matrix by a scalar value. Each element of this Matrix is multiplied by the scalar value.
other | The scalar value to multiply this Matrix's elements by. |
Compound assignment operator (addition). Adds another Matrix to this Matrix.
This operator performs element-wise addition between this Matrix and the 'other' Matrix. Both matrices must have the same dimensions, otherwise, an exception is thrown.
other | The Matrix object to be added to this one. |
Compound assignment operator (addition). Adds a scalar to this Matrix.
This operator performs element-wise addition of a scalar value to this Matrix. The scalar value is added to every element of this Matrix.
other | The scalar value to be added to this Matrix's elements. |
Compound assignment operator (subtraction). Subtracts another Matrix from this Matrix.
This operator performs element-wise subtraction of the 'other' Matrix from this Matrix. Both matrices must have the same dimensions, otherwise, an exception is thrown.
other | The Matrix object to be subtracted from this one. |
Compound assignment operator (subtraction). Subtracts a scalar from this Matrix.
This operator performs element-wise subtraction of a scalar value from this Matrix. The scalar value is subtracted from every element of this Matrix.
other | The scalar value to be subtracted from this Matrix's elements. |
Compound assignment operator (division). Divides this Matrix by another Matrix.
This operator performs element-wise division of this Matrix by the 'other' Matrix. Both matrices must have the same dimensions, and the 'other' matrix must not contain any zero elements, otherwise, an exception is thrown.
other | The Matrix object to divide this one by. |
Compound assignment operator (division). Divides this Matrix by a scalar.
This operator performs element-wise division of this Matrix by a scalar value. Each element of this Matrix is divided by the scalar value. The scalar must not be zero, otherwise, an exception is thrown.
other | The scalar value to divide this Matrix's elements by. |
Constant assignment operator. Assigns all Matrix values to one constant.
constant | The constant to be assigned. |
Calculates the outer product of two matrices.
This function calculates the outer product of two 1D vectors. Both vectors must be column vectors, otherwise, an exception is thrown.
other | The matrix with which to calculate the outer product. |
void Matrix< T >::print | ( | ) |
Prints the matrix to the console.
This function prints a textual representation of the matrix to the console. Each row is printed on a new line, and the elements are separated by spaces.
Transposes the matrix.
This function returns a new matrix which is the transpose of the current matrix.