public class SimpleBuffer extends BaseBuffer
PyBuffer.PointerANY_CONTIGUOUS, C_CONTIGUOUS, CONTIG, CONTIG_RO, CONTIGUITY, F_CONTIGUOUS, FORMAT, FULL, FULL_RO, INDIRECT, IS_C_CONTIGUOUS, IS_F_CONTIGUOUS, MAX_NDIM, NAVIGATION, ND, RECORDS, RECORDS_RO, SIMPLE, STRIDED, STRIDED_RO, STRIDES, WRITABLE| Constructor and Description |
|---|
SimpleBuffer(byte[] storage)
Provide an instance of
SimpleBuffer, on the entirety of a byte array, with
navigation variables initialised, for sub-class use. |
SimpleBuffer(byte[] storage,
int index0,
int size)
Provide an instance of
SimpleBuffer with navigation variables initialised, for
sub-class use. |
SimpleBuffer(int flags,
byte[] storage)
Provide an instance of
SimpleBuffer, on the entirety of a byte array, meeting
the consumer's expectations as expressed in the flags argument, which is checked
against the capabilities of the buffer type. |
SimpleBuffer(int flags,
byte[] storage,
int index0,
int size)
Provide an instance of
SimpleBuffer, on a slice of a byte array, meeting the
consumer's expectations as expressed in the flags argument, which is checked
against the capabilities of the buffer type. |
| Modifier and Type | Method and Description |
|---|---|
byte |
byteAt(int... indices)
Return the byte indexed from an N-dimensional buffer with item size one.
|
byte |
byteAt(int index)
Return the byte indexed from a one-dimensional buffer with item size one.
|
void |
copyTo(int srcIndex,
byte[] dest,
int destPos,
int length)
Copy a simple slice of the buffer to the destination byte array, defined by a starting index
and length in the source buffer.
|
PyBuffer |
getBufferSlice(int flags,
int start,
int length)
Equivalent to
PyBuffer.getBufferSlice(int, int, int, int) with stride 1. |
PyBuffer |
getBufferSlice(int flags,
int start,
int length,
int stride)
Get a
PyBuffer that represents a slice of the current one described in terms of
a start index, number of items to include in the slice, and the stride in the current buffer. |
int |
getLen()
The total number of units (bytes) stored, which will be the product of the elements of the
shape array, and the item size. |
PyBuffer.Pointer |
getPointer(int... indices)
Return a structure describing the slice of a byte array that points to a single item from the
data being exported to the consumer, in the case that array may be multi-dimensional.
|
PyBuffer.Pointer |
getPointer(int index)
Return a structure describing the slice of a byte array that points to a single item from the
data being exported to the consumer.
|
int |
intAt(int index)
Return the unsigned byte value indexed from a one-dimensional buffer with item size one.
|
boolean |
isReadonly()
Determine whether the consumer is entitled to write to the exported storage.
|
java.lang.String |
toString()
The toString() method of a buffer reproduces the values in the buffer (as unsigned integers)
as the character codes of a
String. |
copyFrom, copyFrom, copyTo, getBuf, getBuffer, getBufferAgain, getFormat, getItemsize, getNdim, getShape, getStrides, getSuboffsets, intAt, isContiguous, isReleased, release, storeAt, storeAtpublic SimpleBuffer(byte[] storage,
int index0,
int size)
throws PyException,
java.lang.ArrayIndexOutOfBoundsException
SimpleBuffer with navigation variables initialised, for
sub-class use. The buffer (BaseBuffer.storage, BaseBuffer.index0), and the BaseBuffer.shape array
will be initialised from the arguments (which are checked for range). The BaseBuffer.strides is
set for (one-byte) unit stride. Only the call to BaseBuffer.checkRequestFlags(int), passing the
consumer's request flags really remains for the sub-class constructor to do.
super(storage, index0, size); checkRequestFlags(flags); // Check request is compatible with type
storage - the array of bytes storing the implementation of the exporting objectindex0 - offset where the data starts in that array (item[0])size - the number of bytes occupiedjava.lang.NullPointerException - if storage is nulljava.lang.ArrayIndexOutOfBoundsException - if index0 and size are
inconsistent with storage.lengthPyExceptionpublic SimpleBuffer(int flags,
byte[] storage,
int index0,
int size)
throws PyException,
java.lang.ArrayIndexOutOfBoundsException,
java.lang.NullPointerException
SimpleBuffer, on a slice of a byte array, meeting the
consumer's expectations as expressed in the flags argument, which is checked
against the capabilities of the buffer type.flags - consumer requirementsstorage - the array of bytes storing the implementation of the exporting objectindex0 - offset where the data starts in that array (item[0])size - the number of bytes occupiedjava.lang.NullPointerException - if storage is nulljava.lang.ArrayIndexOutOfBoundsException - if index0 and size are
inconsistent with storage.lengthPyException - (BufferError) when expectations do not correspond with the typepublic SimpleBuffer(byte[] storage)
throws java.lang.NullPointerException
SimpleBuffer, on the entirety of a byte array, with
navigation variables initialised, for sub-class use. The buffer ( BaseBuffer.storage,
BaseBuffer.index0), and the navigation (BaseBuffer.shape array) will be initialised from the
array argument.storage - the array of bytes storing the implementation of the exporting objectjava.lang.NullPointerException - if storage is nullpublic SimpleBuffer(int flags,
byte[] storage)
throws PyException,
java.lang.NullPointerException
SimpleBuffer, on the entirety of a byte array, meeting
the consumer's expectations as expressed in the flags argument, which is checked
against the capabilities of the buffer type.flags - consumer requirementsstorage - the array of bytes storing the implementation of the exporting objectjava.lang.NullPointerException - if storage is nullPyException - (BufferError) when expectations do not correspond with the typepublic boolean isReadonly()
PyBUFisReadonly in interface PyBUFisReadonly in class BaseBufferpublic int getLen()
shape array, and the item size.
The default implementation in BaseBuffer deals with the general one-dimensional
case, with any item size and stride.
SimpleBuffer provides an implementation optimised for contiguous bytes in
one-dimension.
getLen in interface PyBUFgetLen in class BaseBufferpublic byte byteAt(int index)
throws java.lang.IndexOutOfBoundsException
itemsize>1.
SimpleBuffer provides an implementation optimised for contiguous bytes in
one-dimension.
byteAt in interface PyBufferbyteAt in class BaseBufferindex - to retrieve fromjava.lang.IndexOutOfBoundsExceptionpublic int intAt(int index)
throws java.lang.IndexOutOfBoundsException
itemsize>1.
SimpleBuffer provides an implementation optimised for contiguous bytes in
one-dimension.
intAt in interface PyBufferintAt in class BaseBufferindex - to retrieve from=0xff & byteAt(index)java.lang.IndexOutOfBoundsExceptionpublic byte byteAt(int... indices)
throws java.lang.IndexOutOfBoundsException
itemsize>1.
SimpleBuffer provides an implementation optimised for contiguous bytes in
one-dimension.
byteAt in interface PyBufferbyteAt in class BaseBufferindices - specifying location to retrieve fromjava.lang.IndexOutOfBoundsExceptionpublic void copyTo(int srcIndex,
byte[] dest,
int destPos,
int length)
throws java.lang.IndexOutOfBoundsException
length*itemsize bytes will be occupied
in the destination.
The default implementation in BaseBuffer deals with the general one-dimensional
case of arbitrary item size and stride.
SimpleBuffer provides an implementation optimised for contiguous bytes in
one-dimension.
copyTo in interface PyBuffercopyTo in class BaseBuffersrcIndex - starting index in the source bufferdest - destination byte arraydestPos - index in the destination array of the item [0,...]length - number of items to copyjava.lang.IndexOutOfBoundsException - if access out of bounds in source or destinationpublic PyBuffer getBufferSlice(int flags, int start, int length)
PyBufferPyBuffer.getBufferSlice(int, int, int, int) with stride 1.getBufferSlice in interface PyBuffergetBufferSlice in class BaseBufferflags - specifying features demanded and the navigational capabilities of the consumerstart - index in the current bufferlength - number of items in the required slicepublic PyBuffer getBufferSlice(int flags, int start, int length, int stride)
PyBuffer that represents a slice of the current one described in terms of
a start index, number of items to include in the slice, and the stride in the current buffer.
A consumer that obtains a PyBuffer with getBufferSlice must release
it with PyBuffer.release() just as if it had been obtained with
PyBuffer.getBuffer(int)
Suppose that x(i) denotes the ith element of the current buffer, that is, the
byte retrieved by this.byteAt(i) or the unit indicated by
this.getPointer(i). A request for a slice where start = s,
length = N and stride = m, results in a buffer
y such that y(k) = x(s+km) where k=0..(N-1). In Python terms, this is
the slice x[s : s+(N-1)m+1 : m] (if m>0) or the slice x[s : s+(N-1)m-1 : m]
(if m<0). Implementations should check that this range is entirely within the current
buffer.
In a simple buffer backed by a contiguous byte array, the result is a strided PyBuffer on the
same storage but where the offset is adjusted by s and the stride is as supplied. If
the current buffer is already strided and/or has an item size larger than single bytes, the
new start index, length and stride will be translated from the arguments given, through this
buffer's stride and item size. The consumer always expresses start and
strides in terms of the abstract view of this buffer.
SimpleBuffer provides an implementation for slicing contiguous bytes in one
dimension. In that case, x(i) = u(r+i) for i = 0..L-1 where u is the underlying
buffer, and r and L are the start and length with which x was created
from u. Thus y(k) = u(r+s+km), that is, the composite offset is r+s and
the stride is m.
flags - specifying features demanded and the navigational capabilities of the consumerstart - index in the current bufferlength - number of items in the required slicestride - index-distance in the current buffer between consecutive items in the slicepublic PyBuffer.Pointer getPointer(int index) throws java.lang.IndexOutOfBoundsException
PyBufferobj has type BufferProtocol:
int k = ... ; PyBuffer a = obj.getBuffer(); int itemsize = a.getItemsize(); PyBuffer.Pointer b = a.getPointer(k);the item with index
k is in the array b.storage at index
[b.offset] to [b.offset + itemsize - 1] inclusive. And if
itemsize==1, the item is simply the byte b.storage[b.offset]
Essentially this is a method for computing the offset of a particular index. The client is
free to navigate the underlying buffer b.storage without respecting these
boundaries.
getPointer in interface PyBuffergetPointer in class BaseBufferindex - in the buffer to position the pointerjava.lang.IndexOutOfBoundsExceptionpublic PyBuffer.Pointer getPointer(int... indices) throws java.lang.IndexOutOfBoundsException
PyBufferobj
has type BufferProtocol:
int i, j, k; // ... calculation that assigns i, j, k PyBuffer a = obj.getBuffer(); int itemsize = a.getItemsize(); PyBuffer.Pointer b = a.getPointer(i,j,k);the item with index
[i,j,k] is in the array b.storage at index
[b.offset] to [b.offset + itemsize - 1] inclusive. And if
itemsize==1, the item is simply the byte b.storage[b.offset]
Essentially this is a method for computing the offset of a particular index. The client is
free to navigate the underlying buffer b.storage without respecting these
boundaries.
If the buffer is also non-contiguous, b.storage[b.offset] is still the (first
byte of) the item at index [0,...,0]. However, it is necessary to navigate b
using the shape, strides and sub-offsets provided by the API.
getPointer in interface PyBuffergetPointer in class BaseBufferindices - multidimensional index at which to position the pointerjava.lang.IndexOutOfBoundsExceptionpublic java.lang.String toString()
BaseBufferString.toString in interface PyBuffertoString in class BaseBuffer