19#include <gsl/gsl_statistics.h>
20#include <gsl/gsl_sort.h>
30#include "../AudioLib/audiofile.hpp"
31#include "../../kernel.hpp"
32#include "../../../common/http.h"
68 for (
int i = 0; i < nResults; i++)
75 if (!bReturnFunctionPoints)
77 for (
int i = 0; i < nResults; i++)
78 vResult[i] += dx * (vFunctionValues[i] + v[i]) * 0.5;
84 vResult.push_back(dx * (vFunctionValues[0] + v[0]) * 0.5 + vResult.back());
86 vResult.push_back(dx * (vFunctionValues[0] + v[0]) * 0.5);
90 vFunctionValues.assign(v, v+nResults);
116 for (
int i = 0; i < nResults; i++)
122 vector<mu::value_type> vInter(v, v+nResults);
128 for (
int i = 0; i < nResults; i++)
135 if (!bReturnFunctionPoints)
137 for (
int i = 0; i < nResults; i++)
138 vResult[i] += dx / 6.0 * (vFunctionValues[i] + 4.0 * vInter[i] + v[i]);
144 vResult.push_back(dx / 6.0 * (vFunctionValues[0] + 4.0 * vInter[0] + v[0]) + vResult.back());
146 vResult.push_back(dx / 6.0 * (vFunctionValues[0] + 4.0 * vInter[0] + v[0]));
150 vFunctionValues.assign(v, v+nResults);
164 bool bReturnFunctionPoints = cmdParser.
hasParam(
"points");
165 bool bCalcXvals = cmdParser.
hasParam(
"xvals");
167 vector<mu::value_type> vResult;
185 if ((_idx.
row.
size() == 1 || _idx.
col.
size() == 1) && !bReturnFunctionPoints)
186 vResult.push_back(_data.
sum(sDatatable, _idx.
row, _idx.
col));
194 for (
size_t i = 1; i < _idx.
col.
size(); i++)
195 vResult.push_back(vResult.back() + _data.
getElement(_idx.
row[0], _idx.
col[i], sDatatable));
199 for (
size_t i = 1; i < _idx.
row.
size(); i++)
200 vResult.push_back(vResult.back() + _data.
getElement(_idx.
row[i], _idx.
col[0], sDatatable));
208 for (
size_t i = 0; i < _idx.
row.
size(); i++)
220 for (
long long int i = 0; i < _cache.
getLines(
"table",
false) - 1; i++)
240 if (!bReturnFunctionPoints && !bCalcXvals)
242 else if (bReturnFunctionPoints && !bCalcXvals)
250 vResult.push_back(_cache.
getElement(i + j, 0,
"table"));
255 if (!bReturnFunctionPoints && !bCalcXvals)
256 vResult.push_back(dResult);
280 vector<mu::value_type> vResult;
281 vector<mu::value_type> vFunctionValues;
282 bool bLargeInterval =
false;
283 bool bReturnFunctionPoints = cmdParser.
hasParam(
"points");
284 bool bCalcXvals = cmdParser.
hasParam(
"xvals");
286 size_t nSamples = 1e3;
296 if (!sIntegrationExpression.length())
302 if (_data.
isTable(sIntegrationExpression)
304 && sIntegrationExpression.find_first_not_of(
' ',
getMatchingParenthesis(sIntegrationExpression) + 1) == string::npos)
315 if (ivl[0].
min() == ivl[0].
max())
325 range = ivl[0].range();
333 nSamples =
std::rint(range / vParVal.front().real());
339 nSamples =
std::rint(range / vParVal.front().real());
345 nSamples =
std::rint(range / vParVal.front().real());
363 if (!sParVal.length())
366 if (sParVal ==
"trapezoidal")
368 else if (sParVal ==
"simpson")
373 _parser.
SetExpr(sIntegrationExpression);
375 _parser.
Eval(nResults);
376 vResult.resize(nResults, 0.0);
379 vFunctionValues.resize(nResults, 0.0);
391 for (
size_t i = 0; i < nSamples; i++)
393 vResult.push_back(ivl[0](i, nSamples));
401 _parser.
SetExpr(sIntegrationExpression);
404 if ((nMethod ==
TRAPEZOIDAL && nSamples >= 9.9e6) || (nMethod ==
SIMPSON && nSamples >= 1e4))
405 bLargeInterval =
true;
415 v = _parser.
Eval(nResults);
416 vFunctionValues.assign(v, v+nResults);
418 double dx = range / (nSamples-1);
421 for (
size_t i = 1; i < nSamples; i++)
427 integrationstep_simpson(x, ivl[0](2*i-1, 2*nSamples-1), ivl[0](2*i, 2*nSamples-1), dx, vResult, vFunctionValues, bReturnFunctionPoints);
432 if ((
int)(i / (
double)nSamples * 100) > (
int)((i-1) / (
double)nSamples * 100))
488 vector<mu::value_type> vResult[3];
490 vector<mu::value_type> fx_n[2][3];
491 bool bRenewBoundaries =
false;
492 bool bLargeArray =
false;
494 size_t nSamples = 1e3;
506 if (!sIntegrationExpression.length())
514 if (ivl[0].front() == ivl[0].back())
526 range =
std::min(ivl[0].range(), ivl[1].range());
534 nSamples =
std::rint(range / vParVal.front().real());
540 nSamples =
std::rint(range / vParVal.front().real());
546 nSamples =
std::rint(range / vParVal.front().real());
564 if (!sParVal.length())
567 if (sParVal ==
"trapezoidal")
569 else if (sParVal ==
"simpson")
574 _parser.
SetExpr(sIntegrationExpression);
577 _parser.
Eval(nResults);
579 for (
int i = 0; i < 3; i++)
581 vResult[i].resize(nResults, 0.0);
582 fx_n[0][i].resize(nResults, 0.0);
583 fx_n[1][i].resize(nResults, 0.0);
587 bRenewBoundaries =
true;
599 if ((nMethod ==
TRAPEZOIDAL && nSamples*nSamples >= 1e8) || (nMethod ==
SIMPSON && nSamples*nSamples >= 1e6))
603 if (nSamples*nSamples > 1e10)
614 if (bRenewBoundaries)
619 double dx = ivl[0].range() / (nSamples-1);
620 double dy = ivl[1].range() / (nSamples-1);
623 v = _parser.
Eval(nResults);
624 fx_n[1][0].assign(v, v+nResults);
629 for (
size_t j = 1; j < nSamples; j++)
634 integrationstep_simpson(y, ivl[1](2*j-1, 2*nSamples-1), ivl[1](2*j, 2*nSamples-1), dy, vResult[1], fx_n[1][0],
false);
637 fx_n[0][0] = vResult[1];
643 for (
size_t i = 1; i < nSamples; i++)
647 x = ivl[0](i, nSamples);
650 if (bRenewBoundaries)
653 dy = ivl[1].range() / (nSamples-1);
659 v = _parser.
Eval(nResults);
660 fx_n[1][0].assign(v, v+nResults);
661 vResult[1].assign(nResults, 0.0);
663 for (
size_t j = 1; j < nSamples; j++)
667 for (
int i = 0; i < nResults; i++)
672 vResult[0][i] += dx * (fx_n[0][0][i] + vResult[1][i]) * 0.5;
673 fx_n[0][0][i] = vResult[1][i];
678 for (
size_t n = 1; n <= 2; n++)
680 x = ivl[0](2*i+n-2, 2*nSamples-1);
683 if (bRenewBoundaries)
686 dy = ivl[1].range() / (nSamples-1);
695 v = _parser.
Eval(nResults);
696 fx_n[1][0].assign(v, v+nResults);
699 vResult[n].assign(nResults, 0.0);
701 for (
size_t j = 1; j < nSamples; j++)
702 integrationstep_simpson(y, ivl[1](2*j-1, 2*nSamples-1), ivl[1](2*j, 2*nSamples-1), dy, vResult[n], fx_n[1][0],
false);
705 for (
int i = 0; i < nResults; i++)
712 for (
int i = 0; i < nResults; i++)
714 vResult[0][i] += dx / 6.0 * (fx_n[0][0][i] + 4.0 * vResult[1][i] + vResult[2][i]);
715 fx_n[0][0][i] = vResult[2][i];
724 if ((
int)(i / (double)nSamples * 100) > (int)((i-1) / (double)nSamples * 100))
770 std::vector<mu::value_type> vInterval;
771 std::vector<mu::value_type> vResult;
772 std::vector<mu::value_type> paramVal;
783 order =
intCast(paramVal.front());
794 dEps = fabs(paramVal.front());
799 nSamples =
intCast(fabs(paramVal.front()));
803 if (!_functions.
call(sVar))
807 if (sVar.find(
'=') != string::npos ||
808 (sVar.find(
'[') != string::npos
809 && sVar.find(
']', sVar.find(
'[')) != string::npos
810 && sVar.find(
':', sVar.find(
'[')) != string::npos))
813 if (sVar.substr(0, 2) ==
"--")
814 sVar = sVar.substr(2);
815 else if (sVar.substr(0, 4) ==
"-set")
816 sVar = sVar.substr(4);
819 if (sVar.find(
'[') != string::npos
820 && sVar.find(
']', sVar.find(
'[')) != string::npos
821 && sVar.find(
':', sVar.find(
'[')) != string::npos)
832 int nPos = sVar.find(
'=');
833 sPos = sVar.substr(nPos + 1, sVar.find(
' ', nPos) - nPos - 1);
834 sVar =
" " + sVar.substr(0, nPos);
835 sVar = sVar.substr(sVar.rfind(
' '));
845 if (sPos.find(
':') != string::npos)
846 sPos.replace(sPos.find(
':'), 1,
",");
848 v = _parser.
Eval(nResults);
856 for (
int i = 0; i < nResults; i++)
857 vInterval.push_back(v[i]);
863 _parser.
Eval(nResults);
874 string sCompl_Expr = sExpr;
877 while (sCompl_Expr.length())
886 if (vInterval.size() == 1 || vInterval.size() > 2)
889 for (
unsigned int i = 0; i < vInterval.size(); i++)
892 vResult.push_back(_parser.
Diff(dVar, dPos, dEps, order));
898 for (
int i = 0; i < nSamples; i++)
900 dPos = vInterval[0] + (vInterval[1] - vInterval[0]) / (
double)(nSamples - 1) * (
double)i;
901 vResult.push_back(_parser.
Diff(dVar, dPos, dEps, order));
914 size_t nFilterSize = 5;
919 nFilterSize =
intCast(paramVal.front());
921 if (!(nFilterSize % 2))
939 if (_idx.
row.
size() < nFilterSize)
941 vResult.push_back(NAN);
956 vResult.resize(_idx.
row.
size());
962 for (
size_t i = nFilterSize/2; i < _idx.
row.
size() - nFilterSize/2; i++)
964 for (
int j = 0; j < (int)nFilterSize; j++)
972 for (
size_t i = 0; i < nFilterSize/2; i++)
974 vResult[i] = vResult[nFilterSize/2];
975 vResult[vResult.size()-1-i] = vResult[vResult.size()-1-nFilterSize/2];
986 for (
size_t i = 0; i < _idx.
row.
size(); i++)
1001 for (
int i = 0; i < _cache.
getLines(
"table",
false) - 1; i++)
1007 vResult.push_back((_cache.
getElement(i + 1, 0,
"table") + _cache.
getElement(i, 0,
"table")) / 2.0);
1009 vResult.push_back(NAN);
1014 vResult.resize(_cache.
getLines(
"table",
false));
1018 for (
int i = nFilterSize/2; i < _cache.
getLines(
"table",
false) - (
int)nFilterSize/2; i++)
1020 std::pair<mu::value_type, size_t> avgDiff(0.0, 0);
1022 for (
int j = 0; j < (int)nFilterSize; j++)
1027 vResult[i] += diff.
apply(j, 0, _cache.
getElement(i + j - nFilterSize/2, 1,
"table"));
1030 if (_cache.
isValidElement(i + j - nFilterSize/2 - 1, 0,
"table"))
1032 avgDiff.first += _cache.
getElement(i + j - nFilterSize/2, 0,
"table")
1033 - _cache.
getElement(i + j - nFilterSize/2 - 1, 0,
"table");
1039 if (!avgDiff.second)
1042 vResult[i] /=
intPower(avgDiff.first/(
double)avgDiff.second, order);
1046 for (
size_t i = 0; i < nFilterSize/2; i++)
1048 vResult[i] = vResult[nFilterSize/2];
1049 vResult[vResult.size()-1-i] = vResult[vResult.size()-1-nFilterSize/2];
1077 string sInterval =
"";
1081 if (sParams.find(
'=') != string::npos)
1083 int nPos = sParams.find(
'=');
1086 if (sInterval.front() ==
'[' && sInterval.back() ==
']')
1088 sInterval.pop_back();
1089 sInterval.erase(0, 1);
1092 sVar =
" " + sParams.substr(0, nPos);
1093 sVar = sVar.substr(sVar.rfind(
' '));
1099 sInterval = sParams.substr(sParams.find(
'[') + 1,
getMatchingParenthesis(sParams.substr(sParams.find(
'['))) - 1);
1102 if (sInterval ==
":")
1103 sInterval =
"-10:10";
1129 vector<mu::value_type> vResults;
1134 for (
int i = 0; i < nResults; i++)
1138 v = _parser.
Eval(nResults_x);
1143 for (
int i = 0; i < nResults; i++)
1145 if (i >= nResults_x)
1154 std::string sSortingExpr =
"sort -table cols=1[2]";
1157 double dMedian = 0.0, dExtremum = 0.0;
1158 double* data =
new double[nOrder];
1162 if (nOrder >= nResults / 3)
1163 nOrder = nResults / 3;
1168 vResults.push_back(NAN);
1174 for (
int i = 0; i + nanShift < _cache.
getLines(
"table",
true); i++)
1182 data[i] = _cache.
getElement(i + nanShift, 1,
"table").real();
1186 gsl_sort(data, 1, nOrder);
1187 dExtremum = gsl_stats_median_from_sorted_data(data, 1, nOrder);
1191 for (
int i = nOrder; i + nanShift < _cache.
getLines(
"table",
false) - nOrder; i++)
1193 int currNanShift = 0;
1196 for (
int j = i; j < i + nOrder; j++)
1198 while (
isnan(
std::abs(_cache.
getElement(j + nanShift + currNanShift, 1,
"table"))) && j + nanShift + currNanShift < _cache.
getLines(
"table",
true) - 1)
1201 data[j - i] = _cache.
getElement(j + nanShift + currNanShift, 1,
"table").real();
1204 gsl_sort(data, 1, nOrder);
1205 dMedian = gsl_stats_median_from_sorted_data(data, 1, nOrder);
1209 if (dMedian > dExtremum)
1211 else if (dMedian < dExtremum)
1214 dExtremum = dMedian;
1218 if (nDir*dMedian < nDir*dExtremum)
1220 if (!nMode || nMode == nDir)
1222 int nExtremum = i + nanShift;
1223 double dExtremum = _cache.
getElement(i + nanShift, 1,
"table").real();
1225 for (
long long int k = i + nanShift; k >= 0; k--)
1227 if (k == i - nOrder)
1230 if (nDir*_cache.
getElement(k, 1,
"table").real() > nDir*dExtremum)
1233 dExtremum = _cache.
getElement(k, 1,
"table").real();
1237 vResults.push_back(_cache.
getElement(nExtremum, 0,
"table"));
1238 i = nExtremum + nOrder;
1244 dExtremum = dMedian;
1247 nanShift += currNanShift;
1250 if (!vResults.size())
1251 vResults.push_back(NAN);
1274 vector<double> data;
1276 for (
int i = start; i < start + nOrder; i++)
1278 while (
isnan(v[i + nanShiftStart + nNewNanShift].
real()) && i + nanShiftStart + nNewNanShift < nResults - 1)
1281 if (i + nanShiftStart + nNewNanShift >= nResults)
1284 data.push_back(v[i + nanShiftStart + nNewNanShift].
real());
1287 gsl_sort(&data[0], 1, data.size());
1288 return gsl_stats_median_from_sorted_data(&data[0], 1, data.size());
1309 v = _parser.
Eval(nResults);
1313 if (nOrder >= nResults / 3)
1314 nOrder = nResults / 3;
1316 double dMedian = 0.0, dExtremum = 0.0;
1319 vector<mu::value_type> vResults;
1323 vResults.push_back(NAN);
1329 for (
int i = nOrder; i + nanShift < nResults - nOrder; i++)
1331 int currNanShift = 0;
1332 dMedian =
calculateMedian(v, nResults, i, nOrder, nanShift, currNanShift);
1336 if (dMedian > dExtremum)
1338 else if (dMedian < dExtremum)
1341 dExtremum = dMedian;
1345 if (nDir*dMedian < nDir*dExtremum)
1347 if (!nMode || nMode == nDir)
1349 int nExtremum = i + nanShift;
1350 double dLocalExtremum = v[i + nanShift].real();
1352 for (
long long int k = i + nanShift; k >= 0; k--)
1354 if (k == i + nanShift - nOrder)
1357 if (nDir*v[k].
real() > nDir*dLocalExtremum)
1360 dLocalExtremum = v[k].real();
1364 vResults.push_back(nExtremum + 1);
1365 i = nExtremum + nOrder;
1372 dExtremum = dMedian;
1375 nanShift += currNanShift;
1378 if (!vResults.size())
1379 vResults.push_back(NAN);
1404 unsigned int nSamples = 21;
1411 string sParams =
"";
1412 string sInterval =
"";
1424 sExpr = sExpr.substr(
findCommand(sExpr).sString.length());
1463 sParams.erase(
findParameter(sParams,
"samples",
'=') - 1, 8);
1474 sParams.erase(
findParameter(sParams,
"points",
'=') - 1, 7);
1478 if (sParams.find(
'=') != string::npos
1479 || (sParams.find(
'[') != string::npos
1480 && sParams.find(
']', sParams.find(
'['))
1481 && sParams.find(
':', sParams.find(
'['))))
1483 if (sParams.substr(0, 2) ==
"--")
1484 sParams = sParams.substr(2);
1485 else if (sParams.substr(0, 4) ==
"-set")
1486 sParams = sParams.substr(4);
1493 _parser.
Eval(nResults);
1510 if (sInterval.find(
':') == string::npos || sInterval.length() < 3)
1515 for (
size_t i = 0; i < 2; i++)
1520 dBoundaries[i] = _parser.
Eval();
1535 dBoundaries[1] = dBoundaries[0];
1536 dBoundaries[0] = Temp;
1548 nSamples = (nSamples - 1) *
intCast(
std::abs(dBoundaries[1] - dBoundaries[0])) + 1;
1551 if (nSamples > 10001)
1557 vector<mu::value_type> vResults;
1558 dVal[0] = _parser.
Diff(dVar, dBoundaries[0], 1e-7);
1563 for (
unsigned int i = 1; i < nSamples; i++)
1566 dVal[1] = _parser.
Diff(dVar, dBoundaries[0] + (
double)i * (dBoundaries[1] - dBoundaries[0]) / (
double)(nSamples - 1), 1e-7);
1569 if (dVal[0].
real()*dVal[1].real() < 0)
1572 || (nMode == 1 && (dVal[0].
real() > 0 && dVal[1].real() < 0))
1573 || (nMode == -1 && (dVal[0].real() < 0 && dVal[1].real() > 0)))
1576 vResults.push_back(
localizeExtremum(sExpr, dVar, _parser, instance->
getSettings(), dBoundaries[0] + (double)(i - 1) * (dBoundaries[1] - dBoundaries[0]) / (
double)(nSamples - 1), dBoundaries[0] + (
double)i * (dBoundaries[1] - dBoundaries[0]) / (
double)(nSamples - 1)));
1579 else if (dVal[0].
real()*dVal[1].real() == 0.0)
1582 || (nMode == 1 && (dVal[0].
real() > 0 || dVal[1].real() < 0))
1583 || (nMode == -1 && (dVal[0].real() < 0 || dVal[1].real() > 0)))
1590 while (dVal[0].
real()*dVal[1].real() == 0.0 && i + 1 < nSamples)
1593 dVal[1] = _parser.
Diff(dVar, dBoundaries[0] + (
double)i * (dBoundaries[1] - dBoundaries[0]) / (
double)(nSamples - 1), 1e-7);
1598 while (dVal[1] == 0.0 && i + 1 < nSamples)
1601 dVal[1] = _parser.
Diff(dVar, dBoundaries[0] + (
double)i * (dBoundaries[1] - dBoundaries[0]) / (
double)(nSamples - 1), 1e-7);
1606 vResults.push_back(
localizeExtremum(sExpr, dVar, _parser, instance->
getSettings(), dBoundaries[0] + (double)nTemp * (dBoundaries[1] - dBoundaries[0]) / (double)(nSamples - 1), dBoundaries[0] + (double)i * (dBoundaries[1] - dBoundaries[0]) / (double)(nSamples - 1)));
1614 if (!vResults.size())
1616 dVal[0] = _parser.
Diff(dVar, dBoundaries[0]);
1617 dVal[1] = _parser.
Diff(dVar, dBoundaries[1]);
1618 std::string sRetVal;
1623 || (dVal[0].real() < 0 && nMode == 1)
1624 || (dVal[0].
real() > 0 && nMode == -1)))
1630 || (dVal[1].real() < 0 && nMode == -1)
1631 || (dVal[1].
real() > 0 && nMode == 1)))
1633 if (sRetVal.length())
1674 vector<mu::value_type> vResults;
1677 for (
int i = 0; i < nResults; i++)
1681 v = _parser.
Eval(nResults_x);
1685 for (
int i = 0; i < nResults; i++)
1687 if (i >= nResults_x)
1696 std::string sSortingExpr =
"sort -table cols=1[2]";
1699 for (
long long int i = 1; i < _cache.
getLines(
"table",
false); i++)
1704 if (!nMode && _cache.
getElement(i, 1,
"table").real()*_cache.
getElement(i - 1, 1,
"table").real() <= 0.0)
1708 vResults.push_back(_cache.
getElement(i, 0,
"table"));
1711 else if (_cache.
getElement(i - 1, 1,
"table") == 0.0)
1712 vResults.push_back(_cache.
getElement(i - 1, 0,
"table"));
1713 else if (_cache.
getElement(i, 1,
"table").real()*_cache.
getElement(i - 1, 1,
"table").real() < 0.0)
1714 vResults.push_back(
Linearize(_cache.
getElement(i - 1, 0,
"table").real(), _cache.
getElement(i - 1, 1,
"table").real(), _cache.
getElement(i, 0,
"table").real(), _cache.
getElement(i, 1,
"table").real()));
1716 else if (nMode && _cache.
getElement(i, 1,
"table").real()*_cache.
getElement(i - 1, 1,
"table").real() <= 0.0)
1720 for (
long long int j = i + 1; j < _cache.
getLines(
"table",
false); j++)
1722 if (nMode * _cache.
getElement(j, 1,
"table").real() > 0.0)
1724 for (
long long int k = i - 1; k <= j; k++)
1725 vResults.push_back(_cache.
getElement(k, 0,
"table"));
1729 else if (nMode * _cache.
getElement(j, 1,
"table").real() < 0.0)
1732 if (j + 1 == _cache.
getLines(
"table",
false) && i > 1 && nMode * _cache.
getElement(i - 2, 1,
"table").real() < 0.0)
1734 for (
long long int k = i - 1; k <= j; k++)
1735 vResults.push_back(_cache.
getElement(k, 0,
"table"));
1743 else if (_cache.
getElement(i, 1,
"table") == 0.0 && nMode * _cache.
getElement(i - 1, 1,
"table").real() < 0.0)
1744 vResults.push_back(_cache.
getElement(i, 0,
"table"));
1745 else if (_cache.
getElement(i - 1, 1,
"table") == 0.0 && nMode * _cache.
getElement(i, 1,
"table").real() > 0.0)
1746 vResults.push_back(_cache.
getElement(i - 1, 0,
"table"));
1747 else if (_cache.
getElement(i, 1,
"table").real()*_cache.
getElement(i - 1, 1,
"table").real() < 0.0 && nMode * _cache.
getElement(i - 1, 1,
"table").real() < 0.0)
1748 vResults.push_back(
Linearize(_cache.
getElement(i - 1, 0,
"table").real(), _cache.
getElement(i - 1, 1,
"table").real(), _cache.
getElement(i, 0,
"table").real(), _cache.
getElement(i, 1,
"table").real()));
1752 if (!vResults.size())
1753 vResults.push_back(NAN);
1776 v = _parser.
Eval(nResults);
1780 vector<mu::value_type> vResults;
1782 for (
int i = 1; i < nResults; i++)
1787 if (!nMode && v[i].
real()*v[i - 1].
real() <= 0.0)
1791 vResults.push_back((
double)i + 1);
1794 else if (v[i - 1] == 0.0)
1795 vResults.push_back((
double)i);
1796 else if (fabs(v[i]) <= fabs(v[i - 1]))
1797 vResults.push_back((
double)i + 1);
1799 vResults.push_back((
double)i);
1801 else if (nMode && v[i].
real()*v[i - 1].
real() <= 0.0)
1803 if (v[i] == 0.0 && v[i - 1] == 0.0)
1805 for (
int j = i + 1; j < nResults; j++)
1807 if (nMode * v[j].
real() > 0.0)
1809 for (
int k = i - 1; k <= j; k++)
1810 vResults.push_back((
double)k);
1814 else if (nMode * v[j].
real() < 0.0)
1817 if (j + 1 == nResults && i > 2 && nMode * v[i - 2].
real() < 0.0)
1819 for (
int k = i - 1; k <= j; k++)
1820 vResults.push_back((
double)k);
1828 else if (v[i] == 0.0 && nMode * v[i - 1].
real() < 0.0)
1829 vResults.push_back((
double)i + 1);
1830 else if (v[i - 1] == 0.0 && nMode * v[i].
real() > 0.0)
1831 vResults.push_back((
double)i);
1832 else if (fabs(v[i]) <= fabs(v[i - 1]) && nMode * v[i - 1].
real() < 0.0)
1833 vResults.push_back((
double)i + 1);
1834 else if (nMode * v[i - 1].
real() < 0.0)
1835 vResults.push_back((
double)i);
1839 if (!vResults.size())
1840 vResults.push_back(NAN);
1865 unsigned int nSamples = 21;
1872 string sParams =
"";
1873 string sInterval =
"";
1919 sParams.erase(
findParameter(sParams,
"samples",
'=') - 1, 8);
1923 if (sParams.find(
'=') != string::npos
1924 || (sParams.find(
'[') != string::npos
1925 && sParams.find(
']', sParams.find(
'['))
1926 && sParams.find(
':', sParams.find(
'['))))
1928 if (sParams.substr(0, 2) ==
"--")
1929 sParams = sParams.substr(2);
1930 else if (sParams.substr(0, 4) ==
"-set")
1931 sParams = sParams.substr(4);
1938 _parser.
Eval(nResults);
1955 if (sInterval.find(
':') == string::npos || sInterval.length() < 3)
1960 for (
size_t i = 0; i < 2; i++)
1965 dBoundaries[i] = _parser.
Eval();
1980 dBoundaries[1] = dBoundaries[0];
1981 dBoundaries[0] = Temp;
1992 nSamples = (nSamples - 1) *
intCast(
std::abs(dBoundaries[1] - dBoundaries[0])) + 1;
1996 if (nSamples > 10001)
2005 *dVar = dBoundaries[0];
2006 vector<mu::value_type> vResults;
2007 dVal[0] = _parser.
Eval();
2012 if (dVal[0] != 0.0 && fabs(dVal[0]) < 1e-10)
2014 *dVar = dBoundaries[0] - 1e-10;
2015 dVal[1] = _parser.
Eval();
2017 if (dVal[0].
real()*dVal[1].real() < 0 && (nMode * dVal[0].real() <= 0.0))
2024 for (
unsigned int i = 1; i < nSamples; i++)
2027 *dVar = dBoundaries[0] + (double)i * (dBoundaries[1] - dBoundaries[0]) / (double)(nSamples - 1);
2028 dVal[1] = _parser.
Eval();
2030 if (dVal[0].
real()*dVal[1].real() < 0)
2033 || (nMode == -1 && (dVal[0].
real() > 0 && dVal[1].real() < 0))
2034 || (nMode == 1 && (dVal[0].real() < 0 && dVal[1].real() > 0)))
2037 vResults.push_back((
localizeZero(sExpr, dVar, _parser, instance->
getSettings(), dBoundaries[0] + (double)(i - 1) * (dBoundaries[1] - dBoundaries[0]) / (
double)(nSamples - 1), dBoundaries[0] + (
double)i * (dBoundaries[1] - dBoundaries[0]) / (
double)(nSamples - 1))));
2040 else if (dVal[0].
real()*dVal[1].real() == 0.0)
2043 || (nMode == -1 && (dVal[0].
real() > 0 || dVal[1].real() < 0))
2044 || (nMode == 1 && (dVal[0].real() < 0 || dVal[1].real() > 0)))
2052 while (dVal[0]*dVal[1] == 0.0 && i + 1 < nSamples)
2055 *dVar = dBoundaries[0] + (double)i * (dBoundaries[1] - dBoundaries[0]) / (double)(nSamples - 1);
2056 dVal[1] = _parser.
Eval();
2061 while (dVal[1] == 0.0 && i + 1 < nSamples)
2064 *dVar = dBoundaries[0] + (double)i * (dBoundaries[1] - dBoundaries[0]) / (double)(nSamples - 1);
2065 dVal[1] = _parser.
Eval();
2070 vResults.push_back(
localizeZero(sExpr, dVar, _parser, instance->
getSettings(), dBoundaries[0] + (double)nTemp * (dBoundaries[1] - dBoundaries[0]) / (double)(nSamples - 1), dBoundaries[0] + (double)i * (dBoundaries[1] - dBoundaries[0]) / (double)(nSamples - 1)));
2079 if (dVal[0] != 0.0 && fabs(dVal[0]) < 1e-10)
2081 *dVar = dBoundaries[1] + 1e-10;
2082 dVal[1] = _parser.
Eval();
2084 if (dVal[0].
real()*dVal[1].real() < 0 && nMode * dVal[0].real() <= 0.0)
2085 vResults.push_back(
localizeZero(sExpr, dVar, _parser, instance->
getSettings(), dBoundaries[1], dBoundaries[1] + 1e-10));
2090 if (!vResults.size())
2120 const unsigned int nSamples = 101;
2123 if (_parser.
GetExpr() != sCmd)
2130 dVal[0] = _parser.
Diff(dVarAdress, dLeft, 1e-7);
2134 for (
unsigned int i = 1; i < nSamples; i++)
2137 dVal[1] = _parser.
Diff(dVarAdress, dLeft + (
double)i * (dRight - dLeft) / (
double)(nSamples - 1), 1e-7);
2140 if (dVal[0].
real()*dVal[1].
real() < 0)
2145 if (
std::abs(dRight - dLeft) / (
double)(nSamples - 1) <= dEps || fabs(log(dEps)) + 1 < nRecursion * 2)
2146 return dLeft + (double)(i - 1) * (dRight - dLeft) / (
double)(nSamples - 1) +
Linearize(0.0, dVal[0].
real(), (dRight - dLeft).
real() / (double)(nSamples - 1), dVal[1].real());
2148 return localizeExtremum(sCmd, dVarAdress, _parser, _option, dLeft + (
double)(i - 1) * (dRight - dLeft) / (
double)(nSamples - 1), dLeft + (
double)i * (dRight - dLeft) / (
double)(nSamples - 1), dEps, nRecursion + 1);
2150 else if (dVal[0]*dVal[1] == 0.0)
2159 while (dVal[0]*dVal[1] == 0.0 && i + 1 < nSamples)
2162 dVal[1] = _parser.
Diff(dVarAdress, dLeft + (
double)i * (dRight - dLeft) / (
double)(nSamples - 1), 1e-7);
2167 while (dVal[1] == 0.0 && i + 1 < nSamples)
2170 dVal[1] = _parser.
Diff(dVarAdress, dLeft + (
double)i * (dRight - dLeft) / (
double)(nSamples - 1), 1e-7);
2176 if ((i - nTemp) *
std::abs(dRight - dLeft) / (
double)(nSamples - 1) <= dEps || (!nTemp && i + 1 == nSamples) || fabs(log(dEps)) + 1 < nRecursion * 2)
2177 return dLeft + (double)nTemp * (dRight - dLeft) / (double)(nSamples - 1) +
Linearize(0.0, dVal[0].
real(), (i - nTemp) * (dRight - dLeft).
real() / (
double)(nSamples - 1), dVal[1].
real());
2179 return localizeExtremum(sCmd, dVarAdress, _parser, _option, dLeft + (
double)nTemp * (dRight - dLeft) / (
double)(nSamples - 1), dLeft + (
double)i * (dRight - dLeft) / (
double)(nSamples - 1), dEps, nRecursion + 1);
2187 *dVarAdress = dLeft;
2188 dVal[0] = _parser.
Eval();
2189 *dVarAdress = dRight;
2190 dVal[1] = _parser.
Eval();
2191 return Linearize(dLeft.real(), dVal[0].real(), dRight.real(), dVal[1].real());
2216 const unsigned int nSamples = 101;
2219 if (_parser.
GetExpr() != sCmd)
2226 *dVarAdress = dLeft;
2227 dVal[0] = _parser.
Eval();
2231 for (
unsigned int i = 1; i < nSamples; i++)
2234 *dVarAdress = dLeft + (double)i * (dRight - dLeft) / (double)(nSamples - 1);
2235 dVal[1] = _parser.
Eval();
2238 if (dVal[0].
real()*dVal[1].real() < 0)
2243 if (
std::abs(dRight - dLeft) / (double)(nSamples - 1) <= dEps || fabs(log(dEps)) + 1 < nRecursion * 2)
2244 return dLeft + (
double)(i - 1) * (dRight - dLeft) / (double)(nSamples - 1) +
Linearize(0.0, dVal[0].
real(), (dRight - dLeft).
real() / (
double)(nSamples - 1), dVal[1].
real());
2246 return localizeZero(sCmd, dVarAdress, _parser, _option, dLeft + (
double)(i - 1) * (dRight - dLeft) / (
double)(nSamples - 1), dLeft + (
double)i * (dRight - dLeft) / (
double)(nSamples - 1), dEps, nRecursion + 1);
2248 else if (dVal[0]*dVal[1] == 0.0)
2257 while (dVal[0]*dVal[1] == 0.0 && i + 1 < nSamples)
2260 *dVarAdress = dLeft + (double)i * (dRight - dLeft) / (double)(nSamples - 1);
2261 dVal[1] = _parser.
Eval();
2266 while (dVal[1] == 0.0 && i + 1 < nSamples)
2269 *dVarAdress = dLeft + (double)i * (dRight - dLeft) / (double)(nSamples - 1);
2270 dVal[1] = _parser.
Eval();
2276 if ((i - nTemp) *
std::abs(dRight - dLeft) / (double)(nSamples - 1) <= dEps || (!nTemp && i + 1 == nSamples) || fabs(log(dEps)) + 1 < nRecursion * 2)
2277 return dLeft + (double)nTemp * (dRight - dLeft) / (double)(nSamples - 1) +
Linearize(0.0, dVal[0].
real(), (i - nTemp) * (dRight - dLeft).
real() / (
double)(nSamples - 1), dVal[1].
real());
2279 return localizeZero(sCmd, dVarAdress, _parser, _option, dLeft + (
double)nTemp * (dRight - dLeft) / (
double)(nSamples - 1), dLeft + (
double)i * (dRight - dLeft) / (
double)(nSamples - 1), dEps, nRecursion + 1);
2287 *dVarAdress = dLeft;
2288 dVal[0] = _parser.
Eval();
2289 *dVarAdress = dRight;
2290 dVal[1] = _parser.
Eval();
2291 return Linearize(dLeft.real(), dVal[0].real(), dRight.real(), dVal[1].real());
2310 const double dPRECISION = 1e-1;
2311 string sVarName =
"";
2313 string sExpr_cpy =
"";
2315 string sTaylor =
"Taylor";
2316 string sPolynom =
"";
2317 bool bUseUniqueName = cmdParser.
hasParam(
"unique") || cmdParser.
hasParam(
"u");
2318 size_t nth_taylor = 6;
2319 size_t nSamples = 0;
2322 std::vector<mu::value_type> vCoeffs;
2343 for (
const std::string& sPar : vParams)
2357 if (dVarValue == 0.0)
2359 else if (dVarValue.real() < 0)
2386 if (sVarName.length())
2397 string sOperators =
" ,;-*/%^!<>&|?:=+[]{}()";
2399 for (
unsigned int i = 0; i < sTaylor.length(); i++)
2401 if (sOperators.find(sTaylor[i]) != string::npos)
2403 sTaylor.erase(i, 1);
2409 sTaylor +=
"(x) := ";
2416 vCoeffs.push_back(_parser.
Eval());
2425 vCoeffs.push_back(_parser.
Eval());
2428 nSamples = 6*nth_taylor + 1;
2429 const size_t nFILTERSIZE = 7;
2431 std::vector<mu::value_type> vValues(nSamples, 0.0);
2432 std::vector<mu::value_type> vDiffValues;
2433 double dPrec = dPRECISION / nth_taylor;
2436 for (
size_t i = 0; i < vValues.size(); i++)
2438 *dVar = dVarValue + ((int)i - (
int)nSamples/2)*dPrec;
2439 vValues[i] = _parser.
Eval();
2443 vDiffValues = vValues;
2446 for (
size_t n = 0; n < nth_taylor; n++)
2448 for (
size_t i = nFILTERSIZE/2; i < vValues.size()-nFILTERSIZE/2; i++)
2450 vDiffValues[i] = 0.0;
2452 for (
size_t j = 0; j < nFILTERSIZE; j++)
2453 vDiffValues[i] += filter.
apply(j, 0, vValues[i + j - nFILTERSIZE/2]);
2455 vDiffValues[i] /= dPrec;
2458 vCoeffs.push_back(vDiffValues[vDiffValues.size()/2] / (double)
integralFactorial(n+1));
2460 vValues = vDiffValues;
2463 sTaylor +=
"polynomial(" + sArg +
"," + sPolynom.substr(0, sPolynom.length()-1) +
")";
2469 sTaylor +=
" " +
_lang.
get(
"PARSERFUNCS_TAYLOR_DEFINESTRING", sExpr_cpy, sVarName,
toString(dVarValue, 4),
toString((
int)nth_taylor));
2473 bool bDefinitionSuccess =
false;
2475 if (_functions.
isDefined(sTaylor.substr(0, sTaylor.find(
":="))))
2476 bDefinitionSuccess = _functions.
defineFunc(sTaylor,
true);
2478 bDefinitionSuccess = _functions.
defineFunc(sTaylor);
2480 if (bDefinitionSuccess)
2501 return (fabs(std::arg(cmplx[2]) - std::arg(cmplx[1])) >=
M_PI) && ((std::arg(cmplx[2]) - std::arg(cmplx[1])) * (std::arg(cmplx[1]) - std::arg(cmplx[0])) < 0);
2517 bool isOdd = nElements % 2;
2518 std::vector<size_t> vValues(nElements, 0u);
2522 for (
size_t i = 0; i < nElements; i++)
2533 nOddVal = vValues.back();
2538 nOddVal = vValues.front();
2539 vValues.erase(vValues.begin());
2544 std::vector<size_t> vAxis(vValues.begin() + nElements / 2+(isOdd && inverseTrafo), vValues.end());
2548 vAxis.push_back(nOddVal);
2551 vAxis.insert(vAxis.end(), vValues.begin(), vValues.begin() + nElements / 2+(isOdd && inverseTrafo));
2590 _fftData.Save(
"D:/Software/NumeRe/save/fftdata.txt");
2596 double samples = _fft.
lines/2.0;
2598 _fftData.a[0] /= dual(2*samples, 0.0);
2600 for (
int i = 1; i < _fftData.GetNx(); i++)
2601 _fftData.a[i] /= dual(samples, 0.0);
2605 double samples = _fftData.GetNx()/2.0;
2607 _fftData.a[0] *= dual(2*samples, 0.0);
2609 for (
int i = 1; i < _fftData.GetNx(); i++)
2610 _fftData.a[i] *= dual(samples, 0.0);
2625 size_t nElements = _fftData.GetNx();
2626 double dPhaseOffset = 0.0;
2631 for (
size_t i = 0; i < nElements; i++)
2639 else if (i <= nElements/2)
2653 if (std::arg(_fftData.a[i - 1]) - std::arg(_fftData.a[i - 2]) < 0.0)
2654 dPhaseOffset -= 2 *
M_PI;
2655 else if (std::arg(_fftData.a[i - 1]) - std::arg(_fftData.a[i - 2]) > 0.0)
2656 dPhaseOffset += 2 *
M_PI;
2659 _data.
writeToTable(_idx.
row[vAxis[i]], _idx.
col[2], sTargetTable, std::arg(_fftData.a[i]) + dPhaseOffset);
2684 for (
int i = 0; i < _fftData.GetNx(); i++)
2719 double samples = _fft.
lines*(_fft.
cols-2)/2.0;
2721 _fftData.a[0] /= dual(2*samples, 0.0);
2723 for (
long long int i = 1; i < _fftData.GetNN(); i++)
2724 _fftData.a[i] /= dual(samples, 0.0);
2728 double samples = _fft.
lines*(_fft.
cols-2)/2.0;
2730 _fftData.a[0] *= dual(2*samples, 0.0);
2732 for (
long long int i = 1; i < _fftData.GetNN(); i++)
2733 _fftData.a[i] *= dual(samples, 0.0);
2746 int nElemsLines = _fftData.GetNx();
2747 int nElemsCols = _fftData.GetNy();
2752 for (
int i = 0; i < nElemsLines; i++)
2754 if ((
size_t)i > _idx.
row.
size())
2763 for (
int j = 0; j < nElemsCols; j++)
2767 _data.
writeToTable(_idx.
row[i + (i >= nElemsLines/2 ? -nElemsLines/2 : nElemsLines/2+nElemsLines % 2)],
2768 _idx.
col[j+2 + (j >= nElemsCols/2 ? -nElemsCols/2 : nElemsCols/2+nElemsCols % 2)],
2770 _fft.
bComplex ? _fftData.a[i+j*nElemsLines] :
std::abs(_fftData.a[i+j*nElemsLines]));
2775 _fft.
bComplex ? _fftData.a[i+j*nElemsLines] :
std::abs(_fftData.a[i+j*nElemsLines]));
2780 for (
int i = 0; i < nElemsCols; i++)
2795 for (
int j = 0; j < nElemsCols; j++)
2802 int nElemsLines = _fftData.GetNx();
2803 int nElemsCols = _fftData.GetNy();
2808 for (
int i = 0; i < nElemsLines; i++)
2810 if ((
size_t)i > _idx.
row.
size())
2817 for (
int j = 0; j < nElemsCols; j++)
2819 _data.
writeToTable(_idx.
row[i], _idx.
col[j+2], sTargetTable, _fftData.a[i+j*nElemsLines]);
2824 for (
int i = 0; i < nElemsCols; i++)
2826 if ((
size_t)i > _idx.
row.
size())
2836 for (
int j = 0; j < nElemsCols; j++)
2872 bool bIs2DFFT = cmdParser.
getCommand() ==
"fft2d";
2873 string sTargetTable =
"fftdata";
2888 _fft.
lines = _mem->getElemsInColumn(0);
2889 _fft.
cols = _mem->getCols();
2899 if (_fft.
cols % 2 && _fft.
cols > 1e3)
2902 int collines = _mem->getElemsInColumn(1);
2904 _fft.
dNyquistFrequency[1] = collines / (_mem->readMem(collines - 1, 1).real() - _mem->readMem(0, 1).real()) / 2.0;
2905 _fft.
dTimeInterval[1] = (collines - 1) / (_mem->readMem(collines - 1, 1).real());
2909 if (_fft.
lines < 10 || _fft.
cols < 2 || (bIs2DFFT && _fft.
cols < _mem->getElemsInColumn(1)+2))
2931 _fftData.Create(_fft.
lines, _fft.
cols-2);
2933 _fftData.Create(_fft.
lines);
2935 std::vector<size_t> vAxis;
2942 for (
size_t i = 0; i < (size_t)_fft.
lines; i++)
2950 for (
int i = 0; i < _fft.
lines; i++)
2953 _fftData.a[i] = nanguard(_mem->readMem(vAxis[i], 1));
2955 _fftData.a[i] = nanguard(dual(_mem->readMem(vAxis[i], 1).real(), _mem->readMem(vAxis[i], 2).real()));
2957 _fftData.a[i] = nanguard(dual(_mem->readMem(vAxis[i], 1).real() * cos(_mem->readMem(vAxis[i], 2).real()),
2958 _mem->readMem(vAxis[i], 1).real() * sin(_mem->readMem(vAxis[i], 2).real())));
2961 int nLines = _fft.
lines;
2962 int nCols = _fft.
cols-2;
2964 for (
int j = 0; j < nCols; j++)
2967 _fftData.a[i+j*nLines] = nanguard(_mem->readMem(i + (i >= nLines/2 ? -nLines/2 : nLines/2 + nLines % 2),
2968 j+2 + (j >= nCols/2 ? -nCols/2 : nCols/2 + nCols % 2)));
2970 _fftData.a[i+j*nLines] = nanguard(_mem->readMem(i, j+2));
2979 calculate2dFFT(_data, _idx, sTargetTable, _fftData, vAxis, _fft);
2981 calculate1dFFT(_data, _idx, sTargetTable, _fftData, vAxis, _fft);
3008 vector<double> vWaveletData;
3009 vector<double> vAxisData;
3012 bool bInverseTrafo = cmdParser.
hasParam(
"inverse");
3013 bool bTargetGrid = cmdParser.
hasParam(
"grid");
3014 string sTargetTable =
"fwtdata";
3020 if (sParVal.length())
3025 if (!sType.length() && sParVal.length())
3047 string sExplType =
"";
3049 if (sType.front() ==
'c')
3050 sExplType =
"Centered ";
3052 if (sType.back() ==
'd' || sType.find(
"daubechies") != string::npos)
3053 sExplType +=
"Daubechies";
3054 else if (sType.back() ==
'h' || sType.find(
"haar") != string::npos)
3055 sExplType +=
"Haar";
3056 else if (sType.back() ==
'b' || sType.find(
"bspline") != string::npos)
3057 sExplType +=
"BSpline";
3065 for (
size_t i = 0; i < (size_t)_mem->getLines(); i++)
3067 vWaveletData.push_back(_mem->readMem(i, 1).real());
3070 vAxisData.push_back(_mem->readMem(i, 0).real());
3074 if (sType ==
"d" || sType ==
"daubechies")
3076 else if (sType ==
"cd" || sType ==
"cdaubechies")
3078 else if (sType ==
"h" || sType ==
"haar")
3080 else if (sType ==
"ch" || sType ==
"chaar")
3082 else if (sType ==
"b" || sType ==
"bspline")
3084 else if (sType ==
"cb" || sType ==
"cbspline")
3088 if (bTargetGrid && !bInverseTrafo)
3098 for (
size_t i = 0; i < tWaveletData.
getLines(); i++)
3103 for (
size_t j = 0; j < tWaveletData.
getCols(); j++)
3108 string sHeadline =
"";
3111 sHeadline =
_lang.
get(
"COMMON_TIME");
3113 sHeadline =
_lang.
get(
"COMMON_LEVEL");
3115 sHeadline =
_lang.
get(
"COMMON_COEFFICIENT");
3140 for (
long long int i = 0; i < vWaveletData.size(); i++)
3179 unsigned int nSamples = 100;
3184 static string zero =
"0.0";
3185 bool bLogarithmic = cmdParser.
hasParam(
"logscale");
3193 if (sExpr.find(
"{") != string::npos)
3204 for (
const std::string& sPar : vParams)
3206 if (sPar !=
"samples")
3211 if (sInterval.front() ==
'[' && sInterval.back() ==
']')
3213 sInterval.pop_back();
3214 sInterval.erase(0, 1);
3219 _parser.
SetExpr(indices[0] +
"," + indices[1]);
3234 if (vSamples.size())
3235 nSamples =
intCast(vSamples.front());
3236 else if (ivl[0].getSamples())
3237 nSamples = ivl[0].getSamples();
3258 if (bLogarithmic && (ivl[0].
min() <= 0.0))
3270 vector<mu::value_type> vResults;
3278 vResults.push_back(_parser.
Eval());
3280 for (
unsigned int i = 1; i < nSamples; i++)
3284 *dVar = ivl[0].log(i, nSamples);
3286 *dVar = ivl[0](i, nSamples);
3288 vResults.push_back(_parser.
Eval());
3295 for (
unsigned int i = 0; i < nSamples; i++)
3296 vResults.push_back(_parser.
Eval());
3314 std::vector<size_t> vSamples = {100, 100};
3315 bool bTranspose = cmdParser.
hasParam(
"transpose");
3318 vector<vector<mu::value_type> > vZVals;
3323 std::string sTargetCache = cmdParser.
getTargetTable(_iTargetIndex,
"grid");
3332 while (ivl.
size() < 2)
3342 vSamples.front() =
abs(
intCast(vParVal.front()));
3344 if (vParVal.size() >= 2)
3347 vSamples[1] = vSamples.front();
3351 if (vSamples.front() < 2 || vSamples.back() < 2)
3358 if (ivl[0].getSamples())
3359 vSamples[bTranspose] = ivl[0].getSamples();
3361 if (ivl[1].getSamples())
3362 vSamples[1-bTranspose] = ivl[1].getSamples();
3383 vector<mu::value_type> vVector;
3394 for (
size_t i = 0; i < _idx.
row.
size(); i++)
3397 vZVals.push_back(vVector);
3403 for (
size_t j = 0; j < _idx.
col.
size(); j++)
3406 vZVals.push_back(vVector);
3412 if (!vZVals.size() || (vZVals.size() == 1 && vZVals[0].size() == 1))
3425 vector<mu::value_type> vVector;
3427 for (
unsigned int x = 0; x < vSamples[bTranspose]; x++)
3431 for (
unsigned int y = 0; y < vSamples[1-bTranspose]; y++)
3434 vVector.push_back(_parser.
Eval());
3437 vZVals.push_back(vVector);
3450 for (
size_t i = 0; i < vSamples[bTranspose]; i++)
3451 _data.
writeToTable(i, _iTargetIndex.
col[0], sTargetCache, ivl[0](i, vSamples[bTranspose]));
3456 for (
size_t i = 0; i < vSamples[1-bTranspose]; i++)
3457 _data.
writeToTable(i, _iTargetIndex.
col[1], sTargetCache, ivl[1](i, vSamples[1-bTranspose]));
3462 for (
size_t i = 0; i < vZVals.size(); i++)
3467 for (
size_t j = 0; j < vZVals[i].size(); j++)
3472 _data.
writeToTable(_iTargetIndex.
row[i], _iTargetIndex.
col[j+2], sTargetCache, vZVals[i][j]);
3494 vector<size_t> vSamples = nSamples;
3521 vSamples.front() = _idx.
row.
size();
3522 vSamples.back() = _idx.
col.
size();
3525 if (vSamples[0] < 2 && vSamples[1] >= 2)
3526 vSamples[0] = vSamples[1];
3527 else if (vSamples[1] < 2 && vSamples[0] >= 2)
3528 vSamples[1] = vSamples[0];
3531 if (vSamples.size() < 2 || vSamples[0] < 2 || vSamples[1] < 2)
3552 if (vZVals.size() == 1 || vZVals[0].size() == 1)
3554 vector<mu::value_type> vVector;
3561 _mData[0].Create(nSamples_x, nSamples_y);
3562 _mData[1].Create(nSamples_x);
3563 _mData[2].Create(nSamples_y);
3565 if (vZVals.size() != 1)
3566 _mData[3].Create(vZVals.size());
3568 _mData[3].Create(vZVals[0].size());
3571 for (
unsigned int i = 0; i < nSamples_x; i++)
3572 _mData[1].a[i] = ivl[0](i, nSamples_x).real();
3574 for (
unsigned int i = 0; i < nSamples_y; i++)
3575 _mData[2].a[i] = ivl[1](i, nSamples_y).real();
3578 if (vZVals.size() != 1)
3580 for (
unsigned int i = 0; i < vZVals.size(); i++)
3581 _mData[3].a[i] = vZVals[i][0].
real();
3585 for (
unsigned int i = 0; i < vZVals[0].size(); i++)
3586 _mData[3].a[i] = vZVals[0][i].
real();
3590 _graph.SetRanges(_mData[1], _mData[2], _mData[3]);
3593 _graph.DataGrid(_mData[0], _mData[1], _mData[2], _mData[3]);
3598 ivl[0] =
Interval(_mData[1].Minimal(), _mData[1].Maximal());
3599 ivl[1] =
Interval(_mData[2].Minimal(), _mData[2].Maximal());
3602 for (
unsigned int i = 0; i < nSamples_x; i++)
3604 for (
unsigned int j = 0; j < nSamples_y; j++)
3605 vVector.push_back(_mData[0].a[i + nSamples_x * j]);
3607 vZVals.push_back(vVector);
3626 string sAudioFileName =
"<savepath>/audiofile.wav";
3627 int nSamples = 44100;
3636 nSamples =
intCast(vVals.front());
3659 nChannels = _idx.
col.
size() > 1 ? 2 : 1;
3663 if (!audiofile.get())
3666 audiofile.get()->setChannels(nChannels);
3667 audiofile.get()->setSampleRate(nSamples);
3668 audiofile.get()->newFile();
3670 if (!audiofile.get()->isValid())
3673 for (
size_t i = 0; i < _idx.
row.
size(); i++)
3701 if (sTarget.length())
3705 if (!audiofile.get() || !audiofile.get()->isValid())
3708 size_t nLen = audiofile.get()->getLength();
3709 size_t nChannels = audiofile.get()->getChannels();
3721 if (nChannels > 1 && _targetIdx.
col.
size() > 1)
3724 for (
size_t i = 0; i < nLen; i++)
3728 if (_targetIdx.
row.
size() <= i)
3733 if (nChannels > 1 && _targetIdx.
col.
size() > 1)
3740 std::vector<mu::value_type> vIndices = {_targetIdx.
row.
min()+1,
3752 if (!audiofile.get() || !audiofile.get()->isValid())
3756 size_t nLen = audiofile.get()->getLength();
3757 size_t nChannels = audiofile.get()->getChannels();
3758 size_t nSampleRate = audiofile.get()->getSampleRate();
3761 std::vector<mu::value_type> vMetaData = {nLen, nChannels, nSampleRate, nLen / (double)nSampleRate};
3783 std::string sTarget = cmdParser.
getTargetTable(_targetIdx,
"audiodata");
3786 if (vSeekIndices.size() < 2)
3794 if (!audiofile.get() || !audiofile.get()->isValid())
3797 size_t nLen = audiofile.get()->getLength();
3798 size_t nChannels = audiofile.get()->getChannels();
3800 if (!audiofile.get()->isSeekable() ||
std::max(vSeekIndices[0].real()-1, 0.0) >= nLen)
3803 std::unique_ptr<Audio::SeekableFile> seekable(
static_cast<Audio::SeekableFile*
>(audiofile.release()));
3805 seekable.get()->setPosition(
std::max(vSeekIndices[0].
real()-1, 0.0));
3806 nLen =
std::min(nLen - seekable.get()->getPosition(), (
size_t)(
std::max(vSeekIndices[1].real(), 0.0)));
3818 if (nChannels > 1 && _targetIdx.
col.
size() > 1)
3821 for (
size_t i = 0; i < nLen; i++)
3825 if (_targetIdx.
row.
size() <= i)
3830 if (nChannels > 1 && _targetIdx.
col.
size() > 1)
3855 string sColHeaders[2] = {
"",
""};
3856 double dXmin, dXmax;
3862 nSamples =
intCast(vParVal.front());
3872 sColHeaders[0] = _mem->getHeadLineElement(0) +
"\n(regularized)";
3873 sColHeaders[1] = _mem->getHeadLineElement(1) +
"\n(regularized)";
3875 long long int nLines = _mem->getLines();
3891 for (
long long int i = 0; i < nSamples; i++)
3918 vector<mu::value_type> vPulseProperties;
3919 double dXmin = NAN, dXmax = NAN;
3920 double dSampleSize = NAN;
3930 long long int nLines = _mem->getLines();
3937 for (
long long int i = 0; i < nLines; i++)
3938 _v.a[i] = _mem->readMem(i, 1).real();
3940 dSampleSize = (dXmax - dXmin) / ((
double)_v.GetNx() - 1.0);
3941 mglData _pulse(_v.Pulse(
'x'));
3945 vPulseProperties.push_back(_pulse[0]);
3946 vPulseProperties.push_back(_pulse[1]*dSampleSize + dXmin);
3947 vPulseProperties.push_back(2.0 * _pulse[2]*dSampleSize);
3948 vPulseProperties.push_back(2.0 * _pulse[3]*dSampleSize);
3949 vPulseProperties.push_back(_pulse[4]*dSampleSize);
3965 for (
unsigned int i = 0; i < vPulseProperties.size(); i++)
3990 mglData _real, _imag, _result;
3993 double dXmin = NAN, dXmax = NAN;
3994 double dFmin = 0.0, dFmax = 1.0;
3995 double dSampleSize = NAN;
4002 std::string sTargetCache = cmdParser.
getTargetTable(_target,
"stfdat");
4012 _real.Create(_idx.
row.
size());
4013 _imag.Create(_idx.
row.
size());
4015 for (
size_t i = 0; i < _idx.
row.
size(); i++)
4018 _real.a[i] = val.real();
4019 _imag.a[i] = val.imag();
4022 if (!nSamples || nSamples > _real.GetNx())
4023 nSamples = _real.GetNx() / 32;
4026 _result = mglSTFA(_real, _imag, nSamples);
4028 dSampleSize = (dXmax - dXmin) / ((
double)_result.GetNx() - 1.0);
4031 dFmax = _real.GetNx() / (dXmax - dXmin) / 2.0;
4044 for (
int i = 0; i < _result.GetNx(); i++)
4049 dSampleSize = 2 * (dFmax - dFmin) / ((
double)_result.GetNy() - 1.0);
4052 for (
int i = 0; i < _result.GetNy() / 2; i++)
4053 _data.
writeToTable(_target.
row[i], _target.
col[1], sTargetCache, dFmin + i * dSampleSize);
4059 for (
int i = 0; i < _result.GetNx(); i++)
4064 for (
int j = 0; j < _result.GetNy() / 2; j++)
4069 _data.
writeToTable(_target.
row[i], _target.
col[j+2], sTargetCache, _result[i + (j + _result.GetNy() / 2)*_result.GetNx()]);
4094static double interpolateToGrid(
const std::vector<double>& vAxis,
double dInterpolVal,
bool bExtent =
false)
4096 if (
isnan(dInterpolVal))
4097 return dInterpolVal;
4100 int nBaseVal =
intCast(dInterpolVal) + (dInterpolVal < 0 ? -1 : 0);
4103 double x = dInterpolVal - nBaseVal;
4105 if (nBaseVal >= 0 && nBaseVal+1 < (
int)vAxis.size())
4106 return vAxis[nBaseVal] + (vAxis[nBaseVal+1] - vAxis[nBaseVal]) * x;
4107 else if (nBaseVal > 0 && nBaseVal < (
int)vAxis.size())
4108 return vAxis[nBaseVal] + (vAxis[nBaseVal] - vAxis[nBaseVal-1]) * x;
4109 else if (nBaseVal == -1 && nBaseVal+1 < (
int)vAxis.size())
4110 return vAxis.front() + (-1 + x) * (vAxis[1] - vAxis.front());
4114 if (nBaseVal >= (
int)vAxis.size())
4115 return vAxis.back() + (nBaseVal - vAxis.size() + 1 + x) * (vAxis.back() - vAxis[vAxis.size()-2]);
4116 else if (nBaseVal < -1)
4117 return vAxis.front() + (nBaseVal + x) * (vAxis[1] - vAxis.front());
4137 double dLevel = NAN, dAttrX = 0.0, dAttrY = 1.0, dMinLen = 0.0;
4143 dLevel = vParVal.front().real();
4147 if (vParVal.size() > 1)
4149 dAttrX = fabs(vParVal[0]);
4150 dAttrY = fabs(vParVal[1]);
4152 else if (vParVal.size())
4153 dAttrY = fabs(vParVal[0]);
4158 dMinLen = fabs(vParVal.front());
4161 std::string sTargetCache = cmdParser.
getTargetTable(_target,
"detectdat");
4185 long long int nLines = _mem->getLines();
4186 long long int nCols = _mem->getCols();
4189 dAttrX =
min(dAttrX, (
double)nLines);
4190 dAttrY =
min(dAttrY, (
double)nCols);
4196 _mData.Create(nLines, nCols);
4199 for (
long long int i = 0; i < nLines; i++)
4201 for (
long long int j = 0; j < nCols; j++)
4203 _mData.a[i+j*nLines] = _mem->readMem(i, j).real();
4208 mglData _res = _mData.Detect(dLevel, dAttrY, dAttrX, dMinLen);
4217 for (
int i = 0; i < _res.GetNy(); i++)
4219 if (_target.
row.
size() <= (
size_t)i)
4222 for (
int j = 0; j < _res.GetNx(); j++)
4224 if (_target.
col.
size() <= (
size_t)j)
4258 vector<double> xVect, yVect;
4267 int nLines = _mem->getLines();
4272 for (
int i = 0; i < nLines; i++)
4274 xVect.push_back(_mem->readMem(i, 0).real());
4275 yVect.push_back(_mem->readMem(i, 1).real());
4279 _spline.set_points(xVect, yVect);
4281 string sDefinition =
"Spline(x) := ";
4284 for (
size_t i = 0; i < xVect.size() - 1; i++)
4286 string sRange =
"polynomial(";
4290 else if (xVect[i] < 0)
4291 sRange +=
"x+" +
toString(fabs(xVect[i]), 4) +
",";
4293 sRange +=
"x-" +
toString(xVect[i], 4) +
",";
4295 vector<double> vCoeffs = _spline[i];
4298 if (i == xVect.size() - 2)
4299 sRange +=
"*ivl(x," +
toString(xVect[i], 4) +
"," +
toString(xVect[i + 1], 4) +
",1,1)";
4301 sRange +=
"*ivl(x," +
toString(xVect[i], 4) +
"," +
toString(xVect[i + 1], 4) +
",1,2)";
4303 sDefinition += sRange;
4305 if (i < xVect.size() - 2)
4306 sDefinition +=
" + ";
4312 bool bDefinitionSuccess =
false;
4314 if (_functions.
isDefined(sDefinition.substr(0, sDefinition.find(
":="))))
4315 bDefinitionSuccess = _functions.
defineFunc(sDefinition,
true);
4317 bDefinitionSuccess = _functions.
defineFunc(sDefinition);
4319 if (bDefinitionSuccess)
4342 double dAlpha = 0.0;
4344 std::vector<double> source_x;
4345 std::vector<double> source_y;
4348 std::string sTargetTable = cmdParser.
getTargetTable(_idx,
"rotdata");
4353 dAlpha = -vParVal.front().real() / 180.0 *
M_PI;
4367 while (
isnan(source_x.back()))
4368 source_x.pop_back();
4370 while (
isnan(source_y.back()))
4371 source_y.pop_back();
4376 auto source_x_minmax = std::minmax_element(source_x.begin(), source_x.end());
4377 auto source_y_minmax = std::minmax_element(source_y.begin(), source_y.end());
4378 double dSizeRelation = source_x.size() / (double)source_y.size();
4379 double dRangeRelation = fabs(*source_x_minmax.second - *source_x_minmax.first) / fabs(*source_y_minmax.second - *source_y_minmax.first);
4382 if (fabs(dSizeRelation - dRangeRelation) > 1e-3)
4396 Point topLeft(0, 0);
4405 Point origin = (bottomRightS + topLeft) / 2.0;
4408 topLeft.
rotate(dAlpha, origin);
4409 topRightS.
rotate(dAlpha, origin);
4410 topRightP.
rotate(dAlpha, origin);
4411 bottomLeftS.
rotate(dAlpha, origin);
4412 bottomLeftP.
rotate(dAlpha, origin);
4413 bottomRightS.
rotate(dAlpha, origin);
4414 bottomRightP.
rotate(dAlpha, origin);
4424 int rows =
ceil(bot - topS);
4425 int cols =
ceil(right - leftS);
4431 for (
int i = 0; i < rows; i++)
4433 if (_idx.
row.
size() <= (
size_t)i)
4440 for (
int i = 0; i < cols; i++)
4442 if (_idx.
row.
size() <= (
size_t)i)
4450 else if (cmdParser.
getCommand() ==
"gridrot")
4457 for (
int i = 0; i < rows; i++)
4459 if (_idx.
row.
size() <= (
size_t)i)
4462 Point p(i+topP, origin.
y);
4463 p.
rotate(-dAlpha, origin);
4468 p.
rotate(dAlpha, origin_axis);
4473 for (
int j = 0; j < cols; j++)
4475 if (_idx.
row.
size() <= (
size_t)j)
4478 Point p(origin.
x, j+leftP);
4479 p.
rotate(-dAlpha, origin);
4484 p.
rotate(dAlpha, origin_axis);
4498 #pragma omp parallel for
4499 for (
int j = 0; j < cols; j++)
4501 if (_idx.
col.
size() <= (
size_t)j)
4504 for (
int i = 0; i < rows; i++)
4506 if (_idx.
row.
size() <= (
size_t)i)
4511 Point p(j + leftP, i + topP);
4512 p.
rotate(-dAlpha, origin);
4522 _data.
shrink(sTargetTable);
4551 size_t nGlobalBest = 0;
4552 size_t nNumParticles = 100;
4553 size_t nMaxIterations = 100;
4563 nNumParticles =
intCast(vParVal.front());
4568 nMaxIterations =
intCast(vParVal.front());
4584 double minRange = fabs(ivl[0].
max() - ivl[0].
min());
4586 for (
size_t i = 1; i < nDims; i++)
4588 if (fabs(ivl[i].
max() - ivl[i].
min()) < minRange)
4589 minRange = fabs(ivl[i].
max() - ivl[i].
min());
4595 double fRandRange = minRange / 10.0;
4597 std::vector<std::vector<double>> vPos;
4598 std::vector<std::vector<double>> vBest;
4599 std::vector<std::vector<double>> vVel;
4600 std::vector<double> vFunctionValues;
4601 std::vector<double> vBestValues;
4604 vBest.resize(nDims);
4608 for (
size_t i = 0; i < nNumParticles; i++)
4610 for (
size_t j = 0; j < nDims; j++)
4618 vFunctionValues.push_back(_parser.
Eval().real());
4621 for (
size_t j = 0; j < nDims; j++)
4626 vBestValues = vFunctionValues;
4629 nGlobalBest = std::min_element(vBestValues.begin(), vBestValues.end()) - vBestValues.begin();
4632 for (
size_t i = 0; i < nMaxIterations; i++)
4636 double fAdaptiveVelFactor = (nMaxIterations - i) / (
double)nMaxIterations;
4638 for (
size_t j = 0; j < nNumParticles; j++)
4640 for (
size_t n = 0; n < nDims; n++)
4643 vVel[n][j] +=
parser_Random(0, fRandRange).real() * (vBest[n][j] - vPos[n][j]) +
parser_Random(0, fRandRange).real() * (vBest[n][nGlobalBest] - vPos[n][j]);
4646 vPos[n][j] += fAdaptiveVelFactor * vVel[n][j];
4656 vFunctionValues[j] = _parser.
Eval().real();
4659 if (vFunctionValues[j] < vBestValues[j])
4661 vBestValues[j] = vFunctionValues[j];
4663 for (
size_t n = 0; n < nDims; n++)
4665 vBest[n][j] = vPos[n][j];
4671 nGlobalBest = std::min_element(vBestValues.begin(), vBestValues.end()) - vBestValues.begin();
4675 std::vector<mu::value_type> vRes;
4677 for (
size_t j = 0; j < nDims; j++)
4679 vRes.push_back(vBest[j][nGlobalBest]);
4713 std::string sFileName = sUrl.substr(sUrl.rfind(
"/"));
4715 if (sFileName.find(
'.') == std::string::npos)
4716 sFileName =
"index.html";
4721 sFileName = cmdParser.
getFileParameterValue(sFileName.substr(sFileName.rfind(
'.')),
"<savepath>", sFileName);
4724 size_t bytes =
url::put(sUrl, sFileName, sUserName, sPassword);
4730 std::string sUrlResponse =
url::get(sUrl, sUserName, sPassword);
4741 file << sUrlResponse;
4751 std::string sUrlResponse =
url::get(sUrl, sUserName, sPassword);
4757 cmdParser.
setReturnValue(std::vector<std::string>({
"\"" + sUrlResponse +
"\""}));
This class extends the generic audio file with seeking functionalities as well as possibilities for r...
This class provides the functionality to extract the different components of a command line into the ...
std::vector< mu::value_type > parseExprAsNumericalValues() const
Parses the expression into numerical values, returned as a vector of doubles.
DataAccessParser getExprAsDataObject() const
Parses the expression to a DataAccessParser, which will extract the needed information for the curren...
std::string getFileParameterValue(std::string sFileExt, const std::string &sBaseFolder="", const std::string &sDefaultName="") const
Parses the value of the common "file" command line parameter and returns a valid filename.
const std::string & getCommandLine() const
Returns the command line used for constructing this instance (e.g. for errors).
std::string getExprAsMathExpression(bool parseDataObjects=false) const
Prepares the expression by calling custom function definitions and resolving vector braces so that th...
std::vector< mu::value_type > getParameterValueAsNumericalValue(const std::string &sParameter) const
Parses the selected parameter as (one or more) numerical value(s) and returns them as a vector of dou...
std::string getParameterValueAsString(const std::string &sParameter, const std::string &sDefaultValue, bool stripAlways=false, bool onlyStringEvaluation=false) const
Parses the selected parameter value as a string and returns it. If the parameter is not found,...
const std::string & getExpr() const
Returns the expression as plain value.
const std::string & getParameterList() const
Returns the parameter list.
std::string getFileParameterValueForSaving(std::string sFileExt, const std::string &sBaseFolder="", const std::string &sDefaultName="") const
Parses the value of the common "file" command line parameter and returns a valid filename....
std::string getTargetTable(Indices &_targetIndices, const std::string &sDefaultTableName)
Evaluates any target=TABLE() statements in the parameter list and returns the needed information....
void setReturnValue(const std::string &sRetVal)
Sets the return value of the current command by simply appending it to the return value statement.
void clearReturnValue()
Removes the return value statement.
const std::string & getCommand() const
Returns the command.
std::string parseExprAsString() const
Prepares the expression by handling all string operations and removing the surrounding quotation mark...
std::string getParameterValue(const std::string &sParameter) const
Simply returns the parameter value or an empty string. Does not do any parsing steps.
std::vector< std::string > getAllParametersWithValues() const
Returns a vector containing all parameters with values in the current parameter list....
std::string getExprAsFileName(std::string sFileExt, const std::string &sBasePath="") const
Converts the expression to a file name and removes the surrounding quotation marks,...
bool exprContainsDataObjects() const
Simply returns, whether the expression contains any data objects.
IntervalSet parseIntervals(bool bErase=false)
Parses intervals in the parameter list and returns them as a vector. The interval may be deleted,...
bool hasParam(const std::string &sParameter) const
Simple wrapper around findParameter(), if used as a boolean flag.
This class is defined to abstrahize the determination of the correct data object and the calculation ...
Indices & getIndices()
Returns a reference to the stored indices.
void evalIndices()
Evaluates open end indices using the identified data object size.
bool isCluster() const
Determines, whether the data access references a cluster.
std::string & getDataObject()
Returns a reference to the data object identifier.
void info(const std::string &sMessage)
Convenience member function.
void debug(const std::string &sMessage)
Convenience member function.
This class implements the function definition managing instance.
bool defineFunc(const std::string &sExpr, bool bRedefine=false, bool bFallback=false)
This function defines a custom function, by passing it to a new FunctionDefinition class 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...
bool isDefined(const std::string &sFunc)
This method checks, whether the passed function is already defined.
This class represents a single interval in code providing reading access functionality.
std::string get(const std::string &sMessage, const std::vector< std::string > &vTokens) const
This member function returns the language string for the passed language identifier and replaces all ...
This class represents a single table in memory, or a - so to say - single memory page to be handled b...
void writeDataDirect(int _nLine, int _nCol, const mu::value_type &_dData)
This member function provides an unsafe but direct way of writing data to the table....
mu::value_type readMemInterpolated(double _dLine, double _dCol) const
This member function returns a (bilinearily) interpolated element at the selected double positions.
int getLines(bool _bFull=false) const
This member function will return the number of lines, which are currently available in this table.
void markModified()
Mark this table as modified.
int getCols(bool _bFull=false) const
This member function will return the number of columns, which are currently available in this table.
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....
bool resizeMemory(size_t _nLines, size_t _nCols)
This member function will handle all memory grow operations by doubling the base size,...
bool shrink()
This member function shrinks the table memory to the smallest possible dimensions reachable in powers...
Memory * extractRange(const VectorIndex &_vLine, const VectorIndex &_vCol) const
This member function extracts a range of this table and returns it as a new Memory instance.
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
int getAppendedZeroes(int _i, const std::string &_sTable) const
std::vector< int > sortElements(const std::string &sLine)
This member function wraps the sorting functionality and evaluates the passed parameter string before...
bool isValidElement(long long int _nLine, long long int _nCol, const std::string &_sTable) const
std::vector< mu::value_type > min(const std::string &sTable, std::string sDir) const
int getLines(StringView sTable, bool _bFull=false) const
void shrink(const std::string &_sCache)
bool isTable(const std::string &sTable) const
This member function returns, whether the passed table name corresponds to a known table.
std::string getHeadLineElement(int _i, const std::string &_sTable) const
std::vector< mu::value_type > max(const std::string &sTable, std::string sDir) const
std::vector< mu::value_type > sum(const std::string &sTable, std::string sDir) const
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.
void writeToTable(int _nLine, int _nCol, const std::string &_sCache, const mu::value_type &_dData)
bool setHeadLineElement(int _i, const std::string &_sTable, std::string _sHead)
int getCols(StringView sTable, bool _bFull=false) const
int getColElements(const VectorIndex &cols, const std::string &_sTable) const
Returns the maximal number of elements in the selected column range.
This class implements a Savitzky-Golay filter for differentiation providing a derivative up to degree...
virtual mu::value_type apply(size_t i, size_t j, const mu::value_type &val) const override
Override for the abstract apply method of the base class. Applies the filter to the value at the sele...
virtual bool isStringExpression(const std::string &sExpression) override
Returns true, if the passed expression is an expression containing strings, string variables or strin...
This data container is a copy- efficient table to interchange data between Kernel and GUI.
size_t getCols() const
Get the number of columns.
size_t getLines() const
Get the number of lines.
mu::value_type getValue(size_t i, size_t j) const
Getter function for the value of the selected cell.
This class provides the interface to the core of NumeRe. It provides all functionalities,...
static NumeReKernel * getInstance()
This static member function returns a a pointer to the singleton instance of the kernel.
NumeRe::StringParser & getStringParser()
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...
MemoryManager & getMemoryManager()
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...
FunctionDefinitionManager & getDefinitions()
static void issueWarning(std::string sWarningMessage)
This static function may be used to issue a warning to the user. The warning will be printed by the t...
static bool GetAsyncCancelState()
This function is used by the kernel to get informed, when the user pressed ESC or used other means of...
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...
Common exception class for all exceptions thrown in NumeRe.
@ INVALID_INTEGRATION_RANGES
@ TABLE_DOESNT_EXIST
INSERT HERE.
@ NO_INTEGRATION_FUNCTION
@ INVALID_INTEGRATION_PRECISION
@ ZEROES_VAR_NOT_FOUND
INSERT HERE.
@ STRINGS_MAY_NOT_BE_EVALUATED_WITH_CMD
@ WRONG_PLOT_INTERVAL_FOR_LOGSCALE
@ PROCESS_ABORTED_BY_USER
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(...
void setOpenEndIndex(int nLast) const
This member function can be used to replace the open end state with a defined index value although th...
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...
int min() const
This member function calculates the minimal index value obtained from the values stored internally.
int & front()
This member function returns a reference to the first index value stored internally.
const string_type & GetExpr() const
Retrieve the formula.
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.
Mathematical expressions parser.
value_type Diff(value_type *a_Var, value_type a_fPos, value_type a_fEpsilon=0, size_t order=1)
Numerically differentiate with regard to a variable.
A class for URL exceptions.
virtual const char * what() const noexcept
bool findZeroes(CommandLineParser &cmdParser)
This function is a wrapper to the actual zeros localisation function localizeZero() further below.
void urlExecute(CommandLineParser &cmdParser)
This function implements the url command providing an interface to http(s) and (s)ftp URLs.
static double calculateMedian(value_type *v, int nResults, int start, int nOrder, int nanShiftStart, int &nNewNanShift)
Static helper function for findExtremaInData.
bool writeAudioFile(CommandLineParser &cmdParser)
This function creates a WAVE file from the selected data set.
bool shortTimeFourierAnalysis(CommandLineParser &cmdParser)
This function performs the short-time fourier analysis on the passed data set.
static vector< mu::value_type > integrateSingleDimensionData(CommandLineParser &cmdParser)
This static function integrates single dimension data.
static bool findExtremaInMultiResult(CommandLineParser &cmdParser, string &sExpr, string &sInterval, int nOrder, int nMode)
This static function finds extrema in a multi-result expression, i.e. an expression containing a tabl...
static bool findZeroesInMultiResult(CommandLineParser &cmdParser, string &sExpr, string &sInterval, int nMode)
This static function finds zeroes in a multi-result expression, i.e. an expression containing a table...
bool integrate2d(CommandLineParser &cmdParser)
Calculate the integral of a function in two dimensions.
void rotateTable(CommandLineParser &cmdParser)
This function rotates a table, an image or a datagrid around a specified angle.
static mu::value_type localizeZero(string &sCmd, mu::value_type *dVarAdress, Parser &_parser, const Settings &_option, mu::value_type dLeft, mu::value_type dRight, double dEps=1e-10, int nRecursion=0)
This function searches for the positions of all zeroes (roots), which are located in the selected int...
bool analyzePulse(CommandLineParser &cmdParser)
This function performs a pulse analysis on the selected data set.
static void expandVectorToDatagrid(IntervalSet &ivl, std::vector< std::vector< mu::value_type > > &vZVals, size_t nSamples_x, size_t nSamples_y)
This function will expand the z vector into a z matrix using triangulation.
bool createDatagrid(CommandLineParser &cmdParser)
This function calculates a datagrid from passed functions or (x-y-z) data values.
static void integrationstep_simpson(mu::value_type &x, mu::value_type x0, mu::value_type x1, double dx, vector< mu::value_type > &vResult, vector< mu::value_type > &vFunctionValues, bool bReturnFunctionPoints)
This static function performs an integration step using the Simpson approximation algorithm.
bool readAudioFile(CommandLineParser &cmdParser)
Reads either the audio file meta information or the whole audio file to memory.
bool fastWaveletTransform(CommandLineParser &cmdParser)
This function calculates the fast wavelet transform of the passed data set.
std::string removeQuotationMarks(const std::string &)
This function simply removes the surrounding quotation marks.
DefaultVariables _defVars
static mu::value_type localizeExtremum(string &sCmd, mu::value_type *dVarAdress, Parser &_parser, const Settings &_option, mu::value_type dLeft, mu::value_type dRight, double dEps=1e-10, int nRecursion=0)
This function searches for the positions of all extrema, which are located in the selected interval.
static string getIntervalForSearchFunctions(const string &sParams, string &sVar)
This static function extracts the interval definition for the extrema and root search functions.
static bool findExtremaInData(CommandLineParser &cmdParser, string &sExpr, int nOrder, int nMode)
This static function finds extrema in the selected data sets.
static double interpolateToGrid(const std::vector< double > &vAxis, double dInterpolVal, bool bExtent=false)
This static function is a helper for boneDetection to map/interpolate the calculated values to the fi...
void boneDetection(CommandLineParser &cmdParser)
This function is the implementation of the detect command.
bool differentiate(CommandLineParser &cmdParser)
Calculate the numerical differential of the passed expression or data set.
static std::vector< size_t > getShiftedAxis(size_t nElements, bool inverseTrafo)
Calculates an axis index, which performs the necessary data flips used for the shifted fft axis.
static void calculate2dFFT(MemoryManager &_data, Indices &_idx, const std::string &sTargetTable, mglDataC &_fftData, std::vector< size_t > &vAxis, FFTData &_fft)
This static function calculates a 2D FFT and stores the result in the target table.
static void integrationstep_trapezoidal(mu::value_type &x, mu::value_type x0, mu::value_type dx, vector< mu::value_type > &vResult, vector< mu::value_type > &vFunctionValues, bool bReturnFunctionPoints)
This static function performs an integration step using a trapezoidal approximation algorithm.
bool findExtrema(CommandLineParser &cmdParser)
This function is a wrapper to the actual extrema localisation function localizeExtremum() further bel...
bool seekInAudioFile(CommandLineParser &cmdParser)
Seek a position in an audiofile and extract a length of samples from it.
void taylor(CommandLineParser &cmdParser)
This function approximates the passed expression using Taylor's method.
bool calculateSplines(CommandLineParser &cmdParser)
This function approximates the passed data set using cubic splines.
value_type parser_Random(const value_type &vRandMin, const value_type &vRandMax)
This function returns a uniformly distributed random number between both boundaries.
bool regularizeDataSet(CommandLineParser &cmdParser)
This function regularizes the samples of a defined x-y-data array such that DeltaX is equal for every...
static void calculate1dFFT(MemoryManager &_data, Indices &_idx, const std::string &sTargetTable, mglDataC &_fftData, std::vector< size_t > &vAxis, FFTData &_fft)
This static function calculates a 1D FFT and stores the result in the target table.
bool integrate(CommandLineParser &cmdParser)
Calculate the integral of a function or a data set in a single dimension.
static bool findZeroesInData(CommandLineParser &cmdParser, string &sExpr, int nMode)
This static function finds zeroes in the selected data set.
void particleSwarmOptimizer(CommandLineParser &cmdParser)
This function implements a particle swarm optimizer in up to four dimensions (depending on the number...
bool evalPoints(CommandLineParser &cmdParser)
This function samples a defined expression in an array of discrete values.
static void refreshBoundaries(IntervalSet &ivl, const string &sIntegrationExpression)
This static function re-evaluates the boundary expression and updates the internal variables correspo...
static bool detectPhaseOverflow(std::complex< double > cmplx[3])
This static function is a helper function for fastFourierTransform() and detects phase overflows,...
bool fastFourierTransform(CommandLineParser &cmdParser)
This function calculates the fast fourier transform of the passed data set.
static std::vector< size_t > getSamplesForDatagrid(CommandLineParser &cmdParser, const std::vector< size_t > &nSamples)
This function will obtain the samples of the datagrid for each spatial direction.
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 isNotEmptyExpression(const string &sExpr)
This function checks, whether the passed expression is non-empty (i.e. it contains more than white sp...
Memory * extractRange(const std::string &sCmd, DataAccessParser &_accessParser, int nDesiredCols, bool bSort)
This function extracts a portion of a table and returns it to the calling function....
bool isValidIndexSet(const Indices &_idx)
std::string toSystemCodePage(std::string)
Converts an internal to an external string. Does nothing currently.
size_t findVariableInExpression(const std::string &sExpr, const std::string &sVarName, size_t nPosStart)
This function searches for the selected variable in the passed string and returns the position of the...
unsigned int getMatchingParenthesis(const StringView &)
Returns the position of the closing parenthesis.
std::complex< double > intPower(const std::complex< double > &, int)
This function calculates the power of a value with the specialization that the exponent is an integer...
File * getAudioFileByType(const std::string &sFileName)
Return a audio file type depending on the file extension or a nullptr if the file type is not support...
CONSTCD11 std::enable_if<!std::chrono::treat_as_floating_point< T >::value, T >::type trunc(T t) NOEXCEPT
CONSTCD11 std::chrono::duration< Rep, Period > abs(std::chrono::duration< Rep, Period > d)
CONSTCD14 To ceil(const std::chrono::duration< Rep, Period > &d)
MUP_BASETYPE value_type
The numeric datatype used by the parser.
bool isnan(const value_type &v)
std::vector< double > real(const std::vector< value_type > &vVec)
std::vector< double > imag(const std::vector< value_type > &vVec)
bool isinf(const value_type &v)
value_type rint(value_type v)
size_t put(const std::string &sUrl, const std::string &sFileName, const std::string &sUserName, const std::string &sPassWord)
Upload a file to a destination and return the transmitted bytes.
std::string get(const std::string &sUrl, const std::string &sUserName, const std::string &sPassWord)
Get the contents of a URL.
void convertVectorToExpression(string &sLine, const Settings &_option)
This function replaces vector expressions with their corresponding multi- expression equation.
int integralFactorial(int nNumber)
This function returns the factorial of the passed integral value.
mu::value_type * getPointerToVariable(const string &sVarName, Parser &_parser)
This function returns the pointer to the passed variable.
void StripSpaces(std::string &)
Removes leading and trailing white spaces and tabulator characters.
int findParameter(const std::string &sCmd, const std::string &sParam, const char cFollowing)
This function searches the passed parameter in the passed command string. If something is found,...
Defines a sample in the audio stream, i.e. a single value per channel.
Structure for the four standard variables.
mu::value_type vValue[4][4]
This structure gathers all information needed for calculating a FFT in one or two dimensions.
double dNyquistFrequency[2]
This structure is central for managing the indices of a table or cluster read or write data access....
This class represents a set of intervals used together for calculations and simulations.
size_t size() const
Return the number of intervals.
std::vector< Interval > intervals
This represents a point in 2D space.
void rotate(double dAlpha, const Point &origin=Point(0, 0))
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.
void calculateWavelet(std::vector< double > &data, WaveletType _type, int k, int dir)
NumeRe::Table decodeWaveletData(const std::vector< double > &vWaveletData, const std::vector< double > &vAxisData)