test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ArrayShape.cc
Go to the documentation of this file.
1 #include <cassert>
3 
5 
6 namespace npstat {
8  {
9  return ArrayShape();
10  }
11 
12  ArrayShape makeShape(unsigned i0)
13  {
14  return ArrayShape(1, i0);
15  }
16 
17  ArrayShape makeShape(unsigned i0, unsigned i1)
18  {
19  ArrayShape s;
20  s.reserve(2);
21  s.push_back(i0);
22  s.push_back(i1);
23  return s;
24  }
25 
26  ArrayShape makeShape(unsigned i0, unsigned i1, unsigned i2)
27  {
28  ArrayShape s;
29  s.reserve(3);
30  s.push_back(i0);
31  s.push_back(i1);
32  s.push_back(i2);
33  return s;
34  }
35 
36  ArrayShape makeShape(unsigned i0, unsigned i1, unsigned i2, unsigned i3)
37  {
38  ArrayShape s;
39  s.reserve(4);
40  s.push_back(i0);
41  s.push_back(i1);
42  s.push_back(i2);
43  s.push_back(i3);
44  return s;
45  }
46 
47  ArrayShape makeShape(unsigned i0, unsigned i1, unsigned i2, unsigned i3,
48  unsigned i4)
49  {
50  ArrayShape s;
51  s.reserve(5);
52  s.push_back(i0);
53  s.push_back(i1);
54  s.push_back(i2);
55  s.push_back(i3);
56  s.push_back(i4);
57  return s;
58  }
59 
60  ArrayShape makeShape(unsigned i0, unsigned i1, unsigned i2, unsigned i3,
61  unsigned i4, unsigned i5)
62  {
63  ArrayShape s;
64  s.reserve(6);
65  s.push_back(i0);
66  s.push_back(i1);
67  s.push_back(i2);
68  s.push_back(i3);
69  s.push_back(i4);
70  s.push_back(i5);
71  return s;
72  }
73 
74  ArrayShape makeShape(unsigned i0, unsigned i1, unsigned i2, unsigned i3,
75  unsigned i4, unsigned i5, unsigned i6)
76  {
77  ArrayShape s;
78  s.reserve(7);
79  s.push_back(i0);
80  s.push_back(i1);
81  s.push_back(i2);
82  s.push_back(i3);
83  s.push_back(i4);
84  s.push_back(i5);
85  s.push_back(i6);
86  return s;
87  }
88 
89  ArrayShape makeShape(unsigned i0, unsigned i1, unsigned i2, unsigned i3,
90  unsigned i4, unsigned i5, unsigned i6, unsigned i7)
91  {
92  ArrayShape s;
93  s.reserve(8);
94  s.push_back(i0);
95  s.push_back(i1);
96  s.push_back(i2);
97  s.push_back(i3);
98  s.push_back(i4);
99  s.push_back(i5);
100  s.push_back(i6);
101  s.push_back(i7);
102  return s;
103  }
104 
105  ArrayShape makeShape(unsigned i0, unsigned i1, unsigned i2, unsigned i3,
106  unsigned i4, unsigned i5, unsigned i6, unsigned i7,
107  unsigned i8)
108  {
109  ArrayShape s;
110  s.reserve(9);
111  s.push_back(i0);
112  s.push_back(i1);
113  s.push_back(i2);
114  s.push_back(i3);
115  s.push_back(i4);
116  s.push_back(i5);
117  s.push_back(i6);
118  s.push_back(i7);
119  s.push_back(i8);
120  return s;
121  }
122 
123  ArrayShape makeShape(unsigned i0, unsigned i1, unsigned i2, unsigned i3,
124  unsigned i4, unsigned i5, unsigned i6, unsigned i7,
125  unsigned i8, unsigned i9)
126  {
127  ArrayShape s;
128  s.reserve(10);
129  s.push_back(i0);
130  s.push_back(i1);
131  s.push_back(i2);
132  s.push_back(i3);
133  s.push_back(i4);
134  s.push_back(i5);
135  s.push_back(i6);
136  s.push_back(i7);
137  s.push_back(i8);
138  s.push_back(i9);
139  return s;
140  }
141 
142  ArrayShape makeShape(const unsigned* indices, const unsigned nIndices)
143  {
144  ArrayShape s;
145  if (nIndices)
146  {
147  assert(indices);
148  s.reserve(nIndices);
149  for (unsigned i=0; i<nIndices; ++i)
150  s.push_back(indices[i]);
151  }
152  return s;
153  }
154 
155  ArrayShape doubleShape(const ArrayShape& inputShape)
156  {
157  ArrayShape s(inputShape);
158  const unsigned len = s.size();
159  for (unsigned i=0; i<len; ++i)
160  s[i] *= 2U;
161  return s;
162  }
163 
164  ArrayShape halfShape(const ArrayShape& inputShape)
165  {
166  ArrayShape s(inputShape);
167  const unsigned len = s.size();
168  for (unsigned i=0; i<len; ++i)
169  {
170  if (!(s[i] % 2U == 0)) throw npstat::NpstatInvalidArgument(
171  "In npstat::halfShape: array span must be "
172  "even in each dimension");
173  s[i] /= 2U;
174  }
175  return s;
176  }
177 
178  bool isSubShape(const ArrayShape& sh1, const ArrayShape& sh2)
179  {
180  const unsigned len = sh1.size();
181  if (len != sh2.size())
182  return false;
183  for (unsigned i=0; i<len; ++i)
184  if (sh1[i] > sh2[i])
185  return false;
186  return true;
187  }
188 }
int i
Definition: DBlmapReader.cc:9
assert(m_qm.get())
bool isSubShape(const ArrayShape &sh1, const ArrayShape &sh2)
Definition: ArrayShape.cc:178
std::vector< unsigned > ArrayShape
Definition: ArrayShape.h:21
Exceptions for the npstat namespace.
ArrayShape makeShape()
Definition: ArrayShape.cc:7
ArrayShape doubleShape(const ArrayShape &inputShape)
Definition: ArrayShape.cc:155
Utilities for defining shapes of multidimensional arrays.
ArrayShape halfShape(const ArrayShape &inputShape)
Definition: ArrayShape.cc:164