c_physics_engine
A custom physics engine written in C/C++
Loading...
Searching...
No Matches
cpp_physics::Matrix Class Reference

#include <matrix.hpp>

Public Member Functions

 Matrix (std::size_t rows, std::size_t cols=1)
 Constructs a Matrix with the specified number of rows and columns.
 
std::pair< std::size_t, std::size_t > Shape () const
 return the shape of the matrix as a tuple of (rows, cols).
 
float Get (std::size_t row, std::size_t col) const
 Retrieves a value from the matrix at the specified row and column.
 
void applyFunction (std::function< float(float)> func)
 Apply a function to all elements of the matrix.
 
Matrix Submatrix (std::size_t rows, std::size_t cols, std::size_t row_start, std::size_t col_start) const
 Extract a submatrix from the matrix.
 
float Sum () const
 Sum all elements in the matrix.
 
Matrix memwise_iMul (const Matrix &other)
 Memberwise-multiply a matrix to this one.
 
Matrix memwise_iDiv (const Matrix &other)
 Memberwise-divide this matrix by anoter one.
 
Matrix operator+= (const Matrix &other)
 Add another matrix to this one.
 
Matrix operator+ (const Matrix &other) const
 Add two matrices.
 
Matrix operator-= (const Matrix &other)
 Subtract another matrix from this one.
 
Matrix operator- (const Matrix &other) const
 Subtract two matrices.
 
Matrix operator*= (const Matrix &other)
 Multiply another matrix to this one.
 
Matrix operator* (const Matrix &other) const
 Multiply two matrices.
 
Matrix operator*= (float scalar)
 Scale this matrix.
 
Matrix operator* (float scalar) const
 Scale a matrix.
 
Matrix operator/= (float scalar)
 Divide this matrix by a scalar.
 
Matrix operator/ (float scalar) const
 Divide a matrix by a scalar.
 
Matrix operator= (const Matrix &other)
 Copy this matrix.
 
Matrix operator- () const
 Negate this matrix.
 
Matrix operator! () const
 Transpose this matrix.
 
float & operator[] (std::size_t row, std::size_t col)
 Access values inside the matrix.
 
bool operator== (const Matrix &other)
 Check if this matrices is equal to another matrix.
 
bool operator!= (const Matrix &other)
 Check if this matrices is different from another matrix.
 

Static Public Member Functions

static Matrix Identity (std::size_t size)
 Creates a new identity-matrix.
 
static Matrix Combine (std::vector< Matrix > matrices, bool vertical=false)
 Combine multiple matrices into a new matrix.
 
static Matrix memwise_Mul (const Matrix &lhs, const Matrix &rhs)
 Memberwise-multiply two matrices.
 
static Matrix memwise_Div (const Matrix &lhs, const Matrix &rhs)
 Memberwise-divide two matrices.
 

Constructor & Destructor Documentation

◆ Matrix()

cpp_physics::Matrix::Matrix ( std::size_t rows,
std::size_t cols = 1 )

Constructs a Matrix with the specified number of rows and columns.

Parameters
rowsThe number of rows in the matrix.
colsThe number of columns in the matrix. Defaults to 1.

Member Function Documentation

◆ applyFunction()

void cpp_physics::Matrix::applyFunction ( std::function< float(float)> func)

Apply a function to all elements of the matrix.

Parameters
funcA function that takes a float as Argument and return a float.

◆ Combine()

Matrix cpp_physics::Matrix::Combine ( std::vector< Matrix > matrices,
bool vertical = false )
static

Combine multiple matrices into a new matrix.

Parameters
matricesA vector containing the matrices to combine.
verticalAlign the matrices horizontally or vertically. Defaults to false, for horizontal.
Returns
A new Matrix containing copies of all the other matrices.

◆ Get()

float cpp_physics::Matrix::Get ( std::size_t row,
std::size_t col ) const

Retrieves a value from the matrix at the specified row and column.

Parameters
rowThe row index from which to retrieve the value.
colThe column index from which to retrieve the value.
Returns
The value at the specified row and column.

◆ Identity()

Matrix cpp_physics::Matrix::Identity ( std::size_t size)
static

Creates a new identity-matrix.

Parameters
sizeAmount o frows and columns in the Matrix
Returns
The new identity-matrix

◆ memwise_Div()

Matrix cpp_physics::Matrix::memwise_Div ( const Matrix & lhs,
const Matrix & rhs )
static

Memberwise-divide two matrices.

Parameters
lhsThe dividend.
rhsThe divisor.
Returns
A new matrix containing the result.

◆ memwise_iDiv()

Matrix cpp_physics::Matrix::memwise_iDiv ( const Matrix & other)

Memberwise-divide this matrix by anoter one.

Parameters
otherThe divisor.

◆ memwise_iMul()

Matrix cpp_physics::Matrix::memwise_iMul ( const Matrix & other)

Memberwise-multiply a matrix to this one.

Parameters
otherThe multiplier.

◆ memwise_Mul()

Matrix cpp_physics::Matrix::memwise_Mul ( const Matrix & lhs,
const Matrix & rhs )
static

Memberwise-multiply two matrices.

Parameters
lhsThe multiplicand.
rhsThe multiplier.
Returns
A new matrix containing the result.

◆ operator!()

Matrix cpp_physics::Matrix::operator! ( ) const

Transpose this matrix.

Returns
A new transposed matrix.

◆ operator!=()

bool cpp_physics::Matrix::operator!= ( const Matrix & other)

Check if this matrices is different from another matrix.

Parameters
otherThe matrix to compare to.
Returns
true, if the matrices are different.

◆ operator*() [1/2]

Matrix cpp_physics::Matrix::operator* ( const Matrix & other) const

Multiply two matrices.

Parameters
otherThe multiplier.
Returns
A new matrix containing the result.

◆ operator*() [2/2]

Matrix cpp_physics::Matrix::operator* ( float scalar) const

Scale a matrix.

Parameters
scalarThe scalar to scale by.
Returns
A new matrix containing the result.

◆ operator*=() [1/2]

Matrix cpp_physics::Matrix::operator*= ( const Matrix & other)

Multiply another matrix to this one.

Parameters
otherThe matrix to multiply with.

◆ operator*=() [2/2]

Matrix cpp_physics::Matrix::operator*= ( float scalar)

Scale this matrix.

Parameters
scalarThe factor to scale the matrix by.

◆ operator+()

Matrix cpp_physics::Matrix::operator+ ( const Matrix & other) const

Add two matrices.

Parameters
otherThe addend.
Returns
A new matrix containing the result.

◆ operator+=()

Matrix cpp_physics::Matrix::operator+= ( const Matrix & other)

Add another matrix to this one.

Parameters
otherThe matrix to add.

◆ operator-() [1/2]

Matrix cpp_physics::Matrix::operator- ( ) const

Negate this matrix.

Returns
A new negated matrix.

◆ operator-() [2/2]

Matrix cpp_physics::Matrix::operator- ( const Matrix & other) const

Subtract two matrices.

Parameters
otherThe subtrahend.
Returns
A new matrix containing the result.

◆ operator-=()

Matrix cpp_physics::Matrix::operator-= ( const Matrix & other)

Subtract another matrix from this one.

Parameters
otherThe matrix to subtract.

◆ operator/()

Matrix cpp_physics::Matrix::operator/ ( float scalar) const

Divide a matrix by a scalar.

Parameters
scalarThe scalar to divide by.
Returns
A new matrix containing the result.

◆ operator/=()

Matrix cpp_physics::Matrix::operator/= ( float scalar)

Divide this matrix by a scalar.

Parameters
scalarThe factor to divide the matrix by.

◆ operator=()

Matrix cpp_physics::Matrix::operator= ( const Matrix & other)

Copy this matrix.

Parameters
otherThe matrix to copy.
Returns
A copy of the other matrix.

◆ operator==()

bool cpp_physics::Matrix::operator== ( const Matrix & other)

Check if this matrices is equal to another matrix.

Parameters
otherThe matrix to compare to.
Returns
true, if the matrices are equal.

◆ operator[]()

float & cpp_physics::Matrix::operator[] ( std::size_t row,
std::size_t col )

Access values inside the matrix.

Parameters
rowThe row of the value to access.
colThe row of the value to access.
Returns
A reference to the specified value.

◆ Shape()

std::pair< std::size_t, std::size_t > cpp_physics::Matrix::Shape ( ) const

return the shape of the matrix as a tuple of (rows, cols).

Returns
A tuple containing the number of rows and columns in the matrix.

◆ Submatrix()

Matrix cpp_physics::Matrix::Submatrix ( std::size_t rows,
std::size_t cols,
std::size_t row_start,
std::size_t col_start ) const

Extract a submatrix from the matrix.

Parameters
rowsAmount of rows in the submatrix.
colsAmount of columns in the submatrix.
row_startThe starting row index for the submatrix.
col_startThe starting column index for the submatrix.
Returns
A new submatrix.

◆ Sum()

float cpp_physics::Matrix::Sum ( ) const

Sum all elements in the matrix.

Returns
The sum of all elements.

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