public class Strided1DWritableBuffer extends Strided1DBuffer
Strided1DBuffer
of which this is
an extension providing write operations and a writable slice.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 |
---|
Strided1DWritableBuffer(int flags,
BufferProtocol obj,
byte[] storage,
int index0,
int count,
int stride)
Provide an instance of
Strided1DWritableBuffer on a particular array of bytes
specifying a starting index, the number of items in the result, and a byte-indexing stride. |
Modifier and Type | Method and Description |
---|---|
PyBuffer |
getBufferSlice(int flags,
int start,
int count,
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.
|
byteIndex, getPointer, getPointer
byteIndex, copyFrom, copyFrom, copyTo, getBuf
getLen, isContiguous
byteAt, byteAt, close, copyTo, getBuffer, getBufferAgain, getBufferSlice, getFormat, getItemsize, getNdim, getNIOByteBuffer, getObj, getShape, getStrides, getSuboffsets, hasArray, intAt, intAt, isReleased, release, storeAt, storeAt, toString
public Strided1DWritableBuffer(int flags, BufferProtocol obj, byte[] storage, int index0, int count, int stride) throws ArrayIndexOutOfBoundsException, NullPointerException, PyException
Strided1DWritableBuffer
on a particular array of bytes
specifying a starting index, the number of items in the result, and a byte-indexing stride.
The result of byteAt(i)
will be equal to storage[index0+stride*i]
(whatever the sign of stride>0
), valid for 0<=i<count
.
The constructed PyBuffer
meets the consumer's expectations as expressed in the
flags
argument, or an exception will be thrown if these are incompatible with
the type (e.g. the consumer does not specify that it understands the strides array). Note
that the actual range in the storage
array, the lowest and highest index, is not
explicitly passed, but is implicit in index0
, count
and
stride
. The caller is responsible for checking these fall within the array, or
the sub-range the caller is allowed to use.
flags
- consumer requirementsobj
- exporting object (or null
)storage
- raw byte array containing exported dataindex0
- index into storage of item[0]count
- number of items in the slicestride
- byte-index distance from one element to the next in the new PyBufferNullPointerException
- if storage
is nullArrayIndexOutOfBoundsException
- if index0
, count
and
stride
are inconsistent with storage.length
PyException
- (BufferError) when expectations do not correspond with the typepublic final boolean isReadonly()
Declared final
returning true
in
Strided1DWritableBuffer
to make checks unnecessary.
isReadonly
in interface PyBUF
isReadonly
in class Strided1DBuffer
public PyBuffer getBufferSlice(int flags, int start, int count, 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,
count
= 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, count
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.
Strided1DBuffer
provides an implementation for slicing already-strided bytes in
one dimension. In that case, x(i) = u(r+ip) for i = 0..L-1 where u is the
underlying buffer, and r, p and L are the start, stride and count with
which x was created from u. Thus y(k) = u(r+sp+kmp), that is, the
composite index0
is r+sp and the composite stride
is
mp.
Strided1DWritableBuffer
provides an implementation that returns a writable
slice.
getBufferSlice
in interface PyBuffer
getBufferSlice
in class Strided1DBuffer
flags
- specifying features demanded and the navigational capabilities of the consumerstart
- index in the current buffercount
- number of items in the required slicestride
- index-distance in the current buffer between consecutive items in the slice