PyO3 / rust-numpy

PyO3-based Rust bindings of the NumPy C-API
BSD 2-Clause "Simplified" License
1.11k stars 106 forks source link

Returning PyArray from struct #392

Closed realiti4 closed 1 year ago

realiti4 commented 1 year ago

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
    }
}