I'm able to expose simple functions written in Rust to python using pyo3 but can see no way to expose complex "eigen" / matrix types. Does anyone know if this is possible?
lib.rs
extern crate nalgebra as na;
use pyo3::prelude::*;
use na::{SMatrix, Vector3, Matrix3};
/// Formats the sum of two numbers as string.
#[pyfunction]
fn sum_as_string(a: usize, b: usize) -> PyResult<String> {
Ok((a + b).to_string())
}
#[pyfunction]
fn matrix_math(v3: Vector3<f64>, m3x3: Matrix3<f64>) -> PyResult<SMatrix<f64, 3, 1>>{
let mxv = m3x3 * v3;
Ok(mxv)
}
// Neiter way works
type Matrix3f = Matrix3<f64>;
type Vector3f = Vector3<f64>;
#[pyfunction]
fn matrix_math_w_types(v3: Vector3f, m3x3: Matrix3f) -> PyResult<SMatrix<f64, 3, 1>>{
let mxv = m3x3 * v3;
mxv
}
#[pymodule]
fn libpytest(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_function(wrap_pyfunction!(sum_as_string, m)?)?;
m.add_function(wrap_pyfunction!(matrix_math, m)?)?;
Ok(())
}