Top Description Fields Methods
org.python.core

public Interface PyBUF

Known Direct Subinterfaces
org.python.core.PyBuffer

This interface provides a base for the key interface of the buffer API, PyBuffer, including symbolic constants used by the consumer of a PyBuffer to specify its requirements and assumptions. The Jython buffer API emulates the CPython buffer API. There are two reasons for separating parts of PyBuffer into this interface: It is unlikely any classes would implement PyBUF, except indirectly through other interfaces. Users of the Jython buffer API can mostly overlook the distinction and just use PyBuffer.

Field Summary

Modifier and TypeField and Description
public static final int
ANY_CONTIGUOUS

A constant used by the consumer in its call to BufferProtocol#getBuffer(int) to specify that it will assume a contiguous organisation of the items, but will enquire which organisation it actually is.

public static final int
AS_ARRAY

A constant used by the consumer in its call to BufferProtocol#getBuffer(int) to specify that it expects to access the buffer contents directly as an array (rather than through the purely abstract part of the API).

public static final int
C_CONTIGUOUS

A constant used by the consumer in its call to BufferProtocol#getBuffer(int) to specify that it will assume C-order organisation of the items.

public static final int
CONTIG

Equivalent to (ND | WRITABLE)

public static final int
CONTIG_RO

Equivalent to ND

public static final int
CONTIGUITY

Field mask, used as in if ((flags&CONTIGUITY;)== ...

public static final int
F_CONTIGUOUS

A constant used by the consumer in its call to BufferProtocol#getBuffer(int) to specify that it will assume Fortran-order organisation of the items.

public static final int
FORMAT

A constant used by the consumer in its call to BufferProtocol#getBuffer(int) to specify that it requires PyBuffer#getFormat() to return a String indicating the type of the unit.

public static final int
FULL

Equivalent to (INDIRECT | WRITABLE | FORMAT).

public static final int
FULL_RO

Equivalent to (INDIRECT | FORMAT).

public static final int
INDIRECT

A constant used by the consumer in its call to BufferProtocol#getBuffer(int) to specify that it understands the suboffsets array.

public static final int
IS_C_CONTIGUOUS

A constant used by the exporter in processing BufferProtocol#getBuffer(int) to check for assumed C-order organisation of the items.

public static final int
IS_F_CONTIGUOUS

A constant used by the exporter in processing BufferProtocol#getBuffer(int) to check for assumed C-order Fortran-order organisation of the items.

public static final int
MAX_NDIM

The maximum allowed number of dimensions (CPython restriction).

public static final int
ND

A constant used by the consumer in its call to BufferProtocol#getBuffer(int) to specify that it is prepared to navigate the buffer as multi-dimensional using the shape array.

public static final int
RECORDS

Equivalent to (STRIDES | WRITABLE | FORMAT)

public static final int
RECORDS_RO

Equivalent to (STRIDES | FORMAT)

public static final int
SIMPLE

A constant used by the consumer in its call to BufferProtocol#getBuffer(int) to specify that it assumes a simple one-dimensional organisation of the exported storage with item size of one.

public static final int
STRIDED

Equivalent to (STRIDES | WRITABLE)

public static final int
STRIDED_RO

Equivalent to STRIDES

public static final int
STRIDES

A constant used by the consumer in its call to BufferProtocol#getBuffer(int) to specify that it expects to use the strides array.

public static final int
WRITABLE

A constant used by the consumer in its call to BufferProtocol#getBuffer(int) to specify that it expects to write to the buffer contents.

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

the number of bytes comprising each item.
getItemsize
()

The number of bytes stored in each indexable item.

public int

Returns:

the total number of bytes represented.
getLen
()

The total number of bytes represented by the view, which will be the product of the elements of the shape array, and the item size in bytes.

public int

Returns:

number of dimensions
getNdim
()

The number of dimensions to the buffer.

public int[]

Returns:

the dimensions of the buffer as an array
getShape
()

An array reporting the size of the buffer, considered as a multidimensional array, in each dimension and (by its length) giving the number of dimensions.

public int[]

Returns:

the distance in the storage array between adjacent items (in each dimension)
getStrides
()

The strides array gives the distance in the storage array between adjacent items (in each dimension).

public int[]

Returns:

suboffsets array or null if not necessary for navigation
getSuboffsets
()

The suboffsets array is a further part of the support for interpreting the buffer as an n-dimensional array of items, where the array potentially uses indirect addressing (like a real Java array of arrays, in fact).

public boolean

Returns:

true iff the array is stored contiguously in the order specified
isContiguous
(char
'C', 'F' or 'A', as the storage order is C, Fortran or either.
order
)

Enquire whether the array is represented contiguously in the backing storage, according to C or Fortran ordering.

public boolean

Returns:

true if writing is not allowed, false if it is.
isReadonly
()

Determine whether the consumer is entitled to write to the exported storage.

Field Detail

ANY_CONTIGUOUSback to summary
public static final int ANY_CONTIGUOUS

A constant used by the consumer in its call to BufferProtocol#getBuffer(int) to specify that it will assume a contiguous organisation of the items, but will enquire which organisation it actually is. getBuffer will raise an exception if the exporter's buffer is not contiguous. ANY_CONTIGUOUS implies STRIDES.

AS_ARRAYback to summary
public static final int AS_ARRAY

A constant used by the consumer in its call to BufferProtocol#getBuffer(int) to specify that it expects to access the buffer contents directly as an array (rather than through the purely abstract part of the API). getBuffer will raise an exception if the exporter cannot expose its storage as Java array.

C_CONTIGUOUSback to summary
public static final int C_CONTIGUOUS

A constant used by the consumer in its call to BufferProtocol#getBuffer(int) to specify that it will assume C-order organisation of the items. getBuffer will raise an exception if the exporter's buffer is not C-ordered. C_CONTIGUOUS implies STRIDES.

CONTIGback to summary
public static final int CONTIG

Equivalent to (ND | WRITABLE)

CONTIG_ROback to summary
public static final int CONTIG_RO

Equivalent to ND

CONTIGUITYback to summary
public static final int CONTIGUITY

Field mask, used as in if ((flags&CONTIGUITY)== ... ) ....

F_CONTIGUOUSback to summary
public static final int F_CONTIGUOUS

A constant used by the consumer in its call to BufferProtocol#getBuffer(int) to specify that it will assume Fortran-order organisation of the items. getBuffer will raise an exception if the exporter's buffer is not Fortran-ordered. F_CONTIGUOUS implies STRIDES.

FORMATback to summary
public static final int FORMAT

A constant used by the consumer in its call to BufferProtocol#getBuffer(int) to specify that it requires PyBuffer#getFormat() to return a String indicating the type of the unit. This exists for compatibility with CPython, as in Jython the format is always provided by getFormat().

FULLback to summary
public static final int FULL

Equivalent to (INDIRECT | WRITABLE | FORMAT). Also use this in the request if you plan only to use the fully-encapsulated API (byteAt, storeAt, copyTo, copyFrom, etc.), without ever calling PyBuffer#getNIOByteBuffer() or using PyBuffer.Pointer.

FULL_ROback to summary
public static final int FULL_RO

Equivalent to (INDIRECT | FORMAT). Also use this in the request if you plan only to use the fully-encapsulated API (byteAt, copyTo, etc.), read only, without ever calling PyBuffer#getNIOByteBuffer() or using PyBuffer.Pointer.

INDIRECTback to summary
public static final int INDIRECT

A constant used by the consumer in its call to BufferProtocol#getBuffer(int) to specify that it understands the suboffsets array. getBuffer will raise an exception if consumer does not specify the flag but the exporter's buffer cannot be navigated without understanding the suboffsets array. INDIRECT implies STRIDES.

IS_C_CONTIGUOUSback to summary
public static final int IS_C_CONTIGUOUS

A constant used by the exporter in processing BufferProtocol#getBuffer(int) to check for assumed C-order organisation of the items. C_CONTIGUOUS = IS_C_CONTIGUOUS | STRIDES.

IS_F_CONTIGUOUSback to summary
public static final int IS_F_CONTIGUOUS

A constant used by the exporter in processing BufferProtocol#getBuffer(int) to check for assumed C-order Fortran-order organisation of the items. F_CONTIGUOUS = IS_F_CONTIGUOUS | STRIDES.

MAX_NDIMback to summary
public static final int MAX_NDIM

The maximum allowed number of dimensions (CPython restriction).

NDback to summary
public static final int ND

A constant used by the consumer in its call to BufferProtocol#getBuffer(int) to specify that it is prepared to navigate the buffer as multi-dimensional using the shape array. getBuffer will raise an exception if consumer does not specify the flag but the exporter's buffer cannot be navigated without taking into account its multiple dimensions.

RECORDSback to summary
public static final int RECORDS

Equivalent to (STRIDES | WRITABLE | FORMAT)

RECORDS_ROback to summary
public static final int RECORDS_RO

Equivalent to (STRIDES | FORMAT)

SIMPLEback to summary
public static final int SIMPLE

A constant used by the consumer in its call to BufferProtocol#getBuffer(int) to specify that it assumes a simple one-dimensional organisation of the exported storage with item size of one. getBuffer will raise an exception if the consumer sets this flag and the exporter cannot represent itself as byte array data.

STRIDEDback to summary
public static final int STRIDED

Equivalent to (STRIDES | WRITABLE)

STRIDED_ROback to summary
public static final int STRIDED_RO

Equivalent to STRIDES

STRIDESback to summary
public static final int STRIDES

A constant used by the consumer in its call to BufferProtocol#getBuffer(int) to specify that it expects to use the strides array. getBuffer will raise an exception if consumer does not specify the flag but the exporter's buffer cannot be navigated without using the strides array.

WRITABLEback to summary
public static final int WRITABLE

A constant used by the consumer in its call to BufferProtocol#getBuffer(int) to specify that it expects to write to the buffer contents. getBuffer will raise an exception if the exporter's buffer cannot meet this requirement.

Method Detail

getItemsizeback to summary
public int getItemsize()

The number of bytes stored in each indexable item.

Returns:int

the number of bytes comprising each item.

getLenback to summary
public int getLen()

The total number of bytes represented by the view, which will be the product of the elements of the shape array, and the item size in bytes.

Returns:int

the total number of bytes represented.

getNdimback to summary
public int getNdim()

The number of dimensions to the buffer. This number is the length of the shape array. The actual storage may be a linear array, but this is the number of dimensions in the interpretation that the exporting object gives the data.

Returns:int

number of dimensions

getShapeback to summary
public int[] getShape()

An array reporting the size of the buffer, considered as a multidimensional array, in each dimension and (by its length) giving the number of dimensions. The size of the buffer is its size in "items". An item is the amount of buffer content addressed by one index or set of indices. In the simplest case an item is a single unit (byte), and there is one dimension. In complex cases, the array is multi-dimensional, and the item at each location is multi-unit (multi-byte). The consumer must not modify this array. A valid shape array is always returned (difference from CPython).

Returns:int[]

the dimensions of the buffer as an array

getStridesback to summary
public int[] getStrides()

The strides array gives the distance in the storage array between adjacent items (in each dimension). In the rawest parts of the buffer API, the consumer of the buffer is able to navigate the exported storage. The "strides" array is part of the support for interpreting the buffer as an n-dimensional array of items. It provides the coefficients of the "addressing polynomial". (More on this in the CPython documentation.) The consumer must not modify this array. A valid strides array is always returned (difference from CPython).

Returns:int[]

the distance in the storage array between adjacent items (in each dimension)

getSuboffsetsback to summary
public int[] getSuboffsets()

The suboffsets array is a further part of the support for interpreting the buffer as an n-dimensional array of items, where the array potentially uses indirect addressing (like a real Java array of arrays, in fact). This is only applicable when there is more than 1 dimension, and it works in conjunction with the strides array. (More on this in the CPython documentation.) When used, suboffsets[k] is an integer index, not a byte offset as in CPython. The consumer must not modify this array. When not needed for navigation null is returned (as in CPython).

Returns:int[]

suboffsets array or null if not necessary for navigation

isContiguousback to summary
public boolean isContiguous(char order)

Enquire whether the array is represented contiguously in the backing storage, according to C or Fortran ordering. A one-dimensional contiguous array is both.

Parameters
order:char

'C', 'F' or 'A', as the storage order is C, Fortran or either.

Returns:boolean

true iff the array is stored contiguously in the order specified

isReadonlyback to summary
public boolean isReadonly()

Determine whether the consumer is entitled to write to the exported storage.

Returns:boolean

true if writing is not allowed, false if it is.