23#include "../../kernel.hpp"
24#include "../utils/stringtools.hpp"
25#include "../io/logger.hpp"
57static vector<mu::value_type>
calcDeltasForMatFill(
const std::vector<std::vector<mu::value_type>>& _mMatrix,
unsigned int nLine);
90 string sTargetName =
"";
93 bool bAllowMatrixClearing =
false;
94 bool isCluster =
false;
103 if (!_functions.
call(sCmd))
115 if (sCmd.find(
'=') != string::npos
117 && sCmd[sCmd.find(
'=')+1] !=
'='
118 && sCmd[sCmd.find(
'=')-1] !=
'!'
119 && sCmd[sCmd.find(
'=')-1] !=
'<'
120 && sCmd[sCmd.find(
'=')-1] !=
'>'
121 && sCmd.substr(0, sCmd.find(
'=')).find_first_of(
"({") != string::npos
122 && sCmd[sCmd.find_first_not_of(
' ')] !=
'{')
124 sTargetName = sCmd.substr(0, sCmd.find(
'='));
126 size_t parens = sTargetName.find_first_of(
"({");
128 if (parens == string::npos)
132 if (sTargetName[parens] ==
'(')
135 if (!_data.
isTable(sTargetName))
136 _data.
addTable(sTargetName.substr(0, parens), _option);
138 if (sTargetName.substr(sTargetName.find(
'('),2) ==
"()")
140 bAllowMatrixClearing =
true;
145 else if (sTargetName[parens] ==
'{')
153 if (sTargetName.substr(sTargetName.find(
'{'),2) ==
"{}")
155 bAllowMatrixClearing =
true;
161 if (!bAllowMatrixClearing)
162 getIndices(sTargetName, _idx, _parser, _data, _option);
167 sCmd.erase(0, sCmd.find(
'=')+1);
169 sTargetName.erase(sTargetName.find_first_of(
"({"));
173 sTargetName =
"matrix";
180 bAllowMatrixClearing =
true;
186 Matrix _mResult =
evalMatOp(sCmd, _parser, _data, _functions, _option, _cache);
198 if (bAllowMatrixClearing)
207 for (
size_t j = 0; j < _mResult.
cols(); j++)
216 #pragma omp parallel for
217 for (
unsigned int j = 0; j < _mResult.
cols(); j++)
222 for (
unsigned int i = 0; i < _mResult.
rows(); i++)
238 if (bAllowMatrixClearing)
242 if (_mResult.
rows() == 1)
245 for (
size_t i = 0; i < _mResult.
cols(); i++)
256 for (
size_t i = 0; i < _mResult.
rows(); i++)
290 size_t iter_start = 0;
297 size_t nEqPos = sCmd.find(
'=');
299 if (nEqPos != string::npos
301 && sCmd[nEqPos+1] !=
'='
302 && sCmd[nEqPos-1] !=
'!'
303 && sCmd[nEqPos-1] !=
'<'
304 && sCmd[nEqPos-1] !=
'>'
305 && sCmd.substr(0, nEqPos).find(
'{') != string::npos)
307 iter_start = nEqPos+1;
313 for (
unsigned int i = iter_start; i < sCmd.length(); i++)
315 size_t nMatchingParens;
319 if ((!i ||
isDelimiter(sCmd[i-1])) && (isalpha(sCmd[i]) || sCmd[i] ==
'{'))
321 for (
auto fIter = mMatrixFunctions.begin(); fIter != mMatrixFunctions.end(); ++fIter)
326 if (
StringView(sCmd, i, fIter->first.length()+1) == fIter->first +
"("
330 std::string sSubExpr = sCmd.substr(i+fIter->first.length()+1, nMatchingParens-1);
337 switch (fIter->second.signature)
351 if (sSubExpr.length())
354 v = _parser.
Eval(nResults);
364 _cache.
vReturnedMatrices.push_back(fIter->second.func(
MatFuncData(
evalMatOp(sMatrix1, _parser, _data, _functions, _option, _cache),
evalMatOp(sSubExpr, _parser, _data, _functions, _option, _cache)),
errorInfo));
371 _cache.
vReturnedMatrices.push_back(fIter->second.func(
MatFuncData(
evalMatOp(sMatrix1, _parser, _data, _functions, _option, _cache),
evalMatOp(sMatrix2, _parser, _data, _functions, _option, _cache),
evalMatOp(sSubExpr, _parser, _data, _functions, _option, _cache)),
errorInfo));
379 v = _parser.
Eval(nResults);
381 _cache.
vReturnedMatrices.push_back(fIter->second.func(
MatFuncData(
evalMatOp(sMatrix1, _parser, _data, _functions, _option, _cache),
evalMatOp(sMatrix2, _parser, _data, _functions, _option, _cache), n),
errorInfo));
389 v = _parser.
Eval(nResults);
400 v = _parser.
Eval(nResults);
402 int n = nResults > 1 ?
intCast(v[1]) : 0;
412 v = _parser.
Eval(nResults);
425 v = _parser.
Eval(nResults);
437 __sCmd += sCmd.substr(pos_back, i-pos_back);
441 pos_back = i+nMatchingParens+fIter->first.length()+1;
450 if (sCmd.substr(i,6) ==
"matfc("
453 string sSubExpr = sCmd.substr(i+6, nMatchingParens-1);
454 __sCmd += sCmd.substr(pos_back, i-pos_back);
456 pos_back = i+nMatchingParens+6;
462 if (sCmd.substr(i,6) ==
"matfl("
465 string sSubExpr = sCmd.substr(i+6, nMatchingParens-1);
466 __sCmd += sCmd.substr(pos_back, i-pos_back);
468 pos_back = i+nMatchingParens+6;
474 if (sCmd.substr(i,7) ==
"matfcf("
477 string sSubExpr = sCmd.substr(i+7, nMatchingParens-1);
478 __sCmd += sCmd.substr(pos_back, i-pos_back);
480 pos_back = i+nMatchingParens+7;
486 if (sCmd.substr(i,7) ==
"matflf("
489 string sSubExpr = sCmd.substr(i+7, nMatchingParens-1);
490 __sCmd += sCmd.substr(pos_back, i-pos_back);
492 pos_back = i+nMatchingParens+7;
498 if (sCmd.substr(i,2) ==
"{{"
501 string sSubExpr = sCmd.substr(i+1, nMatchingParens-1);
502 __sCmd += sCmd.substr(pos_back, i-pos_back);
504 pos_back = i+nMatchingParens+1;
513 string sSubExpr = sCmd.substr(i, nMatchingParens+1);
514 __sCmd += sCmd.substr(pos_back, i-pos_back);
516 pos_back = i+nMatchingParens+1;
526 && sCmd.find_last_not_of(
' ',i-1) != string::npos
527 && (__sCmd.back() ==
']' || __sCmd.back() ==
')'))
530 nMatrix =
StrToInt(__sCmd.substr(__sCmd.rfind(
'[')+1, __sCmd.rfind(
']')-__sCmd.rfind(
'[')-1));
531 if (__sCmd.substr(__sCmd.rfind(
'[')-16,17) ==
"_~returnedMatrix[")
534 string sSubExpr = sCmd.substr(i, nMatchingParens+1);
535 pos_back = i+nMatchingParens+1;
547 if (sCmd.substr(i, nMatchingParens).find(
"**") != string::npos
548 || (sCmd.length() > i+nMatchingParens+1 && sCmd[i+nMatchingParens+1] ==
'('))
554 string sSubExpr = sCmd.substr(i+1, nMatchingParens-1);
555 size_t closing_par_pos = i+nMatchingParens;
557 if (sCmd.length() > closing_par_pos+1 && sCmd[closing_par_pos+1] ==
'(')
559 if (i && (isalnum(sCmd[i-1]) || sCmd[i-1] ==
'_'))
561 for (
int j = i-1; j >= 0; j--)
563 if ((j && !isalnum(sCmd[j-1]) && sCmd[j-1] !=
'_') || !j)
565 __sCmd += sCmd.substr(pos_back, j-pos_back);
566 sSubExpr = sCmd.substr(j, closing_par_pos+1 - j);
572 __sCmd += sCmd.substr(pos_back, i-pos_back);
579 __sCmd += sCmd.substr(pos_back, i-pos_back);
585 while (sSubExpr.length())
597 if (sSubExpr.length())
604 pos_back = closing_par_pos+1;
611 if (pos_back < sCmd.length())
612 __sCmd += sCmd.substr(pos_back);
614 unsigned int nPos = 0;
622 while ((nPos = __sCmd.find(iter->first+
"(", nPos)) != string::npos)
641 _access.
sName = iter->first;
662 while ((nPos = __sCmd.find(iter->first+
"{", nPos)) != string::npos)
681 for (
size_t i = 0; i < _idx.
row.
size(); i++)
683 _mClusterMatrix(i) = iter->second.getDouble(_idx.
row[i]);
691 __sCmd.replace(nPos,
getMatchingParenthesis(__sCmd.substr(nPos+(iter->first).length()))+(iter->first).length()+1,
696 pos_back = sCmd.length();
699 if (__sCmd.find(
"**") != string::npos)
703 for (
int n = __sCmd.length()-1; n >= 0; n--)
706 if (__sCmd.substr(n, 2) ==
"**")
712 unsigned int nPositions[2];
713 nPositions[1] = __sCmd.find(
']',n)+1;
714 string sElement = __sCmd.substr(__sCmd.find_first_not_of(
' ', n+2));
719 for (
size_t i = 0; i < sElement.length(); i++)
721 if ((sElement[i] ==
'(' || sElement[i] ==
'{' || sElement[i] ==
'[')
725 if (!isalnum(sElement[i]) && sElement[i] !=
'_' && sElement[i] !=
'~')
727 std::string sSubExpr = sElement.substr(0, i);
728 nPositions[1] = i+__sCmd.find_first_not_of(
' ', n+2);
730 _mRight =
evalMatOp(sSubExpr, _parser, _data, _functions, _option, _cache);
741 p = __sCmd.find_last_not_of(
" *", n);
743 for (
int i = p; i >= 0; i--)
745 if (__sCmd[i] ==
')' || __sCmd[i] ==
'}' || __sCmd[i] ==
']')
748 if (__sCmd[i] ==
'(' || __sCmd[i] ==
'{' || __sCmd[i] ==
'[')
752 && (!i || (!isalnum(__sCmd[i-1]) && __sCmd[i-1] !=
'_' && __sCmd[i-1] !=
'~')))
754 std::string sSubExpr = __sCmd.substr(i, p - i+1);
757 _mLeft =
evalMatOp(sSubExpr, _parser, _data, _functions, _option, _cache);
770 __sCmd.replace(nPositions[0], nPositions[1]-nPositions[0],
779 std::map<size_t, std::string> mDataMatrices;
780 std::map<size_t, std::string> mReturnedMatrices;
781 size_t nColCount = 1;
782 size_t nRowCount = 1;
789 for (
unsigned int i = 0; i < _cache.
vDataAccesses.size(); i++)
791 std::string sMatrixName =
"_~matrix["+
toString((
int)i)+
"]";
793 if (sCmd.find(sMatrixName) == string::npos)
796 mDataMatrices[i] = sMatrixName;
806 std::string sMatrixName =
"_~returnedMatrix["+
toString((
int)i)+
"]";
808 if (sCmd.find(sMatrixName) == string::npos)
811 mReturnedMatrices[i] = sMatrixName;
817 if (mDataMatrices.size() == 1 &&
isEqualStripped(sCmd, mDataMatrices.begin()->second))
819 auto iter = mDataMatrices.begin();
824 if (mReturnedMatrices.size() == 1 &&
isEqualStripped(sCmd, mReturnedMatrices.begin()->second))
831 for (
const auto& iter : mDataMatrices)
838 mat.
extend(nRowCount, nColCount);
845 for (
const auto& iter : mReturnedMatrices)
860 v = _parser.
Eval(nResults);
864 return Matrix((nResults > 1 && nRowCount == 1 && nColCount == 1) ? nResults : nRowCount,
884 for (
int i = nLastPos; i >= 0; i--)
886 if (sCmd[i] ==
'(' || sCmd[i] ==
'{')
889 if (sCmd[i] ==
')' || sCmd[i] ==
'}')
892 if (!(nQuotes%2) && sCmd.substr(i,2) ==
"**")
917 if (_mRight.
rows() != _mLeft.
cols())
921 return _mLeft * _mRight;
953 if (!nLines || !nCols)
1013 std::vector<std::vector<mu::value_type>> _matfl;
1016 unsigned int nLineLength = 0;
1017 vector<mu::value_type> vLine;
1020 _matfl.push_back(vector<mu::value_type>(1,NAN));
1022 if (!_functions.
call(sCmd))
1028 while (sCmd.length())
1033 v = _parser.
Eval(nResults);
1034 if ((
unsigned)nResults > nLineLength)
1035 nLineLength = (unsigned)nResults;
1036 for (
int n = 0; n < nResults; n++)
1037 vLine.push_back(v[n]);
1038 _matfl.push_back(vLine);
1043 _matfl.push_back(vector<mu::value_type>(1,NAN));
1048 for (
unsigned int i = 0; i < _matfl.size(); i++)
1050 _matfl[i].resize(nLineLength, 0.0);
1072 std::vector<std::vector<mu::value_type>> _matfl;
1075 unsigned int nLineLength = 0;
1076 vector<mu::value_type> vLine;
1079 _matfl.push_back(vector<mu::value_type>(1,NAN));
1081 if (!_functions.
call(sCmd))
1087 while (sCmd.length())
1092 v = _parser.
Eval(nResults);
1093 if ((
unsigned)nResults > nLineLength)
1094 nLineLength = (unsigned)nResults;
1095 for (
int n = 0; n < nResults; n++)
1096 vLine.push_back(v[n]);
1097 _matfl.push_back(vLine);
1102 _matfl.push_back(vector<mu::value_type>(1,NAN));
1107 for (
unsigned int i = 0; i < _matfl.size(); i++)
1109 if (_matfl[i].size() == 1)
1112 _matfl[i].resize(nLineLength, _matfl[i][0]);
1117 while (_matfl[i].size() < nLineLength)
1119 _matfl[i].push_back(_matfl[i].back() + vDeltas[(_matfl[i].size()+1) % vDeltas.size()]);
1140static vector<mu::value_type>
calcDeltasForMatFill(
const std::vector<std::vector<mu::value_type>>& _mMatrix,
unsigned int nLine)
1142 vector<mu::value_type> vDeltas;
1143 for (
unsigned int j = 1; j < _mMatrix[nLine].size(); j++)
1145 vDeltas.push_back(_mMatrix[nLine][j]-_mMatrix[nLine][j-1]);
1178 for (
unsigned int i = 0; i < _idx.
row.
size(); i++)
1180 for (
unsigned int j = 0; j < _idx.
col.
size(); j++)
1182 if (_idx.
row[i] >= (
int)_mMatrix.
rows() || _idx.
col[j] >= (
int)_mMatrix.
cols())
1186 _mReturn(i, j) = _mMatrix(_idx.
row[i], _idx.
col[j]);
1196 const size_t FIELDLENGTH = 21;
1197 const size_t FIELDLENGTH_W_FILLER = 23;
1198 const size_t PRECISION = 7;
1202 for (
unsigned int col = 0; col < _mResult.
cols(); col++)
1204 if (_mResult.
cols() > (_option.
getWindow()-2-15) / FIELDLENGTH_W_FILLER
1205 && (_option.
getWindow()-2-15) / FIELDLENGTH_W_FILLER / 2 == col)
1207 sRow +=
strfill(
"..., ", FIELDLENGTH_W_FILLER);
1208 col = _mResult.
cols() - (_option.
getWindow()-2-15) / FIELDLENGTH_W_FILLER / 2 - 1;
1212 sRow +=
strfill(
toString(_mResult(row, col), PRECISION), FIELDLENGTH);
1214 if (col+1 < _mResult.
cols())
1236 const size_t FIELDLENGTH = 21;
1237 const size_t FIELDLENGTH_W_FILLER = 23;
1241 if (_mResult.
rows() > 10)
1243 for (
unsigned int i = 0; i < _mResult.
rows(); i++)
1247 else if (i+1 == _mResult.
rows())
1256 for (
unsigned int j = 0; j < _mResult.
cols(); j++)
1258 if (_mResult.
cols() > (_option.
getWindow()-2-15) / FIELDLENGTH_W_FILLER
1259 && (_option.
getWindow()-2-15) / FIELDLENGTH_W_FILLER / 2 == j)
1262 j = _mResult.
cols() - (_option.
getWindow()-2-15) / FIELDLENGTH_W_FILLER / 2 - 1;
1268 if (j+1 < _mResult.
cols())
1272 i = _mResult.
rows()-6;
1279 else if (i+1 == _mResult.
rows())
1285 else if (_mResult.
rows() == 1)
1287 if (_mResult.
cols() == 1)
1294 for (
unsigned int i = 0; i < _mResult.
rows(); i++)
1296 if (!i && _mResult.
rows() == 2)
1300 else if (i+1 == _mResult.
rows())
1302 else if (i == (_mResult.
rows()-1)/2)
1311 else if (i+1 == _mResult.
rows())
1340 string sI[2] = {
"<<NONE>>",
"<<NONE>>"};
1341 string sJ[2] = {
"<<NONE>>",
"<<NONE>>"};
1342 string sArgument =
"";
1343 unsigned int nPos = 0;
1344 int nParenthesis = 0;
1348 if (sCmd.find(
'(') == string::npos)
1351 nPos = sCmd.find(
'(');
1353 for (
unsigned int n = nPos; n < sCmd.length(); n++)
1363 sArgument = sCmd.substr(nPos+1, n-nPos-1);
1374 if (!sArgument.length())
1381 if (sArgument.find(
',') != string::npos)
1386 for (
unsigned int n = 0; n < sArgument.length(); n++)
1388 if (sArgument[n] ==
'(' || sArgument[n] ==
'{')
1391 if (sArgument[n] ==
')' || sArgument[n] ==
'}')
1394 if (sArgument[n] ==
':' && !nParenthesis)
1399 sI[0] =
"<<EMPTY>>";
1401 sI[0] = sArgument.substr(0, n);
1405 sJ[0] =
"<<EMPTY>>";
1409 sJ[0] = sArgument.substr(nPos, n-nPos);
1415 if (sArgument[n] ==
',' && !nParenthesis)
1420 sI[0] =
"<<EMPTY>>";
1422 sI[0] = sArgument.substr(0, n);
1427 sI[1] =
"<<EMPTY>>";
1429 sI[1] = sArgument.substr(nPos, n - nPos);
1436 if (sJ[0] ==
"<<NONE>>")
1438 if (nPos < sArgument.length())
1439 sJ[0] = sArgument.substr(nPos);
1441 sJ[0] =
"<<EMPTY>>";
1443 else if (nPos < sArgument.length())
1444 sJ[1] = sArgument.substr(nPos);
1446 sJ[1] =
"<<EMPTY>>";
1449 if (sI[0] !=
"<<NONE>>" && sI[1] ==
"<<NONE>>")
1452 v = _parser.
Eval(nResults);
1462 if (sJ[0] !=
"<<NONE>>" && sJ[1] ==
"<<NONE>>")
1465 v = _parser.
Eval(nResults);
1475 for (
int n = 0; n < 2; n++)
1477 if (sI[n] ==
"<<EMPTY>>")
1484 else if (sI[n] !=
"<<NONE>>")
1493 if (sJ[n] ==
"<<EMPTY>>")
1500 else if (sJ[n] !=
"<<NONE>>")
1542 for (
unsigned int j = 0; j < vReturnedMatrices.size(); j++)
1544 vector<mu::value_type> v;
1545 if (vReturnedMatrices[j].isScalar())
1547 v.push_back(vReturnedMatrices[j](0));
1549 else if (vReturnedMatrices[j].rows() == 1
1550 || vReturnedMatrices[j].cols() == 1)
1552 v = vReturnedMatrices[j].data();
1556 for (
size_t i = 0; i < vReturnedMatrices[j].rows(); i++)
1557 v.push_back(vReturnedMatrices[j](i));
1561 if (_sCmd.find(
"_~returnedMatrix["+
toString((
int)j)+
"]") != string::npos)
1582 for (
unsigned int j = 0; j < _cache.
vDataAccesses.size(); j++)
1584 vector<mu::value_type> v;
1594 if (_sCmd.find(
"_~matrix["+
toString((
int)j)+
"]") != string::npos)
1616 string _sCmd = sCmd;
1629 return getIndices(_sCmd, _parser, _data, _option);
1651 for (
auto iter = mMatrixFunctionsMap.begin(); iter != mMatrixFunctionsMap.end(); ++iter)
1653 if (!iter->second.isPureMatFunc)
1656 size_t match = sExpr.find(iter->first+
"(");
1658 if (match != string::npos && (!match || (!isalpha(sExpr[match-1]) && sExpr[match-1] !=
'_')))
void checkAssertion(mu::value_type *v, int nNum)
Checks the return value of a muParser evaluated result.
void debug(const std::string &sMessage)
Convenience member function.
This class implements the function definition managing instance.
bool call(std::string &sExpr, int nRecursion=0)
This function searches for known custom definitions in the passed expression and replaces them with t...
This class defines a dynamic size 2D matrix with a single 1D internal buffer. If the internal buffer ...
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 ...
std::vector< mu::value_type > & data()
Get a reference to the internal data structure.
bool isEmpty() const
Simple function to identify empty matrices.
size_t cols() const
The cols of this matrix.
size_t rows() const
The rows of this matrix.
This class represents a single table in memory, or a - so to say - single memory page to be handled b...
void markModified()
Mark this table as modified.
void writeData(int _nLine, int _nCol, const mu::value_type &_dData)
This member function writes the passed value to the selected position. The table is automatically enl...
void writeDataDirectUnsafe(int _nLine, int _nCol, const mu::value_type &_dData)
This member function provides an even more unsafe but direct way of writing data to the table....
Matrix readMemAsMatrix(const VectorIndex &_vLine, const VectorIndex &_vCol) const
This member function returns the elements stored at the selected positions as a Matrix.
This class represents the central memory managing instance. It will handle all tables and clusters,...
mu::value_type getElement(int _nLine, int _nCol, const std::string &_sTable) const
void deleteBulk(const std::string &_sCache, int i1, int i2, int j1=0, int j2=0)
int getLines(StringView sTable, bool _bFull=false) const
const std::map< std::string, std::pair< size_t, size_t > > & getTableMap() const
bool isTable(const std::string &sTable) const
This member function returns, whether the passed table name corresponds to a known table.
bool addTable(const std::string &sCache, const Settings &_option)
This member function creates a new table. It is checked, whether its name is valid and not already us...
bool resizeTable(int _nCols, const std::string &_sTable)
Memory * getTable(const std::string &sTable)
This member function returns a pointer to an existing Memory instance representing the selected table...
bool containsTablesOrClusters(const std::string &sCmdLine)
This member function evaluates, whether the passed command line contains tables or clusters.
int getCols(StringView sTable, bool _bFull=false) const
This class represents a whole cluster. The single items are stored as pointers to the abstract cluste...
void clear()
This member function clears the internal memory buffer and frees the associated memory.
void setDouble(size_t i, const mu::value_type &value)
This member function assigns a value as data for the i-th cluster item in memory. The type of the i-t...
Cluster & getCluster(StringView sCluster)
This member function returns a reference to the cluster indicated by the passed cluster identifier.
Cluster & newCluster(const std::string &sCluster)
This member function creates a new cluster from the passed cluster identifier and returns a reference...
bool isCluster(StringView sCluster) const
This member function returns true, if the passed cluster identifier can be found in the internal map.
const std::map< std::string, Cluster > & getClusterMap() const
static NumeReKernel * getInstance()
This static member function returns a a pointer to the singleton instance of the kernel.
static bool bSupressAnswer
static void printPreFmt(const std::string &__sLine, bool printingEnabled=true)
This member function appends the pre- formatted string to the buffer and informs the terminal that we...
static void print(const std::string &__sLine, bool printingEnabled=true)
This member function appends the passed string as a new output line to the buffer and informs the ter...
static void flush()
Inform the terminal to write the current output buffer as soon as possible.
static void toggleTableStatus()
Toggles the table writing status, which will reduce the number or events send to the terminal.
This class manages the setting values of the internal (kernel) settings of this application.
bool systemPrints() const
Returns, whether system messages shall be printed to the terminal.
size_t getPrecision() const
Returns the precision for displaying floating numbers in the terminal. This value determines the numb...
size_t getWindow(int nWindow=0) const
Returns the current window size of the terminal.
This class is the immutable (const) version of a string view. It can be constructed from a MutableStr...
Common exception class for all exceptions thrown in NumeRe.
@ MATRIX_CANNOT_HAVE_ZERO_SIZE
@ WRONG_MATRIX_DIMENSIONS_FOR_MATOP
static size_t invalid_position
This class abstracts all the index logics, i.e. the logical differences between single indices and in...
VectorIndex subidx(size_t pos, size_t nLen=std::string::npos) const
This member function returns a subset of the internal stored index just like the std::string::substr(...
int max() const
This function calculates the maximal index value obtained from the values stored internally.
size_t size() const
This member function returns the size of the indices stored in this class.
bool isOpenEnd() const
This member function determines, whether the internal index set has an open end.
void setRange(int nMin, int nMax)
This member function can be used to force the indices stored internally to be in a defined interval....
std::string to_string() const
This member function converts the vector indexes contents into a human-readable string representation...
void setIndex(size_t nthIndex, int nVal)
This member function can be used to set the index at a special position. This will expand the interna...
int & back()
This member function returns a reference to the final index value stored internally.
int & front()
This member function returns a reference to the first index value stored internally.
void SetExpr(StringView a_sExpr)
Set the expression. Triggers first time calculation thus the creation of the bytecode and scanning of...
value_type Eval()
Single-value wrapper around the vectorized overload of this member function.
void SetVectorVar(const std::string &sVarName, const std::vector< mu::value_type > &vVar, bool bAddVectorType=false)
This member function copies the passed vector into the internal storage referencing it with the passe...
Mathematical expressions parser.
string getDataElements(string &sLine, Parser &_parser, MemoryManager &_data, const Settings &_option, int options)
Searches the passed string for calls to any table or cluster and replaces them with internal vectors ...
bool isValidIndexSet(const Indices &_idx)
Assertion _assertionHandler
std::string strfill(const std::string &sString, unsigned int nWidth, char cFill=' ', bool limit=false)
This function fills the passed string up to the width nWidth with the characters cFill....
static std::map< std::string, MatFuncDef > getMatrixFunctions()
Returns a map containing all declared and "standard" matrix functions.
int const MatFuncErrorInfo & errorInfo
static Matrix createFilledMatrix(size_t n, size_t m, const mu::value_type &val)
This static function returns a matrix filled with the passed value of the defined size.
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 par...
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 ex...
static void showMatrixResult(const Matrix &_mResult, const Settings &_option)
This static function formats and prints the calculated matrix to the terminal.
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.
Matrix transposeMatrix(const Matrix &_mMatrix)
This static function will transpose the passed matrix (exchange rows with columns).
bool performMatrixOperation(string &sCmd, Parser &_parser, MemoryManager &_data, FunctionDefinitionManager &_functions, const Settings &_option)
This function is the main interface to the matrix operations.
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 matri...
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 equa...
static std::string formatMatrixRow(const Matrix &_mResult, const Settings &_option, size_t row)
Matrix createZeroesMatrix(unsigned int nLines, unsigned int nCols)
This function returns a matrix filled with zeros with the defined lines and columns.
static Matrix createMatFromColsFilled(string &sCmd, Parser &_parser, MemoryManager &_data, FunctionDefinitionManager &_functions, const Settings &_option)
This static function creates a matrix from the passed columns.
static bool containsMatrices(const string &sExpr, MemoryManager &_data)
This static function evaluates, whether there are matrix expressions in the passed expression.
static Matrix createMatFromLines(string &sCmd, Parser &_parser, MemoryManager &_data, FunctionDefinitionManager &_functions, const Settings &_option)
This static function creates a matrix from the passed lines.
static Matrix createMatFromLinesFilled(string &sCmd, Parser &_parser, MemoryManager &_data, FunctionDefinitionManager &_functions, const Settings &_option)
This static function creates a matrix from the passed lines.
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.
void showMatrix(const vector< vector< mu::value_type > > &_mMatrix)
Simple wrapper for the function parser_ShowMatrixResult() to be accessible from the outside.
static Matrix createMatFromCols(string &sCmd, Parser &_parser, MemoryManager &_data, FunctionDefinitionManager &_functions, const Settings &_option)
This static function creates a matrix from the passed columns.
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...
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.
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 opera...
unsigned int getMatchingParenthesis(const StringView &)
Returns the position of the closing parenthesis.
MUP_BASETYPE value_type
The numeric datatype used by the parser.
bool isnan(const value_type &v)
bool isinf(const value_type &v)
string addMissingVectorComponent(const string &sVectorComponent, const string &sLeft, const string &sRight, bool bAddStrings)
This function determines the value of missing vector components (i.e. a vector contains not enough el...
bool evaluateIndices(const string &sCache, Indices &_idx, MemoryManager &_data)
This function will evaluate the passed indices, so that they match the dimensions of the passed cache...
void StripSpaces(std::string &)
Removes leading and trailing white spaces and tabulator characters.
int StrToInt(const std::string &)
Converts a string into an integer.
This structure is central for managing the indices of a table or cluster read or write data access....
Defines the needed information for displaying a reasonable error information.
std::vector< MatOpDataAccess > vDataAccesses
std::vector< Matrix > vReturnedMatrices
long long int intCast(const std::complex< double > &)
Casts the real part of the complex number to an integer and avoids rounding errors.
std::string toString(int)
Converts an integer to a string without the Settings bloat.