9const std::out_of_range
OOB = std::out_of_range(
"Row or column index out of bounds.");
10const std::out_of_range
SUBMAT_OOB = std::out_of_range(
"Submatrix exceeds bounds of original matrix.");
11const std::invalid_argument
SHAPE_MISMATCH = std::invalid_argument(
"Matrix-shapes don't match.");
12const std::invalid_argument
INNERDIM_MISMATCH = std::invalid_argument(
"Inner matrix-dimensions don't align.");
13const std::invalid_argument
DIM_MISMATCH = std::invalid_argument(
"Matrix-columns or -rows don't match.");
14const std::invalid_argument
TOO_FEW = std::invalid_argument(
"Too few matrices, minimum 1.");
15const std::invalid_argument
DIV_ZERO = std::invalid_argument(
"Division by 0.");
19 std::vector<float> data;
29 Matrix(std::size_t rows, std::size_t cols = 1);
42 std::pair<std::size_t, std::size_t>
Shape()
const;
50 float Get(std::size_t row, std::size_t col)
const;
66 Matrix Submatrix(std::size_t rows, std::size_t cols, std::size_t row_start, std::size_t col_start)
const;
74 static Matrix Combine(std::vector<Matrix> matrices,
bool vertical =
false);
190 float&
operator[](std::size_t row, std::size_t col);
Matrix operator/(float scalar) const
Divide a matrix by a scalar.
Definition matrix.cpp:192
void applyFunction(std::function< float(float)> func)
Apply a function to all elements of the matrix.
Definition matrix.cpp:45
Matrix operator+(const Matrix &other) const
Add two matrices.
Definition matrix.cpp:136
Matrix memwise_iDiv(const Matrix &other)
Memberwise-divide this matrix by anoter one.
Definition matrix.cpp:124
Matrix operator*(const Matrix &other) const
Multiply two matrices.
Definition matrix.cpp:160
Matrix operator=(const Matrix &other)
Copy this matrix.
Definition matrix.cpp:199
static Matrix memwise_Mul(const Matrix &lhs, const Matrix &rhs)
Memberwise-multiply two matrices.
Definition matrix.cpp:103
Matrix operator/=(float scalar)
Divide this matrix by a scalar.
Definition matrix.cpp:186
float & operator[](std::size_t row, std::size_t col)
Access values inside the matrix.
Definition matrix.cpp:222
static Matrix Identity(std::size_t size)
Creates a new identity-matrix.
Definition matrix.cpp:7
Matrix operator-=(const Matrix &other)
Subtract another matrix from this one.
Definition matrix.cpp:143
Matrix(std::size_t rows, std::size_t cols=1)
Constructs a Matrix with the specified number of rows and columns.
Definition matrix.cpp:5
Matrix memwise_iMul(const Matrix &other)
Memberwise-multiply a matrix to this one.
Definition matrix.cpp:110
static Matrix memwise_Div(const Matrix &lhs, const Matrix &rhs)
Memberwise-divide two matrices.
Definition matrix.cpp:116
bool operator==(const Matrix &other)
Check if this matrices is equal to another matrix.
Definition matrix.cpp:227
bool operator!=(const Matrix &other)
Check if this matrices is different from another matrix.
Definition matrix.cpp:232
float Sum() const
Sum all elements in the matrix.
Definition matrix.cpp:97
Matrix operator!() const
Transpose this matrix.
Definition matrix.cpp:212
Matrix operator+=(const Matrix &other)
Add another matrix to this one.
Definition matrix.cpp:131
Matrix operator*=(const Matrix &other)
Multiply another matrix to this one.
Definition matrix.cpp:155
std::pair< std::size_t, std::size_t > Shape() const
return the shape of the matrix as a tuple of (rows, cols).
Definition matrix.cpp:38
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.
Definition matrix.cpp:49
float Get(std::size_t row, std::size_t col) const
Retrieves a value from the matrix at the specified row and column.
Definition matrix.cpp:40
static Matrix Combine(std::vector< Matrix > matrices, bool vertical=false)
Combine multiple matrices into a new matrix.
Definition matrix.cpp:60
Matrix operator-() const
Negate this matrix.
Definition matrix.cpp:206
Definition cpp-physics.hpp:6
const std::out_of_range OOB
Definition matrix.hpp:9
const std::invalid_argument DIM_MISMATCH
Definition matrix.hpp:13
std::ostream & operator<<(std::ostream &flux, const Matrix &mat)
Print a matrix.
Definition matrix.cpp:13
const std::invalid_argument TOO_FEW
Definition matrix.hpp:14
const std::invalid_argument SHAPE_MISMATCH
Definition matrix.hpp:11
const std::invalid_argument INNERDIM_MISMATCH
Definition matrix.hpp:12
Matrix operator*(float scalar, const Matrix &mat)
Scale a matrix.
Definition matrix.cpp:237
const std::out_of_range SUBMAT_OOB
Definition matrix.hpp:10
const std::invalid_argument DIV_ZERO
Definition matrix.hpp:15