CMS 3D CMS Logo

ArrayNDScanner.cc
Go to the documentation of this file.
2 #include <cassert>
3 
5 
6 namespace npstat {
7  void ArrayNDScanner::initialize(const unsigned* shape, const unsigned lenShape) {
8  // Check argument validity
9  if (lenShape == 0U || lenShape >= CHAR_BIT * sizeof(unsigned long))
10  throw npstat::NpstatInvalidArgument("In npstat::ArrayNDScanner::initialize: invalid scan shape");
11  assert(shape);
12  for (unsigned j = 0; j < lenShape; ++j)
13  if (!shape[j])
15  "In npstat::ArrayNDScanner::initialize: "
16  "number of scans must be positive in each dimension");
17 
18  // Initialize the scanner data
19  state_ = 0UL;
20  dim_ = lenShape;
21  strides_[dim_ - 1] = 1UL;
22  for (unsigned j = dim_ - 1; j > 0; --j)
23  strides_[j - 1] = strides_[j] * shape[j];
24  maxState_ = strides_[0] * shape[0];
25  }
26 
27  void ArrayNDScanner::getIndex(unsigned* ix, const unsigned indexBufferLen) const {
28  if (indexBufferLen < dim_)
30  "In npstat::ArrayNDScanner::getIndex: "
31  "insufficient length of the output buffer");
32  if (state_ >= maxState_)
33  throw npstat::NpstatRuntimeError("In npstat::ArrayNDScanner::getIndex: invalid scanner state");
34  assert(ix);
35 
36  unsigned long l = state_;
37  for (unsigned i = 0; i < dim_; ++i) {
38  unsigned long idx = l / strides_[i];
39  ix[i] = static_cast<unsigned>(idx);
40  l -= (idx * strides_[i]);
41  }
42  }
43 } // namespace npstat
npstat::ArrayNDScanner::strides_
unsigned long strides_[CHAR_BIT *sizeof(unsigned long)]
Definition: ArrayNDScanner.h:86
mps_fire.i
i
Definition: mps_fire.py:355
npstat::ArrayNDScanner::initialize
void initialize(const unsigned *shape, unsigned lenShape)
Definition: ArrayNDScanner.cc:7
cms::cuda::assert
assert(be >=bs)
npstat::ArrayNDScanner::maxState_
unsigned long maxState_
Definition: ArrayNDScanner.h:88
training_settings.idx
idx
Definition: training_settings.py:16
npstat::ArrayNDScanner::getIndex
void getIndex(unsigned *index, unsigned indexBufferLen) const
Definition: ArrayNDScanner.cc:27
npstat
Definition: AbsArrayProjector.h:14
npstat::NpstatRuntimeError
Definition: NpstatException.h:46
npstat::NpstatInvalidArgument
Definition: NpstatException.h:38
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
npstat::ArrayNDScanner::dim_
unsigned dim_
Definition: ArrayNDScanner.h:89
npstat::ArrayNDScanner::state_
unsigned long state_
Definition: ArrayNDScanner.h:87
cmsLHEtoEOSManager.l
l
Definition: cmsLHEtoEOSManager.py:193
ArrayNDScanner.h
Iteration over indices of a multidimensional array.
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
NpstatException.h
Exceptions for the npstat namespace.