1 #ifndef NPSTAT_BOXNDSCANNER_HH_
2 #define NPSTAT_BOXNDSCANNER_HH_
37 template <
typename Numeric>
47 const std::vector<unsigned>& shape)
49 {
initialize(shape.empty() ?
static_cast<unsigned*
>(0) :
50 &shape[0], shape.size());}
53 const unsigned* shape,
const unsigned lenShape)
58 inline unsigned dim()
const {
return box_.dim();}
70 void getCoords(Numeric* x,
unsigned nx)
const;
73 void getIndex(
unsigned*
index,
unsigned indexBufferLen)
const;
92 void initialize(
const unsigned* shape,
unsigned lenShape);
96 std::vector<double>
bw_;
106 template <
typename Numeric>
111 "In npstat::BoxNDScanner::initialize: incompatible scan shape");
113 for (
unsigned j=0;
j<dim; ++
j)
115 "In npstat::BoxNDScanner::initialize: "
116 "number of scans must be positive in each dimension");
118 strides_.resize(dim);
119 strides_[dim - 1] = 1UL;
120 for (
unsigned j=dim - 1; j>0; --
j)
121 strides_[j - 1] = strides_[j]*shape[j];
122 maxState_ = strides_[0]*shape[0];
125 for (
unsigned j=0; j<dim; ++
j)
126 bw_.push_back(box_[j].length()*1.0/shape[
j]);
129 template <
typename Numeric>
132 const unsigned dim = strides_.size();
134 "In npstat::BoxNDScanner::getCoords: "
135 "insufficient length of the output buffer");
137 "In npstat::BoxNDScanner::getCoords: invalid scanner state");
140 unsigned long l = state_;
141 for (
unsigned i=0;
i<dim; ++
i)
143 unsigned long idx = l / strides_[
i];
144 x[
i] = box_[
i].min() + (idx + 0.5)*bw_[
i];
145 l -= (idx * strides_[
i]);
149 template <
typename Numeric>
152 const unsigned dim = strides_.size();
154 "In npstat::BoxNDScanner::getIndex: "
155 "insufficient length of the output buffer");
157 "In npstat::BoxNDScanner::getIndex: invalid scanner state");
160 unsigned long l = state_;
161 for (
unsigned i=0;
i<dim; ++
i)
163 unsigned long idx = l / strides_[
i];
164 ix[
i] =
static_cast<unsigned>(idx);
165 l -= (idx * strides_[
i]);
171 #endif // NPSTAT_BOXNDSCANNER_HH_
void setState(const unsigned long state)
void getCoords(Numeric *x, unsigned nx) const
BoxNDScanner(const BoxND< Numeric > &box, const std::vector< unsigned > &shape)
BoxNDScanner(const BoxND< Numeric > &box, const unsigned *shape, const unsigned lenShape)
Exceptions for the npstat namespace.
void getIndex(unsigned *index, unsigned indexBufferLen) const
void initialize(const unsigned *shape, unsigned lenShape)
BoxNDScanner & operator++()
std::vector< unsigned long > strides_
std::vector< double > bw_
unsigned long state() const
unsigned long maxState() const
Template to represent rectangles, boxes, and hyperboxes.