NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
matrixoperations.cpp File Reference
#include <Eigen/Dense>
#include "matrixoperations.hpp"
#include "matfuncs.hpp"
#include "parser_functions.hpp"
#include "../../kernel.hpp"
#include "../utils/stringtools.hpp"
#include "../io/logger.hpp"
#include <list>
#include <cmath>
Include dependency graph for matrixoperations.cpp:

Go to the source code of this file.

Classes

struct  MatOpCache
 
struct  MatOpCache::MatOpDataAccess
 

Macros

#define EIGENVALUES   0
 
#define EIGENVECTORS   1
 
#define DIAGONALIZE   2
 

Functions

static Matrix evalMatOp (string &sCmd, Parser &_parser, MemoryManager &_data, FunctionDefinitionManager &_functions, const Settings &_option, MatOpCache &_cache)
 This is the actual worker function for matrix operations. It will be called recursively for functions and parentheses. More...
 
static size_t getPrevMatMultiOp (const string &sCmd, size_t nLastPos)
 This static function will search for the position of the next (left-hand) matrix multiplication operator. More...
 
static Matrix multiplyMatrices (const Matrix &_mLeft, const Matrix &_mRight, const string &sCmd, const string &sExpr, size_t position)
 This static function performs the multiplication of two matrices. More...
 
static Matrix getMatrixElements (string &sExpr, const Matrix &_mMatrix, Parser &_parser, MemoryManager &_data, FunctionDefinitionManager &_functions, const Settings &_option)
 This static function extracts parts of the passed matrix based upon the passed index equations. More...
 
static vector< mu::value_typecalcDeltasForMatFill (const std::vector< std::vector< mu::value_type > > &_mMatrix, unsigned int nLine)
 This static function is used to calculate the differences between consecutive matrix elements. More...
 
static void showMatrixResult (const Matrix &_mResult, const Settings &_option)
 This static function formats and prints the calculated matrix to the terminal. More...
 
static Indices getIndicesForMatrix (const string &sCmd, const MatOpCache &_cache, Parser &_parser, MemoryManager &_data, const Settings &_option)
 Static wrapper function for resolving already parsed datafile matrix elements and evaluated matrix expressions, which are used as indices for datafile matrices. More...
 
static bool containsMatrices (const string &sExpr, MemoryManager &_data)
 This static function evaluates, whether there are matrix expressions in the passed expression. More...
 
Matrix transposeMatrix (const Matrix &_mMatrix)
 This static function will transpose the passed matrix (exchange rows with columns). More...
 
Matrix createZeroesMatrix (unsigned int nLines, unsigned int nCols)
 This function returns a matrix filled with zeros with the defined lines and columns. More...
 
static Matrix createMatFromCols (string &sCmd, Parser &_parser, MemoryManager &_data, FunctionDefinitionManager &_functions, const Settings &_option)
 This static function creates a matrix from the passed columns. More...
 
static Matrix createMatFromColsFilled (string &sCmd, Parser &_parser, MemoryManager &_data, FunctionDefinitionManager &_functions, const Settings &_option)
 This static function creates a matrix from the passed columns. More...
 
static Matrix createMatFromLines (string &sCmd, Parser &_parser, MemoryManager &_data, FunctionDefinitionManager &_functions, const Settings &_option)
 This static function creates a matrix from the passed lines. More...
 
static Matrix createMatFromLinesFilled (string &sCmd, Parser &_parser, MemoryManager &_data, FunctionDefinitionManager &_functions, const Settings &_option)
 This static function creates a matrix from the passed lines. More...
 
bool performMatrixOperation (string &sCmd, Parser &_parser, MemoryManager &_data, FunctionDefinitionManager &_functions, const Settings &_option)
 This function is the main interface to the matrix operations. More...
 
static std::string formatMatrixRow (const Matrix &_mResult, const Settings &_option, size_t row)
 
Indices getIndices (const string &sCmd, const Matrix &_mMatrix, Parser &_parser, MemoryManager &_data, const Settings &_option)
 This function creates an Indices object, which is filled with the indices specified by the index equation. More...
 
void showMatrix (const vector< vector< mu::value_type > > &_mMatrix)
 Simple wrapper for the function parser_ShowMatrixResult() to be accessible from the outside. More...
 
static void parser_declareMatrixReturnValuesForIndices (const string &_sCmd, const vector< Matrix > &vReturnedMatrices, Parser &_parser)
 Static helper function for parser_getIndicesForMatrix(), which will handle the return values of matrix evaluations. More...
 
static void parser_declareDataMatrixValuesForIndices (string &_sCmd, const MatOpCache &_cache, Parser &_parser, MemoryManager &_data)
 Static helper function for parser_getIndicesForMatrix(), which will handle the indices of already parsed datafile matrices. More...
 

Macro Definition Documentation

◆ DIAGONALIZE

#define DIAGONALIZE   2

Definition at line 31 of file matrixoperations.cpp.

◆ EIGENVALUES

#define EIGENVALUES   0

Definition at line 29 of file matrixoperations.cpp.

◆ EIGENVECTORS

#define EIGENVECTORS   1

Definition at line 30 of file matrixoperations.cpp.

Function Documentation

◆ calcDeltasForMatFill()

static vector< mu::value_type > calcDeltasForMatFill ( const std::vector< std::vector< mu::value_type > > &  _mMatrix,
unsigned int  nLine 
)
static

This static function is used to calculate the differences between consecutive matrix elements.

Parameters
_mMatrixconst std::vector<std::vector<mu::value_type>>&
nLineunsigned int
Returns
vector<mu::value_type>

This function is used by the matf*f() functions to derive the filling logic.

Definition at line 1140 of file matrixoperations.cpp.

Referenced by createMatFromLinesFilled().

◆ containsMatrices()

static bool containsMatrices ( const string &  sExpr,
MemoryManager _data 
)
static

This static function evaluates, whether there are matrix expressions in the passed expression.

Parameters
sExprconst string&
_dataDatafile&
Returns
bool

Definition at line 1643 of file matrixoperations.cpp.

References MemoryManager::containsTablesOrClusters(), and getMatrixFunctions().

Referenced by evalMatOp(), and performMatrixOperation().

Here is the call graph for this function:

◆ createMatFromCols()

static Matrix createMatFromCols ( string &  sCmd,
Parser _parser,
MemoryManager _data,
FunctionDefinitionManager _functions,
const Settings _option 
)
static

This static function creates a matrix from the passed columns.

Parameters
sCmdstring&
_parserParser&
_dataDatafile&
_functionsDefine&
_optionconst Settings&
Returns
Matrix

Missing elements are filled up with zeros.

Definition at line 973 of file matrixoperations.cpp.

References createMatFromLines(), and transposeMatrix().

Referenced by evalMatOp().

Here is the call graph for this function:

◆ createMatFromColsFilled()

static Matrix createMatFromColsFilled ( string &  sCmd,
Parser _parser,
MemoryManager _data,
FunctionDefinitionManager _functions,
const Settings _option 
)
static

This static function creates a matrix from the passed columns.

Parameters
sCmdstring&
_parserParser&
_dataDatafile&
_functionsDefine&
_optionconst Settings&
Returns
Matrix

Missing elements are filled up logically.

Definition at line 992 of file matrixoperations.cpp.

References createMatFromLinesFilled(), and transposeMatrix().

Referenced by evalMatOp().

Here is the call graph for this function:

◆ createMatFromLines()

static Matrix createMatFromLines ( string &  sCmd,
Parser _parser,
MemoryManager _data,
FunctionDefinitionManager _functions,
const Settings _option 
)
static

This static function creates a matrix from the passed lines.

Parameters
sCmdstring&
_parserParser&
_dataDatafile&
_functionsDefine&
_optionconst Settings&
Returns
Matrix

Missing elements are filled up with zeros.

Definition at line 1011 of file matrixoperations.cpp.

References FunctionDefinitionManager::call(), MemoryManager::containsTablesOrClusters(), mu::ParserBase::Eval(), SyntaxError::FUNCTION_ERROR, getDataElements(), getNextArgument(), SyntaxError::invalid_position, and mu::ParserBase::SetExpr().

Referenced by createMatFromCols(), and evalMatOp().

Here is the call graph for this function:

◆ createMatFromLinesFilled()

static Matrix createMatFromLinesFilled ( string &  sCmd,
Parser _parser,
MemoryManager _data,
FunctionDefinitionManager _functions,
const Settings _option 
)
static

This static function creates a matrix from the passed lines.

Parameters
sCmdstring&
_parserParser&
_dataDatafile&
_functionsDefine&
_optionconst Settings&
Returns
Matrix

Missing elements are filled up logically.

Definition at line 1070 of file matrixoperations.cpp.

References calcDeltasForMatFill(), FunctionDefinitionManager::call(), MemoryManager::containsTablesOrClusters(), mu::ParserBase::Eval(), SyntaxError::FUNCTION_ERROR, getDataElements(), getNextArgument(), SyntaxError::invalid_position, and mu::ParserBase::SetExpr().

Referenced by createMatFromColsFilled(), and evalMatOp().

Here is the call graph for this function:

◆ createZeroesMatrix()

Matrix createZeroesMatrix ( unsigned int  nLines,
unsigned int  nCols 
)

This function returns a matrix filled with zeros with the defined lines and columns.

Parameters
nLinesunsigned int
nColsunsigned int
Returns
Matrix

This function is not static, because it is used from somewhere else.

Definition at line 951 of file matrixoperations.cpp.

References createFilledMatrix(), SyntaxError::invalid_position, and SyntaxError::MATRIX_CANNOT_HAVE_ZERO_SIZE.

Referenced by evalMatOp(), and getMatrixElements().

Here is the call graph for this function:

◆ evalMatOp()

static Matrix evalMatOp ( string &  sCmd,
Parser _parser,
MemoryManager _data,
FunctionDefinitionManager _functions,
const Settings _option,
MatOpCache _cache 
)
static

This is the actual worker function for matrix operations. It will be called recursively for functions and parentheses.

Parameters
sCmdstring&
_parserParser&
_dataDatafile&
_functionsDefine&
_optionconst Settings&
Returns
Matrix

Definition at line 286 of file matrixoperations.cpp.

References addMissingVectorComponent(), Indices::col, containsMatrices(), createMatFromCols(), createMatFromColsFilled(), createMatFromLines(), createMatFromLinesFilled(), createZeroesMatrix(), Matrix::data(), DetachedLogger::debug(), errorInfo, mu::ParserBase::Eval(), evalMatOp(), evaluateIndices(), Matrix::extend(), g_logger, NumeRe::ClusterManager::getClusterMap(), getIndicesForMatrix(), getMatchingParenthesis(), getMatrixElements(), getMatrixFunctions(), getNextArgument(), getPrevMatMultiOp(), MemoryManager::getTable(), MemoryManager::getTableMap(), MatOpCache::MatOpDataAccess::idx, intCast(), SyntaxError::INVALID_DATA_ACCESS, isDelimiter(), Matrix::isEmpty(), isEqualStripped(), VectorIndex::isOpenEnd(), MATSIG_INVALID, MATSIG_MAT, MATSIG_MAT_F, MATSIG_MAT_F_N, MATSIG_MAT_MAT, MATSIG_MAT_MAT_MAT, MATSIG_MAT_MAT_N, MATSIG_MAT_N_MOPT, MATSIG_MAT_NOPT, MATSIG_N_MOPT, max, MatOpCache::MatOpDataAccess::missingValues, multiplyMatrices(), SyntaxError::NO_MATRIX_FOR_MATOP, Matrix::printDims(), Memory::readMemAsMatrix(), Indices::row, mu::ParserBase::SetExpr(), VectorIndex::setRange(), mu::ParserBase::SetVectorVar(), VectorIndex::size(), MatOpCache::MatOpDataAccess::sName, StrToInt(), toString(), MatOpCache::vDataAccesses, and MatOpCache::vReturnedMatrices.

Referenced by evalMatOp(), and performMatrixOperation().

Here is the call graph for this function:

◆ formatMatrixRow()

static std::string formatMatrixRow ( const Matrix _mResult,
const Settings _option,
size_t  row 
)
static

Definition at line 1194 of file matrixoperations.cpp.

References Matrix::cols(), Settings::getWindow(), strfill(), and toString().

Referenced by showMatrixResult().

Here is the call graph for this function:

◆ getIndices()

Indices getIndices ( const string &  sCmd,
const Matrix _mMatrix,
Parser _parser,
MemoryManager _data,
const Settings _option 
)

This function creates an Indices object, which is filled with the indices specified by the index equation.

Parameters
sCmdconst string&
_mMatrixconst Matrix&
_parserParser&
_dataDatafile&
_optionconst Settings&
Returns
Indices

Definition at line 1337 of file matrixoperations.cpp.

References VectorIndex::back(), Indices::col, Matrix::cols(), MemoryManager::containsTablesOrClusters(), mu::ParserBase::Eval(), VectorIndex::front(), getDataElements(), intCast(), SyntaxError::INVALID_INDEX, SyntaxError::invalid_position, mu::isinf(), mu::isnan(), Indices::row, Matrix::rows(), mu::ParserBase::SetExpr(), VectorIndex::setIndex(), and StripSpaces().

Referenced by getIndicesForMatrix(), getMatrixElements(), and performMatrixOperation().

Here is the call graph for this function:

◆ getIndicesForMatrix()

static Indices getIndicesForMatrix ( const string &  sCmd,
const MatOpCache _cache,
Parser _parser,
MemoryManager _data,
const Settings _option 
)
static

Static wrapper function for resolving already parsed datafile matrix elements and evaluated matrix expressions, which are used as indices for datafile matrices.

Parameters
sCmdconst string&
_cacheconst MatOpCache&
_parserParser&
_dataDatafile&
_optionconst Settings&
Returns
Indices

Definition at line 1614 of file matrixoperations.cpp.

References getIndices(), parser_declareDataMatrixValuesForIndices(), parser_declareMatrixReturnValuesForIndices(), and MatOpCache::vReturnedMatrices.

Referenced by evalMatOp().

Here is the call graph for this function:

◆ getMatrixElements()

static Matrix getMatrixElements ( string &  sExpr,
const Matrix _mMatrix,
Parser _parser,
MemoryManager _data,
FunctionDefinitionManager _functions,
const Settings _option 
)
static

This static function extracts parts of the passed matrix based upon the passed index equations.

Parameters
sExprstring&
_mMatrixconst Matrix&
_parserParser&
_dataDatafile&
_functionsDefine&
_optionconst Settings&
Returns
Matrix

Definition at line 1165 of file matrixoperations.cpp.

References Indices::col, Matrix::cols(), createZeroesMatrix(), getIndices(), SyntaxError::INVALID_INDEX, SyntaxError::invalid_position, VectorIndex::isOpenEnd(), Indices::row, Matrix::rows(), VectorIndex::setRange(), VectorIndex::size(), and VectorIndex::to_string().

Referenced by evalMatOp().

Here is the call graph for this function:

◆ getPrevMatMultiOp()

static size_t getPrevMatMultiOp ( const string &  sCmd,
size_t  nLastPos 
)
static

This static function will search for the position of the next (left-hand) matrix multiplication operator.

Parameters
sCmdconst string&
nLastPossize_t
Returns
size_t

Definition at line 880 of file matrixoperations.cpp.

Referenced by evalMatOp().

◆ multiplyMatrices()

static Matrix multiplyMatrices ( const Matrix _mLeft,
const Matrix _mRight,
const string &  sCmd,
const string &  sExpr,
size_t  position 
)
static

This static function performs the multiplication of two matrices.

Parameters
_mLeftconst Matrix&
_mRightconst Matrix&
sCmdconst string&
sExprconst string&
positionsize_t
Returns
Matrix

Definition at line 912 of file matrixoperations.cpp.

References Matrix::cols(), Matrix::isEmpty(), SyntaxError::MATRIX_CANNOT_HAVE_ZERO_SIZE, Matrix::printDims(), Matrix::rows(), and SyntaxError::WRONG_MATRIX_DIMENSIONS_FOR_MATOP.

Referenced by evalMatOp().

Here is the call graph for this function:

◆ parser_declareDataMatrixValuesForIndices()

static void parser_declareDataMatrixValuesForIndices ( string &  _sCmd,
const MatOpCache _cache,
Parser _parser,
MemoryManager _data 
)
static

Static helper function for parser_getIndicesForMatrix(), which will handle the indices of already parsed datafile matrices.

Parameters
_sCmdstring&
_cacheconst MatOpCache&
Parser&_parser
_dataDatafile&
Returns
void

Definition at line 1580 of file matrixoperations.cpp.

References Indices::col, MemoryManager::getElement(), MatOpCache::MatOpDataAccess::idx, Indices::row, mu::ParserBase::SetVectorVar(), VectorIndex::size(), MatOpCache::MatOpDataAccess::sName, toString(), and MatOpCache::vDataAccesses.

Referenced by getIndicesForMatrix().

Here is the call graph for this function:

◆ parser_declareMatrixReturnValuesForIndices()

static void parser_declareMatrixReturnValuesForIndices ( const string &  _sCmd,
const vector< Matrix > &  vReturnedMatrices,
Parser _parser 
)
static

Static helper function for parser_getIndicesForMatrix(), which will handle the return values of matrix evaluations.

Parameters
_sCmdconst string&
vReturnedMatricesconst vector<Matrix>&
_parserParser&
Returns
void

Definition at line 1540 of file matrixoperations.cpp.

References mu::ParserBase::SetVectorVar(), and toString().

Referenced by getIndicesForMatrix().

Here is the call graph for this function:

◆ performMatrixOperation()

bool performMatrixOperation ( string &  sCmd,
Parser _parser,
MemoryManager _data,
FunctionDefinitionManager _functions,
const Settings _option 
)

◆ showMatrix()

void showMatrix ( const vector< vector< mu::value_type > > &  _mMatrix)

Simple wrapper for the function parser_ShowMatrixResult() to be accessible from the outside.

Parameters
_mMatrixconst vector<vector<mu::value_type>>&
Returns
void

Definition at line 1524 of file matrixoperations.cpp.

References NumeReKernel::getInstance(), and showMatrixResult().

Here is the call graph for this function:

◆ showMatrixResult()

static void showMatrixResult ( const Matrix _mResult,
const Settings _option 
)
static

This static function formats and prints the calculated matrix to the terminal.

Parameters
_mResultconst Matrix&
_optionconst Settings&
Returns
void

Definition at line 1231 of file matrixoperations.cpp.

References NumeReKernel::bSupressAnswer, Matrix::cols(), NumeReKernel::flush(), formatMatrixRow(), Settings::getPrecision(), Settings::getWindow(), NumeReKernel::print(), NumeReKernel::printPreFmt(), Matrix::rows(), strfill(), Settings::systemPrints(), NumeReKernel::toggleTableStatus(), and toString().

Referenced by performMatrixOperation(), and showMatrix().

Here is the call graph for this function:

◆ transposeMatrix()

Matrix transposeMatrix ( const Matrix _mMatrix)

This static function will transpose the passed matrix (exchange rows with columns).

Parameters
_mMatrixconst Matrix&
Returns
Matrix

Definition at line 934 of file matrixoperations.cpp.

References SyntaxError::invalid_position, and transposeMatrix().

Referenced by createMatFromCols(), createMatFromColsFilled(), and transposeMatrix().

Here is the call graph for this function: