// 转换为`ndarray::ArrayView1`,一个完全可操作的原生数组 let point = point.as_array(); ... } 因为point现在是一个ArrayView1,所以我们可以使用它了,如下所示: // 使`norm`函数可用 use ndarray_linalg::Norm; assert_eq!((point.to_owned() - point).norm(), 0.); 现在,我们只需要获取每个...
// Convert to `ndarray::ArrayView1`, a fully operational native array. let point = point.as_array; ... } 左右滑动查看完整代码 由于point已经成为了ArrayView1,因此我们可以使用它了。比如: /// Make the `norm`functionavailable. use ndarray_linalg::Norm; assert_eq!((point.to_owned - point)...
// 转换为`ndarray::ArrayView1`,一个完全可操作的原生数组 let point = point.as_array(); ... } 因为point现在是一个ArrayView1,所以我们可以使用它了,如下所示: // 使`norm`函数可用 use ndarray_linalg::Norm; assert_eq!((point.to_owned() - point).norm(), 0.); 现在,我们只需要获取每个...
// 转换为`ndarray::ArrayView1`,一个完全可操作的原生数组 let point = point.as_array(); ... } 因为point现在是一个ArrayView1,所以我们可以使用它了,如下所示: // 使`norm`函数可用 use ndarray_linalg::Norm; assert_eq!((point.to_owned() - point).norm(), 0.); 现在,我们只需要获取每个...
我们需要三个 crate 来实现我们的函数: 代码语言:javascript 复制 # 针对 Rust 原生数组操作 ndarray="0.15"# 面向数组的`norm`函数 ndarray-linalg="0.16"# 访问 numpy 基于`ndarray`创建的对象 numpy="0.18"
use pyo3::prelude::*;use ndarray_linalg::Norm;use numpy::PyReadonlyArray1;#[pyfunction]fn find_close_polygons(py: Python<'_>,polygons: Vec,point: PyReadonlyArray1,max_dist: f64,) -> PyResult> {let mut close_polygons = vec![];let point = point.as_array();for poly in polygo...
# For Rust-native array operations.ndarray="0.15"# For a `norm` function for arrays.ndarray-linalg="0.16"# For accessing numpy-created objects, based on `ndarray`.numpy="0.18" 首先,我们将 point: PyObject 转换成可以使用的东西。 我们可以利用 PyO3 来转换 numpy 数组: ...
# For Rust-native array operations.ndarray="0.15"# For a `norm` function for arrays.ndarray-linalg="0.16"# For accessing numpy-created objects, based on `ndarray`.numpy="0.18" 1. 2. 3. 4. 5. 6. 首先,让我们将不透明和通用的点:PyObject变成我们可以使用的对象。
usepyo3::prelude::*;usendarray_linalg::Norm;usenumpy::PyReadonlyArray1;#[pyfunction]fnfind_close_polygons(py:Python<'_>,polygons:Vec<PyObject>,point:PyReadonlyArray1<f64>,max_dist:f64,)-> PyResult<Vec<PyObject>> {letmut close_polygons = vec![];letpoint = point.as_array();for...
] }# 随机数rand="0.8.5"rand_distr="0.4.3"fastrand="2.3.0"# 线性代数nalgebra= { version ="0.33.2",features = ["rand"]}ndarray="0.16.1"# winitwgpu="23.0.1"winit="0.30.8"# eguieframe="0.30.0"egui= { version ="0.30.0", features = ["default"]}egui_extras= {version ="0.30...