mir.ndslice.connect.cpython
Jump to: bufferinfo · fromPythonBuffer · Py_buffer · PyBuf_any_contiguous · PyBuf_c_contiguous · PyBuf_contig · PyBuf_contig_ro · PyBuf_f_contiguous · PyBuf_format · PyBuf_indirect · PyBuf_max_ndim · PyBuf_nd · PyBuf_records · PyBuf_records_ro · PyBuf_simple · PyBuf_strided · PyBuf_strided_ro · PyBuf_strides · PyBuf_writable · PyBuf_writeable · PythonBufferErrorCode · pythonBufferFlags · pythonBufferFormat · toPythonBuffer
- enum int
pythonBufferFlags
(SliceKind kind, T); - Construct flags for PyObject_GetBuffer(). If T is not const or immutable then the flags require writable buffer. If slice kind is Contiguous then the flags require c_contiguous buffer.Parameters:
kind slice kind T record type Returns:flags for Py_buffer request. - nothrow @nogc @trusted PythonBufferErrorCode
fromPythonBuffer
(T, size_t N, SliceKind kind)(ref Slice!(T*, N, kind)slice
, ref const Py_bufferview
)
if (N <= PyBuf_max_ndim); - Fills the slice (structure) from the python
view
. The view should be created by PyObject_GetBuffer() that was called with pythonBufferFlags.Parameters:Slice!(T*, N, kind) slice
output ndslice Py_buffer view
Py_buffer requested Returns:Examples:import mir.ndslice.slice: Slice; auto bar(ref const Py_buffer view) { Slice!(const(double)*, 2) mat; if (auto error = mat.fromPythonBuffer(view)) { // has null pointer } return mat; }
- nothrow @nogc @trusted PythonBufferErrorCode
toPythonBuffer
(T, size_t N, SliceKind kind)(Slice!(T*, N, kind)slice
, ref Py_bufferview
, intflags
, ref Structure!NstructureBuffer
)
if (N <= PyBuf_max_ndim); - Fills the python view (structure) from the slice.Parameters:
Slice!(T*, N, kind) slice
input ndslice Py_buffer view
output Py_buffer. Py_buffer.internal is initialized with null value, Py_buffer.obj is not initialized. Other Py_buffer fields are initialized according to the flags and slice. int flags
requester flags Structure!N structureBuffer
Single chunk of memory with the same alignment and size as Structure . The buffer is used to store shape and strides for the view. Returns:Examples:import mir.ndslice.slice : Slice, Structure, Universal, Contiguous, SliceKind; Py_buffer bar(SliceKind kind)(Slice!(double*, 2, kind) slice) { import core.stdc.stdlib; enum N = 2; auto structurePtr = cast(Structure!N*) Structure!N.sizeof.malloc; if (!structurePtr) assert(0); Py_buffer view; if (auto error = slice.toPythonBuffer(view, PyBuf_records_ro, *structurePtr)) { view = view.init; // null buffer structurePtr.free; } else { assert(cast(sizediff_t*)&structurePtr.lengths == view.shape); assert(cast(sizediff_t*)&structurePtr.strides == view.strides); } return view; } alias barUni = bar!Universal; alias barCon = bar!Contiguous;
- Python Buffer structure.
- enum
Jump to: cannot_create_a_buffer_without_strides · cannot_create_any_contiguous_buffer · cannot_create_c_contiguous_buffer · cannot_create_f_contiguous_buffer · cannot_create_format_string · cannot_create_writable_buffer · input_buffer_format_mismatch · input_buffer_itemsize_mismatch · input_buffer_ndim_mismatch · input_buffer_strides_mismatch · success
PythonBufferErrorCode
: int; - Error codes for ndslice - Py_buffer conversion.
success
cannot_create_format_string
cannot_create_writable_buffer
cannot_create_f_contiguous_buffer
cannot_create_c_contiguous_buffer
cannot_create_any_contiguous_buffer
cannot_create_a_buffer_without_strides
input_buffer_ndim_mismatch
input_buffer_itemsize_mismatch
input_buffer_format_mismatch
input_buffer_strides_mismatch
- enum int
PyBuf_max_ndim
; - enum int
PyBuf_simple
; - enum int
PyBuf_writable
; - enum int
PyBuf_writeable
; - enum int
PyBuf_format
; - enum int
PyBuf_nd
; - enum int
PyBuf_strides
; - enum int
PyBuf_c_contiguous
; - enum int
PyBuf_f_contiguous
; - enum int
PyBuf_any_contiguous
; - enum int
PyBuf_indirect
; - enum int
PyBuf_contig
; - enum int
PyBuf_contig_ro
; - enum int
PyBuf_strided
; - enum int
PyBuf_strided_ro
; - enum int
PyBuf_records
; - enum int
PyBuf_records_ro
; - template
pythonBufferFormat
(T)