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()
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)
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()
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.
|
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.public void close()
release()
.close
in interface AutoCloseable
public long[] sizes()
sizes
public long[] strides()
strides
public 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] : -1
protected static final long checkIndex(long i, long size)
public static long[] strides(long... sizes)
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 © 2020. All rights reserved.