Class Strided1DWritableBuffer
- java.lang.Object
-
- org.python.core.buffer.BaseBuffer
-
- org.python.core.buffer.Base1DBuffer
-
- org.python.core.buffer.BaseArrayBuffer
-
- org.python.core.buffer.Strided1DBuffer
-
- org.python.core.buffer.Strided1DWritableBuffer
-
- All Implemented Interfaces:
java.lang.AutoCloseable,BufferProtocol,PyBUF,PyBuffer
public class Strided1DWritableBuffer extends Strided1DBuffer
Read-write buffer API over a one-dimensional array of one-byte items, that are evenly-spaced in a storage array. The storage conventions are described inStrided1DBufferof which this is an extension providing write operations and a writable slice.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.python.core.PyBuffer
PyBuffer.Pointer
-
-
Field Summary
-
Fields inherited from interface org.python.core.PyBUF
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 Summary
Constructors Constructor Description Strided1DWritableBuffer(int flags, BufferProtocol obj, byte[] storage, int index0, int count, int stride)Provide an instance ofStrided1DWritableBufferon a particular array of bytes specifying a starting index, the number of items in the result, and a byte-indexing stride.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description PyBuffergetBufferSlice(int flags, int start, int count, int stride)Get aPyBufferthat 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.booleanisReadonly()Determine whether the consumer is entitled to write to the exported storage.-
Methods inherited from class org.python.core.buffer.Strided1DBuffer
byteIndex, getPointer, getPointer
-
Methods inherited from class org.python.core.buffer.BaseArrayBuffer
byteIndex, copyFrom, copyFrom, copyTo, getBuf
-
Methods inherited from class org.python.core.buffer.Base1DBuffer
getLen, isContiguous
-
Methods inherited from class org.python.core.buffer.BaseBuffer
byteAt, byteAt, close, copyTo, getBuffer, getBufferAgain, getBufferSlice, getFormat, getItemsize, getNdim, getNIOByteBuffer, getObj, getShape, getStrides, getSuboffsets, hasArray, intAt, intAt, isReleased, release, storeAt, storeAt, toString
-
-
-
-
Constructor Detail
-
Strided1DWritableBuffer
public Strided1DWritableBuffer(int flags, BufferProtocol obj, byte[] storage, int index0, int count, int stride) throws java.lang.ArrayIndexOutOfBoundsException, java.lang.NullPointerException, PyExceptionProvide an instance ofStrided1DWritableBufferon a particular array of bytes specifying a starting index, the number of items in the result, and a byte-indexing stride. The result ofbyteAt(i)will be equal tostorage[index0+stride*i](whatever the sign ofstride>0), valid for0<=i<count.The constructed
PyBuffermeets the consumer's expectations as expressed in theflagsargument, 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 thestoragearray, the lowest and highest index, is not explicitly passed, but is implicit inindex0,countandstride. The caller is responsible for checking these fall within the array, or the sub-range the caller is allowed to use.- Parameters:
flags- consumer requirementsobj- exporting object (ornull)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 PyBuffer- Throws:
java.lang.NullPointerException- ifstorageis nulljava.lang.ArrayIndexOutOfBoundsException- ifindex0,countandstrideare inconsistent withstorage.lengthPyException- (BufferError) when expectations do not correspond with the type
-
-
Method Detail
-
isReadonly
public final boolean isReadonly()
Determine whether the consumer is entitled to write to the exported storage.Declared
finalreturningtrueinStrided1DWritableBufferto make checks unnecessary.- Specified by:
isReadonlyin interfacePyBUF- Overrides:
isReadonlyin classStrided1DBuffer- Returns:
- true if writing is not allowed, false if it is.
-
getBufferSlice
public PyBuffer getBufferSlice(int flags, int start, int count, int stride)
Get aPyBufferthat 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 aPyBufferwithgetBufferSlicemust release it withPyBuffer.release()just as if it had been obtained withPyBuffer.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 bythis.getPointer(i). A request for a slice wherestart= s,count= N andstride= 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
startindex,countandstridewill be translated from the arguments given, through this buffer's stride and item size. The caller always expressesstartandstridesin terms of the abstract view of this buffer.Strided1DBufferprovides 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 compositeindex0is r+sp and the compositestrideis mp.Strided1DWritableBufferprovides an implementation that returns a writable slice.- Specified by:
getBufferSlicein interfacePyBuffer- Overrides:
getBufferSlicein classStrided1DBuffer- Parameters:
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- Returns:
- a buffer representing the slice
-
-