86 throw std::invalid_argument(
"Size mismatch between dimensions and provided values.");
99 if (
rows >= this->m_rows ||
cols >= this->m_cols)
103 return this->m_matrix[
rows * this->m_cols +
cols];
116 if (
rows >= this->m_rows ||
cols >= this->m_cols)
120 return this->m_matrix[
rows * this->m_cols +
cols];
131 return this->m_matrix +
value;
153 return this->m_matrix -
value;
175 return this->m_matrix *
value;
189 for (
int i = 0;
i < this->m_rows;
i++)
194 for (
int k = 0;
k < this->m_cols;
k++)
196 sum += this->m_matrix[
i * this->m_cols +
k]
224 return this->m_matrix /
value;
247 std::pair<int, int> size =
dm_1.size();
248 return {size.first, size.second,
dm_1.matrix_add_element_wise(
dm_2)};
287 std::pair<int, int> size =
dm_1.size();
288 return {size.first, size.second,
dm_1.matrix_subtract_element_wise(
dm_2)};
331 std::pair<int, int> size =
dm_1.size();
332 return {size.first, size.second,
dm_1.matrixMultiplyElementWise(
dm_2)};
374 std::pair<int, int> size =
dm_1.size();
375 return {size.first, size.second,
dm_1.matrix_divide_element_wise(
dm_2)};
414 for (
int i = 0;
i < size.first;
i++)
416 for (
int j = 0;
j < size.second;
j++)
436 for (
int i{0};
i < this->m_rows;
i++)
438 for (
int j{0};
j < this->m_cols;
j++)
440 if (this->m_matrix[
i * this->m_cols +
j] != 0)
442 this->m_non_zero_elements.emplace_back(
i,
j);
DenseMatrix< T > operator+(const DenseMatrix< T > &dm_1, const DenseMatrix< T > &dm_2)
Overload of the binary + operator.
Definition DenseMatrix.h:245
DenseMatrix< T > operator/(const DenseMatrix< T > &dm_1, const DenseMatrix< T > &dm_2)
Overload of the binary / operator.
Definition DenseMatrix.h:372
DenseMatrix< T > operator*(const DenseMatrix< T > &dm_1, const DenseMatrix< T > &dm_2)
Overload of the binary * operator. Does matrix multiplication/matrix product.
Definition DenseMatrix.h:329
DenseMatrix< T > operator-(const DenseMatrix< T > &dm_1, const DenseMatrix< T > &dm_2)
Overload of the binary - operator.
Definition DenseMatrix.h:285
std::ostream & operator<<(std::ostream &out, const DenseMatrix< T > &dense_matrix)
Overload of the << operator.
Definition DenseMatrix.h:411
Concrete implemenatation of a matrix class representing a dense matrix. Offers basic access and eleme...
Definition DenseMatrix.h:17
DenseMatrix< T > matrixMultiply(const DenseMatrix &dense_matrix) const
Mathematical matrix multiplication of two DenseMatrix objects.
Definition DenseMatrix.h:184
std::valarray< T > matrixAddElementWise(const DenseMatrix &dense_matrix) const
Addition of two DenseMatrix objects element-wise.
Definition DenseMatrix.h:140
DenseMatrix(DenseMatrix &&)=default
DenseMatrix & operator=(DenseMatrix &&)=default
DenseMatrix & operator=(const DenseMatrix &)=default
const std::vector< std::pair< int, int > > & getNonZeroElements() override
Definition DenseMatrix.h:44
DenseMatrix(const DenseMatrix &)=default
std::valarray< T > scalarSubtract(T value) const override
Subtraction of a scalar from the matrix values element-wise.
Definition DenseMatrix.h:151
std::valarray< T > matrixMultiplyElementWise(const DenseMatrix &dense_matrix) const
Multiplication of two DenseMatrix objects element-wise.
Definition DenseMatrix.h:211
std::valarray< T > matrixDivideElementWise(const DenseMatrix &dense_matrix) const
Division of two DenseMatrix objects element-wise.
Definition DenseMatrix.h:233
std::valarray< T > matrixSubtractElementWise(const DenseMatrix &dense_matrix) const
Subtraction of two DenseMatrix objects element-wise.
Definition DenseMatrix.h:162
std::valarray< T > scalarMultiply(T value) const override
Multiplication of a scalar to the matrix values element-wise.
Definition DenseMatrix.h:173
~DenseMatrix() override=default
std::valarray< T > scalarAdd(T value) const override
Addition of a scalar to the matrix values element-wise.
Definition DenseMatrix.h:129
void buildAtRuntime(int rows, int cols) override
Definition DenseMatrix.h:426
T & operator()(int rows, int cols) override
Parentheses operator to allow access to the matrix values as Matrix(row,column).
Definition DenseMatrix.h:97
std::valarray< T > scalarDivide(T value) const override
Division of a scalar from the matrix values element-wise.
Definition DenseMatrix.h:222
void updateNonZeroElements() override
Definition DenseMatrix.h:434
DenseMatrix()
Constructor used for buildAtRuntime.
Definition DenseMatrix.h:56
Error class to throw when a module chain has circular or missing dependencies. Inherits from std::exc...
Definition ChainManager.h:28
Template generalized Matrix object that should be the base for all further implementations of a matri...
Definition GenericMatrix.h:17
std::vector< std::pair< int, int > > m_non_zero_elements
Definition GenericMatrix.h:23
Error class to throw when the matrix is accessed out of bounds. Inherits from std::exception.
Definition GenericMatrix.h:122