ArrayPositionIterator manipulates an IPosition "cursor" through some volume defined by an origin and shape. This position can in turn be used to index into, or otherwise define a position in, an Array. Normally users won't use this class directly, rather they will use an ArrayIterator, VectorIterator or MatrixIterator object, which in turn uses this class. ArrayPositionIterator is also used in the implementation of Array.
template<class T> void verySlowArrayCopy(Array<T> &to, const Array<T> &from) { if (! to.conform(from)) { // throw some error } ArrayPositionIterator toiter(to.shape(), to.origin(),0); ArrayPositionIterator fromiter(from.shape(), from.origin(),0); // If to.origin() == from.origin() we only need one iterator // or we could offset positions by the difference in origins. // The "0" means we are stepping by scalars. while (! toiter.pastEnd()) { // we know arrays conform to(toiter.pos()) = fromiter(fromiter.pos()); toiter.next(); fromiter.next(); } }
At the moment this only iterates by the simplest "bottom to top" order, and the iteration step always "fills up" its dimensionality. e.g., if we are stepping through a cube by matrices, the matrix completely fills up the plane. These restrictions should be removed eventually.
All the array iterator classes should probably be reimplemented; their implementation is a bit ugly.
Advance the cursor to its next position.
How many steps have we taken from the beginning?