19#ifndef MATDATASTRUCTURES_HPP
20#define MATDATASTRUCTURES_HPP
27#include "../ui/error.hpp"
28#include "../utils/stringtools.hpp"
87 for (
size_t i = 0; i <
m_rows; i++)
89 for (
size_t j = 0; j <
m_cols; j++)
140 Matrix(
const std::vector<std::vector<mu::value_type>>& vectMatrix) :
Matrix()
142 m_rows = vectMatrix.size();
143 m_cols = vectMatrix[0].size();
145 for (
size_t i = 1; i <
m_rows; i++)
152 for (
size_t i = 0; i <
m_rows; i++)
154 for (
size_t j = 0; j < vectMatrix[i].size(); j++)
155 get(i, j) = vectMatrix[i][j];
170 assign(r, c, vVals, nVals);
229 void assign(
size_t r,
size_t c,
const std::vector<mu::value_type>& vVals)
245 std::vector<mu::value_type>&
data()
257 const std::vector<mu::value_type>&
data()
const
302 std::pair<size_t,size_t>
dims()
const
427 std::vector<mu::value_type> buffer(r*c);
430 #pragma omp parallel for
469 bool rowScalar =
m_rows == 1 && r > 1;
470 bool colScalar =
m_cols == 1 && c > 1;
477 for (
size_t i = 1; i <
m_rows; i++)
479 for (
size_t j = 0; j <
m_cols; j++)
487 for (
size_t j = 1; j <
m_cols; j++)
489 for (
size_t i = 0; i <
m_rows; i++)
529 #pragma omp parallel for
530 for (
size_t i = 0; i < ret.
m_rows; i++)
532 for (
size_t j = 0; j < ret.
m_cols; j++)
534 for (
size_t k = 0; k <
m_cols; k++)
538 ret.
get(i, j) +=
get(i, k) * mat.
get(k, j);
561 for (
size_t i = 0; i <
m_rows; i++)
563 for (
size_t j = 0; j <
m_cols; j++)
565 mRet.
get(i, j) =
get(i, j);
570 for (
size_t i = 0; i < mat.
m_rows; i++)
572 for (
size_t j = 0; j < mat.
m_cols; j++)
596 for (
size_t i = 0; i <
m_rows; i++)
598 for (
size_t j = 0; j <
m_cols; j++)
600 mRet.
get(i, j) =
get(i, j);
605 for (
size_t i = 0; i < mat.
m_rows; i++)
607 for (
size_t j = 0; j < mat.
m_cols; j++)
This class defines a dynamic size 2D matrix with a single 1D internal buffer. If the internal buffer ...
Matrix(size_t r, size_t c, mu::value_type *vVals, int nVals)
Assign constructor from large array.
Matrix operator*(const Matrix &mat) const
Multiply this matrix with a matrix from the right.
std::string printDims() const
Convert the dimensions to a printable string.
void extend(size_t r, size_t c)
Extend this matrix to be prepared for the acutal mathematical operation. Scalars are not touched and ...
void bakeTransposition()
Bakes the transposition by swapping the actual elements instead of changing the read order.
const std::vector< mu::value_type > & data() const
Get a const reference to the internal data structure.
const mu::value_type & get(size_t i, size_t j) const
Const declared overload to the indexed access.
Matrix vcat(const Matrix &mat) const
Vertically concatenate two matrices.
void assign(size_t r, size_t c, mu::value_type *vVals, int nVals)
Assign a large array.
size_t m_rows
Number of rows.
Matrix()
Empty matrix default constructor.
std::vector< mu::value_type > & data()
Get a reference to the internal data structure.
Matrix & operator=(const Matrix &mat)
Assignment operator overload.
void resize(size_t r, size_t c)
Resize the matrix to another dimension. New elements will be zero-initialized.
void assign(size_t r, size_t c, const std::vector< mu::value_type > &vVals)
Assign a vector.
mu::value_type & operator()(size_t i, size_t j=0u)
Get a reference to the indexed element.
Matrix & operator*=(const Matrix &mat)
Multiply a matrix from the right to this matrix.
bool isSquare() const
Simple function to identify square matrices.
bool isEmpty() const
Simple function to identify empty matrices.
const mu::value_type & operator()(size_t i, size_t j=0u) const
Get a const reference to the indexed element.
size_t cols() const
The cols of this matrix.
mu::value_type & get(size_t i, size_t j)
Unchecked method to access indexed elements.
void assign(const Matrix &mat)
Assign a matrix.
size_t m_cols
Number of columns.
Matrix(const Matrix &mat)
Matrix copy constructor.
size_t rows() const
The rows of this matrix.
void transpose()
Transpose this matrix.
bool isScalar() const
Check, whether this matrix is actually a scalar.
Matrix hcat(const Matrix &mat) const
Horizontally concatenate two matrices.
std::vector< mu::value_type > m_storage
The internal buffer.
std::pair< size_t, size_t > dims() const
Get both dimensions at once.
Matrix(const std::vector< std::vector< mu::value_type > > &vectMatrix)
Construct a matrix from a vector matrix.
bool m_transpose
Is this Matrix transposed.
Matrix(Matrix &&mat)=default
bool containsInvalidValues() const
Returns true, if this matrix contains invalid values.
Matrix(size_t r, size_t c=1u, const mu::value_type &init=NAN)
Fill constructor.
Common exception class for all exceptions thrown in NumeRe.
@ WRONG_MATRIX_DIMENSIONS_FOR_MATOP
static size_t invalid_position
MatFuncSignature
Defines the different matrix function signatures.
Matrix(* MatFunc)(const MatFuncData &, const MatFuncErrorInfo &)
Defines the MatFunc type.
MUP_BASETYPE value_type
The numeric datatype used by the parser.
bool isnan(const value_type &v)
bool isinf(const value_type &v)
MatFuncData(const Matrix &_mat, int n=0)
MatFuncData(const Matrix &_mat1, const Matrix &_mat2)
MatFuncData(int n, int m=0)
MatFuncData(const Matrix &_mat, mu::value_type f, int n)
MatFuncData(const Matrix &_mat1, const Matrix &_mat2, const Matrix &_mat3)
MatFuncData(const Matrix &_mat, int n, int m)
MatFuncData(const Matrix &_mat1, const Matrix &_mat2, int n)
MatFuncData(const Matrix &_mat, mu::value_type f)
Defines a matrix function itself by containing the signature, the pointer to the implementation and a...
MatFuncDef(MatFuncSignature sig, MatFunc f, bool isMatFunc=true)
MatFuncSignature signature
Defines the needed information for displaying a reasonable error information.
MatFuncErrorInfo(const std::string &_sCmd, const std::string &_sExpr, size_t pos)
const std::string & command
const std::string & expression
std::string toString(int)
Converts an integer to a string without the Settings bloat.