CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ArrayRange.cc
Go to the documentation of this file.
3 
4 namespace npstat {
5  ArrayRange::ArrayRange(const unsigned* ishape, const unsigned imax)
6  {
7  if (imax)
8  {
9  assert(ishape);
10  this->reserve(imax);
11  for (unsigned i=0; i<imax; ++i)
12  this->push_back(Interval<unsigned>(ishape[i]));
13  }
14  }
15 
16  bool ArrayRange::isCompatible(const ArrayShape& ishape) const
17  {
18  const unsigned imax = ishape.size();
19  return isCompatible(imax ? &ishape[0] : (unsigned*)0, imax);
20  }
21 
22  bool ArrayRange::isCompatible(const unsigned* ishape,
23  const unsigned imax) const
24  {
25  if (this->size() != imax)
26  return false;
27  if (imax)
28  {
29  assert(ishape);
30  for (unsigned i=0; i<imax; ++i)
31  if ((*this)[i].length() == 0U)
32  return true;
33  for (unsigned i=0; i<imax; ++i)
34  if ((*this)[i].max() > ishape[i])
35  return false;
36  }
37  return true;
38  }
39 
40  bool ArrayRange::operator<(const ArrayRange& r) const
41  {
42  const unsigned mysize = this->size();
43  const unsigned othersize = r.size();
44  if (mysize < othersize)
45  return true;
46  if (mysize > othersize)
47  return false;
48  for (unsigned i=0; i<mysize; ++i)
49  {
50  const Interval<unsigned>& left((*this)[i]);
51  const Interval<unsigned>& right(r[i]);
52  if (left.min() < right.min())
53  return true;
54  if (left.min() > right.min())
55  return false;
56  if (left.max() < right.max())
57  return true;
58  if (left.max() > right.max())
59  return false;
60  }
61  return false;
62  }
63 
65  {
66  const unsigned mysize = this->size();
67  for (unsigned i=0; i<mysize; ++i)
68  {
69  (*this)[i].setMin((*this)[i].min() + 1U);
70  const unsigned uplim = (*this)[i].max();
71  if (uplim)
72  (*this)[i].setMax(uplim - 1U);
73  }
74  return *this;
75  }
76 
77  unsigned long ArrayRange::rangeSize() const
78  {
79  unsigned long result = 0UL;
80  const unsigned imax = this->size();
81  if (imax)
82  {
83  result = 1UL;
84  for (unsigned i=0; i<imax; ++i)
85  result *= (*this)[i].length();
86  }
87  return result;
88  }
89 
91  {
92  const unsigned imax = this->size();
93  ArrayShape oshape(imax);
94  for (unsigned i=0; i<imax; ++i)
95  oshape[i] = (*this)[i].length();
96  return oshape;
97  }
98 
99  void ArrayRange::lowerLimits(unsigned* limits,
100  const unsigned limitsLen) const
101  {
102  const unsigned imax = this->size();
103  if (limitsLen < imax) throw npstat::NpstatInvalidArgument(
104  "In npstat::ArrayRange::lowerLimits: "
105  "insufficient size of the output buffer");
106  if (imax)
107  {
108  assert(limits);
109  const Interval<unsigned>* data = &(*this)[0];
110  for (unsigned i=0; i<imax; ++i)
111  limits[i] = data[i].min();
112  }
113  }
114 
115  void ArrayRange::upperLimits(unsigned* limits,
116  const unsigned limitsLen) const
117  {
118  const unsigned imax = this->size();
119  if (limitsLen < imax) throw npstat::NpstatInvalidArgument(
120  "In npstat::ArrayRange::upperLimits: "
121  "insufficient size of the output buffer");
122  if (imax)
123  {
124  assert(limits);
125  const Interval<unsigned>* data = &(*this)[0];
126  for (unsigned i=0; i<imax; ++i)
127  limits[i] = data[i].max();
128  }
129  }
130 
131  void ArrayRange::rangeLength(unsigned* limits,
132  const unsigned limitsLen) const
133  {
134  const unsigned imax = this->size();
135  if (limitsLen < imax) throw npstat::NpstatInvalidArgument(
136  "In npstat::ArrayRange::rangeLength: "
137  "insufficient size of the output buffer");
138  if (imax)
139  {
140  assert(limits);
141  const Interval<unsigned>* data = &(*this)[0];
142  for (unsigned i=0; i<imax; ++i)
143  limits[i] = data[i].length();
144  }
145  }
146 }
int i
Definition: DBlmapReader.cc:9
void upperLimits(unsigned *limits, unsigned limitsLen) const
Definition: ArrayRange.cc:115
const Numeric max() const
Definition: Interval.h:94
std::vector< unsigned > ArrayShape
Definition: ArrayShape.h:21
ArrayShape shape() const
Definition: ArrayRange.cc:90
Multidimensional range of array indices.
unsigned long rangeSize() const
Definition: ArrayRange.cc:77
Exceptions for the npstat namespace.
tuple result
Definition: query.py:137
bool isCompatible(const ArrayShape &shape) const
Definition: ArrayRange.cc:16
T min(T a, T b)
Definition: MathUtil.h:58
void rangeLength(unsigned *range, unsigned rangeLen) const
Definition: ArrayRange.cc:131
void lowerLimits(unsigned *limits, unsigned limitsLen) const
Definition: ArrayRange.cc:99
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
ArrayRange & stripOuterLayer()
Definition: ArrayRange.cc:64
const Numeric min() const
Definition: Interval.h:91
bool operator<(const ArrayRange &) const
Definition: ArrayRange.cc:40
tuple size
Write out results.