1 #ifndef NPSTAT_ARRAYND_HH_ 2 #define NPSTAT_ARRAYND_HH_ 16 #include "Alignment/Geners/interface/ClassId.hh" 47 template <
typename Numeric,
unsigned StackLen=1U,
unsigned StackDim=10U>
50 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
97 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
104 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
108 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
113 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
128 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
130 const unsigned *indices,
unsigned nIndices);
133 template <
typename Num1,
unsigned Len1,
unsigned Dim1,
134 typename Num2,
unsigned Len2,
unsigned Dim2>
145 ArrayND(
unsigned n0,
unsigned n1,
unsigned n2);
146 ArrayND(
unsigned n0,
unsigned n1,
unsigned n2,
unsigned n3);
147 ArrayND(
unsigned n0,
unsigned n1,
unsigned n2,
unsigned n3,
149 ArrayND(
unsigned n0,
unsigned n1,
unsigned n2,
unsigned n3,
150 unsigned n4,
unsigned n5);
151 ArrayND(
unsigned n0,
unsigned n1,
unsigned n2,
unsigned n3,
152 unsigned n4,
unsigned n5,
unsigned n6);
153 ArrayND(
unsigned n0,
unsigned n1,
unsigned n2,
unsigned n3,
154 unsigned n4,
unsigned n5,
unsigned n6,
unsigned n7);
155 ArrayND(
unsigned n0,
unsigned n1,
unsigned n2,
unsigned n3,
156 unsigned n4,
unsigned n5,
unsigned n6,
unsigned n7,
158 ArrayND(
unsigned n0,
unsigned n1,
unsigned n2,
unsigned n3,
159 unsigned n4,
unsigned n5,
unsigned n6,
unsigned n7,
160 unsigned n8,
unsigned n9);
177 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
181 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
197 Numeric&
value(
const unsigned *
index,
unsigned indexLen);
198 const Numeric&
value(
const unsigned *
index,
unsigned indexLen)
const;
206 Numeric&
valueAt(
const unsigned *
index,
unsigned indexLen);
207 const Numeric&
valueAt(
const unsigned *
index,
unsigned indexLen)
const;
224 unsigned indexLen)
const;
227 unsigned long linearIndex(
const unsigned*
idx,
unsigned idxLen)
const;
252 unsigned span(
unsigned dim)
const;
274 template <
typename Num2>
278 template <
unsigned Len2,
unsigned Dim2>
282 template <
unsigned Len2,
unsigned Dim2>
286 template <
unsigned Len2,
unsigned Dim2>
296 template <
unsigned Len2,
unsigned Dim2>
300 template <
unsigned Len2,
unsigned Dim2>
304 template <
typename Num2>
308 template <
typename Num2>
316 template <
typename Num2>
319 template <
typename Num2>
322 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
325 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
330 template <
typename Num3,
typename Num2,
unsigned Len2,
unsigned Dim2>
334 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
348 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
365 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
367 const unsigned* indexMap,
unsigned mapLen)
const;
381 template <
typename Num2>
388 template <
typename Num2>
399 template <
typename Num2>
406 template <
typename Num2>
413 template <
typename Num2>
414 Num2
cdfValue(
const unsigned *
index,
unsigned indexLen)
const;
427 template <
typename Num2>
434 Numeric
min(
unsigned *index,
unsigned indexLen)
const;
440 Numeric
max(
unsigned *index,
unsigned indexLen)
const;
451 Numeric&
closest(
const double *
x,
unsigned xDim);
452 const Numeric&
closest(
const double *x,
unsigned xDim)
const;
463 Numeric
interpolate1(
const double *x,
unsigned xDim)
const;
471 Numeric
interpolate3(
const double *x,
unsigned xDim)
const;
482 template <
class Functor>
492 template <
class Functor>
515 template <
class Functor>
544 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
549 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
574 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
576 const unsigned* thisCorner,
577 const unsigned* range,
578 const unsigned* otherCorner,
580 Functor binaryFunct);
587 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
589 const unsigned* thisCorner,
590 const unsigned* range,
591 const unsigned* otherCorner,
593 Functor binaryFunct);
599 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
601 const unsigned* thisCorner,
602 const unsigned* range,
603 const unsigned* otherCorner,
605 Functor binaryFunct);
611 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
613 const unsigned* thisCorner,
614 const unsigned* range,
615 const unsigned* otherCorner,
617 Functor binaryFunct);
625 template <
typename Num2,
typename Integer>
636 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
637 void exportSubrange(
const unsigned* fromCorner,
unsigned lenCorner,
641 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
642 void importSubrange(
const unsigned* fromCorner,
unsigned lenCorner,
650 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
660 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
672 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
674 const unsigned *fixedIndices,
675 const unsigned *fixedIndexValues,
676 unsigned nFixedIndices,
677 Functor binaryFunct);
687 template <
typename Num2,
class Functor>
689 const unsigned *fixedIndices,
690 const unsigned *fixedIndexValues,
691 unsigned nFixedIndices,
692 Functor binaryFunct);
696 unsigned nFixedIndices)
const;
699 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
701 const unsigned *fixedIndices,
702 const unsigned *fixedIndexValues,
703 unsigned nFixedIndices)
const 706 (
const_cast<ArrayND*
>(
this))->jointSliceScan(
707 *slice, fixedIndices, fixedIndexValues, nFixedIndices,
715 template <
typename Num2>
717 const unsigned *fixedIndices,
718 const unsigned *fixedIndexValues,
719 unsigned nFixedIndices)
const 721 (
const_cast<ArrayND*
>(
this))->jointMemSliceScan(
722 buffer, bufLen, fixedIndices, fixedIndexValues,
727 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
729 const unsigned *fixedIndices,
730 const unsigned *fixedIndexValues,
731 unsigned nFixedIndices)
734 fixedIndices, fixedIndexValues, nFixedIndices,
742 template <
typename Num2>
744 const unsigned *fixedIndices,
745 const unsigned *fixedIndexValues,
746 unsigned nFixedIndices)
749 fixedIndices, fixedIndexValues, nFixedIndices,
759 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
761 const unsigned *fixedIndices,
unsigned nFixedIndices,
762 Functor binaryFunct);
768 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
770 const unsigned *fixedIndices,
771 unsigned nFixedIndices)
774 fixedIndices, nFixedIndices,
787 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
typename Num3>
790 const unsigned *projectedIndices,
791 unsigned nProjectedIndices)
const;
793 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
typename Num3>
796 const unsigned *projectedIndices,
797 unsigned nProjectedIndices)
const;
806 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
typename Num3>
809 const unsigned *projectedIndices,
810 unsigned nProjectedIndices)
const;
812 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
typename Num3>
815 const unsigned *projectedIndices,
816 unsigned nProjectedIndices)
const;
818 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
typename Num3>
821 const unsigned *projectedIndices,
822 unsigned nProjectedIndices)
const;
824 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
typename Num3>
827 const unsigned *projectedIndices,
828 unsigned nProjectedIndices)
const;
836 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
837 void rotate(
const unsigned* shifts,
unsigned lenShifts,
845 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
859 Numeric&
operator()(
unsigned i0,
unsigned i1);
860 const Numeric&
operator()(
unsigned i0,
unsigned i1)
const;
862 Numeric&
operator()(
unsigned i0,
unsigned i1,
unsigned i2);
863 const Numeric&
operator()(
unsigned i0,
unsigned i1,
unsigned i2)
const;
866 unsigned i2,
unsigned i3);
867 const Numeric&
operator()(
unsigned i0,
unsigned i1,
868 unsigned i2,
unsigned i3)
const;
871 unsigned i2,
unsigned i3,
unsigned i4);
872 const Numeric&
operator()(
unsigned i0,
unsigned i1,
873 unsigned i2,
unsigned i3,
unsigned i4)
const;
875 Numeric&
operator()(
unsigned i0,
unsigned i1,
unsigned i2,
876 unsigned i3,
unsigned i4,
unsigned i5);
877 const Numeric&
operator()(
unsigned i0,
unsigned i1,
unsigned i2,
878 unsigned i3,
unsigned i4,
unsigned i5)
const;
880 Numeric&
operator()(
unsigned i0,
unsigned i1,
unsigned i2,
881 unsigned i3,
unsigned i4,
unsigned i5,
883 const Numeric&
operator()(
unsigned i0,
unsigned i1,
unsigned i2,
884 unsigned i3,
unsigned i4,
unsigned i5,
887 Numeric&
operator()(
unsigned i0,
unsigned i1,
unsigned i2,
888 unsigned i3,
unsigned i4,
unsigned i5,
889 unsigned i6,
unsigned i7);
890 const Numeric&
operator()(
unsigned i0,
unsigned i1,
unsigned i2,
891 unsigned i3,
unsigned i4,
unsigned i5,
892 unsigned i6,
unsigned i7)
const;
894 Numeric&
operator()(
unsigned i0,
unsigned i1,
unsigned i2,
895 unsigned i3,
unsigned i4,
unsigned i5,
896 unsigned i6,
unsigned i7,
unsigned i8);
897 const Numeric&
operator()(
unsigned i0,
unsigned i1,
unsigned i2,
898 unsigned i3,
unsigned i4,
unsigned i5,
899 unsigned i6,
unsigned i7,
unsigned i8)
const;
901 Numeric&
operator()(
unsigned i0,
unsigned i1,
unsigned i2,
902 unsigned i3,
unsigned i4,
unsigned i5,
903 unsigned i6,
unsigned i7,
unsigned i8,
905 const Numeric&
operator()(
unsigned i0,
unsigned i1,
unsigned i2,
906 unsigned i3,
unsigned i4,
unsigned i5,
907 unsigned i6,
unsigned i7,
unsigned i8,
917 const Numeric&
at()
const;
919 Numeric&
at(
unsigned i0);
920 const Numeric&
at(
unsigned i0)
const;
922 Numeric&
at(
unsigned i0,
unsigned i1);
923 const Numeric&
at(
unsigned i0,
unsigned i1)
const;
925 Numeric&
at(
unsigned i0,
unsigned i1,
unsigned i2);
926 const Numeric&
at(
unsigned i0,
unsigned i1,
unsigned i2)
const;
928 Numeric&
at(
unsigned i0,
unsigned i1,
929 unsigned i2,
unsigned i3);
930 const Numeric&
at(
unsigned i0,
unsigned i1,
931 unsigned i2,
unsigned i3)
const;
933 Numeric&
at(
unsigned i0,
unsigned i1,
934 unsigned i2,
unsigned i3,
unsigned i4);
935 const Numeric&
at(
unsigned i0,
unsigned i1,
936 unsigned i2,
unsigned i3,
unsigned i4)
const;
938 Numeric&
at(
unsigned i0,
unsigned i1,
unsigned i2,
939 unsigned i3,
unsigned i4,
unsigned i5);
940 const Numeric&
at(
unsigned i0,
unsigned i1,
unsigned i2,
941 unsigned i3,
unsigned i4,
unsigned i5)
const;
943 Numeric&
at(
unsigned i0,
unsigned i1,
unsigned i2,
944 unsigned i3,
unsigned i4,
unsigned i5,
946 const Numeric&
at(
unsigned i0,
unsigned i1,
unsigned i2,
947 unsigned i3,
unsigned i4,
unsigned i5,
950 Numeric&
at(
unsigned i0,
unsigned i1,
unsigned i2,
951 unsigned i3,
unsigned i4,
unsigned i5,
952 unsigned i6,
unsigned i7);
953 const Numeric&
at(
unsigned i0,
unsigned i1,
unsigned i2,
954 unsigned i3,
unsigned i4,
unsigned i5,
955 unsigned i6,
unsigned i7)
const;
957 Numeric&
at(
unsigned i0,
unsigned i1,
unsigned i2,
958 unsigned i3,
unsigned i4,
unsigned i5,
959 unsigned i6,
unsigned i7,
unsigned i8);
960 const Numeric&
at(
unsigned i0,
unsigned i1,
unsigned i2,
961 unsigned i3,
unsigned i4,
unsigned i5,
962 unsigned i6,
unsigned i7,
unsigned i8)
const;
964 Numeric&
at(
unsigned i0,
unsigned i1,
unsigned i2,
965 unsigned i3,
unsigned i4,
unsigned i5,
966 unsigned i6,
unsigned i7,
unsigned i8,
968 const Numeric&
at(
unsigned i0,
unsigned i1,
unsigned i2,
969 unsigned i3,
unsigned i4,
unsigned i5,
970 unsigned i6,
unsigned i7,
unsigned i8,
980 const Numeric&
cl()
const;
982 Numeric&
cl(
double x0);
983 const Numeric&
cl(
double x0)
const;
985 Numeric&
cl(
double x0,
double x1);
986 const Numeric&
cl(
double x0,
double x1)
const;
988 Numeric&
cl(
double x0,
double x1,
double x2);
989 const Numeric&
cl(
double x0,
double x1,
double x2)
const;
991 Numeric&
cl(
double x0,
double x1,
992 double x2,
double x3);
993 const Numeric&
cl(
double x0,
double x1,
994 double x2,
double x3)
const;
996 Numeric&
cl(
double x0,
double x1,
997 double x2,
double x3,
double x4);
998 const Numeric&
cl(
double x0,
double x1,
999 double x2,
double x3,
double x4)
const;
1001 Numeric&
cl(
double x0,
double x1,
double x2,
1002 double x3,
double x4,
double x5);
1003 const Numeric&
cl(
double x0,
double x1,
double x2,
1004 double x3,
double x4,
double x5)
const;
1006 Numeric&
cl(
double x0,
double x1,
double x2,
1007 double x3,
double x4,
double x5,
1009 const Numeric&
cl(
double x0,
double x1,
double x2,
1010 double x3,
double x4,
double x5,
1013 Numeric&
cl(
double x0,
double x1,
double x2,
1014 double x3,
double x4,
double x5,
1015 double x6,
double x7);
1016 const Numeric&
cl(
double x0,
double x1,
double x2,
1017 double x3,
double x4,
double x5,
1018 double x6,
double x7)
const;
1020 Numeric&
cl(
double x0,
double x1,
double x2,
1021 double x3,
double x4,
double x5,
1022 double x6,
double x7,
double x8);
1023 const Numeric&
cl(
double x0,
double x1,
double x2,
1024 double x3,
double x4,
double x5,
1025 double x6,
double x7,
double x8)
const;
1027 Numeric&
cl(
double x0,
double x1,
double x2,
1028 double x3,
double x4,
double x5,
1029 double x6,
double x7,
double x8,
1031 const Numeric&
cl(
double x0,
double x1,
double x2,
1032 double x3,
double x4,
double x5,
1033 double x6,
double x7,
double x8,
1039 inline gs::ClassId
classId()
const {
return gs::ClassId(*
this);}
1040 bool write(std::ostream&
of)
const;
1045 static void restore(
const gs::ClassId&
id, std::istream&
in,
1071 const double* coeffs);
1074 template <
class Functor>
1076 Functor f,
unsigned*
farg);
1080 const Numeric*
base)
const;
1083 template <
typename Num1,
unsigned Len1,
unsigned Dim1,
1084 typename Num2,
unsigned Len2,
unsigned Dim2>
1086 unsigned long idx1,
unsigned long idx2,
1091 void contractLoop(
unsigned thisLevel,
unsigned resLevel,
1092 unsigned pos1,
unsigned pos2,
1093 unsigned long idxThis,
unsigned long idxRes,
1098 unsigned long idxThis,
unsigned long idxRes,
1102 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
1104 unsigned long idx1,
unsigned long idx2,
1109 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
1111 unsigned levelPr,
unsigned long idxPr,
1113 const unsigned* indexMap)
const;
1114 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
1116 unsigned levelRes,
unsigned long idxRes,
1118 const unsigned* indexMap,
ArrayND&
res)
const;
1122 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
1131 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
1134 const unsigned* thisCorner,
1135 const unsigned* range,
1136 const unsigned* otherCorner,
1138 Functor binaryFunct);
1142 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
1145 const unsigned* thisCorner,
1146 const unsigned* range,
1147 const unsigned* otherCorner,
1149 Functor binaryFunct);
1155 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
1158 const unsigned* thisCorner,
1159 const unsigned* range,
1160 const unsigned* otherCorner,
1162 Functor binaryFunct);
1167 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
1170 const unsigned* thisCorner,
1171 const unsigned* range,
1172 const unsigned* otherCorner,
1174 Functor binaryFunct);
1177 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
1180 const unsigned *fixedIndices,
1181 const unsigned *fixedIndexValues,
1182 unsigned nFixedIndices)
const;
1186 unsigned long bufLen,
1187 const unsigned *fixedIndices,
1188 const unsigned *fixedIndexValues,
1189 unsigned nFixedIndices,
1190 unsigned long* sliceStrides)
const;
1193 template <
typename Num2,
class Functor>
1195 unsigned level1,
unsigned long idx1,
1196 Num2* sliceData,
const unsigned long* sliceStrides,
1197 const unsigned *fixedIndices,
1198 const unsigned *fixedIndexValues,
1199 unsigned nFixedIndices, Functor binaryFunctor);
1202 template <
typename Num2,
class Functor>
1205 const unsigned* projectedIndices,
1206 unsigned nProjectedIndices,
1207 Functor binaryFunct);
1209 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
1211 unsigned level1,
unsigned long idx1,
1213 const unsigned *fixedIndices,
1214 unsigned nFixedIndices,
1215 Functor binaryFunct);
1218 template <
typename Num2>
1220 unsigned* currentIndex,
1222 const unsigned* projectedIndices,
1223 unsigned nProjectedIndices)
const;
1225 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
1226 typename Num3,
class Op>
1228 unsigned level1,
unsigned long idx1,
1229 unsigned* currentIndex,
1232 const unsigned* projectedIndices,
1233 unsigned nProjectedIndices, Op
fcn)
const;
1245 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
1246 typename Num3,
class Op>
1248 unsigned level1,
unsigned long idx1,
1251 const unsigned* projectedIndices,
1252 unsigned nProjectedIndices, Op
fcn)
const;
1254 template <
typename Num2>
1257 const unsigned* projectedIndices,
1258 unsigned nProjectedIndices)
const;
1260 template <
typename Num2,
typename Integer>
1262 unsigned* currentIndex,
1267 template <
typename Accumulator>
1269 const unsigned*
limit)
const;
1272 template <
typename Accumulator>
1275 unsigned long idxSlice,
1276 bool useTrapezoids);
1280 unsigned coordToIndex(
double coord,
unsigned idim)
const;
1283 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
1286 const unsigned *projectedIndices,
1287 unsigned nProjectedIndices)
const;
1294 #include <algorithm> 1298 #include "Alignment/Geners/interface/GenericIO.hh" 1299 #include "Alignment/Geners/interface/IOIsUnsigned.hh" 1308 #define me_macro_check_loop_prerequisites(METHOD, INNERLOOP) \ 1309 template<typename Numeric, unsigned Len, unsigned Dim> \ 1310 template <typename Num2, unsigned Len2, unsigned Dim2, class Functor> \ 1311 void ArrayND<Numeric,Len,Dim>:: METHOD ( \ 1312 ArrayND<Num2, Len2, Dim2>& other, \ 1313 const unsigned* thisCorner, \ 1314 const unsigned* range, \ 1315 const unsigned* otherCorner, \ 1316 const unsigned arrLen, \ 1317 Functor binaryFunct) \ 1319 if (!shapeIsKnown_) throw npstat::NpstatInvalidArgument( \ 1320 "Initialize npstat::ArrayND before calling method \"" \ 1322 if (!other.shapeIsKnown_) throw npstat::NpstatInvalidArgument( \ 1323 "In npstat::ArrayND::" #METHOD ": uninitialized argument array");\ 1324 if (dim_ != other.dim_) throw npstat::NpstatInvalidArgument( \ 1325 "In npstat::ArrayND::" #METHOD ": incompatible argument array rank");\ 1326 if (arrLen != dim_) throw npstat::NpstatInvalidArgument( \ 1327 "In npstat::ArrayND::" #METHOD ": incompatible index length"); \ 1330 assert(thisCorner); \ 1332 assert(otherCorner); \ 1333 INNERLOOP (0U, 0UL, 0UL, thisCorner, range, \ 1334 otherCorner, other, binaryFunct); \ 1337 binaryFunct(localData_[0], other.localData_[0]); \ 1341 template<
typename Numeric,
unsigned Len,
unsigned Dim>
1342 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
1344 unsigned level,
unsigned long idx0,
1346 const unsigned* thisCorner,
1347 const unsigned* range,
1348 const unsigned* otherCorner,
1350 Functor binaryFunct)
1352 const unsigned imax = range[
level];
1354 if (level ==
dim_ - 1)
1356 Numeric* left =
data_ + (idx0 + thisCorner[
level]);
1358 Num2* right = r.
data_ + (idx1 + otherCorner[
level]);
1361 for (
unsigned i=0;
i<imax && left<lMax && right<
rMax; ++
i)
1362 binaryFunct(*left++, *right++);
1367 const unsigned long leftMax = idx0 +
shape_[
level]*leftStride;
1368 idx0 += thisCorner[
level]*leftStride;
1370 const unsigned long rightMax = idx1 + r.
shape_[
level]*rightStride;
1371 idx1 += otherCorner[
level]*rightStride;
1373 for (
unsigned i=0;
i<imax && idx0 < leftMax && idx1 < rightMax;
1374 ++
i, idx0 += leftStride, idx1 += rightStride)
1376 otherCorner, r, binaryFunct);
1380 template<
typename Numeric,
unsigned Len,
unsigned Dim>
1381 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
1383 unsigned level,
unsigned long idx0,
1385 const unsigned* thisCorner,
1386 const unsigned* range,
1387 const unsigned* otherCorner,
1389 Functor binaryFunct)
1391 const unsigned imax = range[
level];
1392 const unsigned leftShift = thisCorner[
level];
1394 const unsigned rightShift = otherCorner[
level];
1397 if (level ==
dim_ - 1)
1399 Numeric* left =
data_ + idx0;
1400 Num2* right = r.
data_ + idx1;
1401 for (
unsigned i=0;
i<imax; ++
i)
1402 binaryFunct(left[(
i+leftShift)%leftPeriod],
1403 right[(
i+rightShift)%rightPeriod]);
1409 for (
unsigned i=0;
i<imax; ++
i)
1411 level+1, idx0+((
i+leftShift)%leftPeriod)*leftStride,
1412 idx1+((
i+rightShift)%rightPeriod)*rightStride,
1413 thisCorner, range, otherCorner, r, binaryFunct);
1417 template<
typename Numeric,
unsigned Len,
unsigned Dim>
1418 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
1420 unsigned level,
unsigned long idx0,
1422 const unsigned* thisCorner,
1423 const unsigned* range,
1424 const unsigned* otherCorner,
1426 Functor binaryFunct)
1428 const unsigned imax = range[
level];
1429 const unsigned rightShift = otherCorner[
level];
1432 if (level ==
dim_ - 1)
1434 Numeric* left =
data_ + (idx0 + thisCorner[
level]);
1436 Num2* right = r.
data_ + idx1;
1438 for (
unsigned i=0;
i<imax && left<lMax; ++
i)
1439 binaryFunct(*left++, right[(
i+rightShift)%rightPeriod]);
1444 const unsigned long leftMax = idx0 +
shape_[
level]*leftStride;
1445 idx0 += thisCorner[
level]*leftStride;
1448 for (
unsigned i=0;
i<imax && idx0 < leftMax; ++
i, idx0+=leftStride)
1451 idx1+((
i+rightShift)%rightPeriod)*rightStride,
1452 thisCorner, range, otherCorner, r, binaryFunct);
1456 template<
typename Numeric,
unsigned Len,
unsigned Dim>
1457 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
1459 unsigned level,
unsigned long idx0,
1461 const unsigned* thisCorner,
1462 const unsigned* range,
1463 const unsigned* otherCorner,
1465 Functor binaryFunct)
1467 const unsigned imax = range[
level];
1468 const unsigned leftShift = thisCorner[
level];
1471 if (level ==
dim_ - 1)
1473 Numeric* left =
data_ + idx0;
1474 Num2* right = r.
data_ + (idx1 + otherCorner[
level]);
1477 for (
unsigned i=0;
i<imax && right<
rMax; ++
i)
1478 binaryFunct(left[(
i+leftShift)%leftPeriod], *right++);
1484 const unsigned long rightMax = idx1 + r.
shape_[
level]*rightStride;
1485 idx1 += otherCorner[
level]*rightStride;
1487 for (
unsigned i=0;
i<imax && idx1<rightMax; ++
i, idx1+=rightStride)
1489 level+1, idx0+((
i+leftShift)%leftPeriod)*leftStride,
1490 idx1, thisCorner, range, otherCorner, r, binaryFunct);
1499 template <typename Numeric,
unsigned StackLen,
unsigned StackDim>
1500 template <typename Num2,
unsigned Len2,
unsigned Dim2>
1502 unsigned long idx, const
unsigned levelPr,
unsigned long idxPr,
1504 const
unsigned* indexMap)
const 1506 Numeric
sum = Numeric();
1507 const unsigned long myStride =
strides_[indexMap[levelPr]];
1508 const unsigned imax = prior.shape_[levelPr];
1509 assert(imax ==
shape_[indexMap[levelPr]]);
1510 if (levelPr == prior.dim_ - 1)
1512 for (
unsigned i=0;
i<imax; ++
i)
1513 sum +=
data_[idx+
i*myStride]*prior.data_[idxPr++];
1517 const unsigned long priorStride = prior.strides_[levelPr];
1518 for (
unsigned i=0;
i<imax; ++
i)
1523 idxPr += priorStride;
1529 template <
typename Numeric,
unsigned StackLen,
unsigned StackDim>
1530 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
1532 const unsigned level,
unsigned long idx,
1533 const unsigned levelRes,
unsigned long idxRes,
1540 idx, 0
U, 0UL, prior, indexMap);
1542 result.
data_[idxRes] = res;
1549 bool mapped =
false;
1550 for (
unsigned i=0;
i<prior.
dim_; ++
i)
1551 if (level == indexMap[
i])
1558 prior, indexMap, result);
1563 const unsigned long resStride = result.
strides_[levelRes];
1564 for (
unsigned i=0; i<imax; ++
i)
1567 prior, indexMap, result);
1569 idxRes += resStride;
1575 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
1576 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
1580 const unsigned* indexMap,
const unsigned mapLen)
const 1583 "Initialize npstat::ArrayND before calling method \"marginalize\"");
1585 "In npstat::ArrayND::marginalize: incompatible argument array rank");
1586 const unsigned resultDim =
dim_ - prior.
dim_;
1590 "In npstat::ArrayND::marginalize: incompatible index map length");
1592 for (
unsigned i=0;
i<mapLen; ++
i)
1594 const unsigned thisInd = indexMap[
i];
1596 "In npstat::ArrayND::marginalize: " 1597 "incompatible argument array dimensions");
1599 "In npstat::ArrayND::marginalize: index map entry out of range");
1600 for (
unsigned j=0; j<
i; ++j)
1602 "In npstat::ArrayND::marginalize: " 1603 "duplicate entry in the index map");
1608 newShape.reserve(resultDim);
1609 for (
unsigned i=0;
i<
dim_; ++
i)
1611 bool mapped =
false;
1612 for (
unsigned j=0; j<mapLen; ++j)
1613 if (indexMap[j] ==
i)
1619 newShape.push_back(
shape_[
i]);
1623 assert(result.
dim_ == resultDim);
1624 bool calculated =
false;
1628 for (
unsigned i=0;
i<
dim_; ++
i)
1629 if (indexMap[
i] !=
i)
1636 Numeric
sum = Numeric();
1637 for (
unsigned long i=0;
i<
len_; ++
i)
1649 template<
typename Numeric,
unsigned Len,
unsigned Dim>
1651 const unsigned* sizes,
const unsigned dim)
1657 for (
unsigned i=0;
i<
dim_; ++
i)
1660 "In npstat::ArrayND::buildFromShapePtr: " 1661 "detected span of zero");
1665 for (
unsigned i=0;
i<
dim_; ++
i)
1684 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
1685 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
1688 const unsigned *fixedIndices,
const unsigned nFixedIndices)
1695 assert(fixedIndices);
1697 "In npstat::ArrayND slicing constructor: too many fixed indices");
1699 "In npstat::ArrayND slicing constructor: " 1700 "uninitialized argument array");
1703 for (
unsigned j=0; j<nFixedIndices; ++j)
1704 if (fixedIndices[j] >= slicedArray.
dim_)
1706 "constructor: fixed index out of range");
1711 for (
unsigned i=0;
i<slicedArray.
dim_; ++
i)
1714 for (
unsigned j=0; j<nFixedIndices; ++j)
1715 if (fixedIndices[j] ==
i)
1722 assert(idim <
dim_);
1726 assert(idim ==
dim_);
1731 for (
unsigned i=0;
i<
dim_; ++
i)
1748 new (
this)
ArrayND(slicedArray);
1752 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
1754 const unsigned *fixedIndices,
const unsigned nFixedIndices)
const 1757 "Initialize npstat::ArrayND before calling method \"sliceShape\"");
1760 assert(fixedIndices);
1761 if (nFixedIndices >
dim_)
1763 "In npstat::ArrayND::sliceShape: too many fixed indices");
1764 for (
unsigned j=0; j<nFixedIndices; ++j)
1765 if (fixedIndices[j] >=
dim_)
1767 "fixed index out of range");
1769 sh.reserve(
dim_ - nFixedIndices);
1770 for (
unsigned i=0;
i<
dim_; ++
i)
1773 for (
unsigned j=0; j<nFixedIndices; ++j)
1774 if (fixedIndices[j] ==
i)
1788 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
1789 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
1792 const unsigned *fixedIndices,
1793 const unsigned *fixedIndexValues,
1794 const unsigned nFixedIndices)
const 1796 if (!(nFixedIndices && nFixedIndices <=
dim_))
1798 "In npstat::ArrayND::verifySliceCompatibility: " 1799 "invalid number of fixed indices");
1801 "Initialize npstat::ArrayND before calling " 1802 "method \"verifySliceCompatibility\"");
1804 "In npstat::ArrayND::verifySliceCompatibility: " 1805 "uninitialized argument array");
1807 "In npstat::ArrayND::verifySliceCompatibility: " 1808 "incompatible argument array rank");
1809 assert(fixedIndices);
1810 assert(fixedIndexValues);
1812 for (
unsigned j=0; j<nFixedIndices; ++j)
1814 "In npstat::ArrayND::verifySliceCompatibility: " 1815 "fixed index out of range");
1818 unsigned long idx = 0UL;
1819 unsigned sliceDim = 0
U;
1820 for (
unsigned i=0;
i<
dim_; ++
i)
1823 for (
unsigned j=0; j<nFixedIndices; ++j)
1824 if (fixedIndices[j] ==
i)
1827 if (fixedIndexValues[j] >=
shape_[
i])
1829 "In npstat::ArrayND::verifySliceCompatibility: " 1830 "fixed index value out of range");
1838 "In npstat::ArrayND::verifySliceCompatibility: " 1839 "incompatible argument array dimensions");
1843 assert(sliceDim == slice.
dim_);
1847 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
1850 const unsigned long bufLen,
1851 const unsigned *fixedIndices,
1852 const unsigned *fixedIndexValues,
1853 const unsigned nFixedIndices,
1854 unsigned long* sliceStrides)
const 1856 if (!(nFixedIndices && nFixedIndices <=
dim_))
1858 "In npstat::ArrayND::verifyBufferSliceCompatibility: " 1859 "invalid number of fixed indices");
1861 "Initialize npstat::ArrayND before calling " 1862 "method \"verifyBufferSliceCompatibility\"");
1863 assert(fixedIndices);
1864 assert(fixedIndexValues);
1866 for (
unsigned j=0; j<nFixedIndices; ++j)
1868 "In npstat::ArrayND::verifyBufferSliceCompatibility: " 1869 "fixed index out of range");
1872 unsigned long idx = 0UL;
1873 unsigned sliceDim = 0
U;
1874 for (
unsigned i=0;
i<
dim_; ++
i)
1877 for (
unsigned j=0; j<nFixedIndices; ++j)
1878 if (fixedIndices[j] ==
i)
1881 if (fixedIndexValues[j] >=
shape_[
i])
1883 "In npstat::ArrayND::verifyBufferSliceCompatibility:" 1884 " fixed index value out of range");
1889 sliceStrides[sliceDim++] =
shape_[
i];
1891 assert(sliceDim + nFixedIndices == dim_);
1894 unsigned long expectedBufLen = 1UL;
1897 unsigned long shapeJ = sliceStrides[sliceDim - 1];
1898 sliceStrides[sliceDim - 1] = 1UL;
1899 for (
unsigned j=sliceDim - 1; j>0; --j)
1901 const unsigned long nextStride = sliceStrides[j]*shapeJ;
1902 shapeJ = sliceStrides[j - 1];
1903 sliceStrides[j - 1] = nextStride;
1905 expectedBufLen = sliceStrides[0]*shapeJ;
1907 if (expectedBufLen != bufLen)
1909 "In npstat::ArrayND::verifyBufferSliceCompatibility: " 1910 "invalid memory buffer length");
1915 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
1916 template <
typename Num2,
class Op>
1918 const unsigned level,
const unsigned long idx0,
1919 const unsigned level1,
const unsigned long idx1,
1920 Num2* sliceData,
const unsigned long* sliceStrides,
1921 const unsigned *fixedIndices,
1922 const unsigned *fixedIndexValues,
1923 const unsigned nFixedIndices,
1927 for (
unsigned j=0; j<nFixedIndices; ++j)
1928 if (fixedIndices[j] == level)
1935 sliceData, sliceStrides, fixedIndices,
1936 fixedIndexValues, nFixedIndices, fcn);
1942 if (level1 ==
dim_ - nFixedIndices - 1)
1945 Numeric* localData =
data_ + idx0;
1946 for (
unsigned i = 0;
i<imax; ++
i)
1947 fcn(localData[
i*stride], sliceData[
i]);
1951 const unsigned long stride2 = sliceStrides[level1];
1952 for (
unsigned i = 0;
i<imax; ++
i)
1954 level1+1, idx1+
i*stride2,
1955 sliceData, sliceStrides, fixedIndices,
1956 fixedIndexValues, nFixedIndices, fcn);
1961 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
1962 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
1965 const unsigned *fixedIndices,
1966 const unsigned *fixedIndexValues,
1967 const unsigned nFixedIndices,
1968 Functor binaryFunct)
1971 slice, fixedIndices, fixedIndexValues, nFixedIndices);
1974 fixedIndices, fixedIndexValues,
1975 nFixedIndices, binaryFunct);
1980 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
1981 template <
typename Num2,
class Functor>
1983 Num2* slice,
const unsigned long len,
1984 const unsigned *fixedIndices,
const unsigned *fixedIndexValues,
1985 unsigned nFixedIndices, Functor binaryFunct)
1988 if (
dim_ > CHAR_BIT*
sizeof(
unsigned long))
1990 "In npstat::ArrayND::jointMemSliceScan: " 1991 "rank of this array is too large");
1992 unsigned long sliceStrides[CHAR_BIT*
sizeof(
unsigned long)];
1994 len, fixedIndices, fixedIndexValues, nFixedIndices, sliceStrides);
1995 if (
dim_ > nFixedIndices)
1997 fixedIndices, fixedIndexValues,
1998 nFixedIndices, binaryFunct);
2000 binaryFunct(
data_[idx], *slice);
2003 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
2004 template <
typename Num2>
2006 const unsigned level,
unsigned long idx0,
2007 unsigned* currentIndex,
2009 const unsigned *projectedIndices,
2010 const unsigned nProjectedIndices)
const 2013 const unsigned idx = projectedIndices[
level];
2016 const bool last = (level == nProjectedIndices - 1);
2018 for (
unsigned i = 0;
i<imax; ++
i)
2020 currentIndex[
idx] =
i;
2025 projectedIndices, nProjectedIndices);
2030 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
2031 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
2032 typename Num3,
class Op>
2034 const unsigned level,
const unsigned long idx0,
2035 const unsigned level1,
const unsigned long idx1,
2036 unsigned* currentIndex,
2039 const unsigned *projectedIndices,
2040 const unsigned nProjectedIndices, Op
fcn)
const 2051 assert(level1 == projection->
dim_);
2054 projectedIndices, nProjectedIndices);
2055 if (projection->
dim_)
2062 bool iterated =
false;
2063 for (
unsigned j=0; j<nProjectedIndices; ++j)
2064 if (projectedIndices[j] == level)
2073 currentIndex, projection, projector,
2074 projectedIndices, nProjectedIndices, fcn);
2082 const unsigned long stride2 = projection->
strides_[level1];
2083 for (
unsigned i = 0;
i<imax; ++
i)
2087 level1+1, idx1+
i*stride2,
2088 currentIndex, projection, projector,
2089 projectedIndices, nProjectedIndices, fcn);
2095 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
2096 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
2099 const unsigned *projectedIndices,
2100 const unsigned nProjectedIndices)
const 2102 if (!(nProjectedIndices && nProjectedIndices <=
dim_))
2104 "In npstat::ArrayND::verifyProjectionCompatibility: " 2105 "invalid number of projected indices");
2107 "Initialize npstat::ArrayND before calling " 2108 "method \"verifyProjectionCompatibility\"");
2110 "In npstat::ArrayND::verifyProjectionCompatibility: " 2111 "uninitialized argument array");
2112 if (projection.
dim_ !=
dim_ - nProjectedIndices)
2114 "In npstat::ArrayND::verifyProjectionCompatibility: " 2115 "incompatible argument array rank");
2116 assert(projectedIndices);
2118 for (
unsigned j=0; j<nProjectedIndices; ++j)
2120 "In npstat::ArrayND::verifyProjectionCompatibility: " 2121 "projected index out of range");
2124 unsigned sliceDim = 0
U;
2125 for (
unsigned i=0;
i<
dim_; ++
i)
2128 for (
unsigned j=0; j<nProjectedIndices; ++j)
2129 if (projectedIndices[j] ==
i)
2138 "In npstat::ArrayND::verifyProjectionCompatibility: " 2139 "incompatible argument array dimensions");
2143 assert(sliceDim == projection.
dim_);
2146 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
2147 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
typename Num3>
2151 const unsigned *projectedIndices,
2152 const unsigned nProjectedIndices)
const 2157 unsigned ibuf[StackDim];
2159 for (
unsigned i=0;
i<
dim_; ++
i)
2162 projector, projectedIndices, nProjectedIndices,
2167 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
2168 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
typename Num3>
2172 const unsigned *projectedIndices,
2173 const unsigned nProjectedIndices)
const 2178 unsigned ibuf[StackDim];
2180 for (
unsigned i=0;
i<
dim_; ++
i)
2183 projector, projectedIndices, nProjectedIndices,
2188 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
2189 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
typename Num3>
2193 const unsigned *projectedIndices,
2194 const unsigned nProjectedIndices)
const 2199 unsigned ibuf[StackDim];
2201 for (
unsigned i=0;
i<
dim_; ++
i)
2204 projector, projectedIndices, nProjectedIndices,
2209 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
2210 template <
typename Num2>
2212 const unsigned level,
const unsigned long idx0,
2214 const unsigned *projectedIndices,
2215 const unsigned nProjectedIndices)
const 2217 const unsigned idx = projectedIndices[
level];
2220 const bool last = (level == nProjectedIndices - 1);
2222 for (
unsigned i = 0;
i<imax; ++
i)
2228 projectedIndices, nProjectedIndices);
2232 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
2233 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
2234 typename Num3,
class Op>
2236 const unsigned level,
const unsigned long idx0,
2237 const unsigned level1,
const unsigned long idx1,
2240 const unsigned *projectedIndices,
2241 const unsigned nProjectedIndices, Op
fcn)
const 2245 assert(level1 == projection->
dim_);
2248 projectedIndices, nProjectedIndices);
2249 if (projection->
dim_)
2257 for (
unsigned j=0; j<nProjectedIndices; ++j)
2258 if (projectedIndices[j] == level)
2266 projection, projector,
2267 projectedIndices, nProjectedIndices, fcn);
2273 const unsigned long stride2 = projection->
strides_[level1];
2274 for (
unsigned i = 0;
i<imax; ++
i)
2276 level1+1, idx1+
i*stride2,
2277 projection, projector,
2278 projectedIndices, nProjectedIndices, fcn);
2283 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
2284 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
typename Num3>
2288 const unsigned *projectedIndices,
2289 const unsigned nProjectedIndices)
const 2295 projector, projectedIndices, nProjectedIndices,
2299 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
2300 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
typename Num3>
2304 const unsigned *projectedIndices,
2305 const unsigned nProjectedIndices)
const 2311 projector, projectedIndices, nProjectedIndices,
2315 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
2316 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
typename Num3>
2320 const unsigned *projectedIndices,
2321 const unsigned nProjectedIndices)
const 2327 projector, projectedIndices, nProjectedIndices,
2331 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
2332 template <
typename Num2,
class Functor>
2334 const unsigned level,
const unsigned long idx0,
2335 Num2&
scale,
const unsigned *projectedIndices,
2336 const unsigned nProjectedIndices, Functor binaryFunct)
2338 const unsigned idx = projectedIndices[
level];
2342 if (level == nProjectedIndices - 1)
2345 for (
unsigned i = 0;
i<imax; ++
i)
2346 binaryFunct(data[
i*stride], scale);
2349 for (
unsigned i = 0;
i<imax; ++
i)
2351 projectedIndices, nProjectedIndices,
2355 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
2356 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
2358 unsigned level,
unsigned long idx0,
2359 unsigned level1,
unsigned long idx1,
2361 const unsigned *projectedIndices,
2362 const unsigned nProjectedIndices,
2363 Functor binaryFunct)
2367 assert(level1 == slice.
dim_);
2371 nProjectedIndices, binaryFunct);
2376 for (
unsigned j=0; j<nProjectedIndices; ++j)
2377 if (projectedIndices[j] == level)
2385 projectedIndices, nProjectedIndices,
2392 const unsigned long stride2 = slice.
strides_[level1];
2393 for (
unsigned i = 0;
i<imax; ++
i)
2395 idx1+
i*stride2, slice, projectedIndices,
2396 nProjectedIndices, binaryFunct);
2401 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
2402 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
2407 "In npstat::ArrayND::jointScan: incompatible argument array shape");
2409 for (
unsigned long i=0;
i<
len_; ++
i)
2415 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
2416 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
2419 const unsigned *fixedIndices,
const unsigned nFixedIndices,
2420 Functor binaryFunct)
2425 if (slice.
dim_ == 0
U)
2426 for (
unsigned long i=0;
i<
len_; ++
i)
2430 fixedIndices, nFixedIndices, binaryFunct);
2436 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
2442 if (
dim_ != shape.size())
2446 for (
unsigned i=0;
i<
dim_; ++
i)
2451 assert(
len_ == 1UL);
2455 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
2456 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
2472 for (
unsigned i=0;
i<
dim_; ++
i)
2477 assert(
len_ == 1UL);
2481 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2482 template<
typename Num2,
typename Integer>
2484 const unsigned level,
unsigned long idx0,
2485 unsigned* currentIndex,
2491 long long int iminl =
static_cast<long long int>(levelRange.
min());
2492 if (iminl < 0LL) iminl = 0LL;
2493 long long int imaxl =
static_cast<long long int>(levelRange.
max());
2494 if (imaxl < 0LL) imaxl = 0LL;
2497 const unsigned imin =
static_cast<unsigned>(iminl);
2498 unsigned imax =
static_cast<unsigned>(imaxl);
2499 if (imax >
shape_[level])
2502 if (level ==
dim_ - 1)
2505 for (
unsigned i=imin;
i<imax; ++
i, ++idx0)
2514 idx0 += imin*stride;
2515 for (
unsigned i=imin;
i<imax; ++
i)
2524 template<
typename Numeric,
unsigned Len,
unsigned StackDim>
2525 template <
typename Num2,
typename Integer>
2531 "Initialize npstat::ArrayND before calling method \"processSubrange\"");
2533 "npstat::ArrayND::processSubrange method " 2534 "can not be used with array of 0 rank");
2536 "In npstat::ArrayND::processSubrange: incompatible subrange rank");
2537 unsigned ibuf[StackDim];
2539 for (
unsigned i=0;
i<
dim_; ++
i)
2545 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2546 template<
typename Num2>
2548 const Num2*
data,
const unsigned long dataLength)
2551 "Initialize npstat::ArrayND before calling method \"setData\"");
2553 "In npstat::ArrayND::setData: incompatible input data length");
2558 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2565 for (
unsigned j=
dim_ - 1; j>0; --j)
2569 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
2578 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2599 assert(
len_ == 1UL);
2605 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2606 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
2627 assert(
len_ == 1UL);
2633 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2634 template<
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
2652 for (
unsigned long i=0;
i<
len_; ++
i)
2657 assert(
len_ == 1UL);
2663 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2664 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
2666 const unsigned level,
unsigned long idx0,
2672 if (level ==
dim_ - 1)
2675 const Num2* from = r.
data_ + (idx1 + range[
level].min());
2676 for (
unsigned i=0;
i<imax; ++
i)
2677 *to++ = static_cast<Numeric>(
f(*from++));
2683 idx1 += range[
level].min()*fromstride;
2684 for (
unsigned i=0;
i<imax; ++
i)
2693 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2694 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
2702 "In npstat::ArrayND subrange constructor: invalid subrange");
2708 "In npstat::ArrayND subrange constructor: empty subrange");
2721 if (
dim_ > CHAR_BIT*
sizeof(
unsigned long))
2723 "In npstat::ArrayND subrange constructor: " 2724 "input array rank is too large");
2725 unsigned lolim[CHAR_BIT*
sizeof(
unsigned long)];
2727 unsigned toBuf[CHAR_BIT*
sizeof(
unsigned long)];
2730 0
U, 0UL, 0UL, lolim,
shape_, toBuf, *
this,
2735 assert(
len_ == 1UL);
2741 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2742 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
2751 "In npstat::ArrayND transforming subrange constructor: " 2752 "incompatible subrange");
2758 "In npstat::ArrayND transforming subrange constructor: " 2763 for (
unsigned i=0;
i<
dim_; ++
i)
2777 assert(
len_ == 1UL);
2783 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2787 const unsigned sz = sh.size();
2791 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2799 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2803 const unsigned dim = 1
U;
2804 unsigned sizes[dim];
2809 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2814 const unsigned dim = 2
U;
2815 unsigned sizes[dim];
2821 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2827 const unsigned dim = 3
U;
2828 unsigned sizes[dim];
2835 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2842 const unsigned dim = 4
U;
2843 unsigned sizes[dim];
2851 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2859 const unsigned dim = 5
U;
2860 unsigned sizes[dim];
2869 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2878 const unsigned dim = 6
U;
2879 unsigned sizes[dim];
2889 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2899 const unsigned dim = 7
U;
2900 unsigned sizes[dim];
2911 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2922 const unsigned dim = 8
U;
2923 unsigned sizes[dim];
2935 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2947 const unsigned dim = 9
U;
2948 unsigned sizes[dim];
2961 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2974 const unsigned dim = 10
U;
2975 unsigned sizes[dim];
2989 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2990 template<
typename Num1,
unsigned Len1,
unsigned Dim1,
2991 typename Num2,
unsigned Len2,
unsigned Dim2>
2993 const unsigned level,
unsigned long idx0,
2994 unsigned long idx1,
unsigned long idx2,
2999 if (level ==
dim_ - 1)
3001 for (
unsigned i=0;
i<imax; ++
i)
3006 for (
unsigned i=0;
i<imax; ++
i)
3010 if (level < a1.
dim_)
3018 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3019 template<
typename Num1,
unsigned Len1,
unsigned Dim1,
3020 typename Num2,
unsigned Len2,
unsigned Dim2>
3028 "In npstat::ArrayND outer product constructor: " 3029 "uninitialized argument array");
3036 for (
unsigned i=0;
i<
dim_; ++
i)
3051 for (
unsigned long i=0;
i<
len_; ++
i)
3054 else if (a2.
dim_ == 0)
3056 for (
unsigned long i=0;
i<
len_; ++
i)
3069 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3077 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3086 "In npstat::ArrayND assignment operator: " 3087 "uninitialized argument array");
3089 "In npstat::ArrayND assignment operator: " 3090 "incompatible argument array shape");
3106 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3107 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
3111 if ((
void*)
this == (
void*)(&r))
3116 "In npstat::ArrayND assignment operator: " 3117 "uninitialized argument array");
3119 "In npstat::ArrayND assignment operator: " 3120 "incompatible argument array shape");
3136 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3137 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
3145 "In npstat::ArrayND::assign: uninitialized argument array");
3147 "In npstat::ArrayND::assign: incompatible argument array shape");
3149 for (
unsigned long i=0;
i<
len_; ++
i)
3164 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3168 "Initialize npstat::ArrayND before calling method \"shape\"");
3172 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3176 "Initialize npstat::ArrayND before calling method \"fullRange\"");
3180 range.reserve(
dim_);
3181 for (
unsigned i=0;
i<
dim_; ++
i)
3187 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3191 "Initialize npstat::ArrayND before calling method \"isDensity\"");
3192 const Numeric zero = Numeric();
3193 bool hasPositive =
false;
3195 for (
unsigned long i=0;
i<
len_; ++
i)
3215 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3219 "Initialize npstat::ArrayND before calling method \"isZero\"");
3220 const Numeric zero = Numeric();
3223 for (
unsigned long i=0;
i<
len_; ++
i)
3233 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3235 unsigned long l,
unsigned*
idx,
const unsigned idxLen)
const 3238 "Initialize npstat::ArrayND before calling " 3239 "method \"convertLinearIndex\"");
3241 "npstat::ArrayND::convertLinearIndex method " 3242 "can not be used with array of 0 rank");
3244 "In npstat::ArrayND::convertLinearIndex: incompatible index length");
3246 "In npstat::ArrayND::convertLinearIndex: linear index out of range");
3249 for (
unsigned i=0;
i<
dim_; ++
i)
3256 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3258 const unsigned*
index,
unsigned idxLen)
const 3261 "Initialize npstat::ArrayND before calling method \"linearIndex\"");
3263 "npstat::ArrayND::linearIndex method " 3264 "can not be used with array of 0 rank");
3266 "In npstat::ArrayND::linearIndex: incompatible index length");
3269 unsigned long idx = 0UL;
3270 for (
unsigned i=0;
i<
dim_; ++
i)
3274 "In npstat::ArrayND::linearIndex: index out of range");
3280 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3282 const unsigned *
index,
const unsigned dim)
3285 "Initialize npstat::ArrayND before calling method \"value\"");
3287 "In npstat::ArrayND::value: incompatible index length");
3291 unsigned long idx = 0UL;
3292 for (
unsigned i=0;
i<
dim_; ++
i)
3300 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3302 const unsigned *
index,
const unsigned dim)
const 3305 "Initialize npstat::ArrayND before calling method \"value\"");
3307 "In npstat::ArrayND::value: incompatible index length");
3311 unsigned long idx = 0UL;
3312 for (
unsigned i=0;
i<
dim_; ++
i)
3320 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3322 const unsigned long index)
3327 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3329 const unsigned long index)
const 3334 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3336 const unsigned long index)
3340 "In npstat::ArrayND::linearValueAt: linear index out of range");
3344 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3346 const unsigned long index)
const 3350 "In npstat::ArrayND::linearValueAt: linear index out of range");
3354 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3356 const double x,
const unsigned idim)
const 3360 else if (x >= static_cast<double>(
shape_[idim] - 1))
3363 return static_cast<unsigned>(std::floor(x + 0.5));
3366 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3368 const double *x,
const unsigned dim)
const 3371 "Initialize npstat::ArrayND before calling method \"closest\"");
3373 "In npstat::ArrayND::closest: incompatible data length");
3377 unsigned long idx = 0UL;
3378 for (
unsigned i=0;
i<
dim_; ++
i)
3386 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3388 const double *x,
const unsigned dim)
3391 "Initialize npstat::ArrayND before calling method \"closest\"");
3393 "In npstat::ArrayND::closest: incompatible data length");
3397 unsigned long idx = 0UL;
3398 for (
unsigned i=0;
i<
dim_; ++
i)
3406 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3408 const unsigned *
index,
const unsigned dim)
const 3411 "Initialize npstat::ArrayND before calling method \"valueAt\"");
3413 "In npstat::ArrayND::valueAt: incompatible index length");
3417 unsigned long idx = 0UL;
3418 for (
unsigned i=0;
i<
dim_; ++
i)
3421 "In npstat::ArrayND::valueAt: index out of range");
3430 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3432 const unsigned *
index,
const unsigned dim)
3435 "Initialize npstat::ArrayND before calling method \"valueAt\"");
3437 "In npstat::ArrayND::valueAt: incompatible index length");
3441 unsigned long idx = 0UL;
3442 for (
unsigned i=0;
i<
dim_; ++
i)
3445 "In npstat::ArrayND::valueAt: index out of range");
3454 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3458 "Initialize npstat::ArrayND before calling method \"operator()\"");
3460 "In npstat::ArrayND::operator(): wrong # of args (not rank 0 array)");
3464 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3468 "Initialize npstat::ArrayND before calling method \"operator()\"");
3470 "In npstat::ArrayND::operator(): wrong # of args (not rank 0 array)");
3474 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3479 "In npstat::ArrayND::operator(): wrong # of args (not rank 1 array)");
3483 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3485 const unsigned i)
const 3488 "In npstat::ArrayND::operator(): wrong # of args (not rank 1 array)");
3492 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3496 "Initialize npstat::ArrayND before calling method \"at\"");
3498 "In npstat::ArrayND::at: wrong # of args (not rank 0 array)");
3502 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3506 "Initialize npstat::ArrayND before calling method \"at\"");
3508 "In npstat::ArrayND::at: wrong # of args (not rank 0 array)");
3512 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3514 const unsigned i0)
const 3517 "In npstat::ArrayND::at: wrong # of args (not rank 1 array)");
3519 "In npstat::ArrayND::at: index 0 out of range (rank 1)");
3523 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3528 "In npstat::ArrayND::at: wrong # of args (not rank 1 array)");
3530 "In npstat::ArrayND::at: index 0 out of range (rank 1)");
3534 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3540 "In npstat::ArrayND::operator(): wrong # of args (not rank 2 array)");
3544 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3547 const unsigned i1)
const 3550 "In npstat::ArrayND::operator(): wrong # of args (not rank 2 array)");
3554 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3557 const unsigned i1)
const 3560 "In npstat::ArrayND::at: wrong # of args (not rank 2 array)");
3562 "In npstat::ArrayND::at: index 0 out of range (rank 2)");
3564 "In npstat::ArrayND::at: index 1 out of range (rank 2)");
3568 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3574 "In npstat::ArrayND::at: wrong # of args (not rank 2 array)");
3576 "In npstat::ArrayND::at: index 0 out of range (rank 2)");
3578 "In npstat::ArrayND::at: index 1 out of range (rank 2)");
3582 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3586 const unsigned i2)
const 3589 "In npstat::ArrayND::operator(): wrong # of args (not rank 3 array)");
3593 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3598 const unsigned i3)
const 3601 "In npstat::ArrayND::operator(): wrong # of args (not rank 4 array)");
3605 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3611 const unsigned i4)
const 3614 "In npstat::ArrayND::operator(): wrong # of args (not rank 5 array)");
3619 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3626 const unsigned i5)
const 3629 "In npstat::ArrayND::operator(): wrong # of args (not rank 6 array)");
3634 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3642 const unsigned i6)
const 3645 "In npstat::ArrayND::operator(): wrong # of args (not rank 7 array)");
3650 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3659 const unsigned i7)
const 3662 "In npstat::ArrayND::operator(): wrong # of args (not rank 8 array)");
3668 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3678 const unsigned i8)
const 3681 "In npstat::ArrayND::operator(): wrong # of args (not rank 9 array)");
3687 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3698 const unsigned i9)
const 3701 "In npstat::ArrayND::operator(): wrong # of args (not rank 10 array)");
3707 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3714 "In npstat::ArrayND::operator(): wrong # of args (not rank 3 array)");
3718 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3726 "In npstat::ArrayND::operator(): wrong # of args (not rank 4 array)");
3730 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3739 "In npstat::ArrayND::operator(): wrong # of args (not rank 5 array)");
3744 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3754 "In npstat::ArrayND::operator(): wrong # of args (not rank 6 array)");
3759 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3770 "In npstat::ArrayND::operator(): wrong # of args (not rank 7 array)");
3775 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3787 "In npstat::ArrayND::operator(): wrong # of args (not rank 8 array)");
3793 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3806 "In npstat::ArrayND::operator(): wrong # of args (not rank 9 array)");
3812 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3826 "In npstat::ArrayND::operator(): wrong # of args (not rank 10 array)");
3832 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3836 const unsigned i2)
const 3839 "In npstat::ArrayND::at: wrong # of args (not rank 3 array)");
3841 "In npstat::ArrayND::at: index 0 out of range (rank 3)");
3843 "In npstat::ArrayND::at: index 1 out of range (rank 3)");
3845 "In npstat::ArrayND::at: index 2 out of range (rank 3)");
3849 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3854 const unsigned i3)
const 3857 "In npstat::ArrayND::at: wrong # of args (not rank 4 array)");
3859 "In npstat::ArrayND::at: index 0 out of range (rank 4)");
3861 "In npstat::ArrayND::at: index 1 out of range (rank 4)");
3863 "In npstat::ArrayND::at: index 2 out of range (rank 4)");
3865 "In npstat::ArrayND::at: index 3 out of range (rank 4)");
3869 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3875 const unsigned i4)
const 3878 "In npstat::ArrayND::at: wrong # of args (not rank 5 array)");
3880 "In npstat::ArrayND::at: index 0 out of range (rank 5)");
3882 "In npstat::ArrayND::at: index 1 out of range (rank 5)");
3884 "In npstat::ArrayND::at: index 2 out of range (rank 5)");
3886 "In npstat::ArrayND::at: index 3 out of range (rank 5)");
3888 "In npstat::ArrayND::at: index 4 out of range (rank 5)");
3893 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3900 const unsigned i5)
const 3903 "In npstat::ArrayND::at: wrong # of args (not rank 6 array)");
3905 "In npstat::ArrayND::at: index 0 out of range (rank 6)");
3907 "In npstat::ArrayND::at: index 1 out of range (rank 6)");
3909 "In npstat::ArrayND::at: index 2 out of range (rank 6)");
3911 "In npstat::ArrayND::at: index 3 out of range (rank 6)");
3913 "In npstat::ArrayND::at: index 4 out of range (rank 6)");
3915 "In npstat::ArrayND::at: index 5 out of range (rank 6)");
3920 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3928 const unsigned i6)
const 3931 "In npstat::ArrayND::at: wrong # of args (not rank 7 array)");
3933 "In npstat::ArrayND::at: index 0 out of range (rank 7)");
3935 "In npstat::ArrayND::at: index 1 out of range (rank 7)");
3937 "In npstat::ArrayND::at: index 2 out of range (rank 7)");
3939 "In npstat::ArrayND::at: index 3 out of range (rank 7)");
3941 "In npstat::ArrayND::at: index 4 out of range (rank 7)");
3943 "In npstat::ArrayND::at: index 5 out of range (rank 7)");
3945 "In npstat::ArrayND::at: index 6 out of range (rank 7)");
3950 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3959 const unsigned i7)
const 3962 "In npstat::ArrayND::at: wrong # of args (not rank 8 array)");
3964 "In npstat::ArrayND::at: index 0 out of range (rank 8)");
3966 "In npstat::ArrayND::at: index 1 out of range (rank 8)");
3968 "In npstat::ArrayND::at: index 2 out of range (rank 8)");
3970 "In npstat::ArrayND::at: index 3 out of range (rank 8)");
3972 "In npstat::ArrayND::at: index 4 out of range (rank 8)");
3974 "In npstat::ArrayND::at: index 5 out of range (rank 8)");
3976 "In npstat::ArrayND::at: index 6 out of range (rank 8)");
3978 "In npstat::ArrayND::at: index 7 out of range (rank 8)");
3984 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3994 const unsigned i8)
const 3997 "In npstat::ArrayND::at: wrong # of args (not rank 9 array)");
3999 "In npstat::ArrayND::at: index 0 out of range (rank 9)");
4001 "In npstat::ArrayND::at: index 1 out of range (rank 9)");
4003 "In npstat::ArrayND::at: index 2 out of range (rank 9)");
4005 "In npstat::ArrayND::at: index 3 out of range (rank 9)");
4007 "In npstat::ArrayND::at: index 4 out of range (rank 9)");
4009 "In npstat::ArrayND::at: index 5 out of range (rank 9)");
4011 "In npstat::ArrayND::at: index 6 out of range (rank 9)");
4013 "In npstat::ArrayND::at: index 7 out of range (rank 9)");
4015 "In npstat::ArrayND::at: index 8 out of range (rank 9)");
4021 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4032 const unsigned i9)
const 4035 "In npstat::ArrayND::at: wrong # of args (not rank 10 array)");
4037 "In npstat::ArrayND::at: index 0 out of range (rank 10)");
4039 "In npstat::ArrayND::at: index 1 out of range (rank 10)");
4041 "In npstat::ArrayND::at: index 2 out of range (rank 10)");
4043 "In npstat::ArrayND::at: index 3 out of range (rank 10)");
4045 "In npstat::ArrayND::at: index 4 out of range (rank 10)");
4047 "In npstat::ArrayND::at: index 5 out of range (rank 10)");
4049 "In npstat::ArrayND::at: index 6 out of range (rank 10)");
4051 "In npstat::ArrayND::at: index 7 out of range (rank 10)");
4053 "In npstat::ArrayND::at: index 8 out of range (rank 10)");
4055 "In npstat::ArrayND::at: index 9 out of range (rank 10)");
4061 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4068 "In npstat::ArrayND::at: wrong # of args (not rank 3 array)");
4070 "In npstat::ArrayND::at: index 0 out of range (rank 3)");
4072 "In npstat::ArrayND::at: index 1 out of range (rank 3)");
4074 "In npstat::ArrayND::at: index 2 out of range (rank 3)");
4078 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4086 "In npstat::ArrayND::at: wrong # of args (not rank 4 array)");
4088 "In npstat::ArrayND::at: index 0 out of range (rank 4)");
4090 "In npstat::ArrayND::at: index 1 out of range (rank 4)");
4092 "In npstat::ArrayND::at: index 2 out of range (rank 4)");
4094 "In npstat::ArrayND::at: index 3 out of range (rank 4)");
4098 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4107 "In npstat::ArrayND::at: wrong # of args (not rank 5 array)");
4109 "In npstat::ArrayND::at: index 0 out of range (rank 5)");
4111 "In npstat::ArrayND::at: index 1 out of range (rank 5)");
4113 "In npstat::ArrayND::at: index 2 out of range (rank 5)");
4115 "In npstat::ArrayND::at: index 3 out of range (rank 5)");
4117 "In npstat::ArrayND::at: index 4 out of range (rank 5)");
4122 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4132 "In npstat::ArrayND::at: wrong # of args (not rank 6 array)");
4134 "In npstat::ArrayND::at: index 0 out of range (rank 6)");
4136 "In npstat::ArrayND::at: index 1 out of range (rank 6)");
4138 "In npstat::ArrayND::at: index 2 out of range (rank 6)");
4140 "In npstat::ArrayND::at: index 3 out of range (rank 6)");
4142 "In npstat::ArrayND::at: index 4 out of range (rank 6)");
4144 "In npstat::ArrayND::at: index 5 out of range (rank 6)");
4149 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4160 "In npstat::ArrayND::at: wrong # of args (not rank 7 array)");
4162 "In npstat::ArrayND::at: index 0 out of range (rank 7)");
4164 "In npstat::ArrayND::at: index 1 out of range (rank 7)");
4166 "In npstat::ArrayND::at: index 2 out of range (rank 7)");
4168 "In npstat::ArrayND::at: index 3 out of range (rank 7)");
4170 "In npstat::ArrayND::at: index 4 out of range (rank 7)");
4172 "In npstat::ArrayND::at: index 5 out of range (rank 7)");
4174 "In npstat::ArrayND::at: index 6 out of range (rank 7)");
4179 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4191 "In npstat::ArrayND::at: wrong # of args (not rank 8 array)");
4193 "In npstat::ArrayND::at: index 0 out of range (rank 8)");
4195 "In npstat::ArrayND::at: index 1 out of range (rank 8)");
4197 "In npstat::ArrayND::at: index 2 out of range (rank 8)");
4199 "In npstat::ArrayND::at: index 3 out of range (rank 8)");
4201 "In npstat::ArrayND::at: index 4 out of range (rank 8)");
4203 "In npstat::ArrayND::at: index 5 out of range (rank 8)");
4205 "In npstat::ArrayND::at: index 6 out of range (rank 8)");
4207 "In npstat::ArrayND::at: index 7 out of range (rank 8)");
4213 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4226 "In npstat::ArrayND::at: wrong # of args (not rank 9 array)");
4228 "In npstat::ArrayND::at: index 0 out of range (rank 9)");
4230 "In npstat::ArrayND::at: index 1 out of range (rank 9)");
4232 "In npstat::ArrayND::at: index 2 out of range (rank 9)");
4234 "In npstat::ArrayND::at: index 3 out of range (rank 9)");
4236 "In npstat::ArrayND::at: index 4 out of range (rank 9)");
4238 "In npstat::ArrayND::at: index 5 out of range (rank 9)");
4240 "In npstat::ArrayND::at: index 6 out of range (rank 9)");
4242 "In npstat::ArrayND::at: index 7 out of range (rank 9)");
4244 "In npstat::ArrayND::at: index 8 out of range (rank 9)");
4250 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4264 "In npstat::ArrayND::at: wrong # of args (not rank 10 array)");
4266 "In npstat::ArrayND::at: index 0 out of range (rank 10)");
4268 "In npstat::ArrayND::at: index 1 out of range (rank 10)");
4270 "In npstat::ArrayND::at: index 2 out of range (rank 10)");
4272 "In npstat::ArrayND::at: index 3 out of range (rank 10)");
4274 "In npstat::ArrayND::at: index 4 out of range (rank 10)");
4276 "In npstat::ArrayND::at: index 5 out of range (rank 10)");
4278 "In npstat::ArrayND::at: index 6 out of range (rank 10)");
4280 "In npstat::ArrayND::at: index 7 out of range (rank 10)");
4282 "In npstat::ArrayND::at: index 8 out of range (rank 10)");
4284 "In npstat::ArrayND::at: index 9 out of range (rank 10)");
4290 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4291 template<
unsigned Len2,
unsigned Dim2>
4296 "In npstat::ArrayND::maxAbsDifference: " 4297 "incompatible argument array shape");
4301 for (
unsigned long i=0;
i<
len_; ++
i)
4317 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4318 template<
unsigned Len2,
unsigned Dim2>
4328 for (
unsigned i=0;
i<
dim_; ++
i)
4331 for (
unsigned i=0;
i<
dim_; ++
i)
4333 for (
unsigned long j=0; j<
len_; ++j)
4339 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4340 template<
unsigned Len2,
unsigned Dim2>
4344 return !(*
this ==
r);
4347 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4348 template<
typename Num2>
4353 "Initialize npstat::ArrayND before calling method \"operator*\"");
4355 for (
unsigned long i=0;
i<
len_; ++
i)
4360 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4361 template<
typename Num2>
4366 "Initialize npstat::ArrayND before calling method \"operator/\"");
4368 "In npstat::ArrayND::operator/: division by zero");
4370 for (
unsigned long i=0;
i<
len_; ++
i)
4375 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4376 template <
unsigned Len2,
unsigned Dim2>
4382 "In npstat::ArrayND::operator+: " 4383 "incompatible argument array shape");
4385 for (
unsigned long i=0;
i<
len_; ++
i)
4390 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4391 template <
unsigned Len2,
unsigned Dim2>
4397 "In npstat::ArrayND::operator-: " 4398 "incompatible argument array shape");
4400 for (
unsigned long i=0;
i<
len_; ++
i)
4405 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4409 "Initialize npstat::ArrayND before calling method \"operator+\"");
4413 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4417 "Initialize npstat::ArrayND before calling method \"operator-\"");
4419 for (
unsigned long i=0;
i<
len_; ++
i)
4424 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4425 template <
typename Num2>
4430 "Initialize npstat::ArrayND before calling method \"operator*=\"");
4431 for (
unsigned long i=0;
i<
len_; ++
i)
4436 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4441 "Initialize npstat::ArrayND before calling method \"makeNonNegative\"");
4442 const Numeric zero = Numeric();
4445 for (
unsigned long i=0;
i<
len_; ++
i)
4455 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4457 const double tolerance,
const unsigned nCycles)
4460 "Initialize npstat::ArrayND before calling method \"makeCopulaSteps\"");
4464 "npstat::ArrayND::makeCopulaSteps method " 4465 "can not be used with array of 0 rank");
4467 const Numeric zero = Numeric();
4468 for (
unsigned long i=0;
i<
len_; ++
i)
4472 std::vector<Numeric*> axesPtrBuf(
dim_);
4473 Numeric** axes = &axesPtrBuf[0];
4474 const Numeric
one =
static_cast<Numeric
>(1);
4477 unsigned idxSum = 0;
4478 for (
unsigned i=0; i<
dim_; ++
i)
4480 std::vector<Numeric> axesBuf(idxSum);
4481 axes[0] = &axesBuf[0];
4482 for (
unsigned i=1; i<
dim_; ++
i)
4483 axes[i] = axes[i-1] +
shape_[i-1];
4486 unsigned icycle = 0;
4487 for (; icycle<nCycles; ++icycle)
4489 for (
unsigned i=0; i<idxSum; ++
i)
4493 for (
unsigned long idat=0; idat<
len_; ++idat)
4495 unsigned long l = idat;
4496 for (
unsigned i=0; i<
dim_; ++
i)
4505 bool withinTolerance =
true;
4506 Numeric totalSum = zero;
4507 for (
unsigned i=0; i<
dim_; ++
i)
4509 Numeric axisSum = zero;
4510 const unsigned amax =
shape_[
i];
4511 for (
unsigned a=0;
a<amax; ++
a)
4513 if (axes[i][
a] == zero)
4515 "In npstat::ArrayND::makeCopulaSteps: " 4516 "marginal density is zero");
4517 axisSum += axes[
i][
a];
4519 totalSum += axisSum;
4520 const Numeric axisAverage = axisSum/
static_cast<Numeric
>(amax);
4521 for (
unsigned a=0;
a<amax; ++
a)
4522 axes[i][
a] /= axisAverage;
4523 for (
unsigned a=0;
a<amax && withinTolerance; ++
a)
4526 if (adelta > tolerance)
4527 withinTolerance =
false;
4531 if (withinTolerance)
4534 const Numeric totalAverage = totalSum/
4535 static_cast<Numeric
>(
len_)/static_cast<Numeric>(dim_);
4539 for (
unsigned long idat=0; idat<
len_; ++idat)
4541 unsigned long l = idat;
4542 for (
unsigned i=0; i<
dim_; ++
i)
4548 data_[idat] /= totalAverage;
4555 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4556 template <
typename Num2>
4561 "Initialize npstat::ArrayND before calling method \"operator/=\"");
4563 "In npstat::ArrayND::operator/=: division by zero");
4564 for (
unsigned long i=0;
i<
len_; ++
i)
4569 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4570 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
4575 "In npstat::ArrayND::operator+=: " 4576 "incompatible argument array shape");
4577 for (
unsigned long i=0;
i<
len_; ++
i)
4582 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4583 template <
typename Num3,
typename Num2,
unsigned Len2,
unsigned Dim2>
4589 "In npstat::ArrayND::addmul: " 4590 "incompatible argument array shape");
4591 for (
unsigned long i=0;
i<
len_; ++
i)
4596 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4597 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
4602 "In npstat::ArrayND::operator-=: " 4603 "incompatible argument array shape");
4604 for (
unsigned long i=0;
i<
len_; ++
i)
4609 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4611 const double *coords,
const unsigned dim)
const 4614 "Initialize npstat::ArrayND before calling method \"interpolate1\"");
4616 "In npstat::ArrayND::interpolate1: incompatible coordinate length");
4619 const unsigned maxdim = CHAR_BIT*
sizeof(
unsigned long);
4622 "In npstat::ArrayND::interpolate1: array rank is too large");
4625 unsigned ix[maxdim];
4626 for (
unsigned i=0;
i<dim; ++
i)
4628 const double x = coords[
i];
4634 else if (x >= static_cast<double>(
shape_[
i] - 1))
4641 ix[
i] =
static_cast<unsigned>(std::floor(x));
4646 Numeric
sum = Numeric();
4647 const unsigned long maxcycle = 1UL << dim;
4648 for (
unsigned long icycle=0UL; icycle<maxcycle; ++icycle)
4651 unsigned long icell = 0UL;
4652 for (
unsigned i=0;
i<dim; ++
i)
4654 if (icycle & (1UL <<
i))
4674 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4676 const unsigned level,
const double* coords,
const Numeric*
base)
const 4679 const double x = coords[
level];
4681 unsigned ix, npt = 1;
4685 else if (x > static_cast<double>(npoints - 1))
4689 ix =
static_cast<unsigned>(std::floor(x));
4691 unsigned imax = ix + 3;
4692 while (imax >= npoints)
4698 npt = imax + 1 - ix;
4700 assert(npt >= 1 && npt <= 4);
4703 if (level <
dim_ - 1)
4704 for (
unsigned ipt=0; ipt<npt; ++ipt)
4706 base + (ix + ipt)*
strides_[level]);
4708 const Numeric*
const v = (level ==
dim_ - 1 ? base + ix :
fit);
4725 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4727 const double* coords,
const unsigned dim)
const 4730 "Initialize npstat::ArrayND before calling method \"interpolate3\"");
4732 "In npstat::ArrayND::interpolate3: incompatible coordinate length");
4742 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4743 template<
class Functor>
4747 "Initialize npstat::ArrayND before calling method \"apply\"");
4748 for (
unsigned long i=0;
i<
len_; ++
i)
4753 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4754 template<
class Functor>
4759 "Initialize npstat::ArrayND before calling method \"scanInPlace\"");
4760 for (
unsigned long i=0;
i<
len_; ++
i)