CMS 3D CMS Logo

ArrayRange.cc
Go to the documentation of this file.
3 
4 namespace npstat {
5  ArrayRange::ArrayRange(const unsigned* ishape, const unsigned imax) {
6  if (imax) {
7  assert(ishape);
8  this->reserve(imax);
9  for (unsigned i = 0; i < imax; ++i)
10  this->push_back(Interval<unsigned>(ishape[i]));
11  }
12  }
13 
14  bool ArrayRange::isCompatible(const ArrayShape& ishape) const {
15  const unsigned imax = ishape.size();
16  return isCompatible(imax ? &ishape[0] : (unsigned*)nullptr, imax);
17  }
18 
19  bool ArrayRange::isCompatible(const unsigned* ishape, const unsigned imax) const {
20  if (this->size() != imax)
21  return false;
22  if (imax) {
23  assert(ishape);
24  for (unsigned i = 0; i < imax; ++i)
25  if ((*this)[i].length() == 0U)
26  return true;
27  for (unsigned i = 0; i < imax; ++i)
28  if ((*this)[i].max() > ishape[i])
29  return false;
30  }
31  return true;
32  }
33 
34  bool ArrayRange::operator<(const ArrayRange& r) const {
35  const unsigned mysize = this->size();
36  const unsigned othersize = r.size();
37  if (mysize < othersize)
38  return true;
39  if (mysize > othersize)
40  return false;
41  for (unsigned i = 0; i < mysize; ++i) {
42  const Interval<unsigned>& left((*this)[i]);
43  const Interval<unsigned>& right(r[i]);
44  if (left.min() < right.min())
45  return true;
46  if (left.min() > right.min())
47  return false;
48  if (left.max() < right.max())
49  return true;
50  if (left.max() > right.max())
51  return false;
52  }
53  return false;
54  }
55 
57  const unsigned mysize = this->size();
58  for (unsigned i = 0; i < mysize; ++i) {
59  (*this)[i].setMin((*this)[i].min() + 1U);
60  const unsigned uplim = (*this)[i].max();
61  if (uplim)
62  (*this)[i].setMax(uplim - 1U);
63  }
64  return *this;
65  }
66 
67  unsigned long ArrayRange::rangeSize() const {
68  unsigned long result = 0UL;
69  const unsigned imax = this->size();
70  if (imax) {
71  result = 1UL;
72  for (unsigned i = 0; i < imax; ++i)
73  result *= (*this)[i].length();
74  }
75  return result;
76  }
77 
79  const unsigned imax = this->size();
80  ArrayShape oshape(imax);
81  for (unsigned i = 0; i < imax; ++i)
82  oshape[i] = (*this)[i].length();
83  return oshape;
84  }
85 
86  void ArrayRange::lowerLimits(unsigned* limits, const unsigned limitsLen) const {
87  const unsigned imax = this->size();
88  if (limitsLen < imax)
90  "In npstat::ArrayRange::lowerLimits: "
91  "insufficient size of the output buffer");
92  if (imax) {
93  assert(limits);
94  const Interval<unsigned>* data = &(*this)[0];
95  for (unsigned i = 0; i < imax; ++i)
96  limits[i] = data[i].min();
97  }
98  }
99 
100  void ArrayRange::upperLimits(unsigned* limits, const unsigned limitsLen) const {
101  const unsigned imax = this->size();
102  if (limitsLen < imax)
104  "In npstat::ArrayRange::upperLimits: "
105  "insufficient size of the output buffer");
106  if (imax) {
107  assert(limits);
108  const Interval<unsigned>* data = &(*this)[0];
109  for (unsigned i = 0; i < imax; ++i)
110  limits[i] = data[i].max();
111  }
112  }
113 
114  void ArrayRange::rangeLength(unsigned* limits, const unsigned limitsLen) const {
115  const unsigned imax = this->size();
116  if (limitsLen < imax)
118  "In npstat::ArrayRange::rangeLength: "
119  "insufficient size of the output buffer");
120  if (imax) {
121  assert(limits);
122  const Interval<unsigned>* data = &(*this)[0];
123  for (unsigned i = 0; i < imax; ++i)
124  limits[i] = data[i].length();
125  }
126  }
127 } // namespace npstat
ArrayShape shape() const
Definition: ArrayRange.cc:78
const Numeric max() const
Definition: Interval.h:81
std::vector< unsigned > ArrayShape
Definition: ArrayShape.h:21
assert(be >=bs)
void upperLimits(unsigned *limits, unsigned limitsLen) const
Definition: ArrayRange.cc:100
Multidimensional range of array indices.
Exceptions for the npstat namespace.
bool operator<(const ArrayRange &) const
Definition: ArrayRange.cc:34
void rangeLength(unsigned *range, unsigned rangeLen) const
Definition: ArrayRange.cc:114
bool isCompatible(const ArrayShape &shape) const
Definition: ArrayRange.cc:14
unsigned long rangeSize() const
Definition: ArrayRange.cc:67
const Numeric min() const
Definition: Interval.h:78
deadvectors [0] push_back({0.0175431, 0.538005, 6.80997, 13.29})
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
ArrayRange & stripOuterLayer()
Definition: ArrayRange.cc:56
void lowerLimits(unsigned *limits, unsigned limitsLen) const
Definition: ArrayRange.cc:86