Class BaseArrayBuffer
- All Implemented Interfaces:
AutoCloseable,BufferProtocol,PyBUF,PyBuffer
- Direct Known Subclasses:
SimpleBuffer,Strided1DBuffer,ZeroByteBuffer
byte[].
The description of BaseBuffer mostly applies. Methods provided or overridden here are
appropriate to 1-dimensional arrays, of any item size, backed by byte[].-
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 -
Method Summary
Modifier and TypeMethodDescriptionintbyteIndex(int... indices) Convert a multi-dimensional item index to an absolute byte index in the storage shared by the exporter.voidcopyFrom(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.voidCopy the whole of anotherPyBufferinto this buffer.voidcopyTo(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 thecountof items to copy.getBuf()Return a structure describing the slice of a byte array that holds the data being exported to the consumer.Methods inherited from class org.python.core.buffer.Base1DBuffer
getLen, isContiguousMethods inherited from class org.python.core.buffer.BaseBuffer
byteAt, byteAt, byteIndex, close, copyTo, getBuffer, getBufferAgain, getBufferSlice, getFormat, getItemsize, getNdim, getNIOByteBuffer, getObj, getPointer, getPointer, getShape, getStrides, getSuboffsets, hasArray, intAt, intAt, isReadonly, isReleased, release, storeAt, storeAt, toStringMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.python.core.PyBuffer
getBufferSlice
-
Method Details
-
byteIndex
Description copied from interface:PyBufferConvert a multi-dimensional item index to an absolute byte index in the storage shared by the exporter. The storage exported as aPyBufferis a linearly-indexed sequence of bytes, although it may not actually be a heap-allocated Javabyte[]object. The purpose of this method is to allow the exporter to define the relationship between the item index (as used inPyBuffer.byteAt(int...)and the byte-index (as used with theByteBufferreturned byPyBuffer.getNIOByteBuffer()).- Specified by:
byteIndexin interfacePyBuffer- Overrides:
byteIndexin classBaseBuffer- Parameters:
indices- n-dimensional item-index from consumer- Returns:
- corresponding byte-index in actual storage
- Throws:
IndexOutOfBoundsException
-
copyTo
public void copyTo(int srcIndex, byte[] dest, int destPos, int count) throws IndexOutOfBoundsException Copy a simple slice of the buffer-view to the destination byte array, defined by a starting item-index in the source buffer and thecountof 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*itemsizebytes will be occupied in the destination.The default implementation in
BaseBufferdeals with the general one-dimensional case of arbitrary item size and stride, but is unable to optimise access to sequential bytes.The implementation in
BaseArrayBufferdeals with the general one-dimensional case of arbitrary item size and stride.- Specified by:
copyToin interfacePyBuffer- Overrides:
copyToin classBaseBuffer- Parameters:
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 copy- Throws:
IndexOutOfBoundsException- if access out of bounds in source or destination
-
copyFrom
public void copyFrom(byte[] src, int srcPos, int destIndex, int count) throws IndexOutOfBoundsException, PyException Copy from a slice of a (Java) byte array into the buffer starting at a given destination item-index. This may validly be done only for a one-dimensional buffer, as the meaning of the destination index is not otherwise defined.count*itemsizebytes will be read from the source.The default implementation in
BaseBufferdeals 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
BaseArrayBufferdeals with the general one-dimensional case of arbitrary item size and stride.- Specified by:
copyFromin interfacePyBuffer- Overrides:
copyFromin classBaseBuffer- Parameters:
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 in- Throws:
IndexOutOfBoundsException- if access out of bounds in source or destinationPyException-TypeErrorif read-only buffer
-
copyFrom
Description copied from class:BaseBufferCopy the whole of anotherPyBufferinto this buffer. This may validly be done only for buffers that are consistent in their dimensions. When it is necessary to copy partial buffers, this may be achieved using a buffer slice on the source or destination.The default implementation in
BaseBufferdeals with the general one-dimensional case of arbitrary item size and stride, but is unable to optimise access to sequential bytes.- Specified by:
copyFromin interfacePyBuffer- Overrides:
copyFromin classBaseBuffer- Parameters:
src- source buffer- Throws:
IndexOutOfBoundsException- if access out of bounds in source or destinationPyException-TypeErrorif read-only buffer
-
getBuf
Return a structure describing the slice of a byte array that holds the data being exported to the consumer. For a one-dimensional contiguous buffer, assuming the following client code whereobjhas typeBufferProtocol:PyBuffer a = obj.getBuffer(PyBUF.SIMPLE); int itemsize = a.getItemsize(); PyBuffer.Pointer b = a.getBuf();
the item with indexkis in the arrayb.storageat index[b.offset + k*itemsize]to[b.offset + (k+1)*itemsize - 1]inclusive. And ifitemsize==1, the item is simply the byteb.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 navigateb.storageusing theshape,stridesand maybesuboffsetsprovided by the API.BaseArrayBufferprovides a reference to the storage array even when the buffer is intended not to be writable. There can be no enforcement of read-only character once a reference to the byte array has been handed out.- Specified by:
getBufin interfacePyBuffer- Overrides:
getBufin classBaseBuffer- Returns:
- structure defining the byte[] slice that is the shared data
-