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;
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);
680 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
682 const unsigned *fixedIndices,
683 const unsigned *fixedIndexValues,
684 unsigned nFixedIndices)
const
687 (
const_cast<ArrayND*
>(
this))->jointSliceScan(
688 *slice, fixedIndices, fixedIndexValues, nFixedIndices,
693 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
695 const unsigned *fixedIndices,
696 const unsigned *fixedIndexValues,
697 unsigned nFixedIndices)
700 fixedIndices, fixedIndexValues, nFixedIndices,
711 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
713 const unsigned *fixedIndices,
unsigned nFixedIndices,
714 Functor binaryFunct);
720 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
722 const unsigned *fixedIndices,
723 unsigned nFixedIndices)
726 fixedIndices, nFixedIndices,
739 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
typename Num3>
742 const unsigned *projectedIndices,
743 unsigned nProjectedIndices)
const;
745 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
typename Num3>
748 const unsigned *projectedIndices,
749 unsigned nProjectedIndices)
const;
758 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
typename Num3>
761 const unsigned *projectedIndices,
762 unsigned nProjectedIndices)
const;
764 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
typename Num3>
767 const unsigned *projectedIndices,
768 unsigned nProjectedIndices)
const;
770 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
typename Num3>
773 const unsigned *projectedIndices,
774 unsigned nProjectedIndices)
const;
776 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
typename Num3>
779 const unsigned *projectedIndices,
780 unsigned nProjectedIndices)
const;
788 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
789 void rotate(
const unsigned* shifts,
unsigned lenShifts,
797 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
811 Numeric&
operator()(
unsigned i0,
unsigned i1);
812 const Numeric&
operator()(
unsigned i0,
unsigned i1)
const;
814 Numeric&
operator()(
unsigned i0,
unsigned i1,
unsigned i2);
815 const Numeric&
operator()(
unsigned i0,
unsigned i1,
unsigned i2)
const;
818 unsigned i2,
unsigned i3);
819 const Numeric&
operator()(
unsigned i0,
unsigned i1,
820 unsigned i2,
unsigned i3)
const;
823 unsigned i2,
unsigned i3,
unsigned i4);
824 const Numeric&
operator()(
unsigned i0,
unsigned i1,
825 unsigned i2,
unsigned i3,
unsigned i4)
const;
827 Numeric&
operator()(
unsigned i0,
unsigned i1,
unsigned i2,
828 unsigned i3,
unsigned i4,
unsigned i5);
829 const Numeric&
operator()(
unsigned i0,
unsigned i1,
unsigned i2,
830 unsigned i3,
unsigned i4,
unsigned i5)
const;
832 Numeric&
operator()(
unsigned i0,
unsigned i1,
unsigned i2,
833 unsigned i3,
unsigned i4,
unsigned i5,
835 const Numeric&
operator()(
unsigned i0,
unsigned i1,
unsigned i2,
836 unsigned i3,
unsigned i4,
unsigned i5,
839 Numeric&
operator()(
unsigned i0,
unsigned i1,
unsigned i2,
840 unsigned i3,
unsigned i4,
unsigned i5,
841 unsigned i6,
unsigned i7);
842 const Numeric&
operator()(
unsigned i0,
unsigned i1,
unsigned i2,
843 unsigned i3,
unsigned i4,
unsigned i5,
844 unsigned i6,
unsigned i7)
const;
846 Numeric&
operator()(
unsigned i0,
unsigned i1,
unsigned i2,
847 unsigned i3,
unsigned i4,
unsigned i5,
848 unsigned i6,
unsigned i7,
unsigned i8);
849 const Numeric&
operator()(
unsigned i0,
unsigned i1,
unsigned i2,
850 unsigned i3,
unsigned i4,
unsigned i5,
851 unsigned i6,
unsigned i7,
unsigned i8)
const;
853 Numeric&
operator()(
unsigned i0,
unsigned i1,
unsigned i2,
854 unsigned i3,
unsigned i4,
unsigned i5,
855 unsigned i6,
unsigned i7,
unsigned i8,
857 const Numeric&
operator()(
unsigned i0,
unsigned i1,
unsigned i2,
858 unsigned i3,
unsigned i4,
unsigned i5,
859 unsigned i6,
unsigned i7,
unsigned i8,
869 const Numeric&
at()
const;
871 Numeric&
at(
unsigned i0);
872 const Numeric&
at(
unsigned i0)
const;
874 Numeric&
at(
unsigned i0,
unsigned i1);
875 const Numeric&
at(
unsigned i0,
unsigned i1)
const;
877 Numeric&
at(
unsigned i0,
unsigned i1,
unsigned i2);
878 const Numeric&
at(
unsigned i0,
unsigned i1,
unsigned i2)
const;
880 Numeric&
at(
unsigned i0,
unsigned i1,
881 unsigned i2,
unsigned i3);
882 const Numeric&
at(
unsigned i0,
unsigned i1,
883 unsigned i2,
unsigned i3)
const;
885 Numeric&
at(
unsigned i0,
unsigned i1,
886 unsigned i2,
unsigned i3,
unsigned i4);
887 const Numeric&
at(
unsigned i0,
unsigned i1,
888 unsigned i2,
unsigned i3,
unsigned i4)
const;
890 Numeric&
at(
unsigned i0,
unsigned i1,
unsigned i2,
891 unsigned i3,
unsigned i4,
unsigned i5);
892 const Numeric&
at(
unsigned i0,
unsigned i1,
unsigned i2,
893 unsigned i3,
unsigned i4,
unsigned i5)
const;
895 Numeric&
at(
unsigned i0,
unsigned i1,
unsigned i2,
896 unsigned i3,
unsigned i4,
unsigned i5,
898 const Numeric&
at(
unsigned i0,
unsigned i1,
unsigned i2,
899 unsigned i3,
unsigned i4,
unsigned i5,
902 Numeric&
at(
unsigned i0,
unsigned i1,
unsigned i2,
903 unsigned i3,
unsigned i4,
unsigned i5,
904 unsigned i6,
unsigned i7);
905 const Numeric&
at(
unsigned i0,
unsigned i1,
unsigned i2,
906 unsigned i3,
unsigned i4,
unsigned i5,
907 unsigned i6,
unsigned i7)
const;
909 Numeric&
at(
unsigned i0,
unsigned i1,
unsigned i2,
910 unsigned i3,
unsigned i4,
unsigned i5,
911 unsigned i6,
unsigned i7,
unsigned i8);
912 const Numeric&
at(
unsigned i0,
unsigned i1,
unsigned i2,
913 unsigned i3,
unsigned i4,
unsigned i5,
914 unsigned i6,
unsigned i7,
unsigned i8)
const;
916 Numeric&
at(
unsigned i0,
unsigned i1,
unsigned i2,
917 unsigned i3,
unsigned i4,
unsigned i5,
918 unsigned i6,
unsigned i7,
unsigned i8,
920 const Numeric&
at(
unsigned i0,
unsigned i1,
unsigned i2,
921 unsigned i3,
unsigned i4,
unsigned i5,
922 unsigned i6,
unsigned i7,
unsigned i8,
932 const Numeric&
cl()
const;
934 Numeric&
cl(
double x0);
935 const Numeric&
cl(
double x0)
const;
937 Numeric&
cl(
double x0,
double x1);
938 const Numeric&
cl(
double x0,
double x1)
const;
940 Numeric&
cl(
double x0,
double x1,
double x2);
941 const Numeric&
cl(
double x0,
double x1,
double x2)
const;
943 Numeric&
cl(
double x0,
double x1,
944 double x2,
double x3);
945 const Numeric&
cl(
double x0,
double x1,
946 double x2,
double x3)
const;
948 Numeric&
cl(
double x0,
double x1,
949 double x2,
double x3,
double x4);
950 const Numeric&
cl(
double x0,
double x1,
951 double x2,
double x3,
double x4)
const;
953 Numeric&
cl(
double x0,
double x1,
double x2,
954 double x3,
double x4,
double x5);
955 const Numeric&
cl(
double x0,
double x1,
double x2,
956 double x3,
double x4,
double x5)
const;
958 Numeric&
cl(
double x0,
double x1,
double x2,
959 double x3,
double x4,
double x5,
961 const Numeric&
cl(
double x0,
double x1,
double x2,
962 double x3,
double x4,
double x5,
965 Numeric&
cl(
double x0,
double x1,
double x2,
966 double x3,
double x4,
double x5,
967 double x6,
double x7);
968 const Numeric&
cl(
double x0,
double x1,
double x2,
969 double x3,
double x4,
double x5,
970 double x6,
double x7)
const;
972 Numeric&
cl(
double x0,
double x1,
double x2,
973 double x3,
double x4,
double x5,
974 double x6,
double x7,
double x8);
975 const Numeric&
cl(
double x0,
double x1,
double x2,
976 double x3,
double x4,
double x5,
977 double x6,
double x7,
double x8)
const;
979 Numeric&
cl(
double x0,
double x1,
double x2,
980 double x3,
double x4,
double x5,
981 double x6,
double x7,
double x8,
983 const Numeric&
cl(
double x0,
double x1,
double x2,
984 double x3,
double x4,
double x5,
985 double x6,
double x7,
double x8,
991 inline gs::ClassId
classId()
const {
return gs::ClassId(*
this);}
992 bool write(std::ostream& of)
const;
997 static void restore(
const gs::ClassId&
id, std::istream&
in,
1023 const double* coeffs);
1026 template <
class Functor>
1028 Functor
f,
unsigned* farg);
1032 const Numeric*
base)
const;
1035 template <
typename Num1,
unsigned Len1,
unsigned Dim1,
1036 typename Num2,
unsigned Len2,
unsigned Dim2>
1038 unsigned long idx1,
unsigned long idx2,
1043 void contractLoop(
unsigned thisLevel,
unsigned resLevel,
1044 unsigned pos1,
unsigned pos2,
1045 unsigned long idxThis,
unsigned long idxRes,
1050 unsigned long idxThis,
unsigned long idxRes,
1054 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
1056 unsigned long idx1,
unsigned long idx2,
1061 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
1063 unsigned levelPr,
unsigned long idxPr,
1065 const unsigned* indexMap)
const;
1066 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
1068 unsigned levelRes,
unsigned long idxRes,
1070 const unsigned* indexMap,
ArrayND& res)
const;
1074 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
1083 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
1086 const unsigned* thisCorner,
1087 const unsigned* range,
1088 const unsigned* otherCorner,
1090 Functor binaryFunct);
1094 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
1097 const unsigned* thisCorner,
1098 const unsigned* range,
1099 const unsigned* otherCorner,
1101 Functor binaryFunct);
1107 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
1110 const unsigned* thisCorner,
1111 const unsigned* range,
1112 const unsigned* otherCorner,
1114 Functor binaryFunct);
1119 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
1122 const unsigned* thisCorner,
1123 const unsigned* range,
1124 const unsigned* otherCorner,
1126 Functor binaryFunct);
1129 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
1132 const unsigned *fixedIndices,
1133 const unsigned *fixedIndexValues,
1134 unsigned nFixedIndices)
const;
1137 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
1139 unsigned level1,
unsigned long idx1,
1141 const unsigned *fixedIndices,
1142 const unsigned *fixedIndexValues,
1143 unsigned nFixedIndices, Functor binaryFunctor);
1146 template <
typename Num2,
class Functor>
1149 const unsigned* projectedIndices,
1150 unsigned nProjectedIndices,
1151 Functor binaryFunct);
1153 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
1155 unsigned level1,
unsigned long idx1,
1157 const unsigned *fixedIndices,
1158 unsigned nFixedIndices,
1159 Functor binaryFunct);
1162 template <
typename Num2>
1164 unsigned* currentIndex,
1166 const unsigned* projectedIndices,
1167 unsigned nProjectedIndices)
const;
1169 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
1170 typename Num3,
class Op>
1172 unsigned level1,
unsigned long idx1,
1173 unsigned* currentIndex,
1176 const unsigned* projectedIndices,
1177 unsigned nProjectedIndices, Op
fcn)
const;
1189 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
1190 typename Num3,
class Op>
1192 unsigned level1,
unsigned long idx1,
1195 const unsigned* projectedIndices,
1196 unsigned nProjectedIndices, Op
fcn)
const;
1198 template <
typename Num2>
1201 const unsigned* projectedIndices,
1202 unsigned nProjectedIndices)
const;
1204 template <
typename Num2,
typename Integer>
1206 unsigned* currentIndex,
1211 template <
typename Accumulator>
1213 const unsigned*
limit)
const;
1216 template <
typename Accumulator>
1219 unsigned long idxSlice,
1220 bool useTrapezoids);
1224 unsigned coordToIndex(
double coord,
unsigned idim)
const;
1227 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
1230 const unsigned *projectedIndices,
1231 unsigned nProjectedIndices)
const;
1238 #include <algorithm>
1242 #include "Alignment/Geners/interface/GenericIO.hh"
1243 #include "Alignment/Geners/interface/IOIsUnsigned.hh"
1252 #define me_macro_check_loop_prerequisites(METHOD, INNERLOOP) \
1253 template<typename Numeric, unsigned Len, unsigned Dim> \
1254 template <typename Num2, unsigned Len2, unsigned Dim2, class Functor> \
1255 void ArrayND<Numeric,Len,Dim>:: METHOD ( \
1256 ArrayND<Num2, Len2, Dim2>& other, \
1257 const unsigned* thisCorner, \
1258 const unsigned* range, \
1259 const unsigned* otherCorner, \
1260 const unsigned arrLen, \
1261 Functor binaryFunct) \
1263 if (!shapeIsKnown_) throw npstat::NpstatInvalidArgument( \
1264 "Initialize npstat::ArrayND before calling method \"" \
1266 if (!other.shapeIsKnown_) throw npstat::NpstatInvalidArgument( \
1267 "In npstat::ArrayND::" #METHOD ": uninitialized argument array");\
1268 if (dim_ != other.dim_) throw npstat::NpstatInvalidArgument( \
1269 "In npstat::ArrayND::" #METHOD ": incompatible argument array rank");\
1270 if (arrLen != dim_) throw npstat::NpstatInvalidArgument( \
1271 "In npstat::ArrayND::" #METHOD ": incompatible index length"); \
1274 assert(thisCorner); \
1276 assert(otherCorner); \
1277 INNERLOOP (0U, 0UL, 0UL, thisCorner, range, \
1278 otherCorner, other, binaryFunct); \
1281 binaryFunct(localData_[0], other.localData_[0]); \
1285 template<
typename Numeric,
unsigned Len,
unsigned Dim>
1286 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
1288 unsigned level,
unsigned long idx0,
1290 const unsigned* thisCorner,
1291 const unsigned* range,
1292 const unsigned* otherCorner,
1294 Functor binaryFunct)
1296 const unsigned imax = range[
level];
1298 if (level == dim_ - 1)
1300 Numeric* left = data_ + (idx0 + thisCorner[
level]);
1301 Numeric*
const lMax = data_ + (idx0 + shape_[
level]);
1302 Num2* right = r.
data_ + (idx1 + otherCorner[
level]);
1305 for (
unsigned i=0;
i<imax && left<lMax && right<rMax; ++
i)
1306 binaryFunct(*left++, *right++);
1310 const unsigned long leftStride = strides_[
level];
1311 const unsigned long leftMax = idx0 + shape_[
level]*leftStride;
1312 idx0 += thisCorner[
level]*leftStride;
1314 const unsigned long rightMax = idx1 + r.
shape_[
level]*rightStride;
1315 idx1 += otherCorner[
level]*rightStride;
1317 for (
unsigned i=0;
i<imax && idx0 < leftMax && idx1 < rightMax;
1318 ++
i, idx0 += leftStride, idx1 += rightStride)
1319 commonSubrangeLoop(level+1, idx0, idx1, thisCorner, range,
1320 otherCorner, r, binaryFunct);
1324 template<
typename Numeric,
unsigned Len,
unsigned Dim>
1325 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
1327 unsigned level,
unsigned long idx0,
1329 const unsigned* thisCorner,
1330 const unsigned* range,
1331 const unsigned* otherCorner,
1333 Functor binaryFunct)
1335 const unsigned imax = range[
level];
1336 const unsigned leftShift = thisCorner[
level];
1337 const unsigned leftPeriod = shape_[
level];
1338 const unsigned rightShift = otherCorner[
level];
1341 if (level == dim_ - 1)
1343 Numeric* left = data_ + idx0;
1344 Num2* right = r.
data_ + idx1;
1345 for (
unsigned i=0;
i<imax; ++
i)
1346 binaryFunct(left[(
i+leftShift)%leftPeriod],
1347 right[(
i+rightShift)%rightPeriod]);
1351 const unsigned long leftStride = strides_[
level];
1353 for (
unsigned i=0;
i<imax; ++
i)
1355 level+1, idx0+((
i+leftShift)%leftPeriod)*leftStride,
1356 idx1+((
i+rightShift)%rightPeriod)*rightStride,
1357 thisCorner, range, otherCorner, r, binaryFunct);
1361 template<
typename Numeric,
unsigned Len,
unsigned Dim>
1362 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
1364 unsigned level,
unsigned long idx0,
1366 const unsigned* thisCorner,
1367 const unsigned* range,
1368 const unsigned* otherCorner,
1370 Functor binaryFunct)
1372 const unsigned imax = range[
level];
1373 const unsigned rightShift = otherCorner[
level];
1376 if (level == dim_ - 1)
1378 Numeric* left = data_ + (idx0 + thisCorner[
level]);
1379 Numeric*
const lMax = data_ + (idx0 + shape_[
level]);
1380 Num2* right = r.
data_ + idx1;
1382 for (
unsigned i=0;
i<imax && left<lMax; ++
i)
1383 binaryFunct(*left++, right[(
i+rightShift)%rightPeriod]);
1387 const unsigned long leftStride = strides_[
level];
1388 const unsigned long leftMax = idx0 + shape_[
level]*leftStride;
1389 idx0 += thisCorner[
level]*leftStride;
1392 for (
unsigned i=0;
i<imax && idx0 < leftMax; ++
i, idx0+=leftStride)
1395 idx1+((
i+rightShift)%rightPeriod)*rightStride,
1396 thisCorner, range, otherCorner, r, binaryFunct);
1400 template<
typename Numeric,
unsigned Len,
unsigned Dim>
1401 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
1403 unsigned level,
unsigned long idx0,
1405 const unsigned* thisCorner,
1406 const unsigned* range,
1407 const unsigned* otherCorner,
1409 Functor binaryFunct)
1411 const unsigned imax = range[
level];
1412 const unsigned leftShift = thisCorner[
level];
1413 const unsigned leftPeriod = shape_[
level];
1415 if (level == dim_ - 1)
1417 Numeric* left = data_ + idx0;
1418 Num2* right = r.
data_ + (idx1 + otherCorner[
level]);
1421 for (
unsigned i=0;
i<imax && right<rMax; ++
i)
1422 binaryFunct(left[(
i+leftShift)%leftPeriod], *right++);
1426 const unsigned long leftStride = strides_[
level];
1428 const unsigned long rightMax = idx1 + r.
shape_[
level]*rightStride;
1429 idx1 += otherCorner[
level]*rightStride;
1431 for (
unsigned i=0;
i<imax && idx1<rightMax; ++
i, idx1+=rightStride)
1433 level+1, idx0+((
i+leftShift)%leftPeriod)*leftStride,
1434 idx1, thisCorner, range, otherCorner, r, binaryFunct);
1443 template <typename Numeric,
unsigned StackLen,
unsigned StackDim>
1444 template <typename Num2,
unsigned Len2,
unsigned Dim2>
1445 Numeric
ArrayND<Numeric,StackLen,StackDim>::marginalizeInnerLoop(
1446 unsigned long idx,
const unsigned levelPr,
unsigned long idxPr,
1448 const unsigned* indexMap)
const
1450 Numeric sum = Numeric();
1451 const unsigned long myStride = strides_[indexMap[levelPr]];
1452 const unsigned imax = prior.shape_[levelPr];
1453 assert(imax == shape_[indexMap[levelPr]]);
1454 if (levelPr == prior.dim_ - 1)
1456 for (
unsigned i=0;
i<imax; ++
i)
1457 sum += data_[idx+
i*myStride]*prior.data_[idxPr++];
1461 const unsigned long priorStride = prior.strides_[levelPr];
1462 for (
unsigned i=0;
i<imax; ++
i)
1464 sum += marginalizeInnerLoop(idx, levelPr+1U, idxPr,
1467 idxPr += priorStride;
1473 template <
typename Numeric,
unsigned StackLen,
unsigned StackDim>
1474 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
1476 const unsigned level,
unsigned long idx,
1477 const unsigned levelRes,
unsigned long idxRes,
1483 const Numeric res = marginalizeInnerLoop(
1484 idx, 0U, 0UL, prior, indexMap);
1486 result.
data_[idxRes] = res;
1494 for (
unsigned i=0;
i<prior.
dim_; ++
i)
1495 if (level == indexMap[
i])
1501 marginalizeLoop(level+1U, idx, levelRes, idxRes,
1502 prior, indexMap, result);
1505 const unsigned imax = shape_[
level];
1506 const unsigned long myStride = strides_[
level];
1507 const unsigned long resStride = result.
strides_[levelRes];
1508 for (
unsigned i=0; i<imax; ++
i)
1510 marginalizeLoop(level+1U, idx, levelRes+1U, idxRes,
1511 prior, indexMap, result);
1513 idxRes += resStride;
1519 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
1520 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
1524 const unsigned* indexMap,
const unsigned mapLen)
const
1527 "Initialize npstat::ArrayND before calling method \"marginalize\"");
1529 "In npstat::ArrayND::marginalize: incompatible argument array rank");
1530 const unsigned resultDim = dim_ - prior.
dim_;
1534 "In npstat::ArrayND::marginalize: incompatible index map length");
1536 for (
unsigned i=0;
i<mapLen; ++
i)
1538 const unsigned thisInd = indexMap[
i];
1540 "In npstat::ArrayND::marginalize: "
1541 "incompatible argument array dimensions");
1543 "In npstat::ArrayND::marginalize: index map entry out of range");
1544 for (
unsigned j=0;
j<
i; ++
j)
1546 "In npstat::ArrayND::marginalize: "
1547 "duplicate entry in the index map");
1552 newShape.reserve(resultDim);
1553 for (
unsigned i=0;
i<dim_; ++
i)
1556 for (
unsigned j=0;
j<mapLen; ++
j)
1557 if (indexMap[
j] ==
i)
1563 newShape.push_back(shape_[
i]);
1567 assert(result.
dim_ == resultDim);
1568 bool calculated =
false;
1572 for (
unsigned i=0;
i<dim_; ++
i)
1573 if (indexMap[
i] !=
i)
1580 Numeric sum = Numeric();
1581 for (
unsigned long i=0;
i<len_; ++
i)
1582 sum += data_[
i]*prior.
data_[
i];
1588 marginalizeLoop(0U, 0UL, 0U, 0UL, prior, indexMap, result);
1593 template<
typename Numeric,
unsigned Len,
unsigned Dim>
1595 const unsigned* sizes,
const unsigned dim)
1601 for (
unsigned i=0;
i<dim_; ++
i)
1604 "In npstat::ArrayND::buildFromShapePtr: "
1605 "detected span of zero");
1609 for (
unsigned i=0;
i<dim_; ++
i)
1611 shape_[
i] = sizes[
i];
1623 localData_[0] = Numeric();
1628 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
1629 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
1632 const unsigned *fixedIndices,
const unsigned nFixedIndices)
1633 : data_(0), strides_(0), shape_(0),
1634 len_(1UL), dim_(slicedArray.dim_ - nFixedIndices),
1639 assert(fixedIndices);
1641 "In npstat::ArrayND slicing constructor: too many fixed indices");
1643 "In npstat::ArrayND slicing constructor: "
1644 "uninitialized argument array");
1647 for (
unsigned j=0;
j<nFixedIndices; ++
j)
1648 if (fixedIndices[
j] >= slicedArray.
dim_)
1650 "constructor: fixed index out of range");
1655 for (
unsigned i=0;
i<slicedArray.
dim_; ++
i)
1658 for (
unsigned j=0;
j<nFixedIndices; ++
j)
1659 if (fixedIndices[
j] ==
i)
1666 assert(idim <
dim_);
1670 assert(idim ==
dim_);
1675 for (
unsigned i=0;
i<
dim_; ++
i)
1692 new (
this)
ArrayND(slicedArray);
1696 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
1697 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
1700 const unsigned *fixedIndices,
1701 const unsigned *fixedIndexValues,
1702 const unsigned nFixedIndices)
const
1704 if (!(nFixedIndices && nFixedIndices <= dim_))
1706 "In npstat::ArrayND::verifySliceCompatibility: "
1707 "invalid number of fixed indices");
1709 "Initialize npstat::ArrayND before calling "
1710 "method \"verifySliceCompatibility\"");
1712 "In npstat::ArrayND::verifySliceCompatibility: "
1713 "uninitialized argument array");
1715 "In npstat::ArrayND::verifySliceCompatibility: "
1716 "incompatible argument array rank");
1717 assert(fixedIndices);
1718 assert(fixedIndexValues);
1720 for (
unsigned j=0;
j<nFixedIndices; ++
j)
1722 "In npstat::ArrayND::verifySliceCompatibility: "
1723 "fixed index out of range");
1726 unsigned long idx = 0UL;
1727 unsigned sliceDim = 0U;
1728 for (
unsigned i=0;
i<dim_; ++
i)
1731 for (
unsigned j=0;
j<nFixedIndices; ++
j)
1732 if (fixedIndices[
j] ==
i)
1735 if (fixedIndexValues[
j] >= shape_[
i])
1737 "In npstat::ArrayND::verifySliceCompatibility: "
1738 "fixed index value out of range");
1739 idx += fixedIndexValues[
j]*strides_[
i];
1744 if (shape_[
i] != slice.
shape_[sliceDim])
1746 "In npstat::ArrayND::verifySliceCompatibility: "
1747 "incompatible argument array dimensions");
1751 assert(sliceDim == slice.
dim_);
1755 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
1756 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Op>
1758 const unsigned level,
const unsigned long idx0,
1759 const unsigned level1,
const unsigned long idx1,
1761 const unsigned *fixedIndices,
1762 const unsigned *fixedIndexValues,
1763 const unsigned nFixedIndices,
1767 for (
unsigned j=0;
j<nFixedIndices; ++
j)
1768 if (fixedIndices[
j] == level)
1775 jointSliceLoop(level+1, idx0, level1, idx1,
1776 slice, fixedIndices, fixedIndexValues,
1777 nFixedIndices, fcn);
1781 const unsigned imax = shape_[
level];
1782 assert(imax == slice.
shape_[level1]);
1783 const unsigned long stride = strides_[
level];
1785 if (level1 == slice.
dim_ - 1)
1787 Num2*
to = slice.
data_ + idx1;
1788 for (
unsigned i = 0;
i<imax; ++
i)
1789 fcn(data_[idx0 +
i*stride], to[
i]);
1793 const unsigned long stride2 = slice.
strides_[level1];
1794 for (
unsigned i = 0;
i<imax; ++
i)
1795 jointSliceLoop(level+1, idx0+
i*stride,
1796 level1+1, idx1+
i*stride2,
1797 slice, fixedIndices, fixedIndexValues,
1798 nFixedIndices, fcn);
1803 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
1804 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
1807 const unsigned *fixedIndices,
1808 const unsigned *fixedIndexValues,
1809 const unsigned nFixedIndices,
1810 Functor binaryFunct)
1812 const unsigned long idx = verifySliceCompatibility(
1813 slice, fixedIndices, fixedIndexValues, nFixedIndices);
1815 jointSliceLoop(0U, idx, 0U, 0UL, slice, fixedIndices,
1816 fixedIndexValues, nFixedIndices, binaryFunct);
1818 binaryFunct(data_[idx], slice.
localData_[0]);
1821 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
1822 template <
typename Num2>
1824 const unsigned level,
unsigned long idx0,
1825 unsigned* currentIndex,
1827 const unsigned *projectedIndices,
1828 const unsigned nProjectedIndices)
const
1831 const unsigned idx = projectedIndices[
level];
1832 const unsigned imax = shape_[
idx];
1833 const unsigned long stride = strides_[
idx];
1834 const bool last = (level == nProjectedIndices - 1);
1836 for (
unsigned i = 0;
i<imax; ++
i)
1838 currentIndex[
idx] =
i;
1840 projector.
process(currentIndex, dim_, idx0, data_[idx0]);
1842 projectInnerLoop(level+1, idx0, currentIndex, projector,
1843 projectedIndices, nProjectedIndices);
1848 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
1849 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
1850 typename Num3,
class Op>
1852 const unsigned level,
const unsigned long idx0,
1853 const unsigned level1,
const unsigned long idx1,
1854 unsigned* currentIndex,
1857 const unsigned *projectedIndices,
1858 const unsigned nProjectedIndices, Op
fcn)
const
1869 assert(level1 == projection->
dim_);
1871 projectInnerLoop(0U, idx0, currentIndex, projector,
1872 projectedIndices, nProjectedIndices);
1873 if (projection->
dim_)
1880 bool iterated =
false;
1881 for (
unsigned j=0;
j<nProjectedIndices; ++
j)
1882 if (projectedIndices[
j] == level)
1890 projectLoop(level+1, idx0, level1, idx1,
1891 currentIndex, projection, projector,
1892 projectedIndices, nProjectedIndices, fcn);
1896 const unsigned imax = shape_[
level];
1897 const unsigned long stride = strides_[
level];
1900 const unsigned long stride2 = projection->
strides_[level1];
1901 for (
unsigned i = 0;
i<imax; ++
i)
1904 projectLoop(level+1, idx0+
i*stride,
1905 level1+1, idx1+
i*stride2,
1906 currentIndex, projection, projector,
1907 projectedIndices, nProjectedIndices, fcn);
1913 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
1914 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
1917 const unsigned *projectedIndices,
1918 const unsigned nProjectedIndices)
const
1920 if (!(nProjectedIndices && nProjectedIndices <= dim_))
1922 "In npstat::ArrayND::verifyProjectionCompatibility: "
1923 "invalid number of projected indices");
1925 "Initialize npstat::ArrayND before calling "
1926 "method \"verifyProjectionCompatibility\"");
1928 "In npstat::ArrayND::verifyProjectionCompatibility: "
1929 "uninitialized argument array");
1930 if (projection.
dim_ != dim_ - nProjectedIndices)
1932 "In npstat::ArrayND::verifyProjectionCompatibility: "
1933 "incompatible argument array rank");
1934 assert(projectedIndices);
1936 for (
unsigned j=0;
j<nProjectedIndices; ++
j)
1938 "In npstat::ArrayND::verifyProjectionCompatibility: "
1939 "projected index out of range");
1942 unsigned sliceDim = 0U;
1943 for (
unsigned i=0;
i<dim_; ++
i)
1946 for (
unsigned j=0;
j<nProjectedIndices; ++
j)
1947 if (projectedIndices[
j] ==
i)
1954 if (shape_[
i] != projection.
shape_[sliceDim])
1956 "In npstat::ArrayND::verifyProjectionCompatibility: "
1957 "incompatible argument array dimensions");
1961 assert(sliceDim == projection.
dim_);
1964 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
1965 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
typename Num3>
1969 const unsigned *projectedIndices,
1970 const unsigned nProjectedIndices)
const
1973 verifyProjectionCompatibility(*projection, projectedIndices,
1975 unsigned ibuf[StackDim];
1976 unsigned* buf =
makeBuffer(dim_, ibuf, StackDim);
1977 for (
unsigned i=0;
i<dim_; ++
i)
1979 projectLoop(0U, 0UL, 0U, 0UL, buf, projection,
1980 projector, projectedIndices, nProjectedIndices,
1985 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
1986 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
typename Num3>
1990 const unsigned *projectedIndices,
1991 const unsigned nProjectedIndices)
const
1994 verifyProjectionCompatibility(*projection, projectedIndices,
1996 unsigned ibuf[StackDim];
1997 unsigned* buf =
makeBuffer(dim_, ibuf, StackDim);
1998 for (
unsigned i=0;
i<dim_; ++
i)
2000 projectLoop(0U, 0UL, 0U, 0UL, buf, projection,
2001 projector, projectedIndices, nProjectedIndices,
2006 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
2007 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
typename Num3>
2011 const unsigned *projectedIndices,
2012 const unsigned nProjectedIndices)
const
2015 verifyProjectionCompatibility(*projection, projectedIndices,
2017 unsigned ibuf[StackDim];
2018 unsigned* buf =
makeBuffer(dim_, ibuf, StackDim);
2019 for (
unsigned i=0;
i<dim_; ++
i)
2021 projectLoop(0U, 0UL, 0U, 0UL, buf, projection,
2022 projector, projectedIndices, nProjectedIndices,
2027 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
2028 template <
typename Num2>
2030 const unsigned level,
const unsigned long idx0,
2032 const unsigned *projectedIndices,
2033 const unsigned nProjectedIndices)
const
2035 const unsigned idx = projectedIndices[
level];
2036 const unsigned imax = shape_[
idx];
2037 const unsigned long stride = strides_[
idx];
2038 const bool last = (level == nProjectedIndices - 1);
2040 for (
unsigned i = 0;
i<imax; ++
i)
2043 projector.
process(data_[idx0+
i*stride]);
2045 projectInnerLoop2(level+1, idx0+
i*stride, projector,
2046 projectedIndices, nProjectedIndices);
2050 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
2051 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
2052 typename Num3,
class Op>
2054 const unsigned level,
const unsigned long idx0,
2055 const unsigned level1,
const unsigned long idx1,
2058 const unsigned *projectedIndices,
2059 const unsigned nProjectedIndices, Op
fcn)
const
2063 assert(level1 == projection->
dim_);
2065 projectInnerLoop2(0U, idx0, projector,
2066 projectedIndices, nProjectedIndices);
2067 if (projection->
dim_)
2075 for (
unsigned j=0;
j<nProjectedIndices; ++
j)
2076 if (projectedIndices[
j] == level)
2083 projectLoop2(level+1, idx0, level1, idx1,
2084 projection, projector,
2085 projectedIndices, nProjectedIndices, fcn);
2089 const unsigned imax = shape_[
level];
2090 const unsigned long stride = strides_[
level];
2091 const unsigned long stride2 = projection->
strides_[level1];
2092 for (
unsigned i = 0;
i<imax; ++
i)
2093 projectLoop2(level+1, idx0+
i*stride,
2094 level1+1, idx1+
i*stride2,
2095 projection, projector,
2096 projectedIndices, nProjectedIndices, fcn);
2101 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
2102 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
typename Num3>
2106 const unsigned *projectedIndices,
2107 const unsigned nProjectedIndices)
const
2110 verifyProjectionCompatibility(*projection, projectedIndices,
2112 projectLoop2(0U, 0UL, 0U, 0UL, projection,
2113 projector, projectedIndices, nProjectedIndices,
2117 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
2118 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
typename Num3>
2122 const unsigned *projectedIndices,
2123 const unsigned nProjectedIndices)
const
2126 verifyProjectionCompatibility(*projection, projectedIndices,
2128 projectLoop2(0U, 0UL, 0U, 0UL, projection,
2129 projector, projectedIndices, nProjectedIndices,
2133 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
2134 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
typename Num3>
2138 const unsigned *projectedIndices,
2139 const unsigned nProjectedIndices)
const
2142 verifyProjectionCompatibility(*projection, projectedIndices,
2144 projectLoop2(0U, 0UL, 0U, 0UL, projection,
2145 projector, projectedIndices, nProjectedIndices,
2149 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
2150 template <
typename Num2,
class Functor>
2152 const unsigned level,
const unsigned long idx0,
2153 Num2&
scale,
const unsigned *projectedIndices,
2154 const unsigned nProjectedIndices, Functor binaryFunct)
2156 const unsigned idx = projectedIndices[
level];
2157 const unsigned imax = shape_[
idx];
2158 const unsigned long stride = strides_[
idx];
2160 if (level == nProjectedIndices - 1)
2162 Numeric*
data = data_ + idx0;
2163 for (
unsigned i = 0;
i<imax; ++
i)
2164 binaryFunct(data[
i*stride], scale);
2167 for (
unsigned i = 0;
i<imax; ++
i)
2168 scaleBySliceInnerLoop(level+1, idx0+
i*stride, scale,
2169 projectedIndices, nProjectedIndices,
2173 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
2174 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
2176 unsigned level,
unsigned long idx0,
2177 unsigned level1,
unsigned long idx1,
2179 const unsigned *projectedIndices,
2180 const unsigned nProjectedIndices,
2181 Functor binaryFunct)
2185 assert(level1 == slice.
dim_);
2186 Num2& scaleFactor = slice.
dim_ ? slice.
data_[idx1] :
2188 scaleBySliceInnerLoop(0U, idx0, scaleFactor, projectedIndices,
2189 nProjectedIndices, binaryFunct);
2194 for (
unsigned j=0;
j<nProjectedIndices; ++
j)
2195 if (projectedIndices[
j] == level)
2202 scaleBySliceLoop(level+1, idx0, level1, idx1, slice,
2203 projectedIndices, nProjectedIndices,
2208 const unsigned imax = shape_[
level];
2209 const unsigned long stride = strides_[
level];
2210 const unsigned long stride2 = slice.
strides_[level1];
2211 for (
unsigned i = 0;
i<imax; ++
i)
2212 scaleBySliceLoop(level+1, idx0+
i*stride, level1+1,
2213 idx1+
i*stride2, slice, projectedIndices,
2214 nProjectedIndices, binaryFunct);
2219 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
2220 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
2225 "In npstat::ArrayND::jointScan: incompatible argument array shape");
2227 for (
unsigned long i=0;
i<len_; ++
i)
2228 binaryFunct(data_[
i], r.
data_[i]);
2233 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
2234 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
2237 const unsigned *fixedIndices,
const unsigned nFixedIndices,
2238 Functor binaryFunct)
2242 verifyProjectionCompatibility(slice, fixedIndices, nFixedIndices);
2243 if (slice.
dim_ == 0U)
2244 for (
unsigned long i=0;
i<len_; ++
i)
2247 scaleBySliceLoop(0U, 0UL, 0U, 0UL, slice,
2248 fixedIndices, nFixedIndices, binaryFunct);
2251 jointScan(slice, binaryFunct);
2254 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
2260 if (dim_ != shape.size())
2264 for (
unsigned i=0;
i<dim_; ++
i)
2265 if (shape_[
i] != shape[
i])
2269 assert(len_ == 1UL);
2273 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
2274 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
2290 for (
unsigned i=0;
i<dim_; ++
i)
2295 assert(len_ == 1UL);
2299 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2300 template<
typename Num2,
typename Integer>
2302 const unsigned level,
unsigned long idx0,
2303 unsigned* currentIndex,
2309 long long int iminl =
static_cast<long long int>(levelRange.
min());
2310 if (iminl < 0LL) iminl = 0LL;
2311 long long int imaxl =
static_cast<long long int>(levelRange.
max());
2312 if (imaxl < 0LL) imaxl = 0LL;
2315 const unsigned imin =
static_cast<unsigned>(iminl);
2316 unsigned imax =
static_cast<unsigned>(imaxl);
2317 if (imax > shape_[level])
2318 imax = shape_[
level];
2320 if (level == dim_ - 1)
2323 for (
unsigned i=imin;
i<imax; ++
i, ++idx0)
2326 f.
process(currentIndex, dim_, idx0, data_[idx0]);
2331 const unsigned long stride = strides_[
level];
2332 idx0 += imin*stride;
2333 for (
unsigned i=imin;
i<imax; ++
i)
2336 processSubrangeLoop(level+1U, idx0, currentIndex, f, subrange);
2342 template<
typename Numeric,
unsigned Len,
unsigned StackDim>
2343 template <
typename Num2,
typename Integer>
2349 "Initialize npstat::ArrayND before calling method \"processSubrange\"");
2351 "npstat::ArrayND::processSubrange method "
2352 "can not be used with array of 0 rank");
2354 "In npstat::ArrayND::processSubrange: incompatible subrange rank");
2355 unsigned ibuf[StackDim];
2356 unsigned* buf =
makeBuffer(dim_, ibuf, StackDim);
2357 for (
unsigned i=0;
i<dim_; ++
i)
2359 processSubrangeLoop(0U, 0UL, buf, f, subrange);
2363 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2364 template<
typename Num2>
2366 const Num2*
data,
const unsigned long dataLength)
2369 "Initialize npstat::ArrayND before calling method \"setData\"");
2371 "In npstat::ArrayND::setData: incompatible input data length");
2376 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2381 strides_ =
makeBuffer(dim_, localStrides_, Dim);
2382 strides_[dim_ - 1] = 1UL;
2383 for (
unsigned j=dim_ - 1;
j>0; --
j)
2384 strides_[
j - 1] = strides_[
j]*shape_[
j];
2387 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
2389 : data_(0), strides_(0), shape_(0),
2390 len_(0UL), dim_(0U), shapeIsKnown_(
false)
2396 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2398 : data_(0), strides_(0), shape_(0),
2399 len_(r.len_), dim_(r.dim_), shapeIsKnown_(r.shapeIsKnown_)
2417 assert(
len_ == 1UL);
2423 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2424 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
2426 : data_(0), strides_(0), shape_(0),
2427 len_(r.len_), dim_(r.dim_), shapeIsKnown_(r.shapeIsKnown_)
2445 assert(
len_ == 1UL);
2451 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2452 template<
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
2455 : data_(0), strides_(0), shape_(0),
2456 len_(r.len_), dim_(r.dim_), shapeIsKnown_(r.shapeIsKnown_)
2470 for (
unsigned long i=0;
i<
len_; ++
i)
2475 assert(
len_ == 1UL);
2481 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2482 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
2484 const unsigned level,
unsigned long idx0,
2489 const unsigned imax = shape_[
level];
2490 if (level == dim_ - 1)
2492 Numeric*
to = data_ + idx0;
2493 const Num2* from = r.
data_ + (idx1 + range[
level].min());
2494 for (
unsigned i=0;
i<imax; ++
i)
2495 *to++ = static_cast<Numeric>(
f(*from++));
2500 const unsigned long tostride = strides_[
level];
2501 idx1 += range[
level].min()*fromstride;
2502 for (
unsigned i=0;
i<imax; ++
i)
2504 copyRangeLoopFunct(level+1, idx0, idx1, r, range, f);
2511 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2512 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
2515 : data_(0), strides_(0), shape_(0),
2516 len_(r.len_), dim_(r.dim_), shapeIsKnown_(r.shapeIsKnown_)
2520 "In npstat::ArrayND subrange constructor: invalid subrange");
2526 "In npstat::ArrayND subrange constructor: empty subrange");
2539 if (
dim_ > CHAR_BIT*
sizeof(
unsigned long))
2541 "In npstat::ArrayND subrange constructor: "
2542 "input array rank is too large");
2543 unsigned lolim[CHAR_BIT*
sizeof(
unsigned long)];
2545 unsigned toBuf[CHAR_BIT*
sizeof(
unsigned long)];
2548 0U, 0UL, 0UL, lolim,
shape_, toBuf, *
this,
2553 assert(
len_ == 1UL);
2559 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2560 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
2564 : data_(0), strides_(0), shape_(0),
2565 len_(r.len_), dim_(r.dim_), shapeIsKnown_(r.shapeIsKnown_)
2569 "In npstat::ArrayND transforming subrange constructor: "
2570 "incompatible subrange");
2576 "In npstat::ArrayND transforming subrange constructor: "
2581 for (
unsigned i=0;
i<
dim_; ++
i)
2595 assert(
len_ == 1UL);
2601 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2603 : data_(0), strides_(0), shape_(0), len_(1UL), shapeIsKnown_(
true)
2605 const unsigned sz = sh.size();
2609 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2612 : data_(0), strides_(0), shape_(0), len_(1UL), shapeIsKnown_(
true)
2617 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2619 : data_(0), strides_(0), shape_(0), len_(1UL), shapeIsKnown_(
true)
2621 const unsigned dim = 1U;
2622 unsigned sizes[dim];
2627 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2630 : data_(0), strides_(0), shape_(0), len_(1UL), shapeIsKnown_(
true)
2632 const unsigned dim = 2U;
2633 unsigned sizes[dim];
2639 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2643 : data_(0), strides_(0), shape_(0), len_(1UL), shapeIsKnown_(
true)
2645 const unsigned dim = 3U;
2646 unsigned sizes[dim];
2653 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2658 : data_(0), strides_(0), shape_(0), len_(1UL), shapeIsKnown_(
true)
2660 const unsigned dim = 4U;
2661 unsigned sizes[dim];
2669 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2675 : data_(0), strides_(0), shape_(0), len_(1UL), shapeIsKnown_(
true)
2677 const unsigned dim = 5U;
2678 unsigned sizes[dim];
2687 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2694 : data_(0), strides_(0), shape_(0), len_(1UL), shapeIsKnown_(
true)
2696 const unsigned dim = 6U;
2697 unsigned sizes[dim];
2707 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2715 : data_(0), strides_(0), shape_(0), len_(1UL), shapeIsKnown_(
true)
2717 const unsigned dim = 7U;
2718 unsigned sizes[dim];
2729 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2738 : data_(0), strides_(0), shape_(0), len_(1UL), shapeIsKnown_(
true)
2740 const unsigned dim = 8U;
2741 unsigned sizes[dim];
2753 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2763 : data_(0), strides_(0), shape_(0), len_(1UL), shapeIsKnown_(
true)
2765 const unsigned dim = 9U;
2766 unsigned sizes[dim];
2779 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2790 : data_(0), strides_(0), shape_(0), len_(1UL), shapeIsKnown_(
true)
2792 const unsigned dim = 10U;
2793 unsigned sizes[dim];
2807 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2808 template<
typename Num1,
unsigned Len1,
unsigned Dim1,
2809 typename Num2,
unsigned Len2,
unsigned Dim2>
2811 const unsigned level,
unsigned long idx0,
2812 unsigned long idx1,
unsigned long idx2,
2816 const unsigned imax = shape_[
level];
2817 if (level == dim_ - 1)
2819 for (
unsigned i=0;
i<imax; ++
i)
2824 for (
unsigned i=0;
i<imax; ++
i)
2826 outerProductLoop(level+1, idx0, idx1, idx2, a1, a2);
2827 idx0 += strides_[
level];
2828 if (level < a1.
dim_)
2836 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2837 template<
typename Num1,
unsigned Len1,
unsigned Dim1,
2838 typename Num2,
unsigned Len2,
unsigned Dim2>
2841 : data_(0), strides_(0), shape_(0),
2842 len_(1UL), dim_(a1.dim_ + a2.dim_), shapeIsKnown_(
true)
2846 "In npstat::ArrayND outer product constructor: "
2847 "uninitialized argument array");
2854 for (
unsigned i=0;
i<
dim_; ++
i)
2869 for (
unsigned long i=0;
i<
len_; ++
i)
2872 else if (a2.
dim_ == 0)
2874 for (
unsigned long i=0;
i<
len_; ++
i)
2887 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2895 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2904 "In npstat::ArrayND assignment operator: "
2905 "uninitialized argument array");
2907 "In npstat::ArrayND assignment operator: "
2908 "incompatible argument array shape");
2924 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2925 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
2929 if ((
void*)
this == (
void*)(&r))
2934 "In npstat::ArrayND assignment operator: "
2935 "uninitialized argument array");
2937 "In npstat::ArrayND assignment operator: "
2938 "incompatible argument array shape");
2942 localData_[0] =
static_cast<Numeric
>(r.
localData_[0]);
2954 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2955 template <
typename Num2,
unsigned Len2,
unsigned Dim2,
class Functor>
2963 "In npstat::ArrayND::assign: uninitialized argument array");
2965 "In npstat::ArrayND::assign: incompatible argument array shape");
2967 for (
unsigned long i=0;
i<len_; ++
i)
2968 data_[
i] = static_cast<Numeric>(
f(r.
data_[
i]));
2970 localData_[0] =
static_cast<Numeric
>(
f(r.
localData_[0]));
2982 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2986 "Initialize npstat::ArrayND before calling method \"shape\"");
2990 template<
typename Numeric,
unsigned Len,
unsigned Dim>
2994 "Initialize npstat::ArrayND before calling method \"fullRange\"");
2998 range.reserve(dim_);
2999 for (
unsigned i=0;
i<dim_; ++
i)
3005 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3009 "Initialize npstat::ArrayND before calling method \"isDensity\"");
3010 const Numeric
zero = Numeric();
3011 bool hasPositive =
false;
3013 for (
unsigned long i=0;
i<len_; ++
i)
3020 if (data_[
i] == zero)
3029 zero, localData_[0]);
3033 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3037 "Initialize npstat::ArrayND before calling method \"isZero\"");
3038 const Numeric
zero = Numeric();
3041 for (
unsigned long i=0;
i<len_; ++
i)
3042 if (data_[
i] != zero)
3046 if (localData_[0] != zero)
3051 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3053 unsigned long l,
unsigned*
idx,
const unsigned idxLen)
const
3056 "Initialize npstat::ArrayND before calling "
3057 "method \"convertLinearIndex\"");
3059 "npstat::ArrayND::convertLinearIndex method "
3060 "can not be used with array of 0 rank");
3062 "In npstat::ArrayND::convertLinearIndex: incompatible index length");
3064 "In npstat::ArrayND::convertLinearIndex: linear index out of range");
3067 for (
unsigned i=0;
i<dim_; ++
i)
3069 idx[
i] = l / strides_[
i];
3070 l -= (idx[
i] * strides_[
i]);
3074 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3076 const unsigned*
index,
unsigned idxLen)
const
3079 "Initialize npstat::ArrayND before calling method \"linearIndex\"");
3081 "npstat::ArrayND::linearIndex method "
3082 "can not be used with array of 0 rank");
3084 "In npstat::ArrayND::linearIndex: incompatible index length");
3087 unsigned long idx = 0UL;
3088 for (
unsigned i=0;
i<dim_; ++
i)
3090 if (index[
i] >= shape_[
i])
3092 "In npstat::ArrayND::linearIndex: index out of range");
3093 idx += index[
i]*strides_[
i];
3098 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3100 const unsigned *
index,
const unsigned dim)
3103 "Initialize npstat::ArrayND before calling method \"value\"");
3105 "In npstat::ArrayND::value: incompatible index length");
3109 unsigned long idx = 0UL;
3110 for (
unsigned i=0;
i<dim_; ++
i)
3111 idx += index[
i]*strides_[
i];
3115 return localData_[0];
3118 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3120 const unsigned *
index,
const unsigned dim)
const
3123 "Initialize npstat::ArrayND before calling method \"value\"");
3125 "In npstat::ArrayND::value: incompatible index length");
3129 unsigned long idx = 0UL;
3130 for (
unsigned i=0;
i<dim_; ++
i)
3131 idx += index[
i]*strides_[
i];
3135 return localData_[0];
3138 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3140 const unsigned long index)
3142 return data_[
index];
3145 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3147 const unsigned long index)
const
3149 return data_[
index];
3152 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3154 const unsigned long index)
3158 "In npstat::ArrayND::linearValueAt: linear index out of range");
3159 return data_[
index];
3162 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3164 const unsigned long index)
const
3168 "In npstat::ArrayND::linearValueAt: linear index out of range");
3169 return data_[
index];
3172 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3174 const double x,
const unsigned idim)
const
3178 else if (x >= static_cast<double>(shape_[idim] - 1))
3179 return shape_[idim] - 1;
3181 return static_cast<unsigned>(std::floor(x + 0.5));
3184 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3186 const double *
x,
const unsigned dim)
const
3189 "Initialize npstat::ArrayND before calling method \"closest\"");
3191 "In npstat::ArrayND::closest: incompatible data length");
3195 unsigned long idx = 0UL;
3196 for (
unsigned i=0;
i<dim_; ++
i)
3197 idx += coordToIndex(x[
i], i)*strides_[
i];
3201 return localData_[0];
3204 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3206 const double *
x,
const unsigned dim)
3209 "Initialize npstat::ArrayND before calling method \"closest\"");
3211 "In npstat::ArrayND::closest: incompatible data length");
3215 unsigned long idx = 0UL;
3216 for (
unsigned i=0;
i<dim_; ++
i)
3217 idx += coordToIndex(x[
i], i)*strides_[
i];
3221 return localData_[0];
3224 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3226 const unsigned *
index,
const unsigned dim)
const
3229 "Initialize npstat::ArrayND before calling method \"valueAt\"");
3231 "In npstat::ArrayND::valueAt: incompatible index length");
3235 unsigned long idx = 0UL;
3236 for (
unsigned i=0;
i<dim_; ++
i)
3239 "In npstat::ArrayND::valueAt: index out of range");
3240 idx += index[
i]*strides_[
i];
3245 return localData_[0];
3248 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3250 const unsigned *
index,
const unsigned dim)
3253 "Initialize npstat::ArrayND before calling method \"valueAt\"");
3255 "In npstat::ArrayND::valueAt: incompatible index length");
3259 unsigned long idx = 0UL;
3260 for (
unsigned i=0;
i<dim_; ++
i)
3263 "In npstat::ArrayND::valueAt: index out of range");
3264 idx += index[
i]*strides_[
i];
3269 return localData_[0];
3272 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3276 "Initialize npstat::ArrayND before calling method \"operator()\"");
3278 "In npstat::ArrayND::operator(): wrong # of args (not rank 0 array)");
3279 return localData_[0];
3282 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3286 "Initialize npstat::ArrayND before calling method \"operator()\"");
3288 "In npstat::ArrayND::operator(): wrong # of args (not rank 0 array)");
3289 return localData_[0];
3292 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3297 "In npstat::ArrayND::operator(): wrong # of args (not rank 1 array)");
3301 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3303 const unsigned i)
const
3306 "In npstat::ArrayND::operator(): wrong # of args (not rank 1 array)");
3310 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3314 "Initialize npstat::ArrayND before calling method \"at\"");
3316 "In npstat::ArrayND::at: wrong # of args (not rank 0 array)");
3317 return localData_[0];
3320 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3324 "Initialize npstat::ArrayND before calling method \"at\"");
3326 "In npstat::ArrayND::at: wrong # of args (not rank 0 array)");
3327 return localData_[0];
3330 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3332 const unsigned i0)
const
3335 "In npstat::ArrayND::at: wrong # of args (not rank 1 array)");
3337 "In npstat::ArrayND::at: index 0 out of range (rank 1)");
3341 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3346 "In npstat::ArrayND::at: wrong # of args (not rank 1 array)");
3348 "In npstat::ArrayND::at: index 0 out of range (rank 1)");
3352 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3358 "In npstat::ArrayND::operator(): wrong # of args (not rank 2 array)");
3359 return data_[i0*strides_[0] + i1];
3362 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3365 const unsigned i1)
const
3368 "In npstat::ArrayND::operator(): wrong # of args (not rank 2 array)");
3369 return data_[i0*strides_[0] + i1];
3372 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3375 const unsigned i1)
const
3378 "In npstat::ArrayND::at: wrong # of args (not rank 2 array)");
3380 "In npstat::ArrayND::at: index 0 out of range (rank 2)");
3382 "In npstat::ArrayND::at: index 1 out of range (rank 2)");
3383 return data_[i0*strides_[0] + i1];
3386 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3392 "In npstat::ArrayND::at: wrong # of args (not rank 2 array)");
3394 "In npstat::ArrayND::at: index 0 out of range (rank 2)");
3396 "In npstat::ArrayND::at: index 1 out of range (rank 2)");
3397 return data_[i0*strides_[0] + i1];
3400 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3404 const unsigned i2)
const
3407 "In npstat::ArrayND::operator(): wrong # of args (not rank 3 array)");
3408 return data_[i0*strides_[0] + i1*strides_[1] + i2];
3411 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3416 const unsigned i3)
const
3419 "In npstat::ArrayND::operator(): wrong # of args (not rank 4 array)");
3420 return data_[i0*strides_[0] + i1*strides_[1] + i2*strides_[2] + i3];
3423 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3429 const unsigned i4)
const
3432 "In npstat::ArrayND::operator(): wrong # of args (not rank 5 array)");
3433 return data_[i0*strides_[0] + i1*strides_[1] + i2*strides_[2] +
3434 i3*strides_[3] + i4];
3437 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3444 const unsigned i5)
const
3447 "In npstat::ArrayND::operator(): wrong # of args (not rank 6 array)");
3448 return data_[i0*strides_[0] + i1*strides_[1] + i2*strides_[2] +
3449 i3*strides_[3] + i4*strides_[4] + i5];
3452 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3460 const unsigned i6)
const
3463 "In npstat::ArrayND::operator(): wrong # of args (not rank 7 array)");
3464 return data_[i0*strides_[0] + i1*strides_[1] + i2*strides_[2] +
3465 i3*strides_[3] + i4*strides_[4] + i5*strides_[5] + i6];
3468 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3477 const unsigned i7)
const
3480 "In npstat::ArrayND::operator(): wrong # of args (not rank 8 array)");
3481 return data_[i0*strides_[0] + i1*strides_[1] + i2*strides_[2] +
3482 i3*strides_[3] + i4*strides_[4] + i5*strides_[5] +
3483 i6*strides_[6] + i7];
3486 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3496 const unsigned i8)
const
3499 "In npstat::ArrayND::operator(): wrong # of args (not rank 9 array)");
3500 return data_[i0*strides_[0] + i1*strides_[1] + i2*strides_[2] +
3501 i3*strides_[3] + i4*strides_[4] + i5*strides_[5] +
3502 i6*strides_[6] + i7*strides_[7] + i8];
3505 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3516 const unsigned i9)
const
3519 "In npstat::ArrayND::operator(): wrong # of args (not rank 10 array)");
3520 return data_[i0*strides_[0] + i1*strides_[1] + i2*strides_[2] +
3521 i3*strides_[3] + i4*strides_[4] + i5*strides_[5] +
3522 i6*strides_[6] + i7*strides_[7] + i8*strides_[8] + i9];
3525 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3532 "In npstat::ArrayND::operator(): wrong # of args (not rank 3 array)");
3533 return data_[i0*strides_[0] + i1*strides_[1] + i2];
3536 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3544 "In npstat::ArrayND::operator(): wrong # of args (not rank 4 array)");
3545 return data_[i0*strides_[0] + i1*strides_[1] + i2*strides_[2] + i3];
3548 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3557 "In npstat::ArrayND::operator(): wrong # of args (not rank 5 array)");
3558 return data_[i0*strides_[0] + i1*strides_[1] + i2*strides_[2] +
3559 i3*strides_[3] + i4];
3562 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3572 "In npstat::ArrayND::operator(): wrong # of args (not rank 6 array)");
3573 return data_[i0*strides_[0] + i1*strides_[1] + i2*strides_[2] +
3574 i3*strides_[3] + i4*strides_[4] + i5];
3577 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3588 "In npstat::ArrayND::operator(): wrong # of args (not rank 7 array)");
3589 return data_[i0*strides_[0] + i1*strides_[1] + i2*strides_[2] +
3590 i3*strides_[3] + i4*strides_[4] + i5*strides_[5] + i6];
3593 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3605 "In npstat::ArrayND::operator(): wrong # of args (not rank 8 array)");
3606 return data_[i0*strides_[0] + i1*strides_[1] + i2*strides_[2] +
3607 i3*strides_[3] + i4*strides_[4] + i5*strides_[5] +
3608 i6*strides_[6] + i7];
3611 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3624 "In npstat::ArrayND::operator(): wrong # of args (not rank 9 array)");
3625 return data_[i0*strides_[0] + i1*strides_[1] + i2*strides_[2] +
3626 i3*strides_[3] + i4*strides_[4] + i5*strides_[5] +
3627 i6*strides_[6] + i7*strides_[7] + i8];
3630 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3644 "In npstat::ArrayND::operator(): wrong # of args (not rank 10 array)");
3645 return data_[i0*strides_[0] + i1*strides_[1] + i2*strides_[2] +
3646 i3*strides_[3] + i4*strides_[4] + i5*strides_[5] +
3647 i6*strides_[6] + i7*strides_[7] + i8*strides_[8] + i9];
3650 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3654 const unsigned i2)
const
3657 "In npstat::ArrayND::at: wrong # of args (not rank 3 array)");
3659 "In npstat::ArrayND::at: index 0 out of range (rank 3)");
3661 "In npstat::ArrayND::at: index 1 out of range (rank 3)");
3663 "In npstat::ArrayND::at: index 2 out of range (rank 3)");
3664 return data_[i0*strides_[0] + i1*strides_[1] + i2];
3667 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3672 const unsigned i3)
const
3675 "In npstat::ArrayND::at: wrong # of args (not rank 4 array)");
3677 "In npstat::ArrayND::at: index 0 out of range (rank 4)");
3679 "In npstat::ArrayND::at: index 1 out of range (rank 4)");
3681 "In npstat::ArrayND::at: index 2 out of range (rank 4)");
3683 "In npstat::ArrayND::at: index 3 out of range (rank 4)");
3684 return data_[i0*strides_[0] + i1*strides_[1] + i2*strides_[2] + i3];
3687 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3693 const unsigned i4)
const
3696 "In npstat::ArrayND::at: wrong # of args (not rank 5 array)");
3698 "In npstat::ArrayND::at: index 0 out of range (rank 5)");
3700 "In npstat::ArrayND::at: index 1 out of range (rank 5)");
3702 "In npstat::ArrayND::at: index 2 out of range (rank 5)");
3704 "In npstat::ArrayND::at: index 3 out of range (rank 5)");
3706 "In npstat::ArrayND::at: index 4 out of range (rank 5)");
3707 return data_[i0*strides_[0] + i1*strides_[1] + i2*strides_[2] +
3708 i3*strides_[3] + i4];
3711 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3718 const unsigned i5)
const
3721 "In npstat::ArrayND::at: wrong # of args (not rank 6 array)");
3723 "In npstat::ArrayND::at: index 0 out of range (rank 6)");
3725 "In npstat::ArrayND::at: index 1 out of range (rank 6)");
3727 "In npstat::ArrayND::at: index 2 out of range (rank 6)");
3729 "In npstat::ArrayND::at: index 3 out of range (rank 6)");
3731 "In npstat::ArrayND::at: index 4 out of range (rank 6)");
3733 "In npstat::ArrayND::at: index 5 out of range (rank 6)");
3734 return data_[i0*strides_[0] + i1*strides_[1] + i2*strides_[2] +
3735 i3*strides_[3] + i4*strides_[4] + i5];
3738 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3746 const unsigned i6)
const
3749 "In npstat::ArrayND::at: wrong # of args (not rank 7 array)");
3751 "In npstat::ArrayND::at: index 0 out of range (rank 7)");
3753 "In npstat::ArrayND::at: index 1 out of range (rank 7)");
3755 "In npstat::ArrayND::at: index 2 out of range (rank 7)");
3757 "In npstat::ArrayND::at: index 3 out of range (rank 7)");
3759 "In npstat::ArrayND::at: index 4 out of range (rank 7)");
3761 "In npstat::ArrayND::at: index 5 out of range (rank 7)");
3763 "In npstat::ArrayND::at: index 6 out of range (rank 7)");
3764 return data_[i0*strides_[0] + i1*strides_[1] + i2*strides_[2] +
3765 i3*strides_[3] + i4*strides_[4] + i5*strides_[5] + i6];
3768 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3777 const unsigned i7)
const
3780 "In npstat::ArrayND::at: wrong # of args (not rank 8 array)");
3782 "In npstat::ArrayND::at: index 0 out of range (rank 8)");
3784 "In npstat::ArrayND::at: index 1 out of range (rank 8)");
3786 "In npstat::ArrayND::at: index 2 out of range (rank 8)");
3788 "In npstat::ArrayND::at: index 3 out of range (rank 8)");
3790 "In npstat::ArrayND::at: index 4 out of range (rank 8)");
3792 "In npstat::ArrayND::at: index 5 out of range (rank 8)");
3794 "In npstat::ArrayND::at: index 6 out of range (rank 8)");
3796 "In npstat::ArrayND::at: index 7 out of range (rank 8)");
3797 return data_[i0*strides_[0] + i1*strides_[1] + i2*strides_[2] +
3798 i3*strides_[3] + i4*strides_[4] + i5*strides_[5] +
3799 i6*strides_[6] + i7];
3802 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3812 const unsigned i8)
const
3815 "In npstat::ArrayND::at: wrong # of args (not rank 9 array)");
3817 "In npstat::ArrayND::at: index 0 out of range (rank 9)");
3819 "In npstat::ArrayND::at: index 1 out of range (rank 9)");
3821 "In npstat::ArrayND::at: index 2 out of range (rank 9)");
3823 "In npstat::ArrayND::at: index 3 out of range (rank 9)");
3825 "In npstat::ArrayND::at: index 4 out of range (rank 9)");
3827 "In npstat::ArrayND::at: index 5 out of range (rank 9)");
3829 "In npstat::ArrayND::at: index 6 out of range (rank 9)");
3831 "In npstat::ArrayND::at: index 7 out of range (rank 9)");
3833 "In npstat::ArrayND::at: index 8 out of range (rank 9)");
3834 return data_[i0*strides_[0] + i1*strides_[1] + i2*strides_[2] +
3835 i3*strides_[3] + i4*strides_[4] + i5*strides_[5] +
3836 i6*strides_[6] + i7*strides_[7] + i8];
3839 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3850 const unsigned i9)
const
3853 "In npstat::ArrayND::at: wrong # of args (not rank 10 array)");
3855 "In npstat::ArrayND::at: index 0 out of range (rank 10)");
3857 "In npstat::ArrayND::at: index 1 out of range (rank 10)");
3859 "In npstat::ArrayND::at: index 2 out of range (rank 10)");
3861 "In npstat::ArrayND::at: index 3 out of range (rank 10)");
3863 "In npstat::ArrayND::at: index 4 out of range (rank 10)");
3865 "In npstat::ArrayND::at: index 5 out of range (rank 10)");
3867 "In npstat::ArrayND::at: index 6 out of range (rank 10)");
3869 "In npstat::ArrayND::at: index 7 out of range (rank 10)");
3871 "In npstat::ArrayND::at: index 8 out of range (rank 10)");
3873 "In npstat::ArrayND::at: index 9 out of range (rank 10)");
3874 return data_[i0*strides_[0] + i1*strides_[1] + i2*strides_[2] +
3875 i3*strides_[3] + i4*strides_[4] + i5*strides_[5] +
3876 i6*strides_[6] + i7*strides_[7] + i8*strides_[8] + i9];
3879 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3886 "In npstat::ArrayND::at: wrong # of args (not rank 3 array)");
3888 "In npstat::ArrayND::at: index 0 out of range (rank 3)");
3890 "In npstat::ArrayND::at: index 1 out of range (rank 3)");
3892 "In npstat::ArrayND::at: index 2 out of range (rank 3)");
3893 return data_[i0*strides_[0] + i1*strides_[1] + i2];
3896 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3904 "In npstat::ArrayND::at: wrong # of args (not rank 4 array)");
3906 "In npstat::ArrayND::at: index 0 out of range (rank 4)");
3908 "In npstat::ArrayND::at: index 1 out of range (rank 4)");
3910 "In npstat::ArrayND::at: index 2 out of range (rank 4)");
3912 "In npstat::ArrayND::at: index 3 out of range (rank 4)");
3913 return data_[i0*strides_[0] + i1*strides_[1] + i2*strides_[2] + i3];
3916 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3925 "In npstat::ArrayND::at: wrong # of args (not rank 5 array)");
3927 "In npstat::ArrayND::at: index 0 out of range (rank 5)");
3929 "In npstat::ArrayND::at: index 1 out of range (rank 5)");
3931 "In npstat::ArrayND::at: index 2 out of range (rank 5)");
3933 "In npstat::ArrayND::at: index 3 out of range (rank 5)");
3935 "In npstat::ArrayND::at: index 4 out of range (rank 5)");
3936 return data_[i0*strides_[0] + i1*strides_[1] + i2*strides_[2] +
3937 i3*strides_[3] + i4];
3940 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3950 "In npstat::ArrayND::at: wrong # of args (not rank 6 array)");
3952 "In npstat::ArrayND::at: index 0 out of range (rank 6)");
3954 "In npstat::ArrayND::at: index 1 out of range (rank 6)");
3956 "In npstat::ArrayND::at: index 2 out of range (rank 6)");
3958 "In npstat::ArrayND::at: index 3 out of range (rank 6)");
3960 "In npstat::ArrayND::at: index 4 out of range (rank 6)");
3962 "In npstat::ArrayND::at: index 5 out of range (rank 6)");
3963 return data_[i0*strides_[0] + i1*strides_[1] + i2*strides_[2] +
3964 i3*strides_[3] + i4*strides_[4] + i5];
3967 template<
typename Numeric,
unsigned Len,
unsigned Dim>
3978 "In npstat::ArrayND::at: wrong # of args (not rank 7 array)");
3980 "In npstat::ArrayND::at: index 0 out of range (rank 7)");
3982 "In npstat::ArrayND::at: index 1 out of range (rank 7)");
3984 "In npstat::ArrayND::at: index 2 out of range (rank 7)");
3986 "In npstat::ArrayND::at: index 3 out of range (rank 7)");
3988 "In npstat::ArrayND::at: index 4 out of range (rank 7)");
3990 "In npstat::ArrayND::at: index 5 out of range (rank 7)");
3992 "In npstat::ArrayND::at: index 6 out of range (rank 7)");
3993 return data_[i0*strides_[0] + i1*strides_[1] + i2*strides_[2] +
3994 i3*strides_[3] + i4*strides_[4] + i5*strides_[5] + i6];
3997 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4009 "In npstat::ArrayND::at: wrong # of args (not rank 8 array)");
4011 "In npstat::ArrayND::at: index 0 out of range (rank 8)");
4013 "In npstat::ArrayND::at: index 1 out of range (rank 8)");
4015 "In npstat::ArrayND::at: index 2 out of range (rank 8)");
4017 "In npstat::ArrayND::at: index 3 out of range (rank 8)");
4019 "In npstat::ArrayND::at: index 4 out of range (rank 8)");
4021 "In npstat::ArrayND::at: index 5 out of range (rank 8)");
4023 "In npstat::ArrayND::at: index 6 out of range (rank 8)");
4025 "In npstat::ArrayND::at: index 7 out of range (rank 8)");
4026 return data_[i0*strides_[0] + i1*strides_[1] + i2*strides_[2] +
4027 i3*strides_[3] + i4*strides_[4] + i5*strides_[5] +
4028 i6*strides_[6] + i7];
4031 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4044 "In npstat::ArrayND::at: wrong # of args (not rank 9 array)");
4046 "In npstat::ArrayND::at: index 0 out of range (rank 9)");
4048 "In npstat::ArrayND::at: index 1 out of range (rank 9)");
4050 "In npstat::ArrayND::at: index 2 out of range (rank 9)");
4052 "In npstat::ArrayND::at: index 3 out of range (rank 9)");
4054 "In npstat::ArrayND::at: index 4 out of range (rank 9)");
4056 "In npstat::ArrayND::at: index 5 out of range (rank 9)");
4058 "In npstat::ArrayND::at: index 6 out of range (rank 9)");
4060 "In npstat::ArrayND::at: index 7 out of range (rank 9)");
4062 "In npstat::ArrayND::at: index 8 out of range (rank 9)");
4063 return data_[i0*strides_[0] + i1*strides_[1] + i2*strides_[2] +
4064 i3*strides_[3] + i4*strides_[4] + i5*strides_[5] +
4065 i6*strides_[6] + i7*strides_[7] + i8];
4068 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4082 "In npstat::ArrayND::at: wrong # of args (not rank 10 array)");
4084 "In npstat::ArrayND::at: index 0 out of range (rank 10)");
4086 "In npstat::ArrayND::at: index 1 out of range (rank 10)");
4088 "In npstat::ArrayND::at: index 2 out of range (rank 10)");
4090 "In npstat::ArrayND::at: index 3 out of range (rank 10)");
4092 "In npstat::ArrayND::at: index 4 out of range (rank 10)");
4094 "In npstat::ArrayND::at: index 5 out of range (rank 10)");
4096 "In npstat::ArrayND::at: index 6 out of range (rank 10)");
4098 "In npstat::ArrayND::at: index 7 out of range (rank 10)");
4100 "In npstat::ArrayND::at: index 8 out of range (rank 10)");
4102 "In npstat::ArrayND::at: index 9 out of range (rank 10)");
4103 return data_[i0*strides_[0] + i1*strides_[1] + i2*strides_[2] +
4104 i3*strides_[3] + i4*strides_[4] + i5*strides_[5] +
4105 i6*strides_[6] + i7*strides_[7] + i8*strides_[8] + i9];
4108 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4109 template<
unsigned Len2,
unsigned Dim2>
4114 "In npstat::ArrayND::maxAbsDifference: "
4115 "incompatible argument array shape");
4119 for (
unsigned long i=0;
i<len_; ++
i)
4135 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4136 template<
unsigned Len2,
unsigned Dim2>
4146 for (
unsigned i=0;
i<dim_; ++
i)
4149 for (
unsigned i=0;
i<dim_; ++
i)
4151 for (
unsigned long j=0;
j<len_; ++
j)
4157 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4158 template<
unsigned Len2,
unsigned Dim2>
4162 return !(*
this ==
r);
4165 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4166 template<
typename Num2>
4171 "Initialize npstat::ArrayND before calling method \"operator*\"");
4173 for (
unsigned long i=0;
i<len_; ++
i)
4178 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4179 template<
typename Num2>
4184 "Initialize npstat::ArrayND before calling method \"operator/\"");
4186 "In npstat::ArrayND::operator/: division by zero");
4188 for (
unsigned long i=0;
i<len_; ++
i)
4193 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4194 template <
unsigned Len2,
unsigned Dim2>
4200 "In npstat::ArrayND::operator+: "
4201 "incompatible argument array shape");
4203 for (
unsigned long i=0;
i<len_; ++
i)
4208 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4209 template <
unsigned Len2,
unsigned Dim2>
4215 "In npstat::ArrayND::operator-: "
4216 "incompatible argument array shape");
4218 for (
unsigned long i=0;
i<len_; ++
i)
4223 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4227 "Initialize npstat::ArrayND before calling method \"operator+\"");
4231 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4235 "Initialize npstat::ArrayND before calling method \"operator-\"");
4237 for (
unsigned long i=0;
i<len_; ++
i)
4242 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4243 template <
typename Num2>
4248 "Initialize npstat::ArrayND before calling method \"operator*=\"");
4249 for (
unsigned long i=0;
i<len_; ++
i)
4254 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4259 "Initialize npstat::ArrayND before calling method \"makeNonNegative\"");
4260 const Numeric
zero = Numeric();
4263 for (
unsigned long i=0;
i<len_; ++
i)
4269 localData_[0] =
zero;
4273 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4275 const double tolerance,
const unsigned nCycles)
4278 "Initialize npstat::ArrayND before calling method \"makeCopulaSteps\"");
4282 "npstat::ArrayND::makeCopulaSteps method "
4283 "can not be used with array of 0 rank");
4285 const Numeric
zero = Numeric();
4286 for (
unsigned long i=0;
i<len_; ++
i)
4290 std::vector<Numeric*> axesPtrBuf(dim_);
4291 Numeric** axes = &axesPtrBuf[0];
4292 const Numeric one =
static_cast<Numeric
>(1);
4295 unsigned idxSum = 0;
4296 for (
unsigned i=0; i<dim_; ++
i)
4297 idxSum += shape_[i];
4298 std::vector<Numeric> axesBuf(idxSum);
4299 axes[0] = &axesBuf[0];
4300 for (
unsigned i=1; i<dim_; ++
i)
4301 axes[i] = axes[i-1] + shape_[i-1];
4304 unsigned icycle = 0;
4305 for (; icycle<nCycles; ++icycle)
4307 for (
unsigned i=0; i<idxSum; ++
i)
4311 for (
unsigned long idat=0; idat<len_; ++idat)
4313 unsigned long l = idat;
4314 for (
unsigned i=0; i<dim_; ++
i)
4316 const unsigned idx = l / strides_[
i];
4317 l -= (idx * strides_[
i]);
4318 axes[
i][
idx] += data_[idat];
4323 bool withinTolerance =
true;
4324 Numeric totalSum =
zero;
4325 for (
unsigned i=0; i<dim_; ++
i)
4327 Numeric axisSum =
zero;
4328 const unsigned amax = shape_[
i];
4329 for (
unsigned a=0;
a<amax; ++
a)
4331 if (axes[i][
a] == zero)
4333 "In npstat::ArrayND::makeCopulaSteps: "
4334 "marginal density is zero");
4335 axisSum += axes[
i][
a];
4337 totalSum += axisSum;
4338 const Numeric axisAverage = axisSum/
static_cast<Numeric
>(amax);
4339 for (
unsigned a=0;
a<amax; ++
a)
4340 axes[i][
a] /= axisAverage;
4341 for (
unsigned a=0;
a<amax && withinTolerance; ++
a)
4344 if (adelta > tolerance)
4345 withinTolerance =
false;
4349 if (withinTolerance)
4352 const Numeric totalAverage = totalSum/
4353 static_cast<Numeric
>(len_)/static_cast<Numeric>(dim_);
4357 for (
unsigned long idat=0; idat<len_; ++idat)
4359 unsigned long l = idat;
4360 for (
unsigned i=0; i<dim_; ++
i)
4362 const unsigned idx = l / strides_[
i];
4363 l -= (idx * strides_[
i]);
4364 data_[idat] /= axes[
i][
idx];
4366 data_[idat] /= totalAverage;
4373 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4374 template <
typename Num2>
4379 "Initialize npstat::ArrayND before calling method \"operator/=\"");
4381 "In npstat::ArrayND::operator/=: division by zero");
4382 for (
unsigned long i=0;
i<len_; ++
i)
4387 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4388 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
4393 "In npstat::ArrayND::operator+=: "
4394 "incompatible argument array shape");
4395 for (
unsigned long i=0;
i<len_; ++
i)
4400 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4401 template <
typename Num3,
typename Num2,
unsigned Len2,
unsigned Dim2>
4407 "In npstat::ArrayND::addmul: "
4408 "incompatible argument array shape");
4409 for (
unsigned long i=0;
i<len_; ++
i)
4414 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4415 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
4420 "In npstat::ArrayND::operator-=: "
4421 "incompatible argument array shape");
4422 for (
unsigned long i=0;
i<len_; ++
i)
4427 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4429 const double *coords,
const unsigned dim)
const
4432 "Initialize npstat::ArrayND before calling method \"interpolate1\"");
4434 "In npstat::ArrayND::interpolate1: incompatible coordinate length");
4437 const unsigned maxdim = CHAR_BIT*
sizeof(
unsigned long);
4440 "In npstat::ArrayND::interpolate1: array rank is too large");
4443 unsigned ix[maxdim];
4444 for (
unsigned i=0;
i<dim; ++
i)
4446 const double x = coords[
i];
4452 else if (x >= static_cast<double>(shape_[
i] - 1))
4454 ix[
i] = shape_[
i] - 1;
4459 ix[
i] =
static_cast<unsigned>(std::floor(x));
4464 Numeric sum = Numeric();
4465 const unsigned long maxcycle = 1UL << dim;
4466 for (
unsigned long icycle=0UL; icycle<maxcycle; ++icycle)
4469 unsigned long icell = 0UL;
4470 for (
unsigned i=0;
i<dim; ++
i)
4472 if (icycle & (1UL <<
i))
4475 icell += strides_[
i]*(ix[
i] + 1U);
4480 icell += strides_[
i]*ix[
i];
4489 return localData_[0];
4492 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4494 const unsigned level,
const double* coords,
const Numeric*
base)
const
4496 const unsigned npoints = shape_[
level];
4497 const double x = coords[
level];
4499 unsigned ix, npt = 1;
4503 else if (x > static_cast<double>(npoints - 1))
4507 ix =
static_cast<unsigned>(std::floor(x));
4509 unsigned imax = ix + 3;
4510 while (imax >= npoints)
4516 npt = imax + 1 - ix;
4518 assert(npt >= 1 && npt <= 4);
4521 if (level < dim_ - 1)
4522 for (
unsigned ipt=0; ipt<npt; ++ipt)
4523 fit[ipt] = interpolateLoop(level + 1, coords,
4524 base + (ix + ipt)*strides_[level]);
4526 const Numeric*
const v = (level == dim_ - 1 ? base + ix : fit);
4543 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4545 const double* coords,
const unsigned dim)
const
4548 "Initialize npstat::ArrayND before calling method \"interpolate3\"");
4550 "In npstat::ArrayND::interpolate3: incompatible coordinate length");
4554 return interpolateLoop(0, coords, data_);
4557 return localData_[0];
4560 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4561 template<
class Functor>
4565 "Initialize npstat::ArrayND before calling method \"apply\"");
4566 for (
unsigned long i=0;
i<len_; ++
i)
4567 data_[
i] = static_cast<Numeric>(
f(data_[
i]));
4571 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4572 template<
class Functor>
4577 "Initialize npstat::ArrayND before calling method \"scanInPlace\"");
4578 for (
unsigned long i=0;
i<len_; ++
i)
4583 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4588 "Initialize npstat::ArrayND before calling method \"constFill\"");
4589 for (
unsigned long i=0;
i<len_; ++
i)
4594 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4597 return constFill(Numeric());
4600 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4606 localData_[0] = Numeric();
4612 shapeIsKnown_ =
false;
4616 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4620 "Initialize npstat::ArrayND before calling method \"makeUnit\"");
4622 "npstat::ArrayND::makeUnit method "
4623 "can not be used with arrays of rank less than 2");
4624 constFill(Numeric());
4625 unsigned long stride = 0UL;
4626 const unsigned dimlen = shape_[0];
4627 for (
unsigned i=0;
i<dim_; ++
i)
4630 "npstat::ArrayND::makeUnit method needs "
4631 "the array span to be the same in ech dimension");
4632 stride += strides_[
i];
4634 const Numeric one(static_cast<Numeric>(1));
4635 for (
unsigned i=0;
i<dimlen; ++
i)
4636 data_[
i*stride] = one;
4640 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4642 const unsigned level,
const double s0,
const unsigned long idx,
4643 const double shift,
const double* coeffs)
4645 const unsigned imax = shape_[
level];
4646 const double c = coeffs[
level];
4647 if (level == dim_ - 1)
4649 Numeric* d = &data_[
idx];
4650 for (
unsigned i=0;
i<imax; ++
i)
4655 const double sum = s0 + c*
i +
shift;
4656 d[
i] =
static_cast<Numeric
>(sum);
4661 const unsigned long stride = strides_[
level];
4662 for (
unsigned i=0;
i<imax; ++
i)
4663 linearFillLoop(level+1, s0 + c*
i, idx + i*stride,
4668 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4670 const double* coeffs,
const unsigned dimCoeffs,
const double shift)
4674 "Initialize npstat::ArrayND before calling method \"linearFill\"");
4676 "In npstat::ArrayND::linearFill: incompatible number of coefficients");
4680 linearFillLoop(0U, 0.0, 0UL, shift, coeffs);
4683 localData_[0] =
static_cast<Numeric
>(
shift);
4687 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4688 template<
class Functor>
4690 const unsigned level,
const unsigned long idx,
4691 Functor
f,
unsigned* farg)
4693 const unsigned imax = shape_[
level];
4694 if (level == dim_ - 1)
4696 Numeric* d = &data_[
idx];
4697 const unsigned* myarg = farg;
4698 for (
unsigned i = 0;
i<imax; ++
i)
4701 d[
i] =
static_cast<Numeric
>(
f(myarg, dim_));
4706 const unsigned long stride = strides_[
level];
4707 for (
unsigned i = 0;
i<imax; ++
i)
4710 functorFillLoop(level+1, idx +
i*stride, f, farg);
4715 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4716 template <
typename Accumulator>
4718 ArrayND* sumSlice,
const unsigned level,
unsigned long idx0,
4719 unsigned long idxSlice,
const bool useTrapezoids)
4722 const unsigned imax = shape_[
level];
4723 if (level == dim_ - 1)
4726 Numeric*
data = data_ + idx0;
4729 Numeric oldval = Numeric();
4730 for (
unsigned i = 0;
i<imax; ++
i)
4732 acc += (data[
i] + oldval)*half;
4734 data[
i] =
static_cast<Numeric
>(acc);
4739 for (
unsigned i = 0;
i<imax; ++
i)
4742 data[
i] =
static_cast<Numeric
>(acc);
4745 sumSlice->
data_[idxSlice] =
static_cast<Numeric
>(acc);
4747 sumSlice->
localData_[0] =
static_cast<Numeric
>(acc);
4751 const unsigned long stride = strides_[
level];
4752 unsigned long sumStride = 0UL;
4755 for (
unsigned i = 0;
i<imax; ++
i)
4757 convertToLastDimCdfLoop<Accumulator>(
4758 sumSlice, level+1, idx0, idxSlice, useTrapezoids);
4760 idxSlice += sumStride;
4765 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4766 template <
typename Accumulator>
4768 ArrayND* sumSlice,
const bool useTrapezoids)
4771 "Initialize npstat::ArrayND before calling "
4772 "method \"convertToLastDimCdf\"");
4774 "npstat::ArrayND::convertToLastDimCdf method "
4775 "can not be used with array of 0 rank");
4778 "In npstat::ArrayND::convertToLastDimCdf: "
4779 "uninitialized argument array");
4780 convertToLastDimCdfLoop<Accumulator>(sumSlice, 0U, 0UL, 0UL,
4784 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4785 template<
class Functor>
4789 "Initialize npstat::ArrayND before calling method \"functorFill\"");
4792 unsigned localIndex[Dim];
4794 functorFillLoop(0U, 0UL, f, index);
4798 localData_[0] =
static_cast<Numeric
>(
4799 f(static_cast<unsigned*>(0), 0U));
4803 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4804 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
4809 "In npstat::ArrayND::isClose: tolerance must not be negative");
4811 "In npstat::ArrayND::isClose: incompatible argument array shape");
4814 for (
unsigned long i=0;
i<len_; ++
i)
4824 if (static_cast<double>(
absDifference(localData_[0], rval)) > eps)
4830 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4831 template<
typename Num2,
unsigned Len2,
unsigned Dim2>
4838 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4840 unsigned thisLevel,
const unsigned resLevel,
4841 const unsigned pos1,
const unsigned pos2,
4842 unsigned long idxThis,
unsigned long idxRes,
ArrayND&
result)
const
4844 while (thisLevel == pos1 || thisLevel == pos2)
4846 assert(thisLevel < dim_);
4848 if (resLevel == result.
dim_ - 1)
4850 const unsigned ncontract = shape_[pos1];
4851 const unsigned imax = result.
shape_[resLevel];
4852 const unsigned long stride = strides_[pos1] + strides_[pos2];
4853 for (
unsigned i=0;
i<imax; ++
i)
4855 const Numeric*
tmp = data_ + (idxThis +
i*strides_[thisLevel]);
4856 Numeric sum = Numeric();
4857 for (
unsigned j=0;
j<ncontract; ++
j)
4858 sum += tmp[
j*stride];
4859 result.
data_[idxRes +
i] = sum;
4864 const unsigned imax = result.
shape_[resLevel];
4865 assert(imax == shape_[thisLevel]);
4866 for (
unsigned i=0;
i<imax; ++
i)
4868 contractLoop(thisLevel+1, resLevel+1, pos1, pos2,
4869 idxThis, idxRes, result);
4870 idxThis += strides_[thisLevel];
4871 idxRes += result.
strides_[resLevel];
4876 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4878 const unsigned pos1,
const unsigned pos2)
const
4881 "Initialize npstat::ArrayND before calling method \"contract\"");
4882 if (!(pos1 < dim_ && pos2 < dim_ && pos1 != pos2))
4884 "incompatible contraction indices");
4885 if (shape_[pos1] != shape_[pos2])
4887 "In npstat::ArrayND::contract: incompatible "
4888 "length of contracted dimensions");
4891 unsigned newshapeBuf[Dim];
4892 unsigned* newshape =
makeBuffer(dim_ - 2, newshapeBuf, Dim);
4894 for (
unsigned i=0;
i<dim_; ++
i)
4895 if (
i != pos1 &&
i != pos2)
4896 newshape[ishap++] = shape_[
i];
4901 contractLoop(0, 0, pos1, pos2, 0UL, 0UL, result);
4905 Numeric sum = Numeric();
4906 const unsigned imax = shape_[0];
4907 const unsigned long stride = strides_[0] + strides_[1];
4908 for (
unsigned i=0;
i<imax; ++
i)
4909 sum += data_[
i*stride];
4917 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4919 const unsigned level,
const unsigned pos1,
const unsigned pos2,
4920 unsigned long idxThis,
unsigned long idxRes,
ArrayND&
result)
const
4922 const unsigned imax = shape_[
level];
4923 const unsigned long mystride = strides_[
level];
4924 const unsigned relevel = level == pos1 ? pos2 :
4925 (level == pos2 ? pos1 :
level);
4926 const unsigned long restride = result.
strides_[relevel];
4927 const bool ready = (level == dim_ - 1);
4928 for (
unsigned i=0;
i<imax; ++
i)
4931 result.
data_[idxRes] = data_[idxThis];
4933 transposeLoop(level+1, pos1, pos2, idxThis, idxRes, result);
4934 idxThis += mystride;
4939 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4940 template<
typename Num2>
4944 "Initialize npstat::ArrayND before calling method \"sum\"");
4946 for (
unsigned long i=0;
i<len_; ++
i)
4951 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4952 template<
typename Num2>
4956 "Initialize npstat::ArrayND before calling method \"sumsq\"");
4958 for (
unsigned long i=0;
i<len_; ++
i)
4961 sum += absval*absval;
4966 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4970 "Initialize npstat::ArrayND before calling method \"min\"");
4973 Numeric minval(data_[0]);
4974 for (
unsigned long i=1UL;
i<len_; ++
i)
4980 return localData_[0];
4983 template<
typename Numeric,
unsigned Len,
unsigned Dim>
4985 unsigned *
index,
const unsigned indexLen)
const
4988 "Initialize npstat::ArrayND before calling method \"min\"");
4990 "In npstat::ArrayND::min: incompatible index length");
4993 unsigned long minind = 0UL;
4994 Numeric minval(data_[0]);
4995 for (
unsigned long i=1UL;
i<len_; ++
i)
5001 convertLinearIndex(minind, index, indexLen);
5005 return localData_[0];
5008 template<
typename Numeric,
unsigned Len,
unsigned Dim>
5012 "Initialize npstat::ArrayND before calling method \"max\"");
5015 Numeric maxval(data_[0]);
5016 for (
unsigned long i=1UL;
i<len_; ++
i)
5022 return localData_[0];
5025 template<
typename Numeric,
unsigned Len,
unsigned Dim>
5027 unsigned *
index,
const unsigned indexLen)
const
5030 "Initialize npstat::ArrayND before calling method \"max\"");
5032 "In npstat::ArrayND::max: incompatible index length");
5035 unsigned long maxind = 0UL;
5036 Numeric maxval(data_[0]);
5037 for (
unsigned long i=1UL;
i<len_; ++
i)
5043 convertLinearIndex(maxind, index, indexLen);
5047 return localData_[0];
5051 template<
typename Numeric,
unsigned Len,
unsigned Dim>
5055 "npstat::ArrayND::transpose method "
5056 "can not be used with arrays of rank other than 2");
5057 unsigned newshape[2];
5058 newshape[0] = shape_[1];
5059 newshape[1] = shape_[0];
5061 const unsigned imax = shape_[0];
5062 const unsigned jmax = shape_[1];
5063 for (
unsigned i=0;
i<imax; ++
i)
5064 for (
unsigned j=0;
j<jmax; ++
j)
5065 result.
data_[
j*imax +
i] = data_[
i*jmax +
j];
5069 template<
typename Numeric,
unsigned Len,
unsigned Dim>
5070 template <
typename Accumulator>
5072 const double inscale)
const
5075 "Initialize npstat::ArrayND before calling method \"derivative\"");
5077 "npstat::ArrayND::derivative method "
5078 "can not be used with array of 0 rank");
5081 const unsigned maxdim = CHAR_BIT*
sizeof(
unsigned long);
5083 "In npstat::ArrayND::derivative: array rank is too large");
5084 const unsigned long maxcycle = 1UL << dim_;
5088 for (
unsigned i=0;
i<dim_; ++
i)
5090 if (shape_[
i] <= 1U)
5092 "In npstat::ArrayND::derivative: in some dimendions "
5093 "array size is too small");
5094 sh.push_back(shape_[
i] - 1U);
5098 const unsigned long rLen = result.
length();
5099 for (
unsigned long ilin=0; ilin<rLen; ++ilin)
5104 for (
unsigned long icycle=0UL; icycle<maxcycle; ++icycle)
5106 unsigned long icell = 0UL;
5108 for (
unsigned i=0;
i<dim_; ++
i)
5110 if (icycle & (1UL <<
i))
5113 icell += strides_[
i]*(sh[
i] + 1);
5116 icell += strides_[
i]*sh[
i];
5118 if ((dim_ - n1) % 2U)
5119 deriv -= data_[icell];
5121 deriv += data_[icell];
5123 result.
data_[ilin] =
static_cast<Numeric
>(deriv*
scale);
5129 template<
typename Numeric,
unsigned Len,
unsigned Dim>
5130 template <
typename Accumulator>
5132 const unsigned level,
unsigned long idx0,
5133 const unsigned*
limit)
const
5136 const unsigned imax = limit[
level] + 1U;
5137 if (level == dim_ - 1)
5139 Numeric*
base = data_ + idx0;
5140 for (
unsigned i=0;
i<imax; ++
i)
5145 const unsigned long stride = strides_[
level];
5146 for (
unsigned i=0;
i<imax; ++
i, idx0+=stride)
5147 cdf += sumBelowLoop<Accumulator>(level+1, idx0, limit);
5152 template<
typename Numeric,
unsigned Len,
unsigned Dim>
5153 template <
typename Accumulator>
5155 const unsigned *
index,
const unsigned indexLen)
const
5158 "Initialize npstat::ArrayND before calling method \"cdfValue\"");
5160 "npstat::ArrayND::cdfValue method "
5161 "can not be used with array of 0 rank");
5163 "In npstat::ArrayND::cdfValue: incompatible index length");
5164 for (
unsigned i=0;
i<indexLen; ++
i)
5165 if (index[
i] >= shape_[
i])
5167 "In npstat::ArrayND::cdfValue: index out of range");
5168 return sumBelowLoop<Accumulator>(0, 0U,
index);
5171 template<
typename Numeric,
unsigned Len,
unsigned Dim>
5172 template <
typename Accumulator>
5174 const double inscale)
const
5177 "Initialize npstat::ArrayND before calling method \"cdfArray\"");
5179 "npstat::ArrayND::cdfArray method "
5180 "can not be used with array of 0 rank");
5183 const unsigned maxdim = CHAR_BIT*
sizeof(
unsigned long);
5186 "In npstat::ArrayND::cdfArray: array rank is too large");
5187 const unsigned long maxcycle = 1UL << dim_;
5191 for (
unsigned i=0;
i<dim_; ++
i)
5192 sh.push_back(shape_[
i] + 1U);
5196 unsigned* psh = &sh[0];
5197 const unsigned long len = result.
length();
5198 for (
unsigned long ipre=0; ipre<len; ++ipre)
5203 for (
unsigned i=0;
i<dim_; ++
i)
5211 for (
unsigned long icycle=0UL; icycle<maxcycle; ++icycle)
5213 unsigned long icell = 0UL;
5215 for (
unsigned i=0;
i<dim_; ++
i)
5217 if (icycle & (1UL <<
i))
5227 if ((dim_ - n1) % 2U)
5228 deriv += result.
data_[icell];
5230 deriv -= result.
data_[icell];
5235 result.
data_[ipre] = deriv;
5242 template<
typename Numeric,
unsigned Len,
unsigned Dim>
5244 const unsigned pos1,
const unsigned pos2)
const
5247 "Initialize npstat::ArrayND before calling method \"transpose\"");
5248 if (!(pos1 < dim_ && pos2 < dim_ && pos1 != pos2))
5250 "incompatible transposition indices");
5256 unsigned newshapeBuf[Dim];
5257 unsigned *newshape =
makeBuffer(dim_, newshapeBuf, Dim);
5259 std::swap(newshape[pos1], newshape[pos2]);
5265 transposeLoop(0, pos1, pos2, 0UL, 0UL, result);
5272 template<
typename Numeric,
unsigned Len,
unsigned Dim>
5273 template<
typename Num2,
unsigned Len2,
unsigned Dim2>
5279 "Initialize npstat::ArrayND before calling method \"multiMirror\"");
5283 "In npstat::ArrayND::multiMirror: incompatible argument array rank");
5287 const unsigned *dshape = out->
shape_;
5288 for (
unsigned i=0;
i<dim_; ++
i)
5290 "In npstat::ArrayND::multiMirror: "
5291 "incompatible argument array shape");
5293 if (dim_ >= CHAR_BIT*
sizeof(
unsigned long))
5295 "In npstat::ArrayND::multiMirror: "
5296 "array rank is too large");
5297 const unsigned long maxcycle = 1UL << dim_;
5298 std::vector<unsigned> indexbuf(dim_*2U);
5299 unsigned*
idx = &indexbuf[0];
5300 unsigned* mirror = idx + dim_;
5302 for (
unsigned long ipt=0; ipt<len_; ++ipt)
5304 unsigned long l = ipt;
5305 for (
unsigned i=0;
i<dim_; ++
i)
5307 idx[
i] = l / strides_[
i];
5308 l -= (idx[
i] * strides_[
i]);
5310 for (
unsigned long icycle=0UL; icycle<maxcycle; ++icycle)
5312 for (
unsigned i=0;
i<dim_; ++
i)
5314 if (icycle & (1UL <<
i))
5315 mirror[
i] = dshape[
i] - idx[
i] - 1U;
5319 out->
value(mirror, dim_) = data_[ipt];
5324 out->
localData_[0] =
static_cast<Num2
>(localData_[0]);
5327 template<
typename Numeric,
unsigned Len,
unsigned Dim>
5328 template<
typename Num2,
unsigned Len2,
unsigned Dim2>
5330 const unsigned* shifts,
const unsigned lenShifts,
5335 "Initialize npstat::ArrayND before calling method \"rotate\"");
5338 "In npstat::ArrayND::rotate: can not rotate array into itself");
5342 "In npstat::ArrayND::rotate: incompatible argument array rank");
5344 "In npstat::ArrayND::rotate: incompatible dimensionality of shifts");
5349 if (dim_ > CHAR_BIT*
sizeof(
unsigned long))
5351 "In npstat::ArrayND::rotate: array rank is too large");
5352 unsigned buf[CHAR_BIT*
sizeof(
unsigned long)];
5354 (
const_cast<ArrayND*
>(
this))->flatCircularLoop(
5355 0U, 0UL, 0UL, buf, shape_, shifts,
5359 rotated->
localData_[0] =
static_cast<Num2
>(localData_[0]);
5362 template<
typename Numeric,
unsigned Len,
unsigned Dim>
5363 template<
typename Num2,
unsigned Len2,
unsigned Dim2>
5365 const unsigned level,
unsigned long idx0,
5366 unsigned long idx1,
unsigned long idx2,
5373 if (level == result.
dim_)
5375 Numeric sum = Numeric();
5376 const unsigned imax = r.
shape_[0];
5377 const unsigned rstride = r.
strides_[0];
5378 const Numeric*
l = data_ + idx0;
5379 const Num2* ri = r.
data_ + idx1;
5380 for (
unsigned i=0;
i<imax; ++
i)
5381 sum += l[
i]*ri[
i*rstride];
5382 result.
data_[idx2] = sum;
5387 for (
unsigned i=0;
i<imax; ++
i)
5389 dotProductLoop(level+1, idx0, idx1, idx2, r, result);
5391 if (level < dim_ - 1)
5392 idx0 += strides_[
level];
5394 idx1 += r.
strides_[level + 2 - dim_];
5399 template<
typename Numeric,
unsigned Len,
unsigned Dim>
5400 template<
typename Num2,
unsigned Len2,
unsigned Dim2>
5405 "npstat::ArrayND::dot method "
5406 "can not be used with array of 0 rank");
5408 "npstat::ArrayND::dot method "
5409 "can not be used with argument array of 0 rank");
5411 "In npstat::ArrayND::dot: incompatible argument array shape");
5413 if (dim_ == 1 && r.
dim_ == 1)
5417 Numeric sum = Numeric();
5418 const unsigned imax = shape_[0];
5419 for (
unsigned i=0;
i<imax; ++
i)
5426 unsigned newshapeBuf[2*Dim];
5427 unsigned *newshape =
makeBuffer(dim_+r.
dim_-2, newshapeBuf, 2*Dim);
5432 dotProductLoop(0U, 0UL, 0UL, 0UL, r, result);
5439 template<
typename Numeric,
unsigned Len,
unsigned Dim>
5444 "In npstat::ArrayND::span: dimension number is out of range");
5448 template<
typename Numeric,
unsigned Len,
unsigned Dim>
5451 unsigned maxspan = 0;
5452 for (
unsigned i=0;
i<dim_; ++
i)
5453 if (shape_[
i] > maxspan)
5454 maxspan = shape_[
i];
5458 template<
typename Numeric,
unsigned Len,
unsigned Dim>
5463 unsigned minspan = shape_[0];
5464 for (
unsigned i=1;
i<dim_; ++
i)
5465 if (shape_[
i] < minspan)
5466 minspan = shape_[
i];
5470 template<
typename Numeric,
unsigned Len,
unsigned Dim>
5474 "Initialize npstat::ArrayND before calling method \"cl\"");
5476 "In npstat::ArrayND::cl: wrong # of args (not rank 0 array)");
5477 return localData_[0];
5480 template<
typename Numeric,
unsigned Len,
unsigned Dim>
5482 const double i0)
const
5485 "In npstat::ArrayND::cl: wrong # of args (not rank 1 array)");
5486 return data_[coordToIndex(i0, 0)];
5489 template<
typename Numeric,
unsigned Len,
unsigned Dim>
5492 const double i1)
const
5495 "In npstat::ArrayND::cl: wrong # of args (not rank 2 array)");
5496 return data_[coordToIndex(i0, 0)*strides_[0] +
5497 coordToIndex(i1, 1)];
5500 template<
typename Numeric,
unsigned Len,
unsigned Dim>
5504 const double i2)
const
5507 "In npstat::ArrayND::cl: wrong # of args (not rank 3 array)");
5508 return data_[coordToIndex(i0, 0)*strides_[0] +
5509 coordToIndex(i1, 1)*strides_[1] +
5510 coordToIndex(i2, 2)];
5513 template<
typename Numeric,
unsigned Len,
unsigned Dim>
5518 const double i3)
const
5521 "In npstat::ArrayND::cl: wrong # of args (not rank 4 array)");
5522 return data_[coordToIndex(i0, 0)*strides_[0] +
5523 coordToIndex(i1, 1)*strides_[1] +
5524 coordToIndex(i2, 2)*strides_[2] +
5525 coordToIndex(i3, 3)];
5528 template<
typename Numeric,
unsigned Len,
unsigned Dim>
5534 const double i4)
const
5537 "In npstat::ArrayND::cl: wrong # of args (not rank 5 array)");
5538 return data_[coordToIndex(i0, 0)*strides_[0] +
5539 coordToIndex(i1, 1)*strides_[1] +
5540 coordToIndex(i2, 2)*strides_[2] +
5541 coordToIndex(i3, 3)*strides_[3] +
5542 coordToIndex(i4, 4)];
5545 template<
typename Numeric,
unsigned Len,
unsigned Dim>
5552 const double i5)
const
5555 "In npstat::ArrayND::cl: wrong # of args (not rank 6 array)");
5556 return data_[coordToIndex(i0, 0)*strides_[0] +
5557 coordToIndex(i1, 1)*strides_[1] +
5558 coordToIndex(i2, 2)*strides_[2] +
5559 coordToIndex(i3, 3)*strides_[3] +
5560 coordToIndex(i4, 4)*strides_[4] +
5561 coordToIndex(i5, 5)];
5564 template<
typename Numeric,
unsigned Len,
unsigned Dim>
5572 const double i6)
const
5575 "In npstat::ArrayND::cl: wrong # of args (not rank 7 array)");
5576 return data_[coordToIndex(i0, 0)*strides_[0] +
5577 coordToIndex(i1, 1)*strides_[1] +
5578 coordToIndex(i2, 2)*strides_[2] +
5579 coordToIndex(i3, 3)*strides_[3] +
5580 coordToIndex(i4, 4)*strides_[4] +
5581 coordToIndex(i5, 5)*strides_[5] +
5582 coordToIndex(i6, 6)];
5585 template<
typename Numeric,
unsigned Len,
unsigned Dim>
5594 const double i7)
const
5597 "In npstat::ArrayND::cl: wrong # of args (not rank 8 array)");
5598 return data_[coordToIndex(i0, 0)*strides_[0] +
5599 coordToIndex(i1, 1)*strides_[1] +
5600 coordToIndex(i2, 2)*strides_[2] +
5601 coordToIndex(i3, 3)*strides_[3] +
5602 coordToIndex(i4, 4)*strides_[4] +
5603 coordToIndex(i5, 5)*strides_[5] +
5604 coordToIndex(i6, 6)*strides_[6] +
5605 coordToIndex(i7, 7)];
5608 template<
typename Numeric,
unsigned Len,
unsigned Dim>
5618 const double i8)
const
5621 "In npstat::ArrayND::cl: wrong # of args (not rank 9 array)");
5622 return data_[coordToIndex(i0, 0)*strides_[0] +
5623 coordToIndex(i1, 1)*strides_[1] +
5624 coordToIndex(i2, 2)*strides_[2] +
5625 coordToIndex(i3, 3)*strides_[3] +
5626 coordToIndex(i4, 4)*strides_[4] +
5627 coordToIndex(i5, 5)*strides_[5] +
5628 coordToIndex(i6, 6)*strides_[6] +
5629 coordToIndex(i7, 7)*strides_[7] +
5630 coordToIndex(i8, 8)];
5633 template<
typename Numeric,
unsigned Len,
unsigned Dim>
5644 const double i9)
const
5647 "In npstat::ArrayND::cl: wrong # of args (not rank 10 array)");
5648 return data_[coordToIndex(i0, 0)*strides_[0] +
5649 coordToIndex(i1, 1)*strides_[1] +
5650 coordToIndex(i2, 2)*strides_[2] +
5651 coordToIndex(i3, 3)*strides_[3] +
5652 coordToIndex(i4, 4)*strides_[4] +
5653 coordToIndex(i5, 5)*strides_[5] +
5654 coordToIndex(i6, 6)*strides_[6] +
5655 coordToIndex(i7, 7)*strides_[7] +
5656 coordToIndex(i8, 8)*strides_[8] +
5657 coordToIndex(i9, 9)];
5660 template<
typename Numeric,
unsigned Len,
unsigned Dim>
5664 "Initialize npstat::ArrayND before calling method \"cl\"");
5666 "In npstat::ArrayND::cl: wrong # of args (not rank 0 array)");
5667 return localData_[0];
5670 template<
typename Numeric,
unsigned Len,
unsigned Dim>
5675 "In npstat::ArrayND::cl: wrong # of args (not rank 1 array)");
5676 return data_[coordToIndex(i0, 0)];
5679 template<
typename Numeric,
unsigned Len,
unsigned Dim>
5685 "In npstat::ArrayND::cl: wrong # of args (not rank 2 array)");
5686 return data_[coordToIndex(i0, 0)*strides_[0] +
5687 coordToIndex(i1, 1)];
5690 template<
typename Numeric,
unsigned Len,
unsigned Dim>
5697 "In npstat::ArrayND::cl: wrong # of args (not rank 3 array)");
5698 return data_[coordToIndex(i0, 0)*strides_[0] +
5699 coordToIndex(i1, 1)*strides_[1] +
5700 coordToIndex(i2, 2)];
5703 template<
typename Numeric,
unsigned Len,
unsigned Dim>
5711 "In npstat::ArrayND::cl: wrong # of args (not rank 4 array)");
5712 return data_[coordToIndex(i0, 0)*strides_[0] +
5713 coordToIndex(i1, 1)*strides_[1] +
5714 coordToIndex(i2, 2)*strides_[2] +
5715 coordToIndex(i3, 3)];
5718 template<
typename Numeric,
unsigned Len,
unsigned Dim>
5727 "In npstat::ArrayND::cl: wrong # of args (not rank 5 array)");
5728 return data_[coordToIndex(i0, 0)*strides_[0] +
5729 coordToIndex(i1, 1)*strides_[1] +
5730 coordToIndex(i2, 2)*strides_[2] +
5731 coordToIndex(i3, 3)*strides_[3] +
5732 coordToIndex(i4, 4)];
5735 template<
typename Numeric,
unsigned Len,
unsigned Dim>
5745 "In npstat::ArrayND::cl: wrong # of args (not rank 6 array)");
5746 return data_[coordToIndex(i0, 0)*strides_[0] +
5747 coordToIndex(i1, 1)*strides_[1] +
5748 coordToIndex(i2, 2)*strides_[2] +
5749 coordToIndex(i3, 3)*strides_[3] +
5750 coordToIndex(i4, 4)*strides_[4] +
5751 coordToIndex(i5, 5)];
5754 template<
typename Numeric,
unsigned Len,
unsigned Dim>
5765 "In npstat::ArrayND::cl: wrong # of args (not rank 7 array)");
5766 return data_[coordToIndex(i0, 0)*strides_[0] +
5767 coordToIndex(i1, 1)*strides_[1] +
5768 coordToIndex(i2, 2)*strides_[2] +
5769 coordToIndex(i3, 3)*strides_[3] +
5770 coordToIndex(i4, 4)*strides_[4] +
5771 coordToIndex(i5, 5)*strides_[5] +
5772 coordToIndex(i6, 6)];
5775 template<
typename Numeric,
unsigned Len,
unsigned Dim>
5787 "In npstat::ArrayND::cl: wrong # of args (not rank 8 array)");
5788 return data_[coordToIndex(i0, 0)*strides_[0] +
5789 coordToIndex(i1, 1)*strides_[1] +
5790 coordToIndex(i2, 2)*strides_[2] +
5791 coordToIndex(i3, 3)*strides_[3] +
5792 coordToIndex(i4, 4)*strides_[4] +
5793 coordToIndex(i5, 5)*strides_[5] +
5794 coordToIndex(i6, 6)*strides_[6] +
5795 coordToIndex(i7, 7)];
5798 template<
typename Numeric,
unsigned Len,
unsigned Dim>
5811 "In npstat::ArrayND::cl: wrong # of args (not rank 9 array)");
5812 return data_[coordToIndex(i0, 0)*strides_[0] +
5813 coordToIndex(i1, 1)*strides_[1] +
5814 coordToIndex(i2, 2)*strides_[2] +
5815 coordToIndex(i3, 3)*strides_[3] +
5816 coordToIndex(i4, 4)*strides_[4] +
5817 coordToIndex(i5, 5)*strides_[5] +
5818 coordToIndex(i6, 6)*strides_[6] +
5819 coordToIndex(i7, 7)*strides_[7] +
5820 coordToIndex(i8, 8)];
5823 template<
typename Numeric,
unsigned Len,
unsigned Dim>
5837 "In npstat::ArrayND::cl: wrong # of args (not rank 10 array)");
5838 return data_[coordToIndex(i0, 0)*strides_[0] +
5839 coordToIndex(i1, 1)*strides_[1] +
5840 coordToIndex(i2, 2)*strides_[2] +
5841 coordToIndex(i3, 3)*strides_[3] +
5842 coordToIndex(i4, 4)*strides_[4] +
5843 coordToIndex(i5, 5)*strides_[5] +
5844 coordToIndex(i6, 6)*strides_[6] +
5845 coordToIndex(i7, 7)*strides_[7] +
5846 coordToIndex(i8, 8)*strides_[8] +
5847 coordToIndex(i9, 9)];
5850 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
5854 gs::template_class_name<Numeric>(
"npstat::ArrayND"));
5855 return name.c_str();
5858 template<
typename Numeric,
unsigned StackLen,
unsigned StackDim>
5862 "Initialize npstat::ArrayND before calling method \"write\"");
5863 gs::write_pod_vector(os, shape());
5864 return !os.fail() &&
5865 (dim_ ? gs::write_array(os, data_, len_) :
5866 gs::write_item(os, localData_[0],
false));
5869 template<
typename Numeric,
unsigned Len,
unsigned Dim>
5871 const gs::ClassId&
id, std::istream&
in,
ArrayND* array)
5874 current.ensureSameId(
id);
5877 gs::read_pod_vector(in, &rshape);
5878 if (in.fail())
throw gs::IOReadFailure(
5879 "In npstat::ArrayND::restore: input stream failure (checkpoint 0)");
5883 array->
dim_ = rshape.size();
5889 for (
unsigned i=0;
i<array->
dim_; ++
i)
5897 gs::read_array(in, array->
data_, array->
len_);
5900 gs::restore_item(in, array->
localData_,
false);
5901 if (in.fail())
throw gs::IOReadFailure(
5902 "In npstat::ArrayND::restore: input stream failure (checkpoint 1)");
5905 template<
typename Numeric,
unsigned Len,
unsigned StackDim>
5906 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
5908 const unsigned* corner,
const unsigned lenCorner,
5912 "Initialize npstat::ArrayND before calling method \"exportSubrange\"");
5914 "In npstat::ArrayND::exportSubrange: incompatible corner index length");
5917 "In npstat::ArrayND::exportSubrange: uninitialized argument array");
5919 "In npstat::ArrayND::exportSubrange: incompatible argument array rank");
5924 if (dim_ > CHAR_BIT*
sizeof(
unsigned long))
5926 "In npstat::ArrayND::exportSubrange: "
5927 "array rank is too large");
5928 unsigned toBuf[CHAR_BIT*
sizeof(
unsigned long)];
5930 (
const_cast<ArrayND*
>(
this))->commonSubrangeLoop(
5931 0U, 0UL, 0UL, corner, out->
shape_, toBuf, *out,
5935 out->
localData_[0] =
static_cast<Num2
>(localData_[0]);
5938 template<
typename Numeric,
unsigned Len,
unsigned StackDim>
5939 template <
typename Num2,
unsigned Len2,
unsigned Dim2>
5941 const unsigned* corner,
const unsigned lenCorner,
5945 "Initialize npstat::ArrayND before calling method \"importSubrange\"");
5947 "In npstat::ArrayND::importSubrange: incompatible corner index length");
5949 "In npstat::ArrayND::importSubrange: uninitialized argument array");
5951 "In npstat::ArrayND::importSubrange: incompatible argument array rank");
5956 if (dim_ > CHAR_BIT*
sizeof(
unsigned long))
5958 "In npstat::ArrayND::importSubrange: "
5959 "array rank is too large");
5960 unsigned toBuf[CHAR_BIT*
sizeof(
unsigned long)];
5962 commonSubrangeLoop(0U, 0UL, 0UL, corner, from.
shape_, toBuf,
5967 localData_[0] =
static_cast<Numeric
>(from.
localData_[0]);
5972 #endif // NPSTAT_ARRAYND_HH_
void jointSubrangeScan(ArrayND< Num2, Len2, Dim2 > &other, const unsigned *thisCorner, const unsigned *range, const unsigned *otherCorner, unsigned arrLen, Functor binaryFunct)
void marginalizeLoop(unsigned level, unsigned long idx, unsigned levelRes, unsigned long idxRes, const ArrayND< Num2, Len2, Dim2 > &prior, const unsigned *indexMap, ArrayND &res) const
void copyBuffer(T1 *dest, const T2 *source, const unsigned long len)
unsigned long verifySliceCompatibility(const ArrayND< Num2, Len2, Dim2 > &slice, const unsigned *fixedIndices, const unsigned *fixedIndexValues, unsigned nFixedIndices) const
unsigned localShape_[StackDim]
virtual void process(const Input &value)=0
ArrayND & setData(const Num2 *data, unsigned long dataLength)
void transposeLoop(unsigned level, unsigned pos1, unsigned pos2, unsigned long idxThis, unsigned long idxRes, ArrayND &result) const
void jointSliceLoop(unsigned level, unsigned long idx0, unsigned level1, unsigned long idx1, ArrayND< Num2, Len2, Dim2 > &slice, const unsigned *fixedIndices, const unsigned *fixedIndexValues, unsigned nFixedIndices, Functor binaryFunctor)
bool isShapeCompatible(const ArrayND< Num2, Len2, Dim2 > &r) const
virtual Result result()=0
void subtractFromProjection(ArrayND< Num2, Len2, Dim2 > *projection, AbsArrayProjector< Numeric, Num3 > &projector, const unsigned *projectedIndices, unsigned nProjectedIndices) const
ArrayND dot(const ArrayND< Num2, Len2, Dim2 > &r) const
ArrayND operator-() const
void commonSubrangeLoop(unsigned level, unsigned long idx0, unsigned long idx1, const unsigned *thisCorner, const unsigned *range, const unsigned *otherCorner, ArrayND< Num2, Len2, Dim2 > &other, Functor binaryFunct)
unsigned long linearIndex(const unsigned *idx, unsigned idxLen) const
void convertLinearIndex(unsigned long l, unsigned *index, unsigned indexLen) const
void flatCircularScan(ArrayND< Num2, Len2, Dim2 > &other, const unsigned *thisCorner, const unsigned *range, const unsigned *otherCorner, unsigned arrLen, Functor binaryFunct)
static bool less(const T &l, const T &r)
void dualCircularScan(ArrayND< Num2, Len2, Dim2 > &other, const unsigned *thisCorner, const unsigned *range, const unsigned *otherCorner, unsigned arrLen, Functor binaryFunct)
virtual Result result()=0
void projectInnerLoop(unsigned level, unsigned long idx0, unsigned *currentIndex, AbsArrayProjector< Numeric, Num2 > &projector, const unsigned *projectedIndices, unsigned nProjectedIndices) const
bool write(std::ostream &of) const
void processSubrangeLoop(unsigned level, unsigned long idx0, unsigned *currentIndex, AbsArrayProjector< Numeric, Num2 > &f, const BoxND< Integer > &subrange) const
T * makeBuffer(unsigned sizeNeeded, T *stackBuffer, unsigned sizeofStackBuffer)
ArrayND & operator/=(const Num2 &r)
ArrayND & apply(Functor f)
ArrayND & addmul(const ArrayND< Num2, Len2, Dim2 > &r, const Num3 &c)
void multiMirror(ArrayND< Num2, Len2, Dim2 > *out) const
const unsigned * shapeData() const
void projectLoop(unsigned level, unsigned long idx0, unsigned level1, unsigned long idx1, unsigned *currentIndex, ArrayND< Num2, Len2, Dim2 > *projection, AbsArrayProjector< Numeric, Num3 > &projector, const unsigned *projectedIndices, unsigned nProjectedIndices, Op fcn) const
T interpolate_cubic(const double x, const T &f0, const T &f1, const T &f2, const T &f3)
void verifyProjectionCompatibility(const ArrayND< Num2, Len2, Dim2 > &projection, const unsigned *projectedIndices, unsigned nProjectedIndices) const
Private::AbsReturnType< T >::type absDifference(const T &v1, const T &v2)
virtual void process(const unsigned *index, unsigned indexLen, unsigned long linearIndex, const Input &value)=0
void jointScan(ArrayND< Num2, Len2, Dim2 > &other, Functor binaryFunct)
void scaleBySliceLoop(unsigned level, unsigned long idx0, unsigned level1, unsigned long idx1, ArrayND< Num2, Len2, Dim2 > &slice, const unsigned *fixedIndices, unsigned nFixedIndices, Functor binaryFunct)
Numeric & closest(const double *x, unsigned xDim)
const Numeric max() const
bool isClose(const ArrayND< Num2, Len2, Dim2 > &r, double eps) const
void dotProductLoop(unsigned level, unsigned long idx0, unsigned long idx1, unsigned long idx2, const ArrayND< Num2, Len2, Dim2 > &r, ArrayND &result) const
std::vector< unsigned > ArrayShape
T interpolate_quadratic(const double x, const T &f0, const T &f1, const T &f2)
Numeric & linearValue(unsigned long index)
unsigned long length() const
unsigned span(unsigned dim) const
Interface definition for functors used to make array projections.
Numeric & value(const unsigned *index, unsigned indexLen)
void addToProjection(ArrayND< Num2, Len2, Dim2 > *projection, AbsArrayProjector< Numeric, Num3 > &projector, const unsigned *projectedIndices, unsigned nProjectedIndices) const
ArrayRange fullRange() const
ArrayND contract(unsigned pos1, unsigned pos2) const
static const char * classname()
void linearFillLoop(unsigned level, double s0, unsigned long idx, double shift, const double *coeffs)
Numeric & linearValueAt(unsigned long index)
Compile-time deduction of the underlying floating point type from the given complex type...
void project(ArrayND< Num2, Len2, Dim2 > *projection, AbsArrayProjector< Numeric, Num3 > &projector, const unsigned *projectedIndices, unsigned nProjectedIndices) const
bool operator==(const ArrayND< Numeric, Len2, Dim2 > &) const
Numeric interpolate1(const double *x, unsigned xDim) const
unsigned long dim() const
ArrayND & operator=(const ArrayND &)
ArrayND & functorFill(Functor f)
unsigned long localStrides_[StackDim]
ArrayND & constFill(Numeric c)
Multidimensional range of array indices.
ArrayND & scanInPlace(Functor f)
void applySlice(ArrayND< Num2, Len2, Dim2 > &slice, const unsigned *fixedIndices, unsigned nFixedIndices, Functor binaryFunct)
ArrayND & inPlaceMul(const ArrayND< Num2, Len2, Dim2 > &r)
void functorFillLoop(unsigned level, unsigned long idx, Functor f, unsigned *farg)
Numeric marginalizeInnerLoop(unsigned long idx, unsigned levelPr, unsigned long idxPr, const ArrayND< Num2, Len2, Dim2 > &prior, const unsigned *indexMap) const
void outerProductLoop(unsigned level, unsigned long idx0, unsigned long idx1, unsigned long idx2, const ArrayND< Num1, Len1, Dim1 > &a1, const ArrayND< Num2, Len2, Dim2 > &a2)
unsigned long rangeSize() const
Exceptions for the npstat namespace.
void projectInnerLoop2(unsigned level, unsigned long idx0, AbsVisitor< Numeric, Num2 > &projector, const unsigned *projectedIndices, unsigned nProjectedIndices) const
void convertToLastDimCdfLoop(ArrayND *sumSlice, unsigned level, unsigned long idx0, unsigned long idxSlice, bool useTrapezoids)
gs::ClassId classId() const
void rotate(const unsigned *shifts, unsigned lenShifts, ArrayND< Num2, Len2, Dim2 > *rotated) const
void circularFlatLoop(unsigned level, unsigned long idx0, unsigned long idx1, const unsigned *thisCorner, const unsigned *range, const unsigned *otherCorner, ArrayND< Num2, Len2, Dim2 > &other, Functor binaryFunct)
void dualCircularLoop(unsigned level, unsigned long idx0, unsigned long idx1, const unsigned *thisCorner, const unsigned *range, const unsigned *otherCorner, ArrayND< Num2, Len2, Dim2 > &other, Functor binaryFunct)
double maxAbsDifference(const ArrayND< Numeric, Len2, Dim2 > &) const
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
static unsigned version()
void contractLoop(unsigned thisLevel, unsigned resLevel, unsigned pos1, unsigned pos2, unsigned long idxThis, unsigned long idxRes, ArrayND &result) const
Compile-time deduction of an appropriate precise numeric type.
Numeric & valueAt(const unsigned *index, unsigned indexLen)
ArrayND & operator*=(const Num2 &r)
ArrayND marginalize(const ArrayND< Num2, Len2, Dim2 > &prior, const unsigned *indexMap, unsigned mapLen) const
unsigned minimumSpan() const
ArrayND transpose() const
const Numeric * data() const
unsigned maximumSpan() const
void flatCircularLoop(unsigned level, unsigned long idx0, unsigned long idx1, const unsigned *thisCorner, const unsigned *range, const unsigned *otherCorner, ArrayND< Num2, Len2, Dim2 > &other, Functor binaryFunct)
void importSubrange(const unsigned *fromCorner, unsigned lenCorner, const ArrayND< Num2, Len2, Dim2 > &from)
Numeric interpolateLoop(unsigned level, const double *x, const Numeric *base) const
#define me_macro_check_loop_prerequisites(METHOD, INNERLOOP)
bool isCompatible(const ArrayShape &shape) const
void clearBuffer(T *buf, const unsigned long len)
ArrayND outer(const ArrayND< Num2, Len2, Dim2 > &r) const
Interface definitions and concrete simple functors for a variety of functor-based calculations...
ArrayND & multiplyBySlice(const ArrayND< Num2, Len2, Dim2 > &slice, const unsigned *fixedIndices, unsigned nFixedIndices)
void convertToLastDimCdf(ArrayND *sumSlice, bool useTrapezoids)
Interface for piecemeal processing of a data collection.
unsigned long long int rval
ArrayND & assign(const ArrayND< Num2, Len2, Dim2 > &, Functor f)
Numeric localData_[StackLen]
void jointSliceScan(ArrayND< Num2, Len2, Dim2 > &slice, const unsigned *fixedIndices, const unsigned *fixedIndexValues, unsigned nFixedIndices, Functor binaryFunct)
Ordering extended to complex numbers by comparing their magnitudes.
Private::AbsReturnType< T >::type absValue(const T &v1)
void scaleBySliceInnerLoop(unsigned level, unsigned long idx0, Num2 &scale, const unsigned *projectedIndices, unsigned nProjectedIndices, Functor binaryFunct)
static void restore(const gs::ClassId &id, std::istream &in, ArrayND *array)
void fcn(int &, double *, double &, double *, int)
tuple idx
DEBUGGING if hasattr(process,"trackMonIterativeTracking2012"): print "trackMonIterativeTracking2012 D...
void copyRangeLoopFunct(unsigned level, unsigned long idx0, unsigned long idx1, const ArrayND< Num2, Len2, Dim2 > &r, const ArrayRange &range, Functor f)
void rangeLength(unsigned *range, unsigned rangeLen) const
void importSlice(const ArrayND< Num2, Len2, Dim2 > &slice, const unsigned *fixedIndices, const unsigned *fixedIndexValues, unsigned nFixedIndices)
void lowerLimits(unsigned *limits, unsigned limitsLen) const
void exportSubrange(const unsigned *fromCorner, unsigned lenCorner, ArrayND< Num2, Len2, Dim2 > *dest) const
ArrayND operator+() const
void projectLoop2(unsigned level, unsigned long idx0, unsigned level1, unsigned long idx1, ArrayND< Num2, Len2, Dim2 > *projection, AbsVisitor< Numeric, Num3 > &projector, const unsigned *projectedIndices, unsigned nProjectedIndices, Op fcn) const
unsigned makeCopulaSteps(double tolerance, unsigned maxIterations)
Ordering extended to complex numbers by always returning "false".
ArrayND & makeNonNegative()
std::vector< std::vector< double > > tmp
ArrayND & operator-=(const ArrayND< Num2, Len2, Dim2 > &r)
ArrayShape doubleShape(const ArrayShape &inputShape)
ArrayND derivative(double scale=1.0) const
char data[epos_bytes_allocation]
ArrayND & operator+=(const ArrayND< Num2, Len2, Dim2 > &r)
void circularFlatScan(ArrayND< Num2, Len2, Dim2 > &other, const unsigned *thisCorner, const unsigned *range, const unsigned *otherCorner, unsigned arrLen, Functor binaryFunct)
Accumulator sumBelowLoop(unsigned level, unsigned long idx0, const unsigned *limit) const
void processSubrange(AbsArrayProjector< Numeric, Num2 > &f, const BoxND< Integer > &subrange) const
bool isCompatible(const ArrayShape &shape) const
static unsigned int const shift
const unsigned long * strides() const
const Numeric min() const
ProperDblFromCmpl< Numeric >::type proper_double
bool isShapeKnown() const
ArrayND operator*(const Num2 &r) const
unsigned coordToIndex(double coord, unsigned idim) const
ArrayND operator/(const Num2 &r) const
void buildFromShapePtr(const unsigned *, unsigned)
Num2 cdfValue(const unsigned *index, unsigned indexLen) const
ArrayND cdfArray(double scale=1.0) const
Low-order polynomial interpolation (up to cubic) for equidistant coordinates.
Calculate absolute value of a difference between two numbers for an extended set of types...
T interpolate_linear(const double x, const T &f0, const T &f1)
void destroyBuffer(T *thisBuffer, const T *stackBuffer)
Utilities related to memory management.
bool operator!=(const ArrayND< Numeric, Len2, Dim2 > &) const
void exportSlice(ArrayND< Num2, Len2, Dim2 > *slice, const unsigned *fixedIndices, const unsigned *fixedIndexValues, unsigned nFixedIndices) const
Numeric interpolate3(const double *x, unsigned xDim) const
ArrayND & linearFill(const double *coeff, unsigned coeffLen, double c)