public abstract class Indexer extends Object implements 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 | Field and Description |
---|---|
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 |
---|---|
Object |
array()
Returns the backing array, or
null if none |
Buffer |
buffer()
Returns the backing buffer, or
null if none |
long |
channels()
Returns
sizes[2] |
protected static long |
checkIndex(long i,
long size) |
void |
close()
Calls
release() . |
long |
cols()
Returns
sizes[1] |
abstract double |
getDouble(long... indices)
Calls
get(int...indices) and returns the value as a double. |
long |
height()
Returns
sizes[0] |
long |
index(long... indices)
Computes the linear index as the dot product of indices and strides.
|
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()
Returns
sizes[0] |
long[] |
sizes()
Returns
sizes |
long[] |
strides()
Returns
strides |
String |
toString() |
long |
width()
Returns
sizes[1] |
protected static final long[] ONE_STRIDE
protected long[] sizes
protected long[] strides
strides[i] > strides[i + 1] && strides[strides.length - 1] == 1
must hold.public void close() throws Exception
release()
.close
in interface AutoCloseable
Exception
public long[] sizes()
sizes
public long[] strides()
strides
public long rows()
sizes[0]
public long cols()
sizes[1]
public long width()
sizes[1]
public long height()
sizes[0]
public long channels()
sizes[2]
protected static final long checkIndex(long i, long size)
public long index(long... indices)
indices
- of each dimensionpublic Object array()
null
if nonepublic 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)
.Copyright © 2018. All rights reserved.