Report a bug
		
				If you spot a problem with this page, click here to create a GitHub issue.
		
			Improve this page
		
			Quickly fork, edit online, and submit a pull request for this page.
			Requires a signed-in GitHub account. This works well for small changes.
			If you'd like to make larger changes you may want to consider using
			a local clone.
		
	mir.ndslice.connect.cpython
Utilities for Python Buffer Protocol.
License: 
Authors: 
Ilya Yaroshenko
- enum intpythonBufferFlags(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 PythonBufferErrorCodefromPythonBuffer(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 pythonview. The view should be created by PyObject_GetBuffer() that was called with pythonBufferFlags.Parameters:Slice!(T*, N, kind) sliceoutput ndslice Py_buffer viewPy_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 PythonBufferErrorCodetoPythonBuffer(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) sliceinput ndslice Py_buffer viewoutput 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 flagsrequester flags Structure!N structureBufferSingle 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; 
- structbufferinfo;
 aliasPy_buffer= bufferinfo;
- Python Buffer structure.- void*buf;
- void*obj;
- sizediff_tlen;
- sizediff_titemsize;
- intreadonly;
- intndim;
- char*format;
- sizediff_t*shape;
- sizediff_t*strides;
- sizediff_t*suboffsets;
- void*internal;
 
- enumPythonBufferErrorCode: 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 intPyBuf_max_ndim;
- enum intPyBuf_simple;
- enum intPyBuf_writable;
- enum intPyBuf_writeable;
- enum intPyBuf_format;
- enum intPyBuf_nd;
- enum intPyBuf_strides;
- enum intPyBuf_c_contiguous;
- enum intPyBuf_f_contiguous;
- enum intPyBuf_any_contiguous;
- enum intPyBuf_indirect;
- enum intPyBuf_contig;
- enum intPyBuf_contig_ro;
- enum intPyBuf_strided;
- enum intPyBuf_strided_ro;
- enum intPyBuf_records;
- enum intPyBuf_records_ro;
- templatepythonBufferFormat(T)
Copyright © 2016-2022 by Ilya Yaroshenko | Page generated by
Ddoc on Tue Jan 11 06:37:10 2022