public class SimpleWritableBuffer extends SimpleBuffer
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
Constructor and Description |
---|
SimpleWritableBuffer(int flags,
byte[] storage)
Provide an instance of
SimpleWritableBuffer , 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. |
SimpleWritableBuffer(int flags,
byte[] storage,
int index0,
int size)
Provide an instance of
SimpleWritableBuffer , 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 |
---|---|
void |
copyFrom(byte[] src,
int srcPos,
int destIndex,
int length)
Copy bytes from a slice of a (Java) byte array into the buffer.
|
void |
copyFrom(PyBuffer src)
Copy the whole of another PyBuffer into this 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. |
boolean |
isReadonly()
Determine whether the consumer is entitled to write to the exported storage.
|
void |
storeAt(byte value,
int... indices)
Store the given byte at the indexed location in of an N-dimensional buffer with item size
one.
|
void |
storeAt(byte value,
int index)
Store the given byte at the indexed location in of a one-dimensional buffer with item size
one.
|
byteAt, byteAt, copyTo, getLen, getNIOByteBuffer, getPointer, getPointer, intAt, toString
close, copyTo, getBuf, getBuffer, getBufferAgain, getFormat, getItemsize, getNdim, getShape, getStrides, getSuboffsets, hasArray, intAt, isContiguous, isReleased, release
public SimpleWritableBuffer(int flags, byte[] storage, int index0, int size) throws PyException, NullPointerException
SimpleWritableBuffer
, 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 occupiedPyException
- (BufferError) when expectations do not correspond with the typeNullPointerException
public SimpleWritableBuffer(int flags, byte[] storage) throws PyException, NullPointerException
SimpleWritableBuffer
, 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 objectPyException
- (BufferError) when expectations do not correspond with the typeNullPointerException
public boolean isReadonly()
PyBUF
isReadonly
in interface PyBUF
isReadonly
in class SimpleBuffer
public void storeAt(byte value, int index)
itemsize>1
.
SimpleBuffer
provides an implementation optimised for contiguous bytes in
one-dimension.
storeAt
in interface PyBuffer
storeAt
in class BaseBuffer
value
- to storeindex
- to locationpublic void storeAt(byte value, int... indices)
itemsize>1
.
SimpleBuffer
provides an implementation optimised for contiguous bytes in
one-dimension.
storeAt
in interface PyBuffer
storeAt
in class BaseBuffer
value
- to storeindices
- specifying location to store atpublic void copyFrom(byte[] src, int srcPos, int destIndex, int length)
length*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.
SimpleBuffer
provides an implementation optimised for contiguous bytes in
one-dimension.
copyFrom
in interface PyBuffer
copyFrom
in class BaseBuffer
src
- source byte arraysrcPos
- location in source of first byte to copydestIndex
- starting index in the destination (i.e. this
)length
- number of bytes to copy inpublic void copyFrom(PyBuffer src) throws IndexOutOfBoundsException, PyException
The default implementation in BaseBuffer
deals with the general one-dimensional
case.
SimpleBuffer
provides an implementation optimised for contiguous bytes in
one-dimension.
copyFrom
in interface PyBuffer
copyFrom
in class BaseBuffer
src
- source bufferIndexOutOfBoundsException
- if access out of bounds in source or destinationPyException
- (TypeError) if read-only bufferpublic PyBuffer getBufferSlice(int flags, int start, int length)
PyBuffer.getBufferSlice(int, int, int, int)
with stride 1.
SimpleWritableBuffer
provides an implementation ensuring the returned slice is
writable.
getBufferSlice
in interface PyBuffer
getBufferSlice
in class SimpleBuffer
flags
- 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 caller 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.
SimpleWritableBuffer
provides an implementation ensuring the returned slice is
writable.
getBufferSlice
in interface PyBuffer
getBufferSlice
in class SimpleBuffer
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 slice