storage, index0 and count
properties in the usual way, designating a slice (or all) of a byte array, but also a
stride property (equal to getStrides()[0]).
Let the underlying buffer be the byte array u(i) for i=0..N-1, let x be the
Strided1DBuffer, and let the stride be p. The storage works as follows.
Designate by x(j), for j=0..L-1, the byte at index j, that is, the byte
retrieved by x.byteAt(j). Thus, we store x(j) at u(a+pj), that is,
x(0) = u(a). When we construct such a buffer, we have to supply a =
index0, L = count, and p = stride as the
constructor arguments. The last item in the slice x(L-1) is stored at u(a+p(L-1)).
For the simple case of positive stride, constructor argument index0 is the low index
of the range occupied by the data. When the stride is negative, that is to say p<0, and
L>1, this will be to the left of u(a), and the constructor argument
index0 is not then the low index of the range occupied by the data. Clearly both
these indexes must be in the range 0 to N-1 inclusive, a rule enforced by the constructors
(unless L=0, when it is assumed no array access will take place).
The class may be used by exporters to create a strided slice (e.g. to export the diagonal of a
matrix) and in particular by other buffers to create strided slices of themselves, such as to
create the memoryview that is returned as an extended slice of a
memoryview.
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static class | Strided1DBuffer.
A |
| Modifier and Type | Field and Description |
|---|---|
| protected int | stride
Step size in the underlying buffer essential to correct translation of an index (or indices) into an index into the storage. |
| Access | Constructor and Description |
|---|---|
| protected | Strided1DBuffer(BufferProtocol
exporting object (or obj, byte[] null)raw byte array containing exported data storage, int index into storage of item[0] index0, int number of items in the slice count, int in between successive elements of the new PyBuffer stride)Provide an instance of |
| public | Strided1DBuffer(int
consumer requirements flags, BufferProtocol exporting object (or obj, byte[] null)raw byte array containing exported data storage, int index into storage of item[0] index0, int number of items in the slice count, int byte-index distance from one element to the next in the new PyBuffer stride)Provide an instance of |
| Modifier and Type | Method and Description |
|---|---|
| public final int | byteIndex(int
item-index from consumer index)Overrides org. Implements org. Convert an item index (for a one-dimensional buffer) to an absolute byte index in the storage shared by the exporter. |
| public PyBuffer | getBufferSlice(int
specifying features demanded and the navigational capabilities of the consumer flags, int index in the current buffer start, int number of items in the required slice count, int index-distance in the current buffer between consecutive items in the slice stride)Implements org. Get a |
| public PyBuffer. | getPointer(int
in the buffer to position the pointer index)Overrides org. Implements org.
References Deprecated
PyBuffer.Pointer is deprecated or references (maybe indirectly) at least one deprecated element.
Return a structure describing the position in a byte array of a single item from the data being exported to the consumer. |
| public PyBuffer. | getPointer(int...
multidimensional index at which to position the pointer indices)Overrides org. Implements org.
References Deprecated
PyBuffer.Pointer is deprecated or references (maybe indirectly) at least one deprecated element.
Return a structure describing the position in a byte array of a single item from the data being exported to the consumer, in the case that array may be multi-dimensional. |
| public boolean | isReadonly()
Overrides org. Implements org. Determine whether the consumer is entitled to write to the exported storage. |
| stride | back to summary |
|---|---|
| protected int stride Step size in the underlying buffer essential to correct translation of an index (or indices)
into an index into the storage. The value is returned by | |
| Strided1DBuffer | back to summary |
|---|---|
| protected Strided1DBuffer(BufferProtocol obj, byte[] storage, int index0, int count, int stride) throws ArrayIndexOutOfBoundsException, NullPointerException Provide an instance of
The sub-class constructor should check that the intended access is compatible with this
object by calling
| |
| Strided1DBuffer | back to summary |
|---|---|
| public Strided1DBuffer(int flags, BufferProtocol obj, byte[] storage, int index0, int count, int stride) throws ArrayIndexOutOfBoundsException, NullPointerException, PyException Provide an instance of
The constructed
| |
| byteIndex | back to summary |
|---|---|
| public final int byteIndex(int index) throws IndexOutOfBoundsException Overrides org. Implements org. Doc from org. Convert an item index (for a one-dimensional buffer) to an absolute byte index in the storage
shared by the exporter. The storage exported as a
| |
| getBufferSlice | back to summary |
|---|---|
| public PyBuffer getBufferSlice(int flags, int start, int count, int stride) Implements org. Doc from org. Get a
Suppose that x(i) denotes the ith element of the current buffer, that is, the
byte retrieved by
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
a buffer representing the slice | |
| getPointer | back to summary |
|---|---|
| public PyBuffer. Overrides org. Implements org. Doc from org. References Deprecated
See corresponding docs for further information. Return a structure describing the position in a byte array of a single item from the data
being exported to the consumer. For a one-dimensional contiguous buffer, assuming the
following client code where int k = ... ; PyBuffer a = obj.getBuffer(PyBUF.FULL); int itemsize = a.getItemsize(); PyBuffer.Pointer b = a.getPointer(k);the item with index k is in the array b.storage at index
[b.offset] to [b.offset + itemsize - 1] inclusive. And if
itemsize==1, the item is simply the byte b.storage[b.offset]
Essentially this is a method for computing the offset of a particular index. The client is
free to navigate the underlying buffer
| |
| getPointer | back to summary |
|---|---|
| public PyBuffer. Overrides org. Implements org. Doc from org. References Deprecated
See corresponding docs for further information. Return a structure describing the position in a byte array of a single item from the data
being exported to the consumer, in the case that array may be multi-dimensional. For a
3-dimensional contiguous buffer, assuming the following client code where int i, j, k; // ... calculation that assigns i, j, k PyBuffer a = obj.getBuffer(PyBUF.FULL); int itemsize = a.getItemsize(); PyBuffer.Pointer b = a.getPointer(i,j,k);the item with index [i,j,k] is in the array b.storage at index
[b.offset] to [b.offset + itemsize - 1] inclusive. And if
itemsize==1, the item is simply the byte b.storage[b.offset]
Essentially this is a method for computing the offset of a particular index. The client is
free to navigate the underlying buffer
| |
| isReadonly | back to summary |
|---|---|
| public boolean isReadonly() Overrides org. Implements org. Doc from org. Determine whether the consumer is entitled to write to the exported storage.
| |
Strided1DBuffer.SlicedView represents a non-contiguous subsequence of a simple
buffer.
| Modifier and Type | Field and Description |
|---|---|
| pack-priv PyBuffer | root
The buffer on which this is a slice view |
| Access | Constructor and Description |
|---|---|
| public | SlicedView(PyBuffer
on which release must be called when this is released root, int consumer requirements flags, byte[] raw byte array containing exported data storage, int index into storage of item[0] index0, int number of items in the sliced view count, int in between successive elements of the new PyBuffer stride)Construct a slice of a one-dimensional byte buffer. |
| Modifier and Type | Method and Description |
|---|---|
| protected PyBuffer | getRoot()
Overrides org. Some |
| root | back to summary |
|---|---|
| pack-priv PyBuffer root The buffer on which this is a slice view | |
| SlicedView | back to summary |
|---|---|
| public SlicedView(PyBuffer root, int flags, byte[] storage, int index0, int count, int stride) throws PyException Construct a slice of a one-dimensional byte buffer.
| |
| getRoot | back to summary |
|---|---|
| protected PyBuffer getRoot() Overrides org. Doc from org. Some | |