Steppable 0.0.1
A CAS project written from scratch in C++
|
Represents a mathematical matrix. More...
#include <mat2d.hpp>
Public Member Functions | |
Matrix | roundOffValues (size_t prec) const |
Round off all values to a specified precision. | |
Matrix () | |
Default constructor for the Matrix class. | |
Matrix (size_t rows, size_t cols, const Number &fill=Number("0")) | |
Constructs a matrix with specified dimensions and an optional fill value. | |
Matrix (const MatVec2D< Number > &data, size_t prec=5) | |
Constructs a matrix from a 2D vector of data. | |
template<concepts::Numeric ValueT> | |
Matrix (const MatVec2D< ValueT > &data, const size_t prec) | |
Constructs a matrix from a 2D vector of C++ numbers. | |
Matrix | rref () const |
Converts the matrix to its reduced row echelon form. | |
Matrix | ref () const |
Converts a matrix to row echelon form. | |
Number | det () const |
Find the determinant of a matrix. | |
std::string | present (int endRows=0) const |
Presents the matrix as a string. | |
auto | begin () |
Alias for the data begin() method to allow iterating over the matrix rows,. | |
auto | end () |
Alias for the data end() method to allow iterating over the matrix rows,. | |
Number | rank () const |
Calculates the rank of a matrix. | |
Matrix | transpose () const |
Transposes a matrix. | |
Matrix | operator+ (const Matrix &rhs) const |
Add a matrix to another matrix. | |
Matrix | operator+= (const Matrix &rhs) |
Adds the other matrix to current matrix and assigns result to this matrix. | |
Matrix | operator+ () const |
Unary plus operator. | |
Matrix | operator- (const Matrix &rhs) const |
Subtract a matrix from another matrix. | |
Matrix | operator-= (const Matrix &rhs) |
Subtracts the other matrix from current matrix and assigns result to this matrix. | |
Matrix | operator- () const |
Unary minus operator. | |
Matrix | operator* (const Number &rhs) const |
Scalar multiplication. | |
Matrix | operator*= (const Number &rhs) |
Multiplies the current matrix by a scalar value and assigns the result to this matrix. | |
Matrix | operator* (const Matrix &rhs) const |
Matrix multiplication. | |
Matrix | operator*= (const Matrix &rhs) |
Multiplies this matrix by another matrix and assigns the result to this matrix. | |
Matrix | operator^ (const Number ×) const |
Raises the current matrix to a certain power. | |
Matrix | operator^= (const Number ×) |
Raises the current matrix to a certain power, and assigns result to the current matrix. | |
Matrix | operator<< (const Matrix &rhs) const |
Join a matrix to the right of the current matrix. | |
Matrix | operator<<= (const Matrix &rhs) |
Join a matrix to the right of the current matrix, then assign the result to the current one. | |
Matrix | operator>> (const Matrix &rhs) const |
Join a matrix to the left of the current matrix. | |
Matrix | operator>>= (const Matrix &rhs) |
Join a matrix to the left of the current matrix, then assign the result to the current one. | |
bool | operator== (const Matrix &rhs) const |
Test for equal matrices. | |
bool | operator!= (const Matrix &rhs) const |
Test for unequal matrices. | |
Number & | operator[] (const YXPoint &point) |
Gets the element at a point in the matrix. | |
Number | operator[] (const YXPoint &point) const |
Accesses the matrix element at the specified YXPoint. | |
Matrix | operator[] (const YX2Points &point) const |
Accesses the matrix element at the specified YXPoint. | |
size_t | getRows () const |
Get the number of rows in the matrix. | |
size_t | getCols () const |
Get the number of columns in the matrix. | |
MatVec2D< Number > | getData () const |
Get the data std::vector object from the matrix. |
Static Public Member Functions | |
static Matrix | ones (size_t rows, size_t cols) |
Creates a matrix filled with ones. | |
static Matrix | zeros (size_t rows, size_t cols) |
Creates a matrix filled with zeros. | |
static Matrix | diag (size_t colsRows, const Number &fill=1) |
Creates a diagnal matrix. | |
template<concepts::Numeric NumberT> | |
static Matrix | diag (const size_t colsRows, const NumberT &fill=0) |
Creates a diagnal matrix. |
Private Member Functions | |
void | _checkIdxSanity (const YXPoint *point) const |
Checks whether a point is inside the matrix. Errors and exits the program if not. |
Static Private Member Functions | |
static void | _checkDataSanity (const MatVec2D< Number > &data) |
Checks whether the matrix data is correct in format. | |
static MatVec2D< Number > | roundOffValues (const MatVec2D< Number > &data, size_t prec) |
Rounds off all data inside a vector to a specified precision. |
Private Attributes | |
size_t | _cols |
The number of columns in the matrix. | |
size_t | _rows |
The number of rows in the matrix. | |
size_t | prec = 10 |
Precision of numbers in the matrix. | |
MatVec2D< Number > | data |
The data of the matrix. |
Represents a mathematical matrix.
steppable::Matrix::Matrix | ( | ) |
Constructs a matrix with specified dimensions and an optional fill value.
rows | The number of rows. |
cols | The number of columns. |
fill | The value to fill the matrix with (default is "0"). |
Constructs a matrix from a 2D vector of data.
data | The 2D vector representing the matrix data. |
prec | Precision of the numbers. |
|
inline |
Constructs a matrix from a 2D vector of C++ numbers.
data | The 2D vector representing the matrix data. |
prec | Precision of the numbers. |
ValueT | Type of value in the data parameter. |
Checks whether the matrix data is correct in format.
This method checks for non-uniform rows inside the matrix.
data | The matrix data vector. |
|
private |
Checks whether a point is inside the matrix. Errors and exits the program if not.
point | The point to check. |
|
inline |
Alias for the data begin() method to allow iterating over the matrix rows,.
|
nodiscard |
Find the determinant of a matrix.
Calculates the reduced echelon form of the matrix.
|
inlinestatic |
|
inline |
Alias for the data end() method to allow iterating over the matrix rows,.
|
inlinenodiscard |
Get the number of columns in the matrix.
Get the data std::vector object from the matrix.
|
inlinenodiscard |
Get the number of rows in the matrix.
|
static |
Creates a matrix filled with ones.
rows | The number of rows. |
cols | The number of columns. |
bool steppable::Matrix::operator!= | ( | const Matrix & | rhs | ) | const |
Test for unequal matrices.
If the current matrix is not equal to the other matrix, i.e., equal in all of its values, returns True.
rhs | The other matrix. |
Matrix multiplication.
Multiplies a matrix by another matrix, returning the resulting matrix.
rhs | The other matrix to multiply. |
Scalar multiplication.
Multiplies each element of the matrix by a scalar.
rhs | The scalar to multiply. |
Multiplies this matrix by another matrix and assigns the result to this matrix.
Performs in-place matrix multiplication with the given right-hand side (rhs) matrix. The current matrix is updated to be the product of itself and rhs.
rhs | The matrix to multiply with this matrix. |
Multiplies the current matrix by a scalar value and assigns the result to this matrix.
This operator performs in-place scalar multiplication, updating each element of the matrix by multiplying it with the provided scalar value.
rhs | The scalar value to multiply each element of the matrix by. |
Matrix steppable::Matrix::operator+ | ( | ) | const |
Unary plus operator.
Does nothing. Simply returns a new instance of the current matrix.
Add a matrix to another matrix.
Performs matrix addition, where corresponding elements in both matrices are added.
rhs | The other matrix. |
Adds the other matrix to current matrix and assigns result to this matrix.
This operator performs in-place matrix addition, updating each element of the matrix by addition.
rhs | The other matrix. |
Matrix steppable::Matrix::operator- | ( | ) | const |
Unary minus operator.
Converts the matrix to itself with all values being converted to the opposite sign. Returns a new instance of the matrix.
Subtract a matrix from another matrix.
Performs matrix subtraction, where corresponding elements in both matrices are subtracted.
rhs | The other matrix. |
Subtracts the other matrix from current matrix and assigns result to this matrix.
This operator performs in-place matrix subtraction, updating each element of the matrix by subtraction.
rhs | The other matrix. |
Join a matrix to the right of the current matrix.
Joins a matrix to the right of the current matrix. Requires two matrices to have to same number of rows.
rhs | The other matrix to join. |
Join a matrix to the right of the current matrix, then assign the result to the current one.
Joins a matrix to the right of the current matrix. Requires two matrices to have to same number of rows. The result is assigned to the current matrix.
rhs | The other matrix to join. |
bool steppable::Matrix::operator== | ( | const Matrix & | rhs | ) | const |
Test for equal matrices.
If the current matrix is equal to the other matrix, i.e., equal in all of its values, returns True.
rhs | The other matrix. |
Join a matrix to the left of the current matrix.
Joins a matrix to the left of the current matrix. Requires two matrices to have to same number of rows.
rhs | The other matrix to join. |
Join a matrix to the left of the current matrix, then assign the result to the current one.
Joins a matrix to the left of the current matrix. Requires two matrices to have to same number of rows. The result is assigned to the current matrix.
rhs | The other matrix to join. |
Accesses the matrix element at the specified YXPoint.
This operator allows read-only access to the matrix element located at the given YXPoint coordinates.
point | The YXPoint specifying the (y, x) coordinates of the element. |
Gets the element at a point in the matrix.
Tries to find an element at the index specified by the point. Prints out error and exits when the index does not exist.
point | The position of the element to find. |
Accesses the matrix element at the specified YXPoint.
This operator allows read-only access to the matrix element located at the given YXPoint coordinates.
point | The YXPoint specifying the (y, x) coordinates of the element. |
Raises the current matrix to a certain power.
Only positive integers (including zero) and the negative number -1 are allowed. Only square matrices are supported. The matrix is multiplied by itself for a specified number of times.
times | Times to raise the matrix to. |
Raises the current matrix to a certain power, and assigns result to the current matrix.
Only positive integers (including zero) and the negative number -1 are allowed. Only square matrices are supported.
times | Times to raise the matrix to. |
|
nodiscard |
Presents the matrix as a string.
|
nodiscard |
Calculates the rank of a matrix.
Calculates the number of non-zero rows when the matrix is converted to row-echelon form.
|
nodiscard |
Converts a matrix to row echelon form.
Converts a matrix to row echelon form, with row elimation and swapping.
|
staticprivate |
Rounds off all data inside a vector to a specified precision.
data | A double std::vector object containing matrix data. |
prec | Precision of the matrix. |
|
nodiscard |
Round off all values to a specified precision.
prec | Precision of the new matrix. |
|
nodiscard |
Converts the matrix to its reduced row echelon form.
|
nodiscard |
Transposes a matrix.
Flips the rows and columns of the matrix and returns a new instance of the transposed matrix.
|
static |
Creates a matrix filled with zeros.
rows | The number of rows. |
cols | The number of columns. |
|
private |
The number of columns in the matrix.
|
private |
The number of rows in the matrix.
|
private |
Precision of numbers in the matrix.