NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
|
#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>
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_type > | calcDeltasForMatFill (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... | |
#define DIAGONALIZE 2 |
Definition at line 31 of file matrixoperations.cpp.
#define EIGENVALUES 0 |
Definition at line 29 of file matrixoperations.cpp.
#define EIGENVECTORS 1 |
Definition at line 30 of file matrixoperations.cpp.
|
static |
This static function is used to calculate the differences between consecutive matrix elements.
_mMatrix | const std::vector<std::vector<mu::value_type>>& |
nLine | unsigned int |
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().
|
static |
This static function evaluates, whether there are matrix expressions in the passed expression.
sExpr | const string& |
_data | Datafile& |
Definition at line 1643 of file matrixoperations.cpp.
References MemoryManager::containsTablesOrClusters(), and getMatrixFunctions().
Referenced by evalMatOp(), and performMatrixOperation().
|
static |
This static function creates a matrix from the passed columns.
sCmd | string& |
_parser | Parser& |
_data | Datafile& |
_functions | Define& |
_option | const Settings& |
Missing elements are filled up with zeros.
Definition at line 973 of file matrixoperations.cpp.
References createMatFromLines(), and transposeMatrix().
Referenced by evalMatOp().
|
static |
This static function creates a matrix from the passed columns.
sCmd | string& |
_parser | Parser& |
_data | Datafile& |
_functions | Define& |
_option | const Settings& |
Missing elements are filled up logically.
Definition at line 992 of file matrixoperations.cpp.
References createMatFromLinesFilled(), and transposeMatrix().
Referenced by evalMatOp().
|
static |
This static function creates a matrix from the passed lines.
sCmd | string& |
_parser | Parser& |
_data | Datafile& |
_functions | Define& |
_option | const Settings& |
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().
|
static |
This static function creates a matrix from the passed lines.
sCmd | string& |
_parser | Parser& |
_data | Datafile& |
_functions | Define& |
_option | const Settings& |
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().
Matrix createZeroesMatrix | ( | unsigned int | nLines, |
unsigned int | nCols | ||
) |
This function returns a matrix filled with zeros with the defined lines and columns.
nLines | unsigned int |
nCols | unsigned int |
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().
|
static |
This is the actual worker function for matrix operations. It will be called recursively for functions and parentheses.
sCmd | string& |
_parser | Parser& |
_data | Datafile& |
_functions | Define& |
_option | const Settings& |
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().
|
static |
Definition at line 1194 of file matrixoperations.cpp.
References Matrix::cols(), Settings::getWindow(), strfill(), and toString().
Referenced by showMatrixResult().
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.
sCmd | const string& |
_mMatrix | const Matrix& |
_parser | Parser& |
_data | Datafile& |
_option | const Settings& |
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().
|
static |
Static wrapper function for resolving already parsed datafile matrix elements and evaluated matrix expressions, which are used as indices for datafile matrices.
sCmd | const string& |
_cache | const MatOpCache& |
_parser | Parser& |
_data | Datafile& |
_option | const Settings& |
Definition at line 1614 of file matrixoperations.cpp.
References getIndices(), parser_declareDataMatrixValuesForIndices(), parser_declareMatrixReturnValuesForIndices(), and MatOpCache::vReturnedMatrices.
Referenced by evalMatOp().
|
static |
This static function extracts parts of the passed matrix based upon the passed index equations.
sExpr | string& |
_mMatrix | const Matrix& |
_parser | Parser& |
_data | Datafile& |
_functions | Define& |
_option | const Settings& |
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().
|
static |
This static function will search for the position of the next (left-hand) matrix multiplication operator.
sCmd | const string& |
nLastPos | size_t |
Definition at line 880 of file matrixoperations.cpp.
Referenced by evalMatOp().
|
static |
This static function performs the multiplication of two matrices.
_mLeft | const Matrix& |
_mRight | const Matrix& |
sCmd | const string& |
sExpr | const string& |
position | size_t |
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().
|
static |
Static helper function for parser_getIndicesForMatrix(), which will handle the indices of already parsed datafile matrices.
_sCmd | string& |
_cache | const MatOpCache& |
Parser&_parser | |
_data | Datafile& |
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().
|
static |
Static helper function for parser_getIndicesForMatrix(), which will handle the return values of matrix evaluations.
_sCmd | const string& |
vReturnedMatrices | const vector<Matrix>& |
_parser | Parser& |
Definition at line 1540 of file matrixoperations.cpp.
References mu::ParserBase::SetVectorVar(), and toString().
Referenced by getIndicesForMatrix().
bool performMatrixOperation | ( | string & | sCmd, |
Parser & | _parser, | ||
MemoryManager & | _data, | ||
FunctionDefinitionManager & | _functions, | ||
const Settings & | _option | ||
) |
This function is the main interface to the matrix operations.
sCmd | string& |
_parser | Parser& |
_data | Datafile& |
_functions | Define& |
_option | const Settings& |
Definition at line 86 of file matrixoperations.cpp.
References _assertionHandler, MemoryManager::addTable(), FunctionDefinitionManager::call(), Assertion::checkAssertion(), NumeRe::Cluster::clear(), Indices::col, Matrix::cols(), containsMatrices(), DetachedLogger::debug(), MemoryManager::deleteBulk(), evalMatOp(), evalRecursiveExpressions(), findCommand(), VectorIndex::front(), SyntaxError::FUNCTION_ERROR, g_logger, NumeRe::ClusterManager::getCluster(), MemoryManager::getCols(), getIndices(), MemoryManager::getLines(), MemoryManager::getTable(), VectorIndex::INVALID, SyntaxError::INVALID_DATA_ACCESS, SyntaxError::INVALID_INDEX, SyntaxError::invalid_position, NumeRe::ClusterManager::isCluster(), Matrix::isEmpty(), MemoryManager::isTable(), isValidIndexSet(), Memory::markModified(), VectorIndex::max(), NumeRe::ClusterManager::newCluster(), SyntaxError::NO_MATRIX_FOR_MATOP, VectorIndex::OPEN_END, MemoryManager::resizeTable(), Indices::row, Matrix::rows(), NumeRe::Cluster::setDouble(), showMatrixResult(), StripSpaces(), VectorIndex::subidx(), VectorIndex::to_string(), Memory::writeData(), and Memory::writeDataDirectUnsafe().
Referenced by cmd_matop().
void showMatrix | ( | const vector< vector< mu::value_type > > & | _mMatrix | ) |
Simple wrapper for the function parser_ShowMatrixResult() to be accessible from the outside.
_mMatrix | const vector<vector<mu::value_type>>& |
Definition at line 1524 of file matrixoperations.cpp.
References NumeReKernel::getInstance(), and showMatrixResult().
This static function formats and prints the calculated matrix to the terminal.
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().
This static function will transpose the passed matrix (exchange rows with columns).
_mMatrix | const Matrix& |
Definition at line 934 of file matrixoperations.cpp.
References SyntaxError::invalid_position, and transposeMatrix().
Referenced by createMatFromCols(), createMatFromColsFilled(), and transposeMatrix().