1 #ifndef NPSTAT_MIRRORWEIGHT_HH_
2 #define NPSTAT_MIRRORWEIGHT_HH_
23 template <
typename T,
unsigned StackLen,
unsigned StackDim>
24 void mirrorWeightLoop(
unsigned level,
unsigned long idxFrom,
25 unsigned long idxTo,
unsigned mirrorDirection,
26 const ArrayND<T,StackLen,StackDim>& from,
27 ArrayND<double,StackLen,StackDim>& to)
29 const bool positive(mirrorDirection & (1UL << level));
30 const unsigned imax = from.span(level);
31 if (level == from.rank() - 1)
33 const T* dfrom = from.data() + idxFrom;
34 double* dto =
const_cast<double *
>(to.data() + (idxTo+imax-1));
36 for (
unsigned i=0; i<imax; ++i)
39 for (
unsigned i=0; i<imax; ++i)
44 const unsigned long fromstride = from.strides()[level];
45 const unsigned long tostride = to.strides()[level];
46 idxTo += (imax - 1)*tostride;
47 for (
unsigned i=0; i<imax; ++i)
49 mirrorWeightLoop(level+1, idxFrom, idxTo,
50 mirrorDirection, from, to);
51 idxFrom += fromstride;
67 template <
typename T,
unsigned StackLen,
unsigned StackDim>
68 void mirrorWeight(
const ArrayND<T,StackLen,StackDim>& from,
69 ArrayND<double,StackLen,StackDim>* to)
71 const unsigned dim = from.rank();
74 const unsigned maxdim = CHAR_BIT*
sizeof(
unsigned long);
78 assert(dim == to->rank());
79 for (
unsigned i=0; i<dim; ++i)
80 assert(to->span(i) == 2U*from.span(i) - 1U);
81 const unsigned long maxcycle = 1UL << dim;
82 for (
unsigned long icycle=0UL; icycle<maxcycle; ++icycle)
83 mirrorWeightLoop(0U, 0UL, 0UL, icycle, from, *to);
Arbitrary-dimensional array template.
Definition: AbsArrayProjector.hh:14