PyArray as PyClass attribute #357
-
|
Hi there, a = MyClass()
a.array = np.ones(3)#[pyclass]
struct MyClass {
array: PyArray<f32>,
}And then the compiler screams at me because "the trait |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
|
You will generally not interact with This is not really specific to So long story short, you probably want #[pyclass]
struct MyClass {
#[pyo3(get, set)]
array: Py<PyArray1<f32>>,
} |
Beta Was this translation helpful? Give feedback.
You will generally not interact with
PyArray<..>by value, but rather with&'py PyArray<..>, that is a shared reference to anndarrayobject bound to a lifetime'pyfor which the GIL is held. Or - and this probably applies here - withPy<PyArray<..>>that is a reference-countedndarraywith shared ownership managed by Python's heap.This is not really specific to
PyArraythough but for example applies to most types frompyo3::typesas well. You can read up on the details in PyO3's guide.So long story short, you probably want