19#include <gsl/gsl_statistics.h>
22#include "../ui/error.hpp"
77 for (
size_t i = 0; i < vVals.size(); i++)
102 for (
size_t i = 0; i < vStrings.size(); i++)
128 for (
size_t i = 0; i < _idx.
row.
size(); i++)
130 if (nNum > 1 && (
size_t)nNum <= i)
236 for (
int i = 0; i <= i2-i1; i++)
380 nBytes +=
sizeof(
char) * (
vClusterArray[i]->getParserString().length()-2);
590 std::vector<mu::value_type> vArray;
614 if (vTarget ==
nullptr)
620 vTarget->resize(1, NAN);
623 vTarget->resize(_vLine.
size(), NAN);
626 for (
unsigned int i = 0; i < _vLine.
size(); i++)
654 for (
size_t i = 0; i < vVals.size(); i++)
689 for (
int i = 0; i < nNum; i++)
830 std::vector<std::string> vArray;
850 std::vector<std::string> vArray;
877 for (
size_t i = 0; i < sVals.size(); i++)
935 std::string sVector =
"{";
937 std::vector<std::string> vString =
to_string();
940 for (
const auto& component : vString)
942 sVector += component +
",";
946 sVector.back() =
'}';
969 std::string sVector =
"{";
978 else if (maxStringLength < std::string::npos)
992 sVector.back() =
'}';
1012 return std::vector<int>();
1014 bool bReturnIndex =
false;
1017 std::vector<int> vIndex;
1027 bReturnIndex =
true;
1034 for (
int i = i1; i <= i2; i++)
1035 vIndex.push_back(i);
1038 if (!
qSort(&vIndex[0], i2-i1+1, 0, 0, i2-i1, nSign))
1052 for (
int i = 0; i <= i2-i1; i++)
1057 return std::vector<int>();
1087 for (
long long int i = i1; i < i2; i++)
1120 for (
size_t i = 0; i < vLines.
size(); i++)
1122 if (vLines[i] < 0 || vLines[i] >= (
int)
vClusterArray.size())
1168 unsigned int nInvalid = 0;
1171 for (
unsigned int i = 0; i < _vLine.
size(); i++)
1173 if (_vLine[i] < 0 || _vLine[i] >= (
int)
vClusterArray.size())
1181 if (nInvalid >= _vLine.
size() - 1)
1184 return std::sqrt(dStd / ((_vLine.
size()) - 1 - (
double)nInvalid));
1204 unsigned int nInvalid = 0;
1207 for (
unsigned int i = 0; i < _vLine.
size(); i++)
1209 if (_vLine[i] < 0 || _vLine[i] >= (
int)
vClusterArray.size())
1217 if (nInvalid >= _vLine.
size())
1220 return dAvg / (_vLine.
size() - (double)nInvalid);
1242 for (
unsigned int i = 0; i < _vLine.
size(); i++)
1244 if (_vLine[i] < 0 || _vLine[i] >= (
int)
vClusterArray.size())
1276 std::string sMax =
"";
1280 for (
unsigned int i = 0; i < _vLine.
size(); i++)
1282 if (_vLine[i] < 0 || _vLine[i] >= (
int)
vClusterArray.size())
1314 for (
unsigned int i = 0; i < _vLine.
size(); i++)
1316 if (_vLine[i] < 0 || _vLine[i] >= (
int)
vClusterArray.size())
1348 std::string sMin =
"";
1352 for (
unsigned int i = 0; i < _vLine.
size(); i++)
1354 if (_vLine[i] < 0 || _vLine[i] >= (
int)
vClusterArray.size())
1386 for (
unsigned int i = 0; i < _vLine.
size(); i++)
1388 if (_vLine[i] < 0 || _vLine[i] >= (
int)
vClusterArray.size())
1419 for (
unsigned int i = 0; i < _vLine.
size(); i++)
1421 if (_vLine[i] < 0 || _vLine[i] >= (
int)
vClusterArray.size())
1449 std::string sSum =
"";
1453 for (
unsigned int i = 0; i < _vLine.
size(); i++)
1455 if (_vLine[i] < 0 || _vLine[i] >= (
int)
vClusterArray.size())
1483 for (
unsigned int i = 0; i < _vLine.
size(); i++)
1485 if (_vLine[i] < 0 || _vLine[i] >= (
int)
vClusterArray.size())
1493 return _vLine.
size() - (double)nInvalid;
1511 double dRetVal = NAN;
1514 for (
unsigned int i = 0; i < _vLine.
size(); i++)
1516 if (_vLine[i] < 0 || _vLine[i] >= (
int)
vClusterArray.size())
1548 for (
unsigned int i = 0; i < _vLine.
size(); i++)
1550 if (_vLine[i] < 0 || _vLine[i] >= (
int)
vClusterArray.size())
1577 bool isTrue =
false;
1580 for (
unsigned int i = 0; i < _vLine.
size(); i++)
1582 if (_vLine[i] < 0 || _vLine[i] >= (
int)
vClusterArray.size())
1620 for (
unsigned int i = 0; i < _vLine.
size(); i++)
1622 if (_vLine[i] < 0 || _vLine[i] >= (
int)
vClusterArray.size())
1625 return _vLine.
size() - (double)nInvalid;
1647 for (
unsigned int i = 0; i < _vLine.
size(); i++)
1649 if (_vLine[i] < 0 || _vLine[i] >= (
int)
vClusterArray.size())
1658 return std::sqrt(dNorm);
1695 else if (_nType < 0)
1698 switch (
intCast(fabs(_nType)))
1701 nType |= RETURN_VALUE;
1704 nType |= RETURN_FIRST;
1707 nType |= RETURN_FIRST | RETURN_VALUE;
1712 for (
long long int i = 0; i < _vLine.
size(); i++)
1714 if (_vLine[i] < 0 || _vLine[i] >= (
int)
vClusterArray.size())
1722 if (nType & RETURN_VALUE)
1725 return _vLine[i] + 1;
1729 if (nType & RETURN_FIRST)
1731 if (nType & RETURN_VALUE)
1747 if (nType & RETURN_FIRST)
1749 if (nType & RETURN_VALUE)
1767 else if (nType & RETURN_VALUE)
1790 unsigned int nInvalid = 0;
1791 unsigned int nCount = 0;
1795 for (
unsigned int i = 0; i < _vLine.
size(); i++)
1797 if (_vLine[i] < 0 || _vLine[i] >= (
int)
vClusterArray.size())
1803 if (nInvalid >= _vLine.
size())
1807 dData =
new double[_vLine.
size() - nInvalid];
1810 for (
unsigned int i = 0; i < _vLine.
size(); i++)
1815 dData[nCount] =
vClusterArray[_vLine[i]]->getDouble().real();
1818 if (nCount == _vLine.
size() - nInvalid)
1832 dMed = gsl_stats_median_from_sorted_data(dData, 1, nCount);
1856 unsigned int nInvalid = 0;
1857 unsigned int nCount = 0;
1860 if (dPct.real() >= 1 || dPct.real() <= 0)
1864 for (
unsigned int i = 0; i < _vLine.
size(); i++)
1866 if (_vLine[i] < 0 || _vLine[i] >= (
int)
vClusterArray.size())
1872 if (nInvalid >= _vLine.
size())
1876 dData =
new double[_vLine.
size() - nInvalid];
1879 for (
unsigned int i = 0; i < _vLine.
size(); i++)
1884 dData[nCount] =
vClusterArray[_vLine[i]]->getDouble().real();
1887 if (nCount == _vLine.
size() - nInvalid)
1901 dPct = gsl_stats_quantile_from_sorted_data(dData, 1, nCount, dPct.real());
1926 std::string sClusterName = sCluster.substr(0, sCluster.find(
'{'));
1927 const static std::string sVALIDCHARACTERS =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_~";
1929 if ((sClusterName[0] >=
'0' && sClusterName[0] <=
'9') || sClusterName[0] ==
'~' || sClusterName.find_first_not_of(sVALIDCHARACTERS) != std::string::npos)
1932 return sClusterName;
1949 if (view == iter->first)
1951 else if (view < iter->first)
1971 if (view == iter->first)
1973 else if (view < iter->first)
1993 if (sCmdLine.find(
'{') == std::string::npos)
1997 for (
size_t i = 0; i < sCmdLine.length(); i++)
2000 if (sCmdLine[i] ==
'"' && (!i || sCmdLine[i-1] !=
'\\'))
2009 if (isalpha(sCmdLine[i]) || sCmdLine[i] ==
'_' || sCmdLine[i] ==
'~')
2011 size_t nStartPos = i;
2017 while (isalnum(sCmdLine[i]) || sCmdLine[i] ==
'_' || sCmdLine[i] ==
'~' || sCmdLine[i] ==
'[' || sCmdLine[i] ==
']');
2019 if (sCmdLine[i] ==
'{')
2084 return iter->second;
2099 auto iter =
mClusterMap.find(sCluster.substr(0, sCluster.find(
'{')));
2104 return iter->second;
2121 auto iter =
mClusterMap.find(sCluster.substr(0, sCluster.find(
'{')));
2126 return iter->second;
2193 std::string sTemporaryClusterName =
"_~~TC_" +
toString(
mClusterMap.size()) +
"_" + suffix;
2196 return sTemporaryClusterName +
"{}";
2215 if (iter->first.substr(0, 6) ==
"_~~TC_")
std::string toLowerCase(const std::string &)
Converts uppercase to lowercase letters.
This is a cluster item, which contains a double. It features conversions to and from strings on-the-f...
This class represents a whole cluster. The single items are stored as pointers to the abstract cluste...
void setStringArray(const std::vector< std::string > &sVals)
This member function assigns values as data for the all cluster items in memory. The type of the clus...
bool isString() const
This member function returns, whether the data in the cluster have only string as type.
bool bSortCaseInsensitive
size_t size() const
This member function returns the size of the internal memory buffer as items.
void clear()
This member function clears the internal memory buffer and frees the associated memory.
std::string getParserString(size_t i) const
This member function returns the data of the i-th cluster item in memory as a parser string.
std::string getString(size_t i) const
This member function returns the data of the i-th cluster item in memory as a string.
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...
void push_back(ClusterItem *item)
This member function appends an arbitrary cluster item at the back of the internal cluster array buff...
mu::value_type med(const VectorIndex &_vLine)
This member function calculates the median value of the data in memory. Cluster items,...
void setString(size_t i, const std::string &strval)
This member function assigns a string as data for the i-th cluster item in memory....
void assignVectorResults(Indices _idx, int nNum, mu::value_type *data)
Private result assignment function for values using vectors as indices.
mu::value_type min(const VectorIndex &_vLine)
This member function calculates the minimal value of the data in memory. Cluster items,...
void assignResults(Indices _idx, int nNum, mu::value_type *data)
This member function assigns calculation results as data for the cluster items in memory,...
std::vector< std::string > getInternalStringArray() const
This member function returns the data of all cluster items memory as a value vector.
mu::value_type cnt(const VectorIndex &_vLine)
This member function counts the number of valid cluster items in memory. Cluster items of any type ar...
std::vector< ClusterItem * > vClusterArray
std::vector< std::string > to_string() const
Converts all contents of this cluster to a vector of strings. Intended to be used for data transfer.
mu::value_type and_func(const VectorIndex &_vLine)
This member function applies an "AND" to the data in memory. Cluster items, which do not have the typ...
mu::value_type num(const VectorIndex &_vLine)
This member function counts the number of valid cluster items in memory. Cluster items of any type ar...
mu::value_type xor_func(const VectorIndex &_vLine)
This member function applies an "exclusive OR" to the data in memory. Cluster items,...
mu::value_type avg(const VectorIndex &_vLine)
This member function calculates the average of the data in memory. Cluster items, which do not have t...
void setDoubleArray(const std::vector< mu::value_type > &vVals)
This member function assigns values as data for the all cluster items in memory. The type of the clus...
void insertDataInArray(std::vector< mu::value_type > *vTarget, const VectorIndex &_vLine)
This member function inserts the data of all cluster items memory into the pointer passed to the func...
std::string getVectorRepresentation() const
This member function constructs a plain vector from the data in memory, which can be inserted in the ...
mu::value_type max(const VectorIndex &_vLine)
This member function calculates the maximal value of the data in memory. Cluster items,...
mu::value_type getDouble(size_t i) const
This member function returns the data of the i-th cluster item in memory as a value.
bool isMixed() const
This member function returns, whether the data in the cluster have mixed type.
void reduceSize(size_t z)
Reduces the size of this cluster to the specified number of elements. Does not create anything,...
virtual bool isValue(int line, int col) override
This private member function is an override for the sorter object.
mu::value_type std(const VectorIndex &_vLine)
This member function calculates the standard deviation of the data in memory. Cluster items,...
mu::value_type pct(const VectorIndex &_vLine, mu::value_type dPct)
This member function calculates the p-th percentile of the data in memory. Cluster items,...
void assign(const Cluster &cluster)
Private cluster copy assignment function.
std::vector< int > sortElements(long long int i1, long long int i2, const std::string &sSortingExpression)
This public member function provides access to the sorting algorithm for the cluster object.
std::string getInternalString(size_t i) const
This member function returns the data of the i-th cluster item in memory as a string.
mu::value_type or_func(const VectorIndex &_vLine)
This member function applies an "OR" to the data in memory. Cluster items, which do not have the type...
mu::value_type norm(const VectorIndex &_vLine)
This member function calculates the euclidic vector norm of the data in memory. Cluster items,...
std::string strsum(const VectorIndex &_vLine)
This member function calculates the string concatenation of the data in memory. Cluster items of all ...
void reorderElements(std::vector< int > vIndex, int i1, int i2)
This private member function reorders the elements in the cluster based upon the passed index vector.
virtual int compare(int i, int j, int col) override
This private member function is an override for the sorter object.
mu::value_type cmp(const VectorIndex &_vLine, mu::value_type dRef, int _nType)
This member function compares the values in memory with the referenced value and returns indices or v...
mu::value_type sum(const VectorIndex &_vLine)
This member function calculates the sum of the data in memory. Cluster items, which do not have the t...
std::vector< mu::value_type > getDoubleArray() const
This member function returns the data of all cluster items memory as a value vector.
void pop_back()
This member function removes the last item in the internal memory buffer and frees the associated mem...
mu::value_type prd(const VectorIndex &_vLine)
This member function calculates the product of the data in memory. Cluster items, which do not have t...
size_t getBytes() const
This member function returns the size of the associated memory as bytes.
std::string strmin(const VectorIndex &_vLine)
This member function calculates the minimal string value of the data in memory. Cluster items of all ...
std::string getShortVectorRepresentation(size_t maxStringLength) const
This member function constructs a short version of a plain vector from the data in memory,...
bool isDouble() const
This member function returns, whether the data in the cluster have only double as type.
unsigned short getType(size_t i) const
This member function returns the type of the i-th cluster item in the internal memory buffer.
std::string strmax(const VectorIndex &_vLine)
This member function calculates the maximal string value of the data in memory. Cluster items of all ...
std::vector< std::string > getStringArray() const
This member function returns the data of all cluster items memory as a value vector.
void deleteItems(long long int i1, long long int i2)
This public member function erases elements located from the index i1 to i2.
This is an abstract cluster item. It is used as root class of any cluster items and only contains the...
unsigned short getType() const
Returns the ClusterItemType.
bool containsClusters(const std::string &sCmdLine) const
This member function detects, whether any cluster is used in the current expression.
void appendCluster(const std::string &sCluster, const Cluster &cluster)
This member function appends the passed cluster to the internal cluster map using the passed string a...
void removeTemporaryClusters()
This member function returns all temporary clusters from the internal map. Temporary clusters are ind...
mu::value_type dClusterElementsCount
void removeCluster(const std::string &sCluster)
This member function removes the cluster from memory, which corresponds to the passed cluster identif...
Cluster & getCluster(StringView sCluster)
This member function returns a reference to the cluster indicated by the passed cluster identifier.
bool updateClusterSizeVariables(StringView sCluster)
This member function updates the dimension variable reserved for cluster accesses with the size of th...
Cluster & newCluster(const std::string &sCluster)
This member function creates a new cluster from the passed cluster identifier and returns a reference...
std::map< std::string, Cluster > mClusterMap
bool isCluster(StringView sCluster) const
This member function returns true, if the passed cluster identifier can be found in the internal map.
std::string validateClusterName(const std::string &sCluster)
This member function creates a valid cluster identifier name, which can be used to create or append a...
std::map< std::string, Cluster >::iterator mapStringViewFind(StringView view)
This private member function returns an iterator to the referenced cluster or std::map::end().
std::string createTemporaryCluster(const std::string &suffix="")
This member function creates a temporary cluster with a unique name and returns this name to the call...
void clearAllClusters()
Clear all clusters currently in memory.
This is a cluster item, which contains a string. It features conversions to and from doubles on-the-f...
bool qSort(int *nIndex, int nElements, int nColumn, long long int nLeft, long long int nRight, int nSign)
This public member function is the interface to the quicksort algorithm, which itself is implemented ...
std::string to_string() const
This member function returns a copy of the viewed section of the string (via std::string::substr)....
size_t find(const std::string &findstr, size_t pos=0) const
Wrapper member function for std::string::find()
This class is the immutable (const) version of a string view. It can be constructed from a MutableStr...
StringView subview(size_t pos=0, size_t len=std::string::npos) const
This member function creates a new StringView class instance using the selected position and length a...
Common exception class for all exceptions thrown in NumeRe.
static size_t invalid_position
This class abstracts all the index logics, i.e. the logical differences between single indices and in...
void setOpenEndIndex(int nLast) const
This member function can be used to replace the open end state with a defined index value although th...
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.
int & front()
This member function returns a reference to the first index value stored internally.
CONSTCD11 std::chrono::duration< Rep, Period > abs(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)
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,...
This structure is central for managing the indices of a table or cluster read or write data access....
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.