mir-pybuffer 0.1.2
mir-numpy connection example
To use this package, run the following command in your project's root directory:
Manual usage
Put the following dependency into your project's dependences section:
mir-pybuffer
installation
$ pip install pybuffer
$ dub fetch mir-pybuffer
usage
python side. you should wrap numpy contiguous array with pybuffer.to_bytes
.
also see mir.ndslice.connect.cpython.PythonBufferErrorCode for error handling.
import ctypes
import numpy
import pybuffer
lib = ctypes.CDLL("./libmir-bp.so") # dynamic library written in d
x = numpy.array([[0, 1, 2], [3, 4, 5]]).astype(numpy.float64)
y = numpy.array([0, 1, 2]).astype(numpy.float64)
err = lib.pybuffer_func1(pybuffer.to_bytes(x),
pybuffer.to_bytes(y),
ctypes.c_double(1.0))
assert err == 0
d side. currently mir-pybuffer only supports ndslice functions that returns void. see this dub.json for creating dynamic library for python.
import mir.ndslice : Slice, Contiguous;
import pybuffer : pybuffer;
@pybuffer
void func1(Slice!(Contiguous, [2LU], double*) mat, Slice!(Contiguous, [1LU], double*) vec, double a) {
...
}
@pybuffer
will generate a wrapped function as follows:
pragma(mangle, __traits(identifier, pybuffer_func1))
extern(C) auto pybuffer_func1( ref Py_buffera0 , ref Py_buffera1 , double a2 ) {
import mir.ndslice.connect.cpython;
import std.stdio : writeln;
Slice!(Contiguous, [2LU], double*) _a0;
{
auto err = fromPythonBuffer( _a0 , a0 );
if (err != PythonBufferErrorCode.success) { writeln(err); return err; }
}
Slice!(Contiguous, [2LU], double*) _a1;
{
auto err = fromPythonBuffer( _a1 , a1 );
if (err != PythonBufferErrorCode.success) { writeln(err); return err; }
}
func1( _a0 , _a1 , a2 );
return PythonBufferErrorCode.success;
}
- Registered by shigeki karita
- 0.1.2 released 6 years ago
- ShigekiKarita/mir-pybuffer
- proprietary
- Copyright © 2018, karita
- Authors:
- Dependencies:
- mir-algorithm
- Versions:
-
0.2.0 2018-Sep-10 0.1.7 2018-Apr-05 0.1.6 2018-Apr-03 0.1.5 2018-Apr-03 0.1.4 2018-Apr-02 - Download Stats:
-
-
0 downloads today
-
0 downloads this week
-
0 downloads this month
-
20 downloads total
-
- Score:
- 0.9
- Short URL:
- mir-pybuffer.dub.pm