Returning PyArray from struct #393
-
Hi, I'm having a little bit of an issue when I try to use structs. I want to return an array to python, but without a luck. I tried many things, read docs, search online but coudn't find. I'd appreciate if you could point out what I am doing wrong. I am new to Rust and rust-numpy. Here is an example code: #[pyclass]
pub struct Process {
data: Array1<f64>
}
#[pymethods]
impl Process {
#[new]
fn new(value: PyReadonlyArray1<f64>) -> Self {
let array = value.as_array().to_owned();
Process {
data: array
}
}
fn my_array(&self) -> PyArray1<f64> {
// return array
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
adamreichold
Sep 25, 2023
Replies: 1 comment 5 replies
-
In this case, since you store a fn my_array(&self, py: Python<'_>) -> PyArray1<f64> {
self.data.to_pyarray(py)
} |
Beta Was this translation helpful? Give feedback.
5 replies
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
Ah yes, for methods, the inferred lifetime is always that attached to the
&self
reference, so you have to make the lifetime explicit, i.e.(The inferred version would have been
which does not work as you describe.)