rust-numpy

Build Status Crate docs.rs

Rust binding of NumPy C-API

Dependencies

and more (see Cargo.toml)

Example

Please see example directory for a complete example

```rust

[macro_use]

extern crate cpython; extern crate numpy; extern crate ndarray;

use numpy::; use ndarray::; use cpython::{PyResult, Python, PyObject};

/* Pure rust-ndarray functions */

// immutable example fn axpy(a: f64, x: ArrayViewD, y: ArrayViewD) -> ArrayD { a * &x + &y }

// mutable example (no return) fn mult(a: f64, mut x: ArrayViewMutD) { x *= a; }

/* rust-cpython wrappers (to be exposed) */

// wrapper of axpy fn axpypy(py: Python, a: f64, x: PyArray, y: PyArray) -> PyResult { let np = PyArrayModule::import(py)?; let x = x.asarray().intopyresult(py, "x must be f64 array")?; let y = y.asarray().intopyresult(py, "y must be f64 array")?; Ok(axpy(a, x, y).intopyarray(py, &np)) }

// wrapper of mult fn multpy(py: Python, a: f64, x: PyArray) -> PyResult { let x = x.asarraymut().intopyresult(py, "x must be f64 array")?; mult(a, x); Ok(py.None()) // Python function must returns }

/* Define module "rustext" */ pymoduleinitializer!(rustext, initrustext, PyInitrustext, |py, m| { m.add(py, "doc", "Rust extension for NumPy")?; m.add(py, "axpy", pyfn!(py, axpypy(a: f64, x: PyArray, y: PyArray)))?; m.add(py, "mult", pyfn!(py, mult_py(a: f64, x: PyArray)))?; Ok(()) }); ```

Contribution

This project is in pre-alpha version. We need your feedback. Don't hesitate to open issue!

Version