Class Indexer

java.lang.Object
org.bytedeco.javacpp.indexer.Indexer
All Implemented Interfaces:
AutoCloseable
Direct Known Subclasses:
Bfloat16Indexer, BooleanIndexer, ByteIndexer, CharIndexer, DoubleIndexer, FloatIndexer, HalfIndexer, IntIndexer, LongIndexer, ShortIndexer, UByteIndexer, UIntIndexer, ULongIndexer, UShortIndexer

public abstract class Indexer extends Object implements AutoCloseable
Top-level class of all data indexers, providing easy-to-use and efficient multidimensional access to primitive arrays, NIO buffers, and the raw memory interface.

Subclasses have create() factory methods for arrays, buffers, and pointers. The latter ones feature a direct argument that, when set to false, instructs the method to create a large enough array, fill its content with the data from the pointer, and return an array-backed indexer, with the release() method overridden to write back changes to the pointer. This doubles the memory usage, but is the only way to get acceptable performance on some implementations, such as Android. When direct == true, the raw memory interface (supporting long indexing) is used if available, and if not a buffer-backed indexer is returned.

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final Index
    The Index to be used for index(long...).
    protected Indexable
    The associated (optional) Indexable.
    protected long[]
    Deprecated.
    protected long[]
    Deprecated.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Indexer(long[] sizes, long[] strides)
    Calls Indexer(Index.create(sizes, strides)).
    protected
    Indexer(Index index)
    Constructor to set the index.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the backing array, or null if none
    Returns the backing buffer, or null if none
    long
    Deprecated.
    protected static final long
    checkIndex(long i, long size)
     
    void
    Calls release().
    long
    Deprecated.
    abstract double
    getDouble(long... indices)
    Calls get(int...indices) and returns the value as a double.
    long
    Deprecated.
    long
    index(long i)
    Returns index.index(i).
    long
    index(long... indices)
    Returns index.index(indices).
    long
    index(long i, long j)
    Returns index.index(i, j).
    long
    index(long i, long j, long k)
    Returns index.index(i, j, k).
    Returns indexable.
    indexable(Indexable indexable)
    Sets indexable and returns this.
    Returns the backing pointer, or null if none
    abstract Indexer
    putDouble(long[] indices, double value)
    Casts value to primitive type and calls put(long[] indices, <type> value).
    int
    Returns index.rank().
    abstract <I extends Indexer>
    I
    reindex(Index index)
    Returns a new Indexer using the same data, but with a different Index.
    abstract void
    Makes sure changes are reflected onto the backing memory and clears any references.
    long
    Deprecated.
    long
    size(int i)
    Returns index.size(i).
    long[]
    Returns index.sizes().
    long
    stride(int i)
    Deprecated.
    long[]
    Deprecated.
    static long[]
    strides(long... sizes)
    Deprecated.
     
    long
    Deprecated.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • Indexer

      protected Indexer(Index index)
      Constructor to set the index.
    • Indexer

      protected Indexer(long[] sizes, long[] strides)
      Calls Indexer(Index.create(sizes, strides)).
  • Method Details

    • close

      public void close()
      Calls release().
      Specified by:
      close in interface AutoCloseable
    • rank

      public int rank()
      Returns index.rank().
    • sizes

      public long[] sizes()
      Returns index.sizes().
    • strides

      @Deprecated public long[] strides()
      Deprecated.
      Returns strides or null if there are no strides.
    • size

      public long size(int i)
      Returns index.size(i).
    • stride

      @Deprecated public long stride(int i)
      Deprecated.
      Returns strides[i] or -1 if there are no strides.
    • rows

      @Deprecated public long rows()
      Deprecated.
      Returns sizes.length > 0 && sizes.length < 4 ? sizes[0] : -1.
    • cols

      @Deprecated public long cols()
      Deprecated.
      Returns sizes.length > 1 && sizes.length < 4 ? sizes[1] : -1.
    • width

      @Deprecated public long width()
      Deprecated.
      Returns sizes.length > 1 && sizes.length < 4 ? sizes[1] : -1.
    • height

      @Deprecated public long height()
      Deprecated.
      Returns sizes.length > 0 && sizes.length < 4 ? sizes[0] : -1.
    • channels

      @Deprecated public long channels()
      Deprecated.
      Returns sizes.length > 2 && sizes.length < 4 ? sizes[2] : -1.
    • checkIndex

      protected static final long checkIndex(long i, long size)
    • strides

      @Deprecated public static long[] strides(long... sizes)
      Deprecated.
    • index

      public long index(long i)
      Returns index.index(i).
    • index

      public long index(long i, long j)
      Returns index.index(i, j).
    • index

      public long index(long i, long j, long k)
      Returns index.index(i, j, k).
    • index

      public long index(long... indices)
      Returns index.index(indices).
    • indexable

      public Indexable indexable()
      Returns indexable.
    • indexable

      public Indexer indexable(Indexable indexable)
      Sets indexable and returns this.
    • array

      public Object array()
      Returns the backing array, or null if none
    • buffer

      public Buffer buffer()
      Returns the backing buffer, or null if none
    • pointer

      public Pointer pointer()
      Returns the backing pointer, or null if none
    • release

      public abstract void release()
      Makes sure changes are reflected onto the backing memory and clears any references.
    • getDouble

      public abstract double getDouble(long... indices)
      Calls get(int...indices) and returns the value as a double.
    • putDouble

      public abstract Indexer putDouble(long[] indices, double value)
      Casts value to primitive type and calls put(long[] indices, <type> value).
    • reindex

      public abstract <I extends Indexer> I reindex(Index index)
      Returns a new Indexer using the same data, but with a different Index.
    • toString

      public String toString()
      Overrides:
      toString in class Object