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  // A zero-length IPosition.
124  IPosition() noexcept;
125 
126  // An IPosition of size "length." The values in the object are uninitialized.
127  explicit IPosition(size_t length);
128 
129  // An IPosition initialized from the given list
130  IPosition(std::initializer_list<ssize_t> list);
131 
132  // An IPosition of size "length." All values in the object are
133  // initialized to val.
134  IPosition(size_t length, ssize_t val);
135 
136  // An IPosition initialized from a variable number of parameters.
137  // The first parameter should specify the size, but the actual
138  // size of the resulting IPosition is determined from the number
139  // of parameters (the first argument is ignored).
140  //
141  // This constructor should be disfavoured, because i) of the
142  // dummy parameter and ii) because it may narrow the
143  // specified parameter without a warning.
144  //
145  // Instead, use an initializer list constructor whenever possible.
146  // If an IPosition is created inside a macro, an initializer list
147  // is not possible. In those cases, use the Make(Vals...) factory
148  // method. Both of those methods do not have the above issues.
149  template<typename... Vals>
150  //[[ deprecated("Use the initializer list constructor or Make() method") ]]
151  IPosition (size_t /*dummy*/, ssize_t val1, ssize_t val2, Vals... vals) :
152  IPosition{val1, val2, static_cast<ssize_t>(vals)...} { }
153 
154  // Makes a copy (copy, NOT reference, semantics) of source.
155  IPosition(const IPosition& source);
156 
157  IPosition(IPosition&& source) noexcept;
158 
160 
161  // Construct an IPosition that is initialized from a variable number of parameter.
162  // The resulting size of the IPosition will equal the number of parameters specified.
163  //
164  // In general, using the initializer list constructor should be preferred. Defining
165  // an initializer list inside macros is however not possible. In those cases, this
166  // method can be used to construct the IPosition.
167  //
168  // Example: IPosition::Make(3, 5) creates an IPosition of size 2, with values 3 and 5.
169  // It is identical to IPosition{3, 5}. A program is ill-formed when narrowing of
170  // a parameter is required, causing a compiler warning or error.
171  template<typename... Vals>
172  static IPosition Make (Vals... vals) {
173  return IPosition{vals...};
174  }
175 
176  // Makes this a copy of other. When the dest is not of the same
177  // size, it will resize itself to be the same length as the source.
178  IPosition& operator=(const IPosition& source);
179 
181 
182  // Copy "value" into every position of this IPosition.
184 
185  // Construct a default axis path consisting of the values 0 .. nrdim-1.
186  static IPosition makeAxisPath (size_t nrdim);
187 
188  // Construct a full axis path from a (partially) given axis path.
189  // It fills the path with the non-given axis.
190  // It is checked if the given axis path is valid (i.e. if the axis are
191  // < nrdim and if they are not doubly defined).
192  // E.g.: in the 4D case an axis path [0,2] is returned as [0,2,1,3].
193  static IPosition makeAxisPath (size_t nrdim, const IPosition& partialPath);
194 
195  // Make a list of axes which are the axes not given in <src>axes</src>
196  // up to the given dimension
197  static IPosition otherAxes (size_t nrdim, const IPosition& axes);
198 
199  // Convert an IPosition to and from an Array<int/int64>. In either case, the
200  // array must be one dimensional.
201  // <group>
202  IPosition(const Array<int>& other);
206  // </group>
207 
208  // Convert an IPosition to and from an Array<int/int64>. In either case, the
209  // array must be one dimensional.
210  // <group>
211  IPosition(const std::vector<int>& other);
212  IPosition(const std::vector<long long>& other);
213  std::vector<int> asStdVector() const;
214  std::vector<long long> asStdVector64() const;
215  // </group>
216 
217  // Resize and fill this IPosition object.
218  template<typename InputIterator>
219  void fill (size_t size, InputIterator iter)
220  {
221  resize (size);
222  for (size_t i=0; i<size; ++i, ++iter) {
223  data_p[i] = *iter;
224  }
225  }
226 
227  // Copy the contents of this IPosition object to the output iterator.
228  // The size of the output must be sufficient.
229  template<typename OutputIterator>
230  void copy (OutputIterator iter) const
231  {
232  for (size_t i=0; i<size_p; ++i, ++iter) {
233  *iter = data_p[i];
234  }
235  }
236 
237 
238  // This member functions return an IPosition which has
239  // degenerate (length==1) axes removed and the dimensionality reduced
240  // appropriately.
241  // Only axes greater than startingAxis are considered (normally one
242  // wants to remove trailing axes.
243  // <br>
244  // The functions with argument <src>ignoreAxes</src> do
245  // not consider the axes given in that argument.
246  // <group>
247  IPosition nonDegenerate(size_t startingAxis=0) const;
248  IPosition nonDegenerate(const IPosition& ignoreAxes) const;
249  // </group>
250 
251  // Old values are copied on resize if copy==true.
252  // If the size increases, values beyond the former size are undefined.
253  void resize(size_t newSize, bool copy=true);
254 
255  // Index into the IPosition. Indices are zero-based. If the preprocessor
256  // symbol AIPS_ARRAY_INDEX_CHECK is defined, operator() will check
257  // "index" to ensure it is not out of bounds. If this check fails, an
258  // AipsError will be thrown.
259  // <group>
260  ssize_t& operator[] (size_t index);
261  ssize_t operator[] (size_t index) const;
262  ssize_t& operator() (size_t index);
263  ssize_t operator() (size_t index) const;
264  // </group>
265 
266  // Make an IPosition by using only the specified elements of the current
267  // IPosition. All values of <src>axes</src> must be less than
268  // the number of elements of the current object.
269  // <example>
270  // IPosition ipos(4, 11, 12, 13, 14);
271  // // ex1 is IPosition(3, 11, 12, 13);
272  // IPosition ex1 = ipos(IPosition(3,0,1,2);
273  // // ex2 is IPosition(3, 12, 11)
274  // IPosition ex2 = ipos(IPosition(2,2,1);
275  // // ex3 is IPosition(4,14,14,14,14)
276  // IPosition ex3 = ipos(IPosition(4,3,3,3,3);
277  // </example>
278  IPosition operator() (const IPosition& axes) const;
279 
280  // Index into the IPosition from the end.
281  // By default the last value is returned.
282  // If the preprocessor symbol AIPS_ARRAY_INDEX_CHECK is defined, it will
283  // check if the index is not out of bounds.
284  // <group>
285  ssize_t& last (size_t index=0);
286  ssize_t last (size_t index=0) const;
287  // </group>
288 
289  // Get the storage.
290  const ssize_t *storage() const;
291 
292  // Append this IPosition with another one (causing a resize).
293  void append (const IPosition& other);
294 
295  // Prepend this IPosition with another one (causing a resize).
296  void prepend (const IPosition& other);
297 
298  // Return an IPosition as the concetanation of this and another IPosition.
299  IPosition concatenate (const IPosition& other) const;
300 
301  // Set the first values of this IPosition to another IPosition.
302  // An exception is thrown if the other IPosition is too long.
303  void setFirst (const IPosition& other);
304 
305  // Set the last values of this IPosition to another IPosition.
306  // An exception is thrown if the other IPosition is too long.
307  void setLast (const IPosition& other);
308 
309  // Construct an IPosition from the first <src>n</src> values of this
310  // IPosition.
311  // An exception is thrown if <src>n</src> is too high.
312  IPosition getFirst (size_t n) const;
313 
314  // Construct an IPosition from the last <src>n</src> values of this
315  // IPosition.
316  // An exception is thrown if <src>n</src> is too high.
317  IPosition getLast (size_t n) const;
318 
319  // Return an IPosition where the given axes are reoved.
320  IPosition removeAxes (const IPosition& axes) const;
321 
322  // Return an IPosition containing the given axes only.
323  IPosition keepAxes (const IPosition& axes) const;
324 
325  // The number of elements in this IPosition. Since IPosition
326  // objects use zero-based indexing, the maximum available index is
327  // nelements() - 1.
328  // <group>
329  size_t nelements() const;
330  size_t size() const;
331  // </group>
332 
333  // Is the IPosition empty (i.e. no elements)?
334  bool empty() const;
335 
336  // conform returns true if nelements() == other.nelements().
337  bool conform(const IPosition& other) const;
338 
339  // Element-by-element arithmetic.
340  // <group>
341  void operator += (const IPosition& other);
342  void operator -= (const IPosition& other);
343  void operator *= (const IPosition& other);
344  void operator /= (const IPosition& other);
345  void operator += (ssize_t val);
346  void operator -= (ssize_t val);
347  void operator *= (ssize_t val);
348  void operator /= (ssize_t val);
349  // </group>
350 
351  // Returns 0 if nelements() == 0, otherwise it returns the product of
352  // its elements.
353  long long product() const;
354 
355  // Are all elements equal to 1?
356  // Useful to check if a given stride is really a stride.
357  bool allOne() const;
358 
359  // Element-by-element comparison for equality.
360  // It returns true if the lengths and all elements are equal.
361  // <br>
362  // Note that an important difference between this function and operator==()
363  // is that if the two IPositions have different lengths, this function
364  // returns false, instead of throwing an exception as operator==() does.
365  bool isEqual (const IPosition& other) const;
366 
367  // Element-by-element comparison for equality.
368  // It returns true if all elements are equal.
369  // When <src>skipDegeneratedAxes</src> is true, axes with
370  // length 1 are skipped in both operands.
371  bool isEqual (const IPosition& other, bool skipDegeneratedAxes) const;
372 
373  // Element-by-element comparison for (partial) equality.
374  // It returns true if the lengths and the first <src>nrCompare</src>
375  // elements are equal.
376  bool isEqual (const IPosition& other, size_t nrCompare) const;
377 
378  // Is the other IPosition a subset of (or equal to) this IPosition?
379  // It is a subset if zero or more axes of this IPosition do not occur
380  // or are degenerated in the other and if the remaining axes are
381  // in the same order.
382  bool isSubSet (const IPosition& other) const;
383 
384  // Write the IPosition into a string.
385  // TODO deprecate in favour of to_string(const IPosition&)
386  std::string toString() const;
387 
388  // Write an IPosition to an ostream in a simple text form.
389  friend std::ostream& operator<<(std::ostream& os, const IPosition& ip);
390 
391  // Is this IPosition consistent?
392  bool ok() const;
393 
394  // Define the STL-style iterators.
395  // It makes it possible to iterate through all data elements.
396  // <srcblock>
397  // IPosition shp(2,0);
398  // for (IPosition::iterator iter=shp.begin(); iter!=shp.end(); iter++) {
399  // *iter += 1;
400  // }
401  // </srcblock>
402  // <group name=STL-iterator>
403  // STL-style typedefs.
404  // <group>
405  typedef ssize_t value_type;
406  typedef ssize_t* iterator;
407  typedef const ssize_t* const_iterator;
408  typedef value_type* pointer;
409  typedef const value_type* const_pointer;
411  typedef const value_type& const_reference;
412  typedef size_t size_type;
413  typedef ptrdiff_t difference_type;
414  // </group>
415  // Get the begin and end iterator object for this object.
416  // <group>
418  { return data_p; }
420  { return data_p; }
422  { return data_p + size_p; }
424  { return data_p + size_p; }
425  // </group>
426  // </group>
427 
428 private:
429  // Allocate a buffer with length size_p.
431 
432  // Throw an index error exception.
433  void throwIndexError() const;
434 
435  enum { BufferLength = 4 };
436  size_t size_p;
438  // When the iposition is length BufferSize or less data is just buffer_p,
439  // avoiding calls to new and delete.
440  ssize_t *data_p;
441 };
442 
443 // Allows a way for IPosition to be used as keys in a std::map
445 public:
446  // if sizes aren't equal, returns true if lhs.size() < rhs.size(), false
447  // otherwise. If sizes are equal, does an element by element comparison. The first
448  // corresponding elements that are not equal, returns true if the rhs element is
449  // less than the lhs element, false otherwise. Returns false if all elements are
450  // equal.
451  bool operator()(const IPosition& lhs, const IPosition& rhs) const;
452 };
453 
454 // <summary>Arithmetic Operations for IPosition's</summary>
455 // Element by element arithmetic on IPositions.
456 // <group name="IPosition Arithmetic">
457 // Each operation is done on corresponding elements of the IPositions. The
458 // two IPositions must have the same number of elements otherwise an
459 // exception (ArrayConformanceError) will be thrown.
460 // <group>
461 IPosition operator + (const IPosition& left, const IPosition& right);
462 IPosition operator - (const IPosition& left, const IPosition& right);
463 IPosition operator * (const IPosition& left, const IPosition& right);
464 IPosition operator / (const IPosition& left, const IPosition& right);
465 // </group>
466 // Each operation is done by appliying the integer argument to all elements
467 // of the IPosition argument.
468 // <group>
469 IPosition operator + (const IPosition& left, ssize_t val);
470 IPosition operator - (const IPosition& left, ssize_t val);
471 IPosition operator * (const IPosition& left, ssize_t val);
472 IPosition operator / (const IPosition& left, ssize_t val);
473 // </group>
474 // Same functions as above but with with the int argument on the left side.
475 // <group>
476 IPosition operator + (ssize_t val, const IPosition& right);
477 IPosition operator - (ssize_t val, const IPosition& right);
478 IPosition operator * (ssize_t val, const IPosition& right);
479 IPosition operator / (ssize_t val, const IPosition& right);
480 // </group>
481 
482 // Returns the element by element minimum or maximum.
483 // <group>
484 IPosition max (const IPosition& left, const IPosition& right);
485 IPosition min (const IPosition& left, const IPosition& right);
486 // </group>
487 // </group>
488 
489 // <summary>Logical operations for IPosition's</summary>
490 // Element by element boolean operations on IPositions. The result is true
491 // only if the operation yields true for every element of the IPosition.
492 // <group name="IPosition Logical">
493 // Each operation is done on corresponding elements of the IPositions. The
494 // two IPositions must have the same number of elements otherwise an
495 // exception (ArrayConformanceError) will be thrown.
496 // <group>
497 bool operator == (const IPosition& left, const IPosition& right);
498 bool operator != (const IPosition& left, const IPosition& right);
499 bool operator < (const IPosition& left, const IPosition& right);
500 bool operator <= (const IPosition& left, const IPosition& right);
501 bool operator > (const IPosition& left, const IPosition& right);
502 bool operator >= (const IPosition& left, const IPosition& right);
503 // </group>
504 // Each operation is done by appliying the integer argument to all elements
505 // <group>
506 bool operator == (const IPosition& left, ssize_t val);
507 bool operator != (const IPosition& left, ssize_t val);
508 bool operator < (const IPosition& left, ssize_t val);
509 bool operator <= (const IPosition& left, ssize_t val);
510 bool operator > (const IPosition& left, ssize_t val);
511 bool operator >= (const IPosition& left, ssize_t val);
512 // </group>
513 // Same functions as above but with with the int argument on the left side.
514 // <group>
515 bool operator == (ssize_t val, const IPosition& right);
516 bool operator != (ssize_t val, const IPosition& right);
517 bool operator < (ssize_t val, const IPosition& right);
518 bool operator <= (ssize_t val, const IPosition& right);
519 bool operator > (ssize_t val, const IPosition& right);
520 bool operator >= (ssize_t val, const IPosition& right);
521 // </group>
522 // </group>
523 
524 // <summary>Indexing functions for IPosition's</summary>
525 // Convert between IPosition and offset in an array.
526 //
527 // The offset of an element in an array is the number of elements from the
528 // origin that the element would be if the array were arranged linearly.
529 // The origin of the array has an offset equal to 0, while the
530 // "top right corner" of the array has an offset equal to one less than the
531 // total number of elements in the array.
532 //
533 // Two examples of offset would be the index in a carray and the seek position
534 // in a file.
535 
536 // <group name="IPosition Indexing">
537 // Convert from offset to IPosition in an array.
538 IPosition toIPositionInArray (long long offset, const IPosition& shape);
539 
540 // Convert from IPosition to offset in an array.
541 long long toOffsetInArray (const IPosition& iposition, const IPosition& shape);
542 
543 // Determine if the given offset or IPosition is inside the array. Returns
544 // true if it is inside the Array.
545 // <thrown>
546 // <li> ArrayConformanceError: If all the IPositions are not the same length
547 // </thrown>
548 // <group>
549 bool isInsideArray (const long long offset, const IPosition& shape);
550 bool isInsideArray (const IPosition& iposition, const IPosition& shape);
551 // </group>
552 // </group>
553 
554 std::string to_string(const IPosition& ip);
555 
556 //# Inlined member functions for IPosition
557 
558 inline IPosition::IPosition() noexcept
559 : size_p (0),
560  data_p (buffer_p)
561 {}
562 
563 inline IPosition IPosition::makeAxisPath (size_t nrdim)
564 {
565  return makeAxisPath (nrdim, IPosition());
566 }
567 
568 inline size_t IPosition::nelements() const
569 {
570  return size_p;
571 }
572 inline size_t IPosition::size() const
573 {
574  return size_p;
575 }
576 inline bool IPosition::empty() const
577 {
578  return size_p == 0;
579 }
580 
581 inline ssize_t& IPosition::operator[](size_t index)
582 {
583  return data_p[index];
584 }
585 
586 inline ssize_t IPosition::operator[](size_t index) const
587 {
588  return data_p[index];
589 }
590 
591 inline ssize_t& IPosition::operator()(size_t index)
592 {
593 #if defined(AIPS_ARRAY_INDEX_CHECK)
594  if (index >= nelements()) {
595  throwIndexError();
596  }
597 #endif
598  return data_p[index];
599 }
600 
601 inline ssize_t IPosition::operator()(size_t index) const
602 {
603 #if defined(AIPS_ARRAY_INDEX_CHECK)
604  if (index >= nelements()) {
605  throwIndexError();
606  }
607 #endif
608  return data_p[index];
609 }
610 
611 inline ssize_t& IPosition::last (size_t index)
612 {
613 #if defined(AIPS_ARRAY_INDEX_CHECK)
614  if (size_p - index <= 0) {
615  throwIndexError();
616  }
617 #endif
618  return data_p[size_p-index-1];
619 }
620 
621 inline ssize_t IPosition::last (size_t index) const
622 {
623 #if defined(AIPS_ARRAY_INDEX_CHECK)
624  if (size_p - index <= 0) {
625  throwIndexError();
626  }
627 #endif
628  return data_p[size_p-index-1];
629 }
630 
631 inline const ssize_t *IPosition::storage() const
632 {
633  return data_p;
634 }
635 
636 inline bool IPosition::conform(const IPosition& other) const
637 {
638  return (size_p == other.size_p);
639 }
640 
641 } //# NAMESPACE CASACORE - END
642 
643 #endif
Allows a way for IPosition to be used as keys in a std::map.
Definition: IPosition.h:444
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:581
ptrdiff_t difference_type
Definition: IPosition.h:413
void operator*=(const IPosition &other)
const value_type * const_pointer
Definition: IPosition.h:409
std::vector< int > asStdVector() const
IPosition & operator=(IPosition &&source)
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:572
IPosition(const Array< int > &other)
Convert an IPosition to and from an Array<int/int64>.
ssize_t & operator()(size_t index)
Definition: IPosition.h:591
const_iterator end() const
Definition: IPosition.h:423
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:405
void copy(OutputIterator iter) const
Copy the contents of this IPosition object to the output iterator.
Definition: IPosition.h:230
void setLast(const IPosition &other)
Set the last values of this IPosition to another IPosition.
IPosition & operator=(const IPosition &source)
Makes this a copy of other.
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:558
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:563
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:568
ssize_t * iterator
Definition: IPosition.h:406
IPosition(const std::vector< long long > &other)
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:576
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? Useful to check if a given stride is really a stride.
value_type * pointer
Definition: IPosition.h:408
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:417
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:440
static IPosition Make(Vals... vals)
Construct an IPosition that is initialized from a variable number of parameter.
Definition: IPosition.h:172
const ssize_t * storage() const
Get the storage.
Definition: IPosition.h:631
bool conform(const IPosition &other) const
conform returns true if nelements() == other.nelements().
Definition: IPosition.h:636
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:419
ssize_t & last(size_t index=0)
Index into the IPosition from the end.
Definition: IPosition.h:611
ssize_t buffer_p[BufferLength]
Definition: IPosition.h:437
const value_type & const_reference
Definition: IPosition.h:411
void fill(size_t size, InputIterator iter)
Resize and fill this IPosition object.
Definition: IPosition.h:219
void operator/=(const IPosition &other)
value_type & reference
Definition: IPosition.h:410
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 throwIndexError() const
Throw an index error exception.
const ssize_t * const_iterator
Definition: IPosition.h:407
iterator end()
Definition: IPosition.h:421
IPosition & operator=(ssize_t value)
Copy "value" into every position of this IPosition.
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)