#include <BoxNDScanner.h>
Public Member Functions | |
unsigned | dim () const |
void | getCoords (Numeric *x, unsigned nx) const |
void | getIndex (unsigned *index, unsigned indexBufferLen) const |
bool | isValid () const |
unsigned long | maxState () const |
BoxNDScanner & | operator++ () |
void | operator++ (int) |
void | reset () |
void | setState (const unsigned long state) |
unsigned long | state () const |
BoxNDScanner (const BoxND< Numeric > &box, const std::vector< unsigned > &shape) | |
BoxNDScanner (const BoxND< Numeric > &box, const unsigned *shape, const unsigned lenShape) | |
Private Member Functions | |
BoxNDScanner () | |
void | initialize (const unsigned *shape, unsigned lenShape) |
Private Attributes | |
BoxND< Numeric > | box_ |
std::vector< double > | bw_ |
unsigned long | maxState_ |
unsigned long | state_ |
std::vector< unsigned long > | strides_ |
A class for iterating over all coordinates in a multidimensional box (but not a full-fledeged iterator). The expected usage pattern is as follows:
double* coords = ... (the buffer size should be at least box.dim()) for (BoxNDScanner<double> scan(box,shape); scan.isValid(); ++scan) { scan.getCoords(coords, coordsBufferSize); .... Do what is necessary with coordinates .... .... Extract linear bin number: .............. scan.state(); }
The coordinates will be in the middle of the bins (imagine a multivariate histogram with boundaries defined by the given box).
Definition at line 38 of file BoxNDScanner.h.
npstat::BoxNDScanner< Numeric >::BoxNDScanner | ( | const BoxND< Numeric > & | box, |
const std::vector< unsigned > & | shape | ||
) | [inline] |
Constructor from a bounding box and a multidimensional array shape
Definition at line 46 of file BoxNDScanner.h.
References npstat::BoxNDScanner< Numeric >::initialize().
: box_(box), state_(0UL) {initialize(shape.empty() ? static_cast<unsigned*>(0) : &shape[0], shape.size());}
npstat::BoxNDScanner< Numeric >::BoxNDScanner | ( | const BoxND< Numeric > & | box, |
const unsigned * | shape, | ||
const unsigned | lenShape | ||
) | [inline] |
Definition at line 52 of file BoxNDScanner.h.
References npstat::BoxNDScanner< Numeric >::initialize().
: box_(box), state_(0UL) {initialize(shape, lenShape);}
npstat::BoxNDScanner< Numeric >::BoxNDScanner | ( | ) | [private] |
unsigned npstat::BoxNDScanner< Numeric >::dim | ( | ) | const [inline] |
Dimensionality of the scan
Definition at line 58 of file BoxNDScanner.h.
References npstat::BoxNDScanner< Numeric >::box_.
{return box_.dim();}
void npstat::BoxNDScanner< Numeric >::getCoords | ( | Numeric * | x, |
unsigned | nx | ||
) | const |
Retrieve current coordinates inside the box
Definition at line 130 of file BoxNDScanner.h.
References i, customizeTrackingMonitorSeedNumber::idx, and prof2calltree::l.
{ const unsigned dim = strides_.size(); if (nx < dim) throw npstat::NpstatInvalidArgument( "In npstat::BoxNDScanner::getCoords: " "insufficient length of the output buffer"); if (state_ >= maxState_) throw npstat::NpstatRuntimeError( "In npstat::BoxNDScanner::getCoords: invalid scanner state"); assert(x); unsigned long l = state_; for (unsigned i=0; i<dim; ++i) { unsigned long idx = l / strides_[i]; x[i] = box_[i].min() + (idx + 0.5)*bw_[i]; l -= (idx * strides_[i]); } }
void npstat::BoxNDScanner< Numeric >::getIndex | ( | unsigned * | index, |
unsigned | indexBufferLen | ||
) | const |
Retrieve current multidimensional index
Definition at line 150 of file BoxNDScanner.h.
References i, customizeTrackingMonitorSeedNumber::idx, and prof2calltree::l.
{ const unsigned dim = strides_.size(); if (nx < dim) throw npstat::NpstatInvalidArgument( "In npstat::BoxNDScanner::getIndex: " "insufficient length of the output buffer"); if (state_ >= maxState_) throw npstat::NpstatRuntimeError( "In npstat::BoxNDScanner::getIndex: invalid scanner state"); assert(ix); unsigned long l = state_; for (unsigned i=0; i<dim; ++i) { unsigned long idx = l / strides_[i]; ix[i] = static_cast<unsigned>(idx); l -= (idx * strides_[i]); } }
void npstat::BoxNDScanner< Numeric >::initialize | ( | const unsigned * | shape, |
unsigned | lenShape | ||
) | [private] |
Definition at line 107 of file BoxNDScanner.h.
References j.
Referenced by npstat::BoxNDScanner< Numeric >::BoxNDScanner().
{ if (!(dim && box_.dim() == dim)) throw npstat::NpstatInvalidArgument( "In npstat::BoxNDScanner::initialize: incompatible scan shape"); assert(shape); for (unsigned j=0; j<dim; ++j) if (!shape[j]) throw npstat::NpstatInvalidArgument( "In npstat::BoxNDScanner::initialize: " "number of scans must be positive in each dimension"); strides_.resize(dim); strides_[dim - 1] = 1UL; for (unsigned j=dim - 1; j>0; --j) strides_[j - 1] = strides_[j]*shape[j]; maxState_ = strides_[0]*shape[0]; bw_.reserve(dim); for (unsigned j=0; j<dim; ++j) bw_.push_back(box_[j].length()*1.0/shape[j]); }
bool npstat::BoxNDScanner< Numeric >::isValid | ( | void | ) | const [inline] |
Returns false when iteration is complete
Definition at line 67 of file BoxNDScanner.h.
References npstat::BoxNDScanner< Numeric >::maxState_, and npstat::BoxNDScanner< Numeric >::state_.
unsigned long npstat::BoxNDScanner< Numeric >::maxState | ( | ) | const [inline] |
Maximum possible state (i.e., linear index of the scan)
Definition at line 64 of file BoxNDScanner.h.
References npstat::BoxNDScanner< Numeric >::maxState_.
{return maxState_;}
BoxNDScanner& npstat::BoxNDScanner< Numeric >::operator++ | ( | void | ) | [inline] |
Prefix increment
Definition at line 79 of file BoxNDScanner.h.
References npstat::BoxNDScanner< Numeric >::maxState_, and npstat::BoxNDScanner< Numeric >::state_.
void npstat::BoxNDScanner< Numeric >::operator++ | ( | int | ) | [inline] |
Postfix increment (distinguished by the dummy "int" parameter)
Definition at line 83 of file BoxNDScanner.h.
References npstat::BoxNDScanner< Numeric >::maxState_, and npstat::BoxNDScanner< Numeric >::state_.
void npstat::BoxNDScanner< Numeric >::reset | ( | void | ) | [inline] |
Reset the state (as if the object has just been constructed)
Definition at line 76 of file BoxNDScanner.h.
References npstat::BoxNDScanner< Numeric >::state_.
{state_ = 0UL;}
void npstat::BoxNDScanner< Numeric >::setState | ( | const unsigned long | state | ) | [inline] |
Set the state directly
Definition at line 86 of file BoxNDScanner.h.
References npstat::BoxNDScanner< Numeric >::maxState_, and npstat::BoxNDScanner< Numeric >::state_.
unsigned long npstat::BoxNDScanner< Numeric >::state | ( | ) | const [inline] |
Retrieve current state (i.e., linear index of the scan)
Definition at line 61 of file BoxNDScanner.h.
References npstat::BoxNDScanner< Numeric >::state_.
{return state_;}
BoxND<Numeric> npstat::BoxNDScanner< Numeric >::box_ [private] |
Definition at line 94 of file BoxNDScanner.h.
Referenced by npstat::BoxNDScanner< Numeric >::dim().
std::vector<double> npstat::BoxNDScanner< Numeric >::bw_ [private] |
Definition at line 96 of file BoxNDScanner.h.
unsigned long npstat::BoxNDScanner< Numeric >::maxState_ [private] |
Definition at line 98 of file BoxNDScanner.h.
Referenced by npstat::BoxNDScanner< Numeric >::isValid(), npstat::BoxNDScanner< Numeric >::maxState(), npstat::BoxNDScanner< Numeric >::operator++(), and npstat::BoxNDScanner< Numeric >::setState().
unsigned long npstat::BoxNDScanner< Numeric >::state_ [private] |
Definition at line 97 of file BoxNDScanner.h.
Referenced by npstat::BoxNDScanner< Numeric >::isValid(), npstat::BoxNDScanner< Numeric >::operator++(), npstat::BoxNDScanner< Numeric >::reset(), npstat::BoxNDScanner< Numeric >::setState(), and npstat::BoxNDScanner< Numeric >::state().
std::vector<unsigned long> npstat::BoxNDScanner< Numeric >::strides_ [private] |
Definition at line 95 of file BoxNDScanner.h.