Hi all,
I am reading on how to call rust from python. I am using pyo3
as interface. As a starting point I am trying to send a simple numpy
array to the rust function. Code for passing the numpy
array to rust
function, and corresponding rust function is at here.
Now when I am trying to compile it, I get the following errors,
error[E0277]: the trait bound `numpy::array::PyArray<f64, ndarray::dimension::dim::Dim<[usize; 1]>>: pyo3::conversion::FromPyObject<'_>` is not satisfied
> pylib/src/lib.rs:8:1

8  #[pymodinit]
 ^^^^^^^^^^^^ the trait `pyo3::conversion::FromPyObject<'_>` is not implemented for `numpy::array::PyArray<f64, ndarray::dimension::dim::Dim<[usize; 1]>>`

= help: the following implementations were found:
<&'a numpy::array::PyArray<T, D> as pyo3::conversion::FromPyObject<'a>>
= note: required by `pyo3::objectprotocol::ObjectProtocol::extract`
error[E0308]: mismatched types
> pylib/src/lib.rs:23:19

23  sum_array(&data)
 ^^^^^ expected struct `ndarray::OwnedRepr`, found struct `ndarray::ViewRepr`

= note: expected type `&ndarray::ArrayBase<ndarray::OwnedRepr<f64>, ndarray::dimension::dim::Dim<[usize; 1]>>`
found type `&ndarray::ArrayBase<ndarray::ViewRepr<&f64>, ndarray::dimension::dim::Dim<[usize; 1]>>`
error: aborting due to 2 previous errors
I haven’t understood the first error I haven’t understood it. Actually it was a copy paste from pointprocessrust repo. I thought it should work in my case too.
In the second error I don’t understand how to get a ownedarray
to a pyarray
object.
Thank you for the help.