public abstract class BaseNIOBuffer extends Base1DBuffer
java.nio.ByteBuffer
. The description of BaseBuffer
mostly applies. Methods
provided or overridden here are appropriate to 1-dimensional arrays, of any item size, backed by
a ByteBuffer
.PyBuffer.Pointer
ANY_CONTIGUOUS, AS_ARRAY, 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
Modifier and Type | Method and Description |
---|---|
int |
byteIndex(int... indices)
Convert a multi-dimensional item index to an absolute byte index in the storage shared by the
exporter.
|
void |
copyFrom(byte[] src,
int srcPos,
int destIndex,
int count)
Copy from a slice of a (Java) byte array into the buffer starting at a given destination
item-index.
|
void |
copyTo(ByteBuffer dest)
Copy all items in this buffer into a
ByteBuffer , starting at its current
position. |
void |
copyTo(int srcIndex,
byte[] dest,
int destPos,
int count)
Copy a simple slice of the buffer-view to the destination byte array, defined by a starting
item-index in the source buffer and the
count of items to copy. |
PyBuffer.Pointer |
getBuf()
Return a structure describing the slice of a byte array that holds the data being exported to
the consumer.
|
getLen, isContiguous
byteAt, byteAt, byteIndex, close, copyFrom, copyTo, getBuffer, getBufferAgain, getBufferSlice, getFormat, getItemsize, getNdim, getNIOByteBuffer, getObj, getPointer, getPointer, getShape, getStrides, getSuboffsets, hasArray, intAt, intAt, isReadonly, isReleased, release, storeAt, storeAt, toString
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
getBufferSlice
public int byteIndex(int... indices) throws IndexOutOfBoundsException
PyBuffer
PyBuffer
is a linearly-indexed sequence of
bytes, although it may not actually be a heap-allocated Java byte[]
object. The
purpose of this method is to allow the exporter to define the relationship between the item
index (as used in PyBuffer.byteAt(int...)
and the byte-index (as used with the
ByteBuffer
returned by PyBuffer.getNIOByteBuffer()
).byteIndex
in interface PyBuffer
byteIndex
in class BaseBuffer
indices
- n-dimensional item-index from consumerIndexOutOfBoundsException
public void copyTo(int srcIndex, byte[] dest, int destPos, int count) throws IndexOutOfBoundsException
count
of items to copy. This may validly
be done only for a one-dimensional buffer, as the meaning of the starting item-index is
otherwise not defined. count*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, but is unable to optimise access to sequential bytes.
The default implementation in BaseNIOBuffer
deals with the general
one-dimensional case of arbitrary item size and stride.
copyTo
in interface PyBuffer
copyTo
in class BaseBuffer
srcIndex
- starting item-index in the source bufferdest
- destination byte arraydestPos
- byte-index in the destination array of the source item [0,...]count
- number of items to copyIndexOutOfBoundsException
- if access out of bounds in source or destinationpublic void copyTo(ByteBuffer dest) throws BufferOverflowException, ReadOnlyBufferException
ByteBuffer
, starting at its current
position.dest
- destination bufferBufferOverflowException
ReadOnlyBufferException
public void copyFrom(byte[] src, int srcPos, int destIndex, int count) throws IndexOutOfBoundsException, PyException
count*itemsize
bytes will be read
from the source.
The default implementation in BaseBuffer
deals with the general one-dimensional
case of arbitrary item size and stride, but is unable to optimise access to sequential bytes.
The default implementation in BaseNIOBuffer
deals with the general
one-dimensional case of arbitrary item size and stride.
copyFrom
in interface PyBuffer
copyFrom
in class BaseBuffer
src
- source byte arraysrcPos
- location in source of first byte to copydestIndex
- starting item-index in the destination (i.e. this
)count
- number of items to copy inIndexOutOfBoundsException
- if access out of bounds in source or destinationPyException
- (TypeError) if read-only bufferpublic PyBuffer.Pointer getBuf()
PyBuffer
obj
has type BufferProtocol
:
PyBuffer a = obj.getBuffer(PyBUF.SIMPLE); int itemsize = a.getItemsize(); PyBuffer.Pointer b = a.getBuf();the item with index
k
is in the array b.storage
at index
[b.offset + k*itemsize]
to [b.offset + (k+1)*itemsize - 1]
inclusive. And if itemsize==1
, the item is simply the byte
b.storage[b.offset + k]
If the buffer is multidimensional or non-contiguous, storage[offset]
is still
the (first byte of) the item at index [0] or [0,...,0]. However, it is necessary to navigate
b.storage
using the shape
, strides
and maybe
suboffsets
provided by the API.
getBuf
in interface PyBuffer
getBuf
in class BaseBuffer