Steppable 0.0.1
A CAS project written from scratch in C++
Loading...
Searching...
No Matches
steppable::Matrix Class Reference

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 &times) const
 Raises the current matrix to a certain power.
Matrix operator^= (const Number &times)
 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.
Numberoperator[] (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< NumbergetData () 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< NumberroundOffValues (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< Numberdata
 The data of the matrix.

Detailed Description

Represents a mathematical matrix.

Constructor & Destructor Documentation

◆ Matrix() [1/4]

steppable::Matrix::Matrix ( )

Default constructor for the Matrix class.

Here is the caller graph for this function:

◆ Matrix() [2/4]

steppable::Matrix::Matrix ( size_t rows,
size_t cols,
const Number & fill = Number("0") )

Constructs a matrix with specified dimensions and an optional fill value.

Parameters
rowsThe number of rows.
colsThe number of columns.
fillThe value to fill the matrix with (default is "0").
Here is the call graph for this function:

◆ Matrix() [3/4]

steppable::Matrix::Matrix ( const MatVec2D< Number > & data,
size_t prec = 5 )

Constructs a matrix from a 2D vector of data.

Parameters
dataThe 2D vector representing the matrix data.
precPrecision of the numbers.

◆ Matrix() [4/4]

template<concepts::Numeric ValueT>
steppable::Matrix::Matrix ( const MatVec2D< ValueT > & data,
const size_t prec )
inline

Constructs a matrix from a 2D vector of C++ numbers.

Parameters
dataThe 2D vector representing the matrix data.
precPrecision of the numbers.
Template Parameters
ValueTType of value in the data parameter.

Member Function Documentation

◆ _checkDataSanity()

void steppable::Matrix::_checkDataSanity ( const MatVec2D< Number > & data)
staticprivate

Checks whether the matrix data is correct in format.

This method checks for non-uniform rows inside the matrix.

Parameters
dataThe matrix data vector.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _checkIdxSanity()

void steppable::Matrix::_checkIdxSanity ( const YXPoint * point) const
private

Checks whether a point is inside the matrix. Errors and exits the program if not.

Parameters
pointThe point to check.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ begin()

auto steppable::Matrix::begin ( )
inline

Alias for the data begin() method to allow iterating over the matrix rows,.

Returns
The beginning of the matrix rows.

◆ det()

Number steppable::Matrix::det ( ) const
nodiscard

Find the determinant of a matrix.

Calculates the reduced echelon form of the matrix.

Returns
A Number object representing the determinant.
Here is the call graph for this function:

◆ diag() [1/2]

template<concepts::Numeric NumberT>
Matrix steppable::Matrix::diag ( const size_t colsRows,
const NumberT & fill = 0 )
inlinestatic

Creates a diagnal matrix.

Parameters
colsRowsNumber of columns and rows.
fillNumber to fill into the matrix.
Template Parameters
NumberTType of the number.
Returns
A diagnal matrix filled with the specified values.
Here is the call graph for this function:

◆ diag() [2/2]

Matrix steppable::Matrix::diag ( size_t colsRows,
const Number & fill = 1 )
static

Creates a diagnal matrix.

Parameters
colsRowsNumber of columns and rows.
fillNumber to fill into the matrix.
Returns
A diagnal matrix filled with the specified values.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ end()

auto steppable::Matrix::end ( )
inline

Alias for the data end() method to allow iterating over the matrix rows,.

Returns
The end of the matrix rows.

◆ getCols()

size_t steppable::Matrix::getCols ( ) const
inlinenodiscard

Get the number of columns in the matrix.

Returns
The number of columns in the matrix.

◆ getData()

MatVec2D< Number > steppable::Matrix::getData ( ) const
inlinenodiscard

Get the data std::vector object from the matrix.

Returns
A std::vector object containing all the matrix data.

◆ getRows()

size_t steppable::Matrix::getRows ( ) const
inlinenodiscard

Get the number of rows in the matrix.

Returns
The number of rows in the matrix.

◆ ones()

Matrix steppable::Matrix::ones ( size_t rows,
size_t cols )
static

Creates a matrix filled with ones.

Parameters
rowsThe number of rows.
colsThe number of columns.
Returns
A Matrix filled with ones.
Here is the call graph for this function:

◆ operator!=()

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.

Parameters
rhsThe other matrix.
Returns
Whether the current matrix is not equal to the other one.
Here is the call graph for this function:

◆ operator*() [1/2]

Matrix steppable::Matrix::operator* ( const Matrix & rhs) const

Matrix multiplication.

Multiplies a matrix by another matrix, returning the resulting matrix.

Parameters
rhsThe other matrix to multiply.
Returns
The new matrix after multiplying.
Here is the call graph for this function:

◆ operator*() [2/2]

Matrix steppable::Matrix::operator* ( const Number & rhs) const

Scalar multiplication.

Multiplies each element of the matrix by a scalar.

Parameters
rhsThe scalar to multiply.
Returns
A new matrix after the scalar multiplication
Here is the call graph for this function:

◆ operator*=() [1/2]

Matrix steppable::Matrix::operator*= ( const Matrix & rhs)

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.

Parameters
rhsThe matrix to multiply with this matrix.
Returns
The updated matrix after multiplication.
Here is the call graph for this function:

◆ operator*=() [2/2]

Matrix steppable::Matrix::operator*= ( const Number & rhs)

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.

Parameters
rhsThe scalar value to multiply each element of the matrix by.
Returns
Instance of a modified matrix after multiplication.
Here is the call graph for this function:

◆ operator+() [1/2]

Matrix steppable::Matrix::operator+ ( ) const

Unary plus operator.

Does nothing. Simply returns a new instance of the current matrix.

Returns
A new instance of the current matrix.
Here is the call graph for this function:

◆ operator+() [2/2]

Matrix steppable::Matrix::operator+ ( const Matrix & rhs) const

Add a matrix to another matrix.

Performs matrix addition, where corresponding elements in both matrices are added.

Parameters
rhsThe other matrix.
Returns
A new matrix with the addition result.
Here is the call graph for this function:

◆ operator+=()

Matrix steppable::Matrix::operator+= ( const Matrix & rhs)

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.

Parameters
rhsThe other matrix.
Returns
Instance of a new matrix after addition.
Here is the call graph for this function:

◆ operator-() [1/2]

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.

Returns
A matrix with equal values in the opposite sign.
Here is the call graph for this function:

◆ operator-() [2/2]

Matrix steppable::Matrix::operator- ( const Matrix & rhs) const

Subtract a matrix from another matrix.

Performs matrix subtraction, where corresponding elements in both matrices are subtracted.

Parameters
rhsThe other matrix.
Returns
A new matrix with the subtraction result.
Here is the call graph for this function:

◆ operator-=()

Matrix steppable::Matrix::operator-= ( const Matrix & rhs)

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.

Parameters
rhsThe other matrix.
Returns
Instance of a new matrix after subtraction.
Here is the call graph for this function:

◆ operator<<()

Matrix steppable::Matrix::operator<< ( const Matrix & rhs) const

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.

Parameters
rhsThe other matrix to join.
Returns
A new matrix where the two matrices are joined.
Here is the call graph for this function:

◆ operator<<=()

Matrix steppable::Matrix::operator<<= ( const Matrix & rhs)

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.

Parameters
rhsThe other matrix to join.
Returns
A new matrix where the two matrices are joined.
Here is the call graph for this function:

◆ operator==()

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.

Parameters
rhsThe other matrix.
Returns
Whether the current matrix is equal to the other one.
Here is the call graph for this function:

◆ operator>>()

Matrix steppable::Matrix::operator>> ( const Matrix & rhs) const

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.

Parameters
rhsThe other matrix to join.
Returns
A new matrix where the two matrices are joined.
Here is the call graph for this function:

◆ operator>>=()

Matrix steppable::Matrix::operator>>= ( const Matrix & rhs)

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.

Parameters
rhsThe other matrix to join.
Returns
A new matrix where the two matrices are joined.
Here is the call graph for this function:

◆ operator[]() [1/3]

Matrix steppable::Matrix::operator[] ( const YX2Points & point) const

Accesses the matrix element at the specified YXPoint.

This operator allows read-only access to the matrix element located at the given YXPoint coordinates.

Parameters
pointThe YXPoint specifying the (y, x) coordinates of the element.
Returns
The value of the matrix element at the specified coordinates.
Here is the call graph for this function:

◆ operator[]() [2/3]

Number & steppable::Matrix::operator[] ( const YXPoint & point)

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.

Parameters
pointThe position of the element to find.
Returns
A reference to the element at that position.
Here is the call graph for this function:

◆ operator[]() [3/3]

Number steppable::Matrix::operator[] ( const YXPoint & point) const

Accesses the matrix element at the specified YXPoint.

This operator allows read-only access to the matrix element located at the given YXPoint coordinates.

Parameters
pointThe YXPoint specifying the (y, x) coordinates of the element.
Returns
The value of the matrix element at the specified coordinates.
Here is the call graph for this function:

◆ operator^()

Matrix steppable::Matrix::operator^ ( const Number & times) const

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.

Parameters
timesTimes to raise the matrix to.
Returns
A new matrix of the power result.
Here is the call graph for this function:

◆ operator^=()

Matrix steppable::Matrix::operator^= ( const Number & times)

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.

Parameters
timesTimes to raise the matrix to.
Returns
The current matrix.
Here is the call graph for this function:

◆ present()

std::string steppable::Matrix::present ( int endRows = 0) const
nodiscard

Presents the matrix as a string.

Returns
A string representation of the matrix.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rank()

Number steppable::Matrix::rank ( ) const
nodiscard

Calculates the rank of a matrix.

Calculates the number of non-zero rows when the matrix is converted to row-echelon form.

Returns
The rank of the matrix.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ref()

Matrix steppable::Matrix::ref ( ) const
nodiscard

Converts a matrix to row echelon form.

Converts a matrix to row echelon form, with row elimation and swapping.

Returns
A new Matrix in row echelon form.
Here is the call graph for this function:

◆ roundOffValues() [1/2]

MatVec2D< Number > steppable::Matrix::roundOffValues ( const MatVec2D< Number > & data,
size_t prec )
staticprivate

Rounds off all data inside a vector to a specified precision.

Parameters
dataA double std::vector object containing matrix data.
precPrecision of the matrix.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ roundOffValues() [2/2]

Matrix steppable::Matrix::roundOffValues ( size_t prec) const
nodiscard

Round off all values to a specified precision.

Parameters
precPrecision of the new matrix.
Returns
A new instance of the current matrix, with values rounded to the desired precision.
Here is the call graph for this function:

◆ rref()

Matrix steppable::Matrix::rref ( ) const
nodiscard

Converts the matrix to its reduced row echelon form.

Returns
A new Matrix in reduced row echelon form.
Here is the call graph for this function:

◆ transpose()

Matrix steppable::Matrix::transpose ( ) const
nodiscard

Transposes a matrix.

Flips the rows and columns of the matrix and returns a new instance of the transposed matrix.

Returns
An instance of the transposed matrix.
Here is the call graph for this function:

◆ zeros()

Matrix steppable::Matrix::zeros ( size_t rows,
size_t cols )
static

Creates a matrix filled with zeros.

Parameters
rowsThe number of rows.
colsThe number of columns.
Returns
A Matrix filled with zeros.
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ _cols

size_t steppable::Matrix::_cols
private

The number of columns in the matrix.

◆ _rows

size_t steppable::Matrix::_rows
private

The number of rows in the matrix.

◆ data

MatVec2D<Number> steppable::Matrix::data
private

The data of the matrix.

◆ prec

size_t steppable::Matrix::prec = 10
private

Precision of numbers in the matrix.


The documentation for this class was generated from the following files:
Untitled