我能够使用 pyo3 将用 Rust 编写的简单函数公开给 python,但看不到公开复杂的“特征”/矩阵类型的方法。有谁知道这是否可能?
库文件
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(())
}