Class BaseDenseTensorIterator

java.lang.Object
com.linkedin.feathr.common.featurizeddataset.BaseDenseTensorIterator
All Implemented Interfaces:
ReadableTuple, TensorIterator

public abstract class BaseDenseTensorIterator extends Object implements TensorIterator
The base for custom iterators over dense tensors of ranks 1+. Encapsulates the logic for traversing nested collections, so that it can be shared between e.g. Avro and Spark representations. Examples:
  • A regular tensor of the shape [2, 3]. Numbering of positions: [ [0, 1, 2], [3, 4, 5] ]. The sequence of indices: [(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2)].
  • A ragged tensor of rank 2. Numbering of positions: [ [0, 1], [], [2, 3, 4] ] The sequence of indices: [(0, 0), (0, 1), (2, 0), (2, 1), (2, 2)].
Subclasses are expected to cache their current path through the tree of nested collections. There are as many collections in the cache as the rank of the tensor, starting from the root and ending with the level containing leaves/values: cache[0] = root cache[1] = cache[0][_indices[0]] ... cache[rank] = cache[rank-1][_indices[rank-1]] = current value
  • Constructor Details

    • BaseDenseTensorIterator

      protected BaseDenseTensorIterator(int rank)
    • BaseDenseTensorIterator

      protected BaseDenseTensorIterator(BaseDenseTensorIterator original)
  • Method Details

    • getRank

      protected final int getRank()
    • getFlatIndex

      public final int getFlatIndex()
    • getIndex

      protected final int getIndex(int dimension)
    • cache

      protected abstract boolean cache(int level, int childIndex)
      Fill the level of cache from the childIndex child of the level-1.
      Returns:
      false if j is out of range.
    • cacheRoot

      protected abstract void cacheRoot()
      Fill the 0th level of cache with the root.
    • start

      public void start()
      Description copied from interface: TensorIterator
      Rewinds the iterator to the beginning of its range.
      Specified by:
      start in interface TensorIterator
    • isValid

      public boolean isValid()
      Specified by:
      isValid in interface TensorIterator
      Returns:
      if the iterator is still within its range.
    • next

      public void next()
      Description copied from interface: TensorIterator
      Move iterator to the next row.
      Specified by:
      next in interface TensorIterator