public abstract class Indexer
extends java.lang.Object
implements java.lang.AutoCloseable
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.
Raw| Modifier and Type | Class and Description |
|---|---|
protected class |
Indexer.Index |
| Modifier and Type | Field and Description |
|---|---|
protected Indexer.Index |
index |
protected Indexable |
indexable
The associated (optional)
Indexable. |
protected static long[] |
ONE_STRIDE |
protected long[] |
sizes
The number of elements in each dimension.
|
protected long[] |
strides
The number of elements to skip to reach the next element in a given dimension.
|
| Modifier | Constructor and Description |
|---|---|
protected |
Indexer(long[] sizes,
long[] strides)
|
| Modifier and Type | Method and Description |
|---|---|
java.lang.Object |
array()
Returns the backing array, or
null if none |
java.nio.Buffer |
buffer()
Returns the backing buffer, or
null if none |
long |
channels()
Deprecated.
|
protected static long |
checkIndex(long i,
long size) |
void |
close()
Calls
release(). |
long |
cols()
Deprecated.
|
abstract double |
getDouble(long... indices)
Calls
get(int...indices) and returns the value as a double. |
long |
height()
Deprecated.
|
long |
index(long... indices)
Returns
index.index(indices). |
long |
index(long i)
Returns
index.index(i). |
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). |
Indexable |
indexable()
Returns
indexable. |
Indexer |
indexable(Indexable indexable)
Sets
indexable and returns this. |
Pointer |
pointer()
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). |
abstract void |
release()
Makes sure changes are reflected onto the backing memory and clears any references.
|
long |
rows()
Deprecated.
|
long |
size(int i)
Returns
sizes[i] |
long[] |
sizes()
Returns
sizes |
long |
stride(int i)
Returns
strides[i] |
long[] |
strides()
Returns
strides |
static long[] |
strides(long... sizes)
Returns default (row-major contiguous) strides for the given sizes.
|
java.lang.String |
toString() |
long |
width()
Deprecated.
|
protected static final long[] ONE_STRIDE
protected long[] sizes
protected long[] strides
strides[i] > strides[i + 1] && strides[strides.length - 1] == 1 preferred.protected Indexer.Index index
public void close()
release().close in interface java.lang.AutoCloseablepublic long[] sizes()
sizespublic long[] strides()
stridespublic long size(int i)
sizes[i]public long stride(int i)
strides[i]@Deprecated public long rows()
sizes.length > 0 && sizes.length < 4 ? sizes[0] : -1@Deprecated public long cols()
sizes.length > 1 && sizes.length < 4 ? sizes[1] : -1@Deprecated public long width()
sizes.length > 1 && sizes.length < 4 ? sizes[1] : -1@Deprecated public long height()
sizes.length > 0 && sizes.length < 4 ? sizes[0] : -1@Deprecated public long channels()
sizes.length > 2 && sizes.length < 4 ? sizes[2] : -1protected static final long checkIndex(long i,
long size)
public static long[] strides(long... sizes)
public long index(long i)
index.index(i).public long index(long i,
long j)
index.index(i, j).public long index(long i,
long j,
long k)
index.index(i, j, k).public long index(long... indices)
index.index(indices).public java.lang.Object array()
null if nonepublic java.nio.Buffer buffer()
null if nonepublic Pointer pointer()
null if nonepublic abstract void release()
public abstract double getDouble(long... indices)
get(int...indices) and returns the value as a double.public abstract Indexer putDouble(long[] indices, double value)
put(long[] indices, <type> value).public java.lang.String toString()
toString in class java.lang.Object