casacore
Loading...
Searching...
No Matches
IPosition.h
Go to the documentation of this file.
1// # IPosition.h: A vector of integers, used to index into arrays.
2// # Copyright (C) 1994,1995,1996,1997,1998,1999,2000,2001,2002
3// # Associated Universities, Inc. Washington DC, USA.
4// #
5// # This library is free software; you can redistribute it and/or modify it
6// # under the terms of the GNU Library General Public License as published by
7// # the Free Software Foundation; either version 2 of the License, or (at your
8// # option) any later version.
9// #
10// # This library is distributed in the hope that it will be useful, but WITHOUT
11// # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12// # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13// # License for more details.
14// #
15// # You should have received a copy of the GNU Library General Public License
16// # along with this library; if not, write to the Free Software Foundation,
17// # Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18// #
19// # Correspondence concerning AIPS++ should be addressed as follows:
20// # Internet email: casa-feedback@nrao.edu.
21// # Postal address: AIPS++ Project Office
22// # National Radio Astronomy Observatory
23// # 520 Edgemont Road
24// # Charlottesville, VA 22903-2475 USA
25
26#ifndef CASA_IPOSITION_2_H
27#define CASA_IPOSITION_2_H
28
29// # Includes
30#include "ArrayFwd.h"
31
32#include <vector>
33#include <cstddef> // for ptrdiff_t
34#include <initializer_list>
35
36#include <sys/types.h>
37
38namespace casacore { // # NAMESPACE CASACORE - BEGIN
39
40// # Forward Declarations
41class AipsIO;
42class LogIO;
43
44// <summary> A Vector of integers, for indexing into Array<T> objects. </summary>
45
46// <use visibility=export>
47
48// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
49// </reviewed>
50
51// # <prerequisite>
52// # Classes you should understand before using this one.
53// # </prerequisite>
54
55// <etymology>
56// IPosition is an Index Position in an n-dimensional array.
57// </etymology>
58
59// <synopsis>
60// IPosition is "logically" a Vector<int> constrained so that its origin
61// is zero-based, and in fact that used to be the way it was implemented.
62// It was split out into a separate class to make the inheritance from
63// Arrays simpler (since Arrays use IPositions). The
64// template instantiation mechanism is complicated enough that this
65// simplification was felt to be a good idea.
66// <p>
67// IPosition objects are normally used to index into, and define the shapes
68// of, multi-dimensional arrays. For example, if you have a 5 dimensional
69// array, you need an IPosition of length 5 to index into the array (or
70// to define its shape, etc.).
71// <p>
72// Unlike Vectors, IPositions always use copy semantics.
73// <srcblock>
74// IPosition ip1(5); // An IPosition of length 5
75// ip1(0) = 11; ip1(1) = 5; ... ip1(4) = 6; // Indices 0-based
76// IPosition ip2(ip1); // Copy constructor; a COPY
77// </srcblock>
78//
79// Binary operations must take place either with a conformnat (same size)
80// IPosition or with an integer, which behaves as if it was an IPosition
81// of the same size (i.e., length). All the usual binary arithmetic
82// operations are available, as well as logical operations, which return
83// Booleans. These all operate "element-by-element".
84// <p>
85// All non-inlined member functions of IPosition check invariants if the
86// preprocessor symbol AIPS_DEBUG is defined.
87// That is, the member functions check that ok() is true (constructors
88// check after construction, other functions on entry to the function).
89// If these tests fail, an AipsError exception is thrown; its message
90// contains the line number and source file of the failure (it is thrown
91// by the lAssert macro defined in aips/Assert.h).
92//
93// Constructors and functions exist to construct an IPosition directly from
94// a Vector or std::vector object or to convert to it. Furthermore the
95// <src>fill</src> and <src>copy</src> can be used to fill from or copy to
96// any STL-type iterator.
97//
98// <example>
99// <srcblock>
100// IPosition blc(5), trc(5,1,2,3,4,5);
101// blc = 0; // OR IPosition blc(5,0);
102// //...
103// if (blc > trc) {
104// IPosition tmp;
105// tmp = trc; // Swap
106// trc = blc;
107// blc = tmp;
108// }
109// //...
110// trc += 5; // make the box 5 larger in all dimensions
111// std::vector<int> vec(trc.toStdVector());
112// </srcblock>
113// </example>
114
117
118 public:
119 // A zero-length IPosition.
120 IPosition() noexcept;
121
122 // An IPosition of size "length." The values in the object are uninitialized.
123 explicit IPosition(size_t length);
124
125 // An IPosition initialized from the given list
126 IPosition(std::initializer_list<ssize_t> list);
127
128 // An IPosition of size "length." All values in the object are
129 // initialized to val.
130 IPosition(size_t length, ssize_t val);
131
132 // An IPosition initialized from a variable number of parameters.
133 // The first parameter should specify the size, but the actual
134 // size of the resulting IPosition is determined from the number
135 // of parameters (the first argument is ignored).
136 //
137 // This constructor should be disfavoured, because i) of the
138 // dummy parameter and ii) because it may narrow the
139 // specified parameter without a warning.
140 //
141 // Instead, use an initializer list constructor whenever possible.
142 // If an IPosition is created inside a macro, an initializer list
143 // is not possible. In those cases, use the Make(Vals...) factory
144 // method. Both of those methods do not have the above issues.
145 template <typename... Vals>
146 //[[ deprecated("Use the initializer list constructor or Make() method") ]]
147 IPosition(size_t /*dummy*/, ssize_t val1, ssize_t val2, Vals... vals)
148 : IPosition{val1, val2, static_cast<ssize_t>(vals)...} {}
149
150 // Makes a copy (copy, NOT reference, semantics) of source.
151 IPosition(const IPosition& source);
152
153 IPosition(IPosition&& source) noexcept;
154
156
157 // Construct an IPosition that is initialized from a variable number of parameter.
158 // The resulting size of the IPosition will equal the number of parameters specified.
159 //
160 // In general, using the initializer list constructor should be preferred. Defining
161 // an initializer list inside macros is however not possible. In those cases, this
162 // method can be used to construct the IPosition.
163 //
164 // Example: IPosition::Make(3, 5) creates an IPosition of size 2, with values 3 and 5.
165 // It is identical to IPosition{3, 5}. A program is ill-formed when narrowing of
166 // a parameter is required, causing a compiler warning or error.
167 template <typename... Vals>
168 static IPosition Make(Vals... vals) {
169 return IPosition{vals...};
170 }
171
172 // Makes this a copy of other. When the dest is not of the same
173 // size, it will resize itself to be the same length as the source.
175
177
178 // Copy "value" into every position of this IPosition.
180
181 // Construct a default axis path consisting of the values 0 .. nrdim-1.
182 static IPosition makeAxisPath(size_t nrdim);
183
184 // Construct a full axis path from a (partially) given axis path.
185 // It fills the path with the non-given axis.
186 // It is checked if the given axis path is valid (i.e. if the axis are
187 // < nrdim and if they are not doubly defined).
188 // E.g.: in the 4D case an axis path [0,2] is returned as [0,2,1,3].
189 static IPosition makeAxisPath(size_t nrdim, const IPosition& partialPath);
190
191 // Make a list of axes which are the axes not given in <src>axes</src>
192 // up to the given dimension
193 static IPosition otherAxes(size_t nrdim, const IPosition& axes);
194
195 // Convert an IPosition to and from an Array<int/int64>. In either case, the
196 // array must be one dimensional.
197 // <group>
198 IPosition(const Array<int>& other);
202 // </group>
203
204 // Convert an IPosition to and from an Array<int/int64>. In either case, the
205 // array must be one dimensional.
206 // <group>
207 IPosition(const std::vector<int>& other);
208 IPosition(const std::vector<long long>& other);
209 std::vector<int> asStdVector() const;
210 std::vector<long long> asStdVector64() const;
211 // </group>
212
213 // Resize and fill this IPosition object.
214 template <typename InputIterator>
215 void fill(size_t size, InputIterator iter) {
216 resize(size);
217 for (size_t i = 0; i < size; ++i, ++iter) {
218 data_p[i] = *iter;
219 }
220 }
221
222 // Copy the contents of this IPosition object to the output iterator.
223 // The size of the output must be sufficient.
224 template <typename OutputIterator>
225 void copy(OutputIterator iter) const {
226 for (size_t i = 0; i < size_p; ++i, ++iter) {
227 *iter = data_p[i];
228 }
229 }
230
231 // This member functions return an IPosition which has
232 // degenerate (length==1) axes removed and the dimensionality reduced
233 // appropriately.
234 // Only axes greater than startingAxis are considered (normally one
235 // wants to remove trailing axes.
236 // <br>
237 // The functions with argument <src>ignoreAxes</src> do
238 // not consider the axes given in that argument.
239 // <group>
240 IPosition nonDegenerate(size_t startingAxis = 0) const;
241 IPosition nonDegenerate(const IPosition& ignoreAxes) const;
242 // </group>
243
244 // Old values are copied on resize if copy==true.
245 // If the size increases, values beyond the former size are undefined.
246 void resize(size_t newSize, bool copy = true);
247
248 // Index into the IPosition. Indices are zero-based. If the preprocessor
249 // symbol AIPS_ARRAY_INDEX_CHECK is defined, operator() will check
250 // "index" to ensure it is not out of bounds. If this check fails, an
251 // AipsError will be thrown.
252 // <group>
253 ssize_t& operator[](size_t index);
254 ssize_t operator[](size_t index) const;
255 ssize_t& operator()(size_t index);
256 ssize_t operator()(size_t index) const;
257 // </group>
258
259 // Make an IPosition by using only the specified elements of the current
260 // IPosition. All values of <src>axes</src> must be less than
261 // the number of elements of the current object.
262 // <example>
263 // IPosition ipos(4, 11, 12, 13, 14);
264 // // ex1 is IPosition(3, 11, 12, 13);
265 // IPosition ex1 = ipos(IPosition(3,0,1,2);
266 // // ex2 is IPosition(3, 12, 11)
267 // IPosition ex2 = ipos(IPosition(2,2,1);
268 // // ex3 is IPosition(4,14,14,14,14)
269 // IPosition ex3 = ipos(IPosition(4,3,3,3,3);
270 // </example>
271 IPosition operator()(const IPosition& axes) const;
272
273 // Index into the IPosition from the end.
274 // By default the last value is returned.
275 // If the preprocessor symbol AIPS_ARRAY_INDEX_CHECK is defined, it will
276 // check if the index is not out of bounds.
277 // <group>
278 ssize_t& last(size_t index = 0);
279 ssize_t last(size_t index = 0) const;
280 // </group>
281
282 // Get the storage.
283 const ssize_t* storage() const;
284
285 // Append this IPosition with another one (causing a resize).
286 void append(const IPosition& other);
287
288 // Prepend this IPosition with another one (causing a resize).
289 void prepend(const IPosition& other);
290
291 // Return an IPosition as the concetanation of this and another IPosition.
292 IPosition concatenate(const IPosition& other) const;
293
294 // Set the first values of this IPosition to another IPosition.
295 // An exception is thrown if the other IPosition is too long.
296 void setFirst(const IPosition& other);
297
298 // Set the last values of this IPosition to another IPosition.
299 // An exception is thrown if the other IPosition is too long.
300 void setLast(const IPosition& other);
301
302 // Construct an IPosition from the first <src>n</src> values of this
303 // IPosition.
304 // An exception is thrown if <src>n</src> is too high.
305 IPosition getFirst(size_t n) const;
306
307 // Construct an IPosition from the last <src>n</src> values of this
308 // IPosition.
309 // An exception is thrown if <src>n</src> is too high.
310 IPosition getLast(size_t n) const;
311
312 // Return an IPosition where the given axes are reoved.
313 IPosition removeAxes(const IPosition& axes) const;
314
315 // Return an IPosition containing the given axes only.
316 IPosition keepAxes(const IPosition& axes) const;
317
318 // The number of elements in this IPosition. Since IPosition
319 // objects use zero-based indexing, the maximum available index is
320 // nelements() - 1.
321 // <group>
322 size_t nelements() const;
323 size_t size() const;
324 // </group>
325
326 // Is the IPosition empty (i.e. no elements)?
327 bool empty() const;
328
329 // conform returns true if nelements() == other.nelements().
330 bool conform(const IPosition& other) const;
331
332 // Element-by-element arithmetic.
333 // <group>
334 void operator+=(const IPosition& other);
335 void operator-=(const IPosition& other);
336 void operator*=(const IPosition& other);
337 void operator/=(const IPosition& other);
338 void operator+=(ssize_t val);
339 void operator-=(ssize_t val);
340 void operator*=(ssize_t val);
341 void operator/=(ssize_t val);
342 // </group>
343
344 // Returns 0 if nelements() == 0, otherwise it returns the product of
345 // its elements.
346 long long product() const;
347
348 // Are all elements equal to 1?
349 // Useful to check if a given stride is really a stride.
350 bool allOne() const;
351
352 // Element-by-element comparison for equality.
353 // It returns true if the lengths and all elements are equal.
354 // <br>
355 // Note that an important difference between this function and operator==()
356 // is that if the two IPositions have different lengths, this function
357 // returns false, instead of throwing an exception as operator==() does.
358 bool isEqual(const IPosition& other) const;
359
360 // Element-by-element comparison for equality.
361 // It returns true if all elements are equal.
362 // When <src>skipDegeneratedAxes</src> is true, axes with
363 // length 1 are skipped in both operands.
364 bool isEqual(const IPosition& other, bool skipDegeneratedAxes) const;
365
366 // Element-by-element comparison for (partial) equality.
367 // It returns true if the lengths and the first <src>nrCompare</src>
368 // elements are equal.
369 bool isEqual(const IPosition& other, size_t nrCompare) const;
370
371 // Is the other IPosition a subset of (or equal to) this IPosition?
372 // It is a subset if zero or more axes of this IPosition do not occur
373 // or are degenerated in the other and if the remaining axes are
374 // in the same order.
375 bool isSubSet(const IPosition& other) const;
376
377 // Write the IPosition into a string.
378 // TODO deprecate in favour of to_string(const IPosition&)
379 std::string toString() const;
380
381 // Write an IPosition to an ostream in a simple text form.
382 friend std::ostream& operator<<(std::ostream& os, const IPosition& ip);
383
384 // Is this IPosition consistent?
385 bool ok() const;
386
387 // Define the STL-style iterators.
388 // It makes it possible to iterate through all data elements.
389 // <srcblock>
390 // IPosition shp(2,0);
391 // for (IPosition::iterator iter=shp.begin(); iter!=shp.end(); iter++) {
392 // *iter += 1;
393 // }
394 // </srcblock>
395 // <group name=STL-iterator>
396 // STL-style typedefs.
397 // <group>
398 typedef ssize_t value_type;
399 typedef ssize_t* iterator;
400 typedef const ssize_t* const_iterator;
402 typedef const value_type* const_pointer;
405 typedef size_t size_type;
406 typedef ptrdiff_t difference_type;
407 // </group>
408 // Get the begin and end iterator object for this object.
409 // <group>
410 iterator begin() { return data_p; }
411 const_iterator begin() const { return data_p; }
412 iterator end() { return data_p + size_p; }
413 const_iterator end() const { return data_p + size_p; }
414 // </group>
415 // </group>
416
417 private:
418 // Allocate a buffer with length size_p.
420
421 // Throw an index error exception.
422 void throwIndexError() const;
423
424 enum { BufferLength = 4 };
425 size_t size_p;
427 // When the iposition is length BufferSize or less data is just buffer_p,
428 // avoiding calls to new and delete.
429 ssize_t* data_p;
430};
431
432// Allows a way for IPosition to be used as keys in a std::map
434 public:
435 // if sizes aren't equal, returns true if lhs.size() < rhs.size(), false
436 // otherwise. If sizes are equal, does an element by element comparison. The first
437 // corresponding elements that are not equal, returns true if the rhs element is
438 // less than the lhs element, false otherwise. Returns false if all elements are
439 // equal.
440 bool operator()(const IPosition& lhs, const IPosition& rhs) const;
441};
442
443// <summary>Arithmetic Operations for IPosition's</summary>
444// Element by element arithmetic on IPositions.
445// <group name="IPosition Arithmetic">
446// Each operation is done on corresponding elements of the IPositions. The
447// two IPositions must have the same number of elements otherwise an
448// exception (ArrayConformanceError) will be thrown.
449// <group>
450IPosition operator+(const IPosition& left, const IPosition& right);
451IPosition operator-(const IPosition& left, const IPosition& right);
452IPosition operator*(const IPosition& left, const IPosition& right);
453IPosition operator/(const IPosition& left, const IPosition& right);
454// </group>
455// Each operation is done by appliying the integer argument to all elements
456// of the IPosition argument.
457// <group>
458IPosition operator+(const IPosition& left, ssize_t val);
459IPosition operator-(const IPosition& left, ssize_t val);
460IPosition operator*(const IPosition& left, ssize_t val);
461IPosition operator/(const IPosition& left, ssize_t val);
462// </group>
463// Same functions as above but with with the int argument on the left side.
464// <group>
465IPosition operator+(ssize_t val, const IPosition& right);
466IPosition operator-(ssize_t val, const IPosition& right);
467IPosition operator*(ssize_t val, const IPosition& right);
468IPosition operator/(ssize_t val, const IPosition& right);
469// </group>
470
471// Returns the element by element minimum or maximum.
472// <group>
473IPosition max(const IPosition& left, const IPosition& right);
474IPosition min(const IPosition& left, const IPosition& right);
475// </group>
476// </group>
477
478// <summary>Logical operations for IPosition's</summary>
479// Element by element boolean operations on IPositions. The result is true
480// only if the operation yields true for every element of the IPosition.
481// <group name="IPosition Logical">
482// Each operation is done on corresponding elements of the IPositions. The
483// two IPositions must have the same number of elements otherwise an
484// exception (ArrayConformanceError) will be thrown.
485// <group>
486bool operator==(const IPosition& left, const IPosition& right);
487bool operator!=(const IPosition& left, const IPosition& right);
488bool operator<(const IPosition& left, const IPosition& right);
489bool operator<=(const IPosition& left, const IPosition& right);
490bool operator>(const IPosition& left, const IPosition& right);
491bool operator>=(const IPosition& left, const IPosition& right);
492// </group>
493// Each operation is done by appliying the integer argument to all elements
494// <group>
495bool operator==(const IPosition& left, ssize_t val);
496bool operator!=(const IPosition& left, ssize_t val);
497bool operator<(const IPosition& left, ssize_t val);
498bool operator<=(const IPosition& left, ssize_t val);
499bool operator>(const IPosition& left, ssize_t val);
500bool operator>=(const IPosition& left, ssize_t val);
501// </group>
502// Same functions as above but with with the int argument on the left side.
503// <group>
504bool operator==(ssize_t val, const IPosition& right);
505bool operator!=(ssize_t val, const IPosition& right);
506bool operator<(ssize_t val, const IPosition& right);
507bool operator<=(ssize_t val, const IPosition& right);
508bool operator>(ssize_t val, const IPosition& right);
509bool operator>=(ssize_t val, const IPosition& right);
510// </group>
511// </group>
512
513// <summary>Indexing functions for IPosition's</summary>
514// Convert between IPosition and offset in an array.
515//
516// The offset of an element in an array is the number of elements from the
517// origin that the element would be if the array were arranged linearly.
518// The origin of the array has an offset equal to 0, while the
519// "top right corner" of the array has an offset equal to one less than the
520// total number of elements in the array.
521//
522// Two examples of offset would be the index in a carray and the seek position
523// in a file.
524
525// <group name="IPosition Indexing">
526// Convert from offset to IPosition in an array.
529// Convert from IPosition to offset in an array.
530long long toOffsetInArray(const IPosition& iposition, const IPosition& shape);
531
532// Determine if the given offset or IPosition is inside the array. Returns
533// true if it is inside the Array.
534// <thrown>
535// <li> ArrayConformanceError: If all the IPositions are not the same length
536// </thrown>
537// <group>
538bool isInsideArray(const long long offset, const IPosition& shape);
539bool isInsideArray(const IPosition& iposition, const IPosition& shape);
540// </group>
541// </group>
542
543std::string to_string(const IPosition& ip);
544
545// # Inlined member functions for IPosition
546
547inline IPosition::IPosition() noexcept : size_p(0), data_p(buffer_p) {}
548
549inline IPosition IPosition::makeAxisPath(size_t nrdim) { return makeAxisPath(nrdim, IPosition()); }
550
551inline size_t IPosition::nelements() const { return size_p; }
552inline size_t IPosition::size() const { return size_p; }
553inline bool IPosition::empty() const { return size_p == 0; }
554
555inline ssize_t& IPosition::operator[](size_t index) { return data_p[index]; }
556
557inline ssize_t IPosition::operator[](size_t index) const { return data_p[index]; }
558
559inline ssize_t& IPosition::operator()(size_t index) {
560#if defined(AIPS_ARRAY_INDEX_CHECK)
561 if (index >= nelements()) {
563 }
564#endif
565 return data_p[index];
566}
567
568inline ssize_t IPosition::operator()(size_t index) const {
569#if defined(AIPS_ARRAY_INDEX_CHECK)
570 if (index >= nelements()) {
572 }
573#endif
574 return data_p[index];
575}
576
577inline ssize_t& IPosition::last(size_t index) {
578#if defined(AIPS_ARRAY_INDEX_CHECK)
579 if (size_p - index <= 0) {
581 }
582#endif
583 return data_p[size_p - index - 1];
584}
585
586inline ssize_t IPosition::last(size_t index) const {
587#if defined(AIPS_ARRAY_INDEX_CHECK)
588 if (size_p - index <= 0) {
590 }
591#endif
592 return data_p[size_p - index - 1];
593}
594
595inline const ssize_t* IPosition::storage() const { return data_p; }
596
597inline bool IPosition::conform(const IPosition& other) const { return (size_p == other.size_p); }
598
599} // namespace casacore
600
601#endif
Allows a way for IPosition to be used as keys in a std::map.
Definition IPosition.h:433
bool operator()(const IPosition &lhs, const IPosition &rhs) const
if sizes aren't equal, returns true if lhs.size() < rhs.size(), false otherwise.
ssize_t & operator[](size_t index)
Index into the IPosition.
Definition IPosition.h:555
ptrdiff_t difference_type
Definition IPosition.h:406
void operator*=(const IPosition &other)
friend std::ostream & operator<<(std::ostream &os, const IPosition &ip)
Write an IPosition to an ostream in a simple text form.
const value_type * const_pointer
Definition IPosition.h:402
IPosition(const Array< long long > &other)
bool isEqual(const IPosition &other, size_t nrCompare) const
Element-by-element comparison for (partial) equality.
size_t size() const
Definition IPosition.h:552
IPosition & operator=(IPosition &&source)
IPosition(const Array< int > &other)
Convert an IPosition to and from an Array<int/int64>.
ssize_t & operator()(size_t index)
Definition IPosition.h:559
const_iterator end() const
Definition IPosition.h:413
IPosition nonDegenerate(const IPosition &ignoreAxes) const
IPosition keepAxes(const IPosition &axes) const
Return an IPosition containing the given axes only.
ssize_t value_type
Define the STL-style iterators.
Definition IPosition.h:398
std::vector< long long > asStdVector64() const
void copy(OutputIterator iter) const
Copy the contents of this IPosition object to the output iterator.
Definition IPosition.h:225
void setLast(const IPosition &other)
Set the last values of this IPosition to another IPosition.
long long product() const
Returns 0 if nelements() == 0, otherwise it returns the product of its elements.
void operator-=(const IPosition &other)
IPosition getFirst(size_t n) const
Construct an IPosition from the first n values of this IPosition.
IPosition removeAxes(const IPosition &axes) const
Return an IPosition where the given axes are reoved.
IPosition & operator=(ssize_t value)
Copy "value" into every position of this IPosition.
void operator/=(ssize_t val)
void operator+=(const IPosition &other)
Element-by-element arithmetic.
IPosition() noexcept
A zero-length IPosition.
Definition IPosition.h:547
Vector< long long > asVector64() const
IPosition(IPosition &&source) noexcept
void resize(size_t newSize, bool copy=true)
Old values are copied on resize if copy==true.
std::string toString() const
Write the IPosition into a string.
bool isEqual(const IPosition &other) const
Element-by-element comparison for equality.
bool ok() const
Is this IPosition consistent?
IPosition(const IPosition &source)
Makes a copy (copy, NOT reference, semantics) of source.
void prepend(const IPosition &other)
Prepend this IPosition with another one (causing a resize).
bool isEqual(const IPosition &other, bool skipDegeneratedAxes) const
Element-by-element comparison for equality.
static IPosition makeAxisPath(size_t nrdim)
Construct a default axis path consisting of the values 0.
Definition IPosition.h:549
IPosition nonDegenerate(size_t startingAxis=0) const
This member functions return an IPosition which has degenerate (length==1) axes removed and the dimen...
size_t nelements() const
The number of elements in this IPosition.
Definition IPosition.h:551
IPosition(const std::vector< long long > &other)
void operator-=(ssize_t val)
bool empty() const
Is the IPosition empty (i.e.
Definition IPosition.h:553
static IPosition makeAxisPath(size_t nrdim, const IPosition &partialPath)
Construct a full axis path from a (partially) given axis path.
bool allOne() const
Are all elements equal to 1?
std::vector< int > asStdVector() const
value_type * pointer
Definition IPosition.h:401
friend class IPositionComparator
Definition IPosition.h:116
IPosition concatenate(const IPosition &other) const
Return an IPosition as the concetanation of this and another IPosition.
iterator begin()
Get the begin and end iterator object for this object.
Definition IPosition.h:410
Vector< int > asVector() const
void operator*=(ssize_t val)
void allocateBuffer()
Allocate a buffer with length size_p.
ssize_t * data_p
When the iposition is length BufferSize or less data is just buffer_p, avoiding calls to new and dele...
Definition IPosition.h:429
static IPosition Make(Vals... vals)
Construct an IPosition that is initialized from a variable number of parameter.
Definition IPosition.h:168
const ssize_t * storage() const
Get the storage.
Definition IPosition.h:595
bool conform(const IPosition &other) const
conform returns true if nelements() == other.nelements().
Definition IPosition.h:597
IPosition getLast(size_t n) const
Construct an IPosition from the last n values of this IPosition.
void append(const IPosition &other)
Append this IPosition with another one (causing a resize).
IPosition & operator=(const IPosition &source)
Makes this a copy of other.
const_iterator begin() const
Definition IPosition.h:411
ssize_t & last(size_t index=0)
Index into the IPosition from the end.
Definition IPosition.h:577
ssize_t buffer_p[BufferLength]
Definition IPosition.h:426
const value_type & const_reference
Definition IPosition.h:404
void fill(size_t size, InputIterator iter)
Resize and fill this IPosition object.
Definition IPosition.h:215
void operator/=(const IPosition &other)
IPosition operator()(const IPosition &axes) const
Make an IPosition by using only the specified elements of the current IPosition.
value_type & reference
Definition IPosition.h:403
static IPosition otherAxes(size_t nrdim, const IPosition &axes)
Make a list of axes which are the axes not given in axes up to the given dimension.
IPosition(const std::vector< int > &other)
Convert an IPosition to and from an Array<int/int64>.
void operator+=(ssize_t val)
void throwIndexError() const
Throw an index error exception.
const ssize_t * const_iterator
Definition IPosition.h:400
bool isSubSet(const IPosition &other) const
Is the other IPosition a subset of (or equal to) this IPosition?
void setFirst(const IPosition &other)
Set the first values of this IPosition to another IPosition.
bool operator==(const String &x, const String &y)
Global comparison operators.
Definition String.h:849
String operator+(const String &lhs, const String &rhs)
Global concatenation operators.
Definition String.h:816
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
bool operator<(const String &x, const String &y)
Definition String.h:853
bool operator>=(const String &x, const String &y)
Definition String.h:852
int offset(int, int) const
compute a linear offset from array indicies
LatticeExprNode operator-(const LatticeExprNode &expr)
LatticeExprNode operator/(const LatticeExprNode &left, const LatticeExprNode &right)
IPosition shape(const RecordFieldId &) const
Get the actual shape of this field.
bool operator<=(const String &x, const String &y)
Definition String.h:854
std::string to_string(const IPosition &ip)
LatticeExprNode length(const LatticeExprNode &expr, const LatticeExprNode &axis)
2-argument function to get the length of an axis.
T & operator*()
Provide access to the field's value.
bool operator>(const String &x, const String &y)
Definition String.h:851
bool operator!=(const String &x, const String &y)
Definition String.h:850
NewDelAllocator< T > NewDelAllocator< T >::value
Definition Allocator.h:360
Define real & complex conjugation for non-complex types and put comparisons into std namespace.
Definition Complex.h:344
Arithmetic Operations for IPosition's Element by element arithmetic on IPositions.
Definition IPosition.h:447
IPosition operator/(const IPosition &left, const IPosition &right)
IPosition operator*(const IPosition &left, ssize_t val)
IPosition operator-(const IPosition &left, const IPosition &right)
IPosition operator+(ssize_t val, const IPosition &right)
Same functions as above but with with the int argument on the left side.
IPosition operator/(const IPosition &left, ssize_t val)
IPosition operator*(const IPosition &left, const IPosition &right)
IPosition operator+(const IPosition &left, const IPosition &right)
Each operation is done on corresponding elements of the IPositions.
IPosition operator-(ssize_t val, const IPosition &right)
IPosition min(const IPosition &left, const IPosition &right)
IPosition operator*(ssize_t val, const IPosition &right)
IPosition operator-(const IPosition &left, ssize_t val)
IPosition operator/(ssize_t val, const IPosition &right)
IPosition max(const IPosition &left, const IPosition &right)
Returns the element by element minimum or maximum.
IPosition operator+(const IPosition &left, ssize_t val)
Each operation is done by appliying the integer argument to all elements of the IPosition argument.
Indexing functions for IPosition's Convert between IPosition and offset in an array.
Definition IPosition.h:526
IPosition toIPositionInArray(long long offset, const IPosition &shape)
Convert from offset to IPosition in an array.
long long toOffsetInArray(const IPosition &iposition, const IPosition &shape)
Convert from IPosition to offset in an array.
bool isInsideArray(const long long offset, const IPosition &shape)
Determine if the given offset or IPosition is inside the array.
bool isInsideArray(const IPosition &iposition, const IPosition &shape)
Logical operations for IPosition's Element by element boolean operations on IPositions.
Definition IPosition.h:483
bool operator>(const IPosition &left, const IPosition &right)
bool operator<(const IPosition &left, const IPosition &right)
bool operator!=(const IPosition &left, const IPosition &right)
bool operator!=(const IPosition &left, ssize_t val)
bool operator!=(ssize_t val, const IPosition &right)
bool operator==(const IPosition &left, const IPosition &right)
Each operation is done on corresponding elements of the IPositions.
bool operator>(ssize_t val, const IPosition &right)
bool operator<=(const IPosition &left, ssize_t val)
bool operator<(const IPosition &left, ssize_t val)
bool operator>=(const IPosition &left, ssize_t val)
bool operator>=(ssize_t val, const IPosition &right)
bool operator<=(ssize_t val, const IPosition &right)
bool operator<=(const IPosition &left, const IPosition &right)
bool operator>=(const IPosition &left, const IPosition &right)
bool operator>(const IPosition &left, ssize_t val)
bool operator<(ssize_t val, const IPosition &right)
bool operator==(ssize_t val, const IPosition &right)
Same functions as above but with with the int argument on the left side.
bool operator==(const IPosition &left, ssize_t val)
Each operation is done by appliying the integer argument to all elements.