NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
cluster.cpp
Go to the documentation of this file.
1/*****************************************************************************
2 NumeRe: Framework fuer Numerische Rechnungen
3 Copyright (C) 2019 Erik Haenel et al.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17******************************************************************************/
18
19#include <gsl/gsl_statistics.h>
20
21#include "cluster.hpp"
22#include "../ui/error.hpp"
23
24namespace NumeRe
25{
26 //
27 // class CLUSTER
28 //
29 //
30
39 void Cluster::assign(const Cluster& cluster)
40 {
42
43 // Clear the contents first
44 clear();
45
46 nGlobalType = cluster.nGlobalType;
47
48 // Fill the cluster with copies from the passed cluster
49 for (size_t i = 0; i < cluster.vClusterArray.size(); i++)
50 {
51 if (cluster.vClusterArray[i]->getType() == ClusterItem::ITEMTYPE_DOUBLE)
52 vClusterArray.push_back(new ClusterDoubleItem(cluster.vClusterArray[i]->getDouble()));
53 else
54 vClusterArray.push_back(new ClusterStringItem(cluster.vClusterArray[i]->getInternalString()));
55 }
56 }
57
58
67 void Cluster::assign(const std::vector<mu::value_type>& vVals)
68 {
70
71 // clear the contents first
72 clear();
73
75
76 // Fill the cluster with new double items
77 for (size_t i = 0; i < vVals.size(); i++)
78 {
79 vClusterArray.push_back(new ClusterDoubleItem(vVals[i]));
80 }
81 }
82
83
92 void Cluster::assign(const std::vector<std::string>& vStrings)
93 {
95
96 // Clear the contents first
97 clear();
98
100
101 // Fill the cluster with new string items
102 for (size_t i = 0; i < vStrings.size(); i++)
103 {
104 vClusterArray.push_back(new ClusterStringItem(vStrings[i]));
105 }
106 }
107
108
120 {
123
124 if (nNum == 1)
125 _idx.row.setOpenEndIndex(std::max((size_t)_idx.row.front(), size()) - 1);
126
127 // Assign the single results
128 for (size_t i = 0; i < _idx.row.size(); i++)
129 {
130 if (nNum > 1 && (size_t)nNum <= i)
131 return;
132
133 // Expand the current cluster on-the-fly
134 while (_idx.row[i] >= (int)vClusterArray.size())
136
137 // Assign the value and expand singletons
138 if (vClusterArray[_idx.row[i]]->getType() != ClusterItem::ITEMTYPE_DOUBLE)
139 {
140 // Re-create the current item as double
141 delete vClusterArray[_idx.row[i]];
142 vClusterArray[_idx.row[i]] = new ClusterDoubleItem(nNum == 1 ? data[0] : data[i]);
143 }
144 else
145 vClusterArray[_idx.row[i]]->setDouble(nNum == 1 ? data[0] : data[i]);
146 }
147 }
148
149
160 int Cluster::compare(int i, int j, int col)
161 {
162 if (isString() || isMixed())
163 {
165 {
167 return -1;
168
170 return 0;
171 }
172 else
173 {
175 return -1;
176
178 return 0;
179 }
180
181 return 1;
182 }
183 else if (isDouble())
184 {
186 return -1;
187
189 return 0;
190
191 return 1;
192 }
193
194 return 0;
195 }
196
197
207 bool Cluster::isValue(int line, int col)
208 {
210 return true;
211
213 return true;
214
215 return false;
216 }
217
218
230 void Cluster::reorderElements(std::vector<int> vIndex, int i1, int i2)
231 {
232 std::vector<ClusterItem*> vSortVector = vClusterArray;
233
234 // Copy the contents directly from the
235 // prepared in the new order
236 for (int i = 0; i <= i2-i1; i++)
237 {
238 vClusterArray[i+i1] = vSortVector[vIndex[i]];
239 }
240 }
241
242
253 void Cluster::reduceSize(size_t s)
254 {
255 if (vClusterArray.size() <= s)
256 return;
257
258 for (size_t i = s; i < vClusterArray.size(); i++)
259 delete vClusterArray[i];
260
261 vClusterArray.resize(s);
262 }
263
264
275 {
276 if (item)
277 vClusterArray.push_back(item);
278
280 return;
281
282 if (item->getType() != nGlobalType)
284 }
285
286
297 {
298 vClusterArray.push_back(new ClusterDoubleItem(val));
299
301 return;
302
305 }
306
307
317 void Cluster::push_back(const std::string& strval)
318 {
319 vClusterArray.push_back(new ClusterStringItem(strval));
320
322 return;
323
326 }
327
328
338 {
339 if (vClusterArray.size())
340 {
341 delete vClusterArray.back();
342 vClusterArray.pop_back();
343
345 }
346 }
347
348
356 size_t Cluster::size() const
357 {
358 return vClusterArray.size();
359 }
360
361
369 size_t Cluster::getBytes() const
370 {
371 size_t nBytes = 0;
372
373 // Go through the internal cluster array and calculate
374 // the bytes needed for each single cluster item
375 for (size_t i = 0; i < vClusterArray.size(); i++)
376 {
378 nBytes += sizeof(mu::value_type);
380 nBytes += sizeof(char) * (vClusterArray[i]->getParserString().length()-2);
381 }
382
383 return nBytes;
384 }
385
386
396 {
397 for (size_t i = 0; i < vClusterArray.size(); i++)
398 {
399 delete vClusterArray[i];
400 }
401
402 vClusterArray.clear();
404 }
405
406
414 bool Cluster::isMixed() const
415 {
416 // Only do something, if the array has a length
417 if (vClusterArray.size())
418 {
421
422 // Store the first type
423 int nFirstType = vClusterArray[0]->getType();
424
425 for (size_t i = 1; i < vClusterArray.size(); i++)
426 {
427 // Is there any item with a different type?
428 if (vClusterArray[i]->getType() != nFirstType)
429 {
431 return true;
432 }
433 }
434
435 nGlobalType = nFirstType;
436 return false;
437 }
438
439 return false;
440 }
441
442
451 bool Cluster::isDouble() const
452 {
453 // Only do something, if the array has a length
454 if (vClusterArray.size())
455 {
458
459 for (size_t i = 0; i < vClusterArray.size(); i++)
460 {
461 // Is there any item, which is NOT a double?
463 {
464 if (i)
466
467 return false;
468 }
469 }
470
472 return true;
473 }
474
475 return false;
476 }
477
478
487 bool Cluster::isString() const
488 {
489 // Only do something, if the array has a length
490 if (vClusterArray.size())
491 {
494
495 for (size_t i = 0; i < vClusterArray.size(); i++)
496 {
497 // Is there any item, which is NOT a string?
499 {
500 if (i)
502
503 return false;
504 }
505 }
506
508 return true;
509 }
510
511 return false;
512 }
513
514
524 unsigned short Cluster::getType(size_t i) const
525 {
526 if (vClusterArray.size() > i)
527 return vClusterArray[i]->getType();
528
530 }
531
532
542 {
543 if (vClusterArray.size() > i)
544 return vClusterArray[i]->getDouble();
545
546 return NAN;
547 }
548
549
561 void Cluster::setDouble(size_t i, const mu::value_type& value)
562 {
563 // Create new items if needed
564 while (vClusterArray.size() <= i)
566
567 // Assign the data
569 {
570 // Re-create the item as double item
571 delete vClusterArray[i];
572 vClusterArray[i] = new ClusterDoubleItem(value);
573 }
574 else
575 vClusterArray[i]->setDouble(value);
576
578 }
579
580
588 std::vector<mu::value_type> Cluster::getDoubleArray() const
589 {
590 std::vector<mu::value_type> vArray;
591
592 for (size_t i = 0; i < vClusterArray.size(); i++)
593 {
594 vArray.push_back(vClusterArray[i]->getDouble());
595 }
596
597 return vArray;
598 }
599
600
612 void Cluster::insertDataInArray(std::vector<mu::value_type>* vTarget, const VectorIndex& _vLine)
613 {
614 if (vTarget == nullptr)
615 return;
616
617 // Try to resize the array as copy-efficient as
618 // possible
619 if (_vLine.size() > 1 && !vClusterArray.size())
620 vTarget->resize(1, NAN);
621 else
622 {
623 vTarget->resize(_vLine.size(), NAN);
624
625 // Insert the elements in the passed array
626 for (unsigned int i = 0; i < _vLine.size(); i++)
627 {
628 if (_vLine[i] >= (int)vClusterArray.size() || _vLine[i] < 0)
629 (*vTarget)[i] = NAN;
630 else
631 (*vTarget)[i] = vClusterArray[_vLine[i]]->getDouble();
632
633 }
634 }
635 }
636
637
648 void Cluster::setDoubleArray(const std::vector<mu::value_type>& vVals)
649 {
650 // Create new cluster items, if needed
651 while (vClusterArray.size() < vVals.size())
653
654 for (size_t i = 0; i < vVals.size(); i++)
655 {
656 // Assign the value
658 {
659 // Re-create the current item as double
660 delete vClusterArray[i];
661 vClusterArray[i] = new ClusterDoubleItem(vVals[i]);
662 }
663 else
664 static_cast<ClusterDoubleItem*>(vClusterArray[i])->setDouble(vVals[i]);
665 }
666
667 reduceSize(vVals.size());
669 }
670
671
684 {
685 // Create new cluster items, if needed
686 while (vClusterArray.size() < (size_t)nNum)
688
689 for (int i = 0; i < nNum; i++)
690 {
691 // Assign the value
693 {
694 // Re-create the current item as double
695 delete vClusterArray[i];
696 vClusterArray[i] = new ClusterDoubleItem(data[i]);
697 }
698 else
699 static_cast<ClusterDoubleItem*>(vClusterArray[i])->setDouble(data[i]);
700 }
701
702 reduceSize(nNum);
704 }
705
706
721 {
722 // If the indices indicate a complete override
723 // do that here and return
724 if (_idx.row.isOpenEnd() && _idx.row.front() == 0)
725 {
726 setDoubleArray(nNum, data);
727 return;
728 }
729
730 // Assign the results depending on the type of the
731 // passed indices
732 assignVectorResults(_idx, nNum, data);
733 }
734
735
745 std::string Cluster::getString(size_t i) const
746 {
747 if (vClusterArray.size() > i)
748 return vClusterArray[i]->getString();
749
750 return "\"\"";
751 }
752
753
763 std::string Cluster::getInternalString(size_t i) const
764 {
765 if (vClusterArray.size() > i)
766 return vClusterArray[i]->getInternalString();
767
768 return "";
769 }
770
771
781 std::string Cluster::getParserString(size_t i) const
782 {
783 if (vClusterArray.size() > i)
784 return vClusterArray[i]->getParserString();
785
786 return "\"\"";
787 }
788
789
801 void Cluster::setString(size_t i, const std::string& strval)
802 {
803 // Create new cluster items, if needed
804 while (vClusterArray.size() <= i)
806
807 // Assign the value
809 {
810 // Re-create the current item as a string
811 delete vClusterArray[i];
812 vClusterArray[i] = new ClusterStringItem(strval);
813 }
814 else
815 vClusterArray[i]->setString(strval);
816
818 }
819
820
828 std::vector<std::string> Cluster::getStringArray() const
829 {
830 std::vector<std::string> vArray;
831
832 for (size_t i = 0; i < vClusterArray.size(); i++)
833 {
834 vArray.push_back(vClusterArray[i]->getParserString());
835 }
836
837 return vArray;
838 }
839
840
848 std::vector<std::string> Cluster::getInternalStringArray() const
849 {
850 std::vector<std::string> vArray;
851
852 for (size_t i = 0; i < vClusterArray.size(); i++)
853 {
854 vArray.push_back(vClusterArray[i]->getInternalString());
855 }
856
857 return vArray;
858 }
859
860
871 void Cluster::setStringArray(const std::vector<std::string>& sVals)
872 {
873 // Create new cluster items, if needed
874 while (vClusterArray.size() < sVals.size())
876
877 for (size_t i = 0; i < sVals.size(); i++)
878 {
879 // Assign the value
881 {
882 // Re-create the current item as a string
883 delete vClusterArray[i];
884 vClusterArray[i] = new ClusterStringItem(sVals[i]);
885 }
886 else
887 vClusterArray[i]->setString(sVals[i]);
888 }
889
890 reduceSize(sVals.size());
892 }
893
894
903 std::vector<std::string> Cluster::to_string() const
904 {
905 std::vector<std::string> vString(vClusterArray.size());
906
907 // Append the contained data depending on its type
908 for (size_t i = 0; i < vClusterArray.size(); i++)
909 {
911 vString[i] = toCmdString(vClusterArray[i]->getDouble());
912 else
913 vString[i] = vClusterArray[i]->getParserString();
914 }
915
916 return vString;
917 }
918
919
930 {
931 // Return nan, if no data is available
932 if (!vClusterArray.size())
933 return "nan";
934
935 std::string sVector = "{";
936
937 std::vector<std::string> vString = to_string();
938
939 // Append the contained data depending on its type
940 for (const auto& component : vString)
941 {
942 sVector += component + ",";
943 }
944
945 // Replace the last comma with a closing brace
946 sVector.back() = '}';
947
948 return sVector;
949 }
950
951
962 std::string Cluster::getShortVectorRepresentation(size_t maxStringLength) const
963 {
964 // Return an empty brace pair, if no data is
965 // available
966 if (!vClusterArray.size())
967 return "{}";
968
969 std::string sVector = "{";
970
971 // Append the contained data depending on its type but
972 // restrict the number to maximal five values (use the first
973 // and the last ones) and insert an ellipsis in the middle
974 for (size_t i = 0; i < vClusterArray.size(); i++)
975 {
977 sVector += toString(vClusterArray[i]->getDouble(), 5) + ", ";
978 else if (maxStringLength < std::string::npos)
979 sVector += ellipsize(vClusterArray[i]->getString(), maxStringLength/4) + ", ";
980 else
981 sVector += vClusterArray[i]->getString() + ", ";
982
983 // Insert the ellipsis in the middle
984 if (i == 1 && vClusterArray.size() > 5)
985 {
986 sVector += "..., ";
987 i = vClusterArray.size()-3;
988 }
989 }
990
991 sVector.pop_back();
992 sVector.back() = '}';
993
994 return sVector;
995 }
996
997
1009 std::vector<int> Cluster::sortElements(long long int i1, long long int i2, const std::string& sSortingExpression)
1010 {
1011 if (!vClusterArray.size())
1012 return std::vector<int>();
1013
1014 bool bReturnIndex = false;
1015 bSortCaseInsensitive = false;
1016 int nSign = 1;
1017 std::vector<int> vIndex;
1018
1019 // Look for command line parameters
1020 if (findParameter(sSortingExpression, "desc"))
1021 nSign = -1;
1022
1023 if (findParameter(sSortingExpression, "ignorecase"))
1024 bSortCaseInsensitive = true;
1025
1026 if (findParameter(sSortingExpression, "index"))
1027 bReturnIndex = true;
1028
1029 // Prepare the indices
1030 if (i2 == -1)
1031 i2 = i1;
1032
1033 // Create the sorting index
1034 for (int i = i1; i <= i2; i++)
1035 vIndex.push_back(i);
1036
1037 // Sort everything
1038 if (!qSort(&vIndex[0], i2-i1+1, 0, 0, i2-i1, nSign))
1039 {
1040 throw SyntaxError(SyntaxError::CANNOT_SORT_DATA, "cluster{} " + sSortingExpression, SyntaxError::invalid_position);
1041 }
1042
1043 // If the sorting index is requested,
1044 // then only sort the first column and return
1045 if (!bReturnIndex)
1046 {
1047 reorderElements(vIndex, i1, i2);
1048 }
1049 else
1050 {
1051 // If the index was requested, increment every index by one
1052 for (int i = 0; i <= i2-i1; i++)
1053 vIndex[i]++;
1054 }
1055
1056 if (!bReturnIndex)
1057 return std::vector<int>();
1058
1059 return vIndex;
1060 }
1061
1062
1072 void Cluster::deleteItems(long long int i1, long long int i2)
1073 {
1074 if (i2 >= vClusterArray.size())
1075 i2 = vClusterArray.size()-1;
1076
1077 // If everything shall be erased, use the
1078 // "clear()" function
1079 if (!i1 && i2+1 == vClusterArray.size())
1080 {
1081 clear();
1082 return;
1083 }
1084
1085 // Delete the cluster items first and
1086 // set the pointer to a nullpointer
1087 for (long long int i = i1; i < i2; i++)
1088 {
1089 delete vClusterArray[i];
1090 vClusterArray[i] = nullptr;
1091 }
1092
1093 auto iter = vClusterArray.begin();
1094
1095 // Remove all nullpointers from the array
1096 while (iter != vClusterArray.end())
1097 {
1098 if (!(*iter))
1099 iter = vClusterArray.erase(iter);
1100 else
1101 ++iter;
1102 }
1103
1105 }
1106
1107
1117 {
1118 // Delete the cluster items first and
1119 // set the pointer to a nullpointer
1120 for (size_t i = 0; i < vLines.size(); i++)
1121 {
1122 if (vLines[i] < 0 || vLines[i] >= (int)vClusterArray.size())
1123 continue;
1124
1125 if (vClusterArray[vLines[i]])
1126 delete vClusterArray[vLines[i]];
1127
1128 vClusterArray[vLines[i]] = nullptr;
1129 }
1130
1131 auto iter = vClusterArray.begin();
1132
1133 // Remove all nullpointers from the array
1134 while (iter != vClusterArray.end())
1135 {
1136 if (!(*iter))
1137 iter = vClusterArray.erase(iter);
1138 else
1139 ++iter;
1140 }
1141
1143 }
1144
1145
1146 //
1147 // Statistic functions section
1148 //
1149
1161 {
1162 if (!vClusterArray.size())
1163 return NAN;
1164
1165 // Calculate the average of the referenced items
1166 mu::value_type dAvg = avg(_vLine);
1167 mu::value_type dStd = 0.0;
1168 unsigned int nInvalid = 0;
1169
1170 // Apply the operation and ignore invalid or non-double items
1171 for (unsigned int i = 0; i < _vLine.size(); i++)
1172 {
1173 if (_vLine[i] < 0 || _vLine[i] >= (int)vClusterArray.size())
1174 nInvalid++;
1176 nInvalid++;
1177 else
1178 dStd += (dAvg - vClusterArray[_vLine[i]]->getDouble()) * conj(dAvg - vClusterArray[_vLine[i]]->getDouble());
1179 }
1180
1181 if (nInvalid >= _vLine.size() - 1)
1182 return NAN;
1183
1184 return std::sqrt(dStd / ((_vLine.size()) - 1 - (double)nInvalid));
1185 }
1186
1187
1199 {
1200 if (!vClusterArray.size())
1201 return NAN;
1202
1203 mu::value_type dAvg = 0.0;
1204 unsigned int nInvalid = 0;
1205
1206 // Apply the operation and ignore invalid or non-double items
1207 for (unsigned int i = 0; i < _vLine.size(); i++)
1208 {
1209 if (_vLine[i] < 0 || _vLine[i] >= (int)vClusterArray.size())
1210 nInvalid++;
1212 nInvalid++;
1213 else
1214 dAvg += vClusterArray[_vLine[i]]->getDouble();
1215 }
1216
1217 if (nInvalid >= _vLine.size())
1218 return NAN;
1219
1220 return dAvg / (_vLine.size() - (double)nInvalid);
1221 }
1222
1223
1235 {
1236 if (!vClusterArray.size() || isString())
1237 return NAN;
1238
1239 double dMax = NAN;
1240
1241 // Apply the operation and ignore invalid or non-double items
1242 for (unsigned int i = 0; i < _vLine.size(); i++)
1243 {
1244 if (_vLine[i] < 0 || _vLine[i] >= (int)vClusterArray.size())
1245 continue;
1246
1248 continue;
1249
1250 if (std::isnan(dMax))
1251 dMax = vClusterArray[_vLine[i]]->getDouble().real();
1252
1253 if (dMax < vClusterArray[_vLine[i]]->getDouble().real())
1254 dMax = vClusterArray[_vLine[i]]->getDouble().real();
1255 }
1256
1257 return dMax;
1258 }
1259
1260
1271 std::string Cluster::strmax(const VectorIndex& _vLine)
1272 {
1273 if (!vClusterArray.size() || isDouble())
1274 return "";
1275
1276 std::string sMax = "";
1277
1278 // Apply the operation on all items and convert
1279 // their values on-the-fly
1280 for (unsigned int i = 0; i < _vLine.size(); i++)
1281 {
1282 if (_vLine[i] < 0 || _vLine[i] >= (int)vClusterArray.size())
1283 continue;
1284
1285 if (!sMax.length())
1286 sMax = vClusterArray[_vLine[i]]->getParserString();
1287
1288 if (sMax < vClusterArray[_vLine[i]]->getParserString())
1289 sMax = vClusterArray[_vLine[i]]->getParserString();
1290 }
1291
1292 return sMax;
1293 }
1294
1295
1307 {
1308 if (!vClusterArray.size() || isString())
1309 return NAN;
1310
1311 double dMin = NAN;
1312
1313 // Apply the operation and ignore invalid or non-double items
1314 for (unsigned int i = 0; i < _vLine.size(); i++)
1315 {
1316 if (_vLine[i] < 0 || _vLine[i] >= (int)vClusterArray.size())
1317 continue;
1318
1320 continue;
1321
1322 if (std::isnan(dMin))
1323 dMin = vClusterArray[_vLine[i]]->getDouble().real();
1324
1325 if (dMin > vClusterArray[_vLine[i]]->getDouble().real())
1326 dMin = vClusterArray[_vLine[i]]->getDouble().real();
1327 }
1328
1329 return dMin;
1330 }
1331
1332
1343 std::string Cluster::strmin(const VectorIndex& _vLine)
1344 {
1345 if (!vClusterArray.size() || isDouble())
1346 return "";
1347
1348 std::string sMin = "";
1349
1350 // Apply the operation on all items and convert
1351 // their values on-the-fly
1352 for (unsigned int i = 0; i < _vLine.size(); i++)
1353 {
1354 if (_vLine[i] < 0 || _vLine[i] >= (int)vClusterArray.size())
1355 continue;
1356
1357 if (!sMin.length())
1358 sMin = vClusterArray[_vLine[i]]->getParserString();
1359
1360 if (sMin > vClusterArray[_vLine[i]]->getParserString())
1361 sMin = vClusterArray[_vLine[i]]->getParserString();
1362 }
1363
1364 return sMin;
1365 }
1366
1367
1379 {
1380 if (!vClusterArray.size())
1381 return NAN;
1382
1383 mu::value_type dPrd = 1.0;
1384
1385 // Apply the operation and ignore invalid or non-double items
1386 for (unsigned int i = 0; i < _vLine.size(); i++)
1387 {
1388 if (_vLine[i] < 0 || _vLine[i] >= (int)vClusterArray.size())
1389 continue;
1390
1391 if (std::isnan(std::abs(vClusterArray[_vLine[i]]->getDouble())))
1392 continue;
1393
1394 dPrd *= vClusterArray[_vLine[i]]->getDouble();
1395 }
1396
1397 return dPrd;
1398 }
1399
1400
1412 {
1413 if (!vClusterArray.size() && isString())
1414 return NAN;
1415
1416 mu::value_type dSum = 0.0;
1417
1418 // Apply the operation and ignore invalid or non-double items
1419 for (unsigned int i = 0; i < _vLine.size(); i++)
1420 {
1421 if (_vLine[i] < 0 || _vLine[i] >= (int)vClusterArray.size())
1422 continue;
1423
1425 continue;
1426
1427 dSum += vClusterArray[_vLine[i]]->getDouble();
1428 }
1429
1430 return dSum;
1431 }
1432
1433
1444 std::string Cluster::strsum(const VectorIndex& _vLine)
1445 {
1446 if (!vClusterArray.size() || isDouble())
1447 return "";
1448
1449 std::string sSum = "";
1450
1451 // Apply the operation on all items and convert
1452 // their values on-the-fly
1453 for (unsigned int i = 0; i < _vLine.size(); i++)
1454 {
1455 if (_vLine[i] < 0 || _vLine[i] >= (int)vClusterArray.size())
1456 continue;
1457
1458 sSum += vClusterArray[_vLine[i]]->getParserString();
1459 }
1460
1461 return sSum;
1462 }
1463
1464
1476 {
1477 if (!vClusterArray.size())
1478 return 0;
1479
1480 int nInvalid = 0;
1481
1482 // Apply the operation and ignore invalid values
1483 for (unsigned int i = 0; i < _vLine.size(); i++)
1484 {
1485 if (_vLine[i] < 0 || _vLine[i] >= (int)vClusterArray.size())
1486 nInvalid++;
1487 else if (vClusterArray[_vLine[i]]->getType() == ClusterItem::ITEMTYPE_DOUBLE && std::isnan(vClusterArray[_vLine[i]]->getDouble().real()))
1488 nInvalid++;
1489 else if (vClusterArray[_vLine[i]]->getType() == ClusterItem::ITEMTYPE_STRING && vClusterArray[_vLine[i]]->getParserString() == "\"\"")
1490 nInvalid++;
1491 }
1492
1493 return _vLine.size() - (double)nInvalid;
1494 }
1495
1496
1507 {
1508 if (!vClusterArray.size())
1509 return 0.0;
1510
1511 double dRetVal = NAN;
1512
1513 // Apply the operation and ignore invalid or non-double items
1514 for (unsigned int i = 0; i < _vLine.size(); i++)
1515 {
1516 if (_vLine[i] < 0 || _vLine[i] >= (int)vClusterArray.size())
1517 continue;
1518
1519 if (std::isnan(dRetVal))
1520 dRetVal = 1.0;
1521
1522 if (vClusterArray[_vLine[i]]->getType() != ClusterItem::ITEMTYPE_DOUBLE || std::isnan(vClusterArray[_vLine[i]]->getDouble().real()) || vClusterArray[_vLine[i]]->getDouble() == 0.0)
1523 return 0.0;
1524 }
1525
1526 if (std::isnan(dRetVal))
1527 return 0.0;
1528
1529 return 1.0;
1530 }
1531
1532
1543 {
1544 if (!vClusterArray.size())
1545 return 0.0;
1546
1547 // Apply the operation and ignore invalid or non-double items
1548 for (unsigned int i = 0; i < _vLine.size(); i++)
1549 {
1550 if (_vLine[i] < 0 || _vLine[i] >= (int)vClusterArray.size())
1551 continue;
1552
1554 && (std::isnan(vClusterArray[_vLine[i]]->getDouble().real()) || vClusterArray[_vLine[i]]->getDouble() != 0.0))
1555 return 1.0;
1556 }
1557
1558 return 0.0;
1559 }
1560
1561
1573 {
1574 if (!vClusterArray.size())
1575 return 0.0;
1576
1577 bool isTrue = false;
1578
1579 // Apply the operation and ignore invalid or non-double items
1580 for (unsigned int i = 0; i < _vLine.size(); i++)
1581 {
1582 if (_vLine[i] < 0 || _vLine[i] >= (int)vClusterArray.size())
1583 continue;
1584
1586 && (std::isnan(vClusterArray[_vLine[i]]->getDouble().real()) || vClusterArray[_vLine[i]]->getDouble() != 0.0))
1587 {
1588 if (!isTrue)
1589 isTrue = true;
1590 else
1591 return 0.0;
1592 }
1593 }
1594
1595 if (isTrue)
1596 return 1.0;
1597
1598 return 0.0;
1599 }
1600
1601
1613 {
1614 if (!vClusterArray.size())
1615 return 0;
1616
1617 int nInvalid = 0;
1618
1619 // Apply the operation and ignore invalid locations
1620 for (unsigned int i = 0; i < _vLine.size(); i++)
1621 {
1622 if (_vLine[i] < 0 || _vLine[i] >= (int)vClusterArray.size())
1623 nInvalid++;
1624 }
1625 return _vLine.size() - (double)nInvalid;
1626 }
1627
1628
1640 {
1641 if (!vClusterArray.size())
1642 return NAN;
1643
1644 mu::value_type dNorm = 0.0;
1645
1646 // Apply the operation and ignore invalid or non-double items
1647 for (unsigned int i = 0; i < _vLine.size(); i++)
1648 {
1649 if (_vLine[i] < 0 || _vLine[i] >= (int)vClusterArray.size())
1650 continue;
1651
1653 continue;
1654
1655 dNorm += vClusterArray[_vLine[i]]->getDouble() * conj(vClusterArray[_vLine[i]]->getDouble());
1656 }
1657
1658 return std::sqrt(dNorm);
1659 }
1660
1661
1676 {
1677 if (!vClusterArray.size())
1678 return NAN;
1679
1680 enum
1681 {
1682 RETURN_VALUE = 1,
1683 RETURN_LE = 2,
1684 RETURN_GE = 4,
1685 RETURN_FIRST = 8
1686 };
1687
1688 int nType = 0;
1689
1690 mu::value_type dKeep = dRef;
1691 int nKeep = -1;
1692
1693 if (_nType > 0)
1694 nType = RETURN_GE;
1695 else if (_nType < 0)
1696 nType = RETURN_LE;
1697
1698 switch (intCast(fabs(_nType)))
1699 {
1700 case 2:
1701 nType |= RETURN_VALUE;
1702 break;
1703 case 3:
1704 nType |= RETURN_FIRST;
1705 break;
1706 case 4:
1707 nType |= RETURN_FIRST | RETURN_VALUE;
1708 break;
1709 }
1710
1711 // Apply the operation and ignore invalid or non-double items
1712 for (long long int i = 0; i < _vLine.size(); i++)
1713 {
1714 if (_vLine[i] < 0 || _vLine[i] >= (int)vClusterArray.size())
1715 continue;
1716
1718 continue;
1719
1720 if (vClusterArray[_vLine[i]]->getDouble() == dRef)
1721 {
1722 if (nType & RETURN_VALUE)
1723 return vClusterArray[_vLine[i]]->getDouble();
1724
1725 return _vLine[i] + 1;
1726 }
1727 else if (nType & RETURN_GE && vClusterArray[_vLine[i]]->getDouble().real() > dRef.real())
1728 {
1729 if (nType & RETURN_FIRST)
1730 {
1731 if (nType & RETURN_VALUE)
1732 return vClusterArray[_vLine[i]]->getDouble().real();
1733
1734 return _vLine[i]+1;
1735 }
1736
1737 if (nKeep == -1 || vClusterArray[_vLine[i]]->getDouble().real() < dKeep.real())
1738 {
1739 dKeep = vClusterArray[_vLine[i]]->getDouble().real();
1740 nKeep = _vLine[i];
1741 }
1742 else
1743 continue;
1744 }
1745 else if (nType & RETURN_LE && vClusterArray[_vLine[i]]->getDouble().real() < dRef.real())
1746 {
1747 if (nType & RETURN_FIRST)
1748 {
1749 if (nType & RETURN_VALUE)
1750 return vClusterArray[_vLine[i]]->getDouble().real();
1751
1752 return _vLine[i]+1;
1753 }
1754
1755 if (nKeep == -1 || vClusterArray[_vLine[i]]->getDouble().real() > dKeep.real())
1756 {
1757 dKeep = vClusterArray[_vLine[i]]->getDouble().real();
1758 nKeep = _vLine[i];
1759 }
1760 else
1761 continue;
1762 }
1763 }
1764
1765 if (nKeep == -1)
1766 return NAN;
1767 else if (nType & RETURN_VALUE)
1768 return dKeep;
1769
1770 return nKeep+1;
1771 }
1772
1773
1785 {
1786 if (!vClusterArray.size())
1787 return NAN;
1788
1789 double dMed = 0.0;
1790 unsigned int nInvalid = 0;
1791 unsigned int nCount = 0;
1792 double* dData = 0;
1793
1794 // Calculate the number of valid items
1795 for (unsigned int i = 0; i < _vLine.size(); i++)
1796 {
1797 if (_vLine[i] < 0 || _vLine[i] >= (int)vClusterArray.size())
1798 nInvalid++;
1799 else if (vClusterArray[_vLine[i]]->getType() != ClusterItem::ITEMTYPE_DOUBLE || std::isnan(vClusterArray[_vLine[i]]->getDouble().real()))
1800 nInvalid++;
1801 }
1802
1803 if (nInvalid >= _vLine.size())
1804 return NAN;
1805
1806 // Create a memory buffer of the corresponding size
1807 dData = new double[_vLine.size() - nInvalid];
1808
1809 // copy the data to the buffer
1810 for (unsigned int i = 0; i < _vLine.size(); i++)
1811 {
1812 if (_vLine[i] < 0 || _vLine[i] >= (int)vClusterArray.size() || vClusterArray[_vLine[i]]->getType() != ClusterItem::ITEMTYPE_DOUBLE || std::isnan(vClusterArray[_vLine[i]]->getDouble().real()))
1813 continue;
1814
1815 dData[nCount] = vClusterArray[_vLine[i]]->getDouble().real();
1816 nCount++;
1817
1818 if (nCount == _vLine.size() - nInvalid)
1819 break;
1820 }
1821
1822 // Sort the data
1823 nCount = qSortDouble(dData, nCount);
1824
1825 if (!nCount)
1826 {
1827 delete[] dData;
1828 return NAN;
1829 }
1830
1831 // Calculate the median value
1832 dMed = gsl_stats_median_from_sorted_data(dData, 1, nCount);
1833
1834 delete[] dData;
1835
1836 return dMed;
1837 }
1838
1839
1852 {
1853 if (!vClusterArray.size())
1854 return NAN;
1855
1856 unsigned int nInvalid = 0;
1857 unsigned int nCount = 0;
1858 double* dData = 0;
1859
1860 if (dPct.real() >= 1 || dPct.real() <= 0)
1861 return NAN;
1862
1863 // Calculate the number of valid items
1864 for (unsigned int i = 0; i < _vLine.size(); i++)
1865 {
1866 if (_vLine[i] < 0 || _vLine[i] >= (int)vClusterArray.size())
1867 nInvalid++;
1868 else if (vClusterArray[_vLine[i]]->getType() != ClusterItem::ITEMTYPE_DOUBLE || std::isnan(vClusterArray[_vLine[i]]->getDouble().real()))
1869 nInvalid++;
1870 }
1871
1872 if (nInvalid >= _vLine.size())
1873 return NAN;
1874
1875 // Create a memory buffer of the corresponding size
1876 dData = new double[_vLine.size() - nInvalid];
1877
1878 // copy the data to the buffer
1879 for (unsigned int i = 0; i < _vLine.size(); i++)
1880 {
1881 if (_vLine[i] < 0 || _vLine[i] >= (int)vClusterArray.size() || vClusterArray[_vLine[i]]->getType() != ClusterItem::ITEMTYPE_DOUBLE || std::isnan(vClusterArray[_vLine[i]]->getDouble().real()))
1882 continue;
1883
1884 dData[nCount] = vClusterArray[_vLine[i]]->getDouble().real();
1885 nCount++;
1886
1887 if (nCount == _vLine.size() - nInvalid)
1888 break;
1889 }
1890
1891 // Sort the data
1892 nCount = qSortDouble(dData, nCount);
1893
1894 if (!nCount)
1895 {
1896 delete[] dData;
1897 return NAN;
1898 }
1899
1900 // Calculate the p-th percentile
1901 dPct = gsl_stats_quantile_from_sorted_data(dData, 1, nCount, dPct.real());
1902
1903 delete[] dData;
1904
1905 return dPct;
1906 }
1907
1908
1909 //
1910 // class CLUSTERMANAGER
1911 //
1912 //
1913
1914
1924 std::string ClusterManager::validateClusterName(const std::string& sCluster)
1925 {
1926 std::string sClusterName = sCluster.substr(0, sCluster.find('{'));
1927 const static std::string sVALIDCHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_~";
1928
1929 if ((sClusterName[0] >= '0' && sClusterName[0] <= '9') || sClusterName[0] == '~' || sClusterName.find_first_not_of(sVALIDCHARACTERS) != std::string::npos)
1931
1932 return sClusterName;
1933 }
1934
1935
1945 std::map<std::string, Cluster>::const_iterator ClusterManager::mapStringViewFind(StringView view) const
1946 {
1947 for (auto iter = mClusterMap.begin(); iter != mClusterMap.end(); ++iter)
1948 {
1949 if (view == iter->first)
1950 return iter;
1951 else if (view < iter->first)
1952 return mClusterMap.end();
1953 }
1954
1955 return mClusterMap.end();
1956 }
1957
1967 std::map<std::string, Cluster>::iterator ClusterManager::mapStringViewFind(StringView view)
1968 {
1969 for (auto iter = mClusterMap.begin(); iter != mClusterMap.end(); ++iter)
1970 {
1971 if (view == iter->first)
1972 return iter;
1973 else if (view < iter->first)
1974 return mClusterMap.end();
1975 }
1976
1977 return mClusterMap.end();
1978 }
1979
1980
1989 bool ClusterManager::containsClusters(const std::string& sCmdLine) const
1990 {
1991 size_t nQuotes = 0;
1992
1993 if (sCmdLine.find('{') == std::string::npos)
1994 return false;
1995
1996 // Search through the expression
1997 for (size_t i = 0; i < sCmdLine.length(); i++)
1998 {
1999 // Consider quotation marks
2000 if (sCmdLine[i] == '"' && (!i || sCmdLine[i-1] != '\\'))
2001 nQuotes++;
2002
2003 if (!(nQuotes % 2))
2004 {
2005 // If the current character might probably be an
2006 // identifier for a table, search for the next
2007 // nonmatching character and try to find the obtained
2008 // string in the internal map
2009 if (isalpha(sCmdLine[i]) || sCmdLine[i] == '_' || sCmdLine[i] == '~')
2010 {
2011 size_t nStartPos = i;
2012
2013 do
2014 {
2015 i++;
2016 }
2017 while (isalnum(sCmdLine[i]) || sCmdLine[i] == '_' || sCmdLine[i] == '~' || sCmdLine[i] == '[' || sCmdLine[i] == ']');
2018
2019 if (sCmdLine[i] == '{')
2020 {
2021 if (mClusterMap.find(sCmdLine.substr(nStartPos, i - nStartPos)) != mClusterMap.end())
2022 return true;
2023 }
2024 }
2025 }
2026 }
2027
2028 return false;
2029 }
2030
2031
2042 {
2043 if (mapStringViewFind(sCluster.subview(0, sCluster.find('{'))) != mClusterMap.end())
2044 return true;
2045
2046 return false;
2047 }
2048
2049
2059 bool ClusterManager::isCluster(const std::string& sCluster) const
2060 {
2061 if (mClusterMap.find(sCluster.substr(0, sCluster.find('{'))) != mClusterMap.end())
2062 return true;
2063
2064 return false;
2065 }
2066
2067
2078 {
2079 auto iter = mapStringViewFind(sCluster.subview(0, sCluster.find('{')));
2080
2081 if (iter == mClusterMap.end())
2083
2084 return iter->second;
2085 }
2086
2087
2097 Cluster& ClusterManager::getCluster(const std::string& sCluster)
2098 {
2099 auto iter = mClusterMap.find(sCluster.substr(0, sCluster.find('{')));
2100
2101 if (iter == mClusterMap.end())
2102 throw SyntaxError(SyntaxError::CLUSTER_DOESNT_EXIST, sCluster, sCluster);
2103
2104 return iter->second;
2105 }
2106
2107
2119 const Cluster& ClusterManager::getCluster(const std::string& sCluster) const
2120 {
2121 auto iter = mClusterMap.find(sCluster.substr(0, sCluster.find('{')));
2122
2123 if (iter == mClusterMap.end())
2124 throw SyntaxError(SyntaxError::CLUSTER_DOESNT_EXIST, sCluster, sCluster);
2125
2126 return iter->second;
2127 }
2128
2129
2139 Cluster& ClusterManager::newCluster(const std::string& sCluster)
2140 {
2141 std::string sValidName = validateClusterName(sCluster);
2142 mClusterMap[sValidName] = Cluster();
2143
2144 return mClusterMap[sValidName];
2145 }
2146
2147
2158 void ClusterManager::appendCluster(const std::string& sCluster, const Cluster& cluster)
2159 {
2160 mClusterMap[validateClusterName(sCluster)] = cluster;
2161 }
2162
2163
2173 void ClusterManager::removeCluster(const std::string& sCluster)
2174 {
2175 auto iter = mClusterMap.find(sCluster);
2176
2177 if (iter != mClusterMap.end())
2178 mClusterMap.erase(iter);
2179 }
2180
2181
2191 std::string ClusterManager::createTemporaryCluster(const std::string& suffix)
2192 {
2193 std::string sTemporaryClusterName = "_~~TC_" + toString(mClusterMap.size()) + "_" + suffix;
2194 mClusterMap[sTemporaryClusterName] = Cluster();
2195
2196 return sTemporaryClusterName + "{}";
2197 }
2198
2199
2210 {
2211 auto iter = mClusterMap.begin();
2212
2213 while (iter != mClusterMap.end())
2214 {
2215 if (iter->first.substr(0, 6) == "_~~TC_")
2216 iter = mClusterMap.erase(iter);
2217 else
2218 ++iter;
2219 }
2220 }
2221
2222
2230 {
2231 mClusterMap.clear();
2232 }
2233
2234
2246 {
2247 if (isCluster(sCluster))
2248 dClusterElementsCount = getCluster(sCluster.subview(0, sCluster.find('{'))).size();
2249 else
2251
2252 return true;
2253 }
2254}
2255
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...
Definition: cluster.hpp:145
This class represents a whole cluster. The single items are stored as pointers to the abstract cluste...
Definition: cluster.hpp:325
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...
Definition: cluster.cpp:871
bool isString() const
This member function returns, whether the data in the cluster have only string as type.
Definition: cluster.cpp:487
bool bSortCaseInsensitive
Definition: cluster.hpp:328
size_t size() const
This member function returns the size of the internal memory buffer as items.
Definition: cluster.cpp:356
void clear()
This member function clears the internal memory buffer and frees the associated memory.
Definition: cluster.cpp:395
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.
Definition: cluster.cpp:781
std::string getString(size_t i) const
This member function returns the data of the i-th cluster item in memory as a string.
Definition: cluster.cpp:745
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...
Definition: cluster.cpp:561
void push_back(ClusterItem *item)
This member function appends an arbitrary cluster item at the back of the internal cluster array buff...
Definition: cluster.cpp:274
mu::value_type med(const VectorIndex &_vLine)
This member function calculates the median value of the data in memory. Cluster items,...
Definition: cluster.cpp:1784
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....
Definition: cluster.cpp:801
void assignVectorResults(Indices _idx, int nNum, mu::value_type *data)
Private result assignment function for values using vectors as indices.
Definition: cluster.cpp:119
mu::value_type min(const VectorIndex &_vLine)
This member function calculates the minimal value of the data in memory. Cluster items,...
Definition: cluster.cpp:1306
void assignResults(Indices _idx, int nNum, mu::value_type *data)
This member function assigns calculation results as data for the cluster items in memory,...
Definition: cluster.cpp:720
std::vector< std::string > getInternalStringArray() const
This member function returns the data of all cluster items memory as a value vector.
Definition: cluster.cpp:848
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...
Definition: cluster.cpp:1612
std::vector< ClusterItem * > vClusterArray
Definition: cluster.hpp:327
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.
Definition: cluster.cpp:903
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...
Definition: cluster.cpp:1506
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...
Definition: cluster.cpp:1475
mu::value_type xor_func(const VectorIndex &_vLine)
This member function applies an "exclusive OR" to the data in memory. Cluster items,...
Definition: cluster.cpp:1572
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...
Definition: cluster.cpp:1198
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...
Definition: cluster.cpp:648
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...
Definition: cluster.cpp:612
std::string getVectorRepresentation() const
This member function constructs a plain vector from the data in memory, which can be inserted in the ...
Definition: cluster.cpp:929
mu::value_type max(const VectorIndex &_vLine)
This member function calculates the maximal value of the data in memory. Cluster items,...
Definition: cluster.cpp:1234
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.
Definition: cluster.cpp:541
bool isMixed() const
This member function returns, whether the data in the cluster have mixed type.
Definition: cluster.cpp:414
void reduceSize(size_t z)
Reduces the size of this cluster to the specified number of elements. Does not create anything,...
Definition: cluster.cpp:253
virtual bool isValue(int line, int col) override
This private member function is an override for the sorter object.
Definition: cluster.cpp:207
mu::value_type std(const VectorIndex &_vLine)
This member function calculates the standard deviation of the data in memory. Cluster items,...
Definition: cluster.cpp:1160
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,...
Definition: cluster.cpp:1851
void assign(const Cluster &cluster)
Private cluster copy assignment function.
Definition: cluster.cpp:39
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.
Definition: cluster.cpp:1009
std::string getInternalString(size_t i) const
This member function returns the data of the i-th cluster item in memory as a string.
Definition: cluster.cpp:763
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...
Definition: cluster.cpp:1542
mu::value_type norm(const VectorIndex &_vLine)
This member function calculates the euclidic vector norm of the data in memory. Cluster items,...
Definition: cluster.cpp:1639
std::string strsum(const VectorIndex &_vLine)
This member function calculates the string concatenation of the data in memory. Cluster items of all ...
Definition: cluster.cpp:1444
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.
Definition: cluster.cpp:230
virtual int compare(int i, int j, int col) override
This private member function is an override for the sorter object.
Definition: cluster.cpp:160
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...
Definition: cluster.cpp:1675
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...
Definition: cluster.cpp:1411
std::vector< mu::value_type > getDoubleArray() const
This member function returns the data of all cluster items memory as a value vector.
Definition: cluster.cpp:588
void pop_back()
This member function removes the last item in the internal memory buffer and frees the associated mem...
Definition: cluster.cpp:337
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...
Definition: cluster.cpp:1378
size_t getBytes() const
This member function returns the size of the associated memory as bytes.
Definition: cluster.cpp:369
std::string strmin(const VectorIndex &_vLine)
This member function calculates the minimal string value of the data in memory. Cluster items of all ...
Definition: cluster.cpp:1343
std::string getShortVectorRepresentation(size_t maxStringLength) const
This member function constructs a short version of a plain vector from the data in memory,...
Definition: cluster.cpp:962
bool isDouble() const
This member function returns, whether the data in the cluster have only double as type.
Definition: cluster.cpp:451
unsigned short getType(size_t i) const
This member function returns the type of the i-th cluster item in the internal memory buffer.
Definition: cluster.cpp:524
std::string strmax(const VectorIndex &_vLine)
This member function calculates the maximal string value of the data in memory. Cluster items of all ...
Definition: cluster.cpp:1271
std::vector< std::string > getStringArray() const
This member function returns the data of all cluster items memory as a value vector.
Definition: cluster.cpp:828
void deleteItems(long long int i1, long long int i2)
This public member function erases elements located from the index i1 to i2.
Definition: cluster.cpp:1072
This is an abstract cluster item. It is used as root class of any cluster items and only contains the...
Definition: cluster.hpp:39
unsigned short getType() const
Returns the ClusterItemType.
Definition: cluster.hpp:65
bool containsClusters(const std::string &sCmdLine) const
This member function detects, whether any cluster is used in the current expression.
Definition: cluster.cpp:1989
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...
Definition: cluster.cpp:2158
void removeTemporaryClusters()
This member function returns all temporary clusters from the internal map. Temporary clusters are ind...
Definition: cluster.cpp:2209
mu::value_type dClusterElementsCount
Definition: cluster.hpp:459
void removeCluster(const std::string &sCluster)
This member function removes the cluster from memory, which corresponds to the passed cluster identif...
Definition: cluster.cpp:2173
Cluster & getCluster(StringView sCluster)
This member function returns a reference to the cluster indicated by the passed cluster identifier.
Definition: cluster.cpp:2077
bool updateClusterSizeVariables(StringView sCluster)
This member function updates the dimension variable reserved for cluster accesses with the size of th...
Definition: cluster.cpp:2245
Cluster & newCluster(const std::string &sCluster)
This member function creates a new cluster from the passed cluster identifier and returns a reference...
Definition: cluster.cpp:2139
std::map< std::string, Cluster > mClusterMap
Definition: cluster.hpp:449
bool isCluster(StringView sCluster) const
This member function returns true, if the passed cluster identifier can be found in the internal map.
Definition: cluster.cpp:2041
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...
Definition: cluster.cpp:1924
std::map< std::string, Cluster >::iterator mapStringViewFind(StringView view)
This private member function returns an iterator to the referenced cluster or std::map::end().
Definition: cluster.cpp:1967
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...
Definition: cluster.cpp:2191
void clearAllClusters()
Clear all clusters currently in memory.
Definition: cluster.cpp:2229
This is a cluster item, which contains a string. It features conversions to and from doubles on-the-f...
Definition: cluster.hpp:243
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 ...
Definition: sorter.cpp:40
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.
Definition: error.hpp:32
@ INVALID_CLUSTER_NAME
Definition: error.hpp:137
@ CLUSTER_DOESNT_EXIST
Definition: error.hpp:48
@ CANNOT_SORT_DATA
Definition: error.hpp:85
static size_t invalid_position
Definition: error.hpp:235
This class abstracts all the index logics, i.e. the logical differences between single indices and in...
Definition: structures.hpp:42
void setOpenEndIndex(int nLast) const
This member function can be used to replace the open end state with a defined index value although th...
Definition: structures.hpp:756
size_t size() const
This member function returns the size of the indices stored in this class.
Definition: structures.hpp:314
bool isOpenEnd() const
This member function determines, whether the internal index set has an open end.
Definition: structures.hpp:614
int & front()
This member function returns a reference to the first index value stored internally.
Definition: structures.hpp:640
CONSTCD11 std::chrono::duration< Rep, Period > abs(std::chrono::duration< Rep, Period > d)
Definition: date.h:1317
MUP_BASETYPE value_type
The numeric datatype used by the parser.
Definition: muParserDef.h:251
bool isnan(const value_type &v)
Definition: muParserDef.h:379
std::vector< double > real(const std::vector< value_type > &vVec)
#define max(a, b)
Definition: resampler.cpp:30
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,...
Definition: tools.cpp:113
std::string ellipsize(const std::string &sLongString, size_t nMaxStringLength)
Shortens the passed string by introducing a ellipsis in the middle of the string, if the string is lo...
std::string toCmdString(double dNumber)
Converts a numerical value into a "full" precision string.
This structure is central for managing the indices of a table or cluster read or write data access....
VectorIndex row
long long int intCast(const std::complex< double > &)
Casts the real part of the complex number to an integer and avoids rounding errors.
Definition: tools.cpp:1824
std::string toString(int)
Converts an integer to a string without the Settings bloat.
size_t qSortDouble(double *dArray, size_t nlength)
This is a wrapper for the standard qsort algorithm. It returns the number of valid elements and sorts...
Definition: tools.cpp:3762