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