Creating getters and setters for `ndarray` fields of structs
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 35/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Da chiarire
- Stato di attività
- Ferma
- Ambito
- api, backend-api-design
Direzione di ricerca
Inizia riproducendo l’esempio Rust con rust-numpy v0.22.0, quindi leggi le discussioni collegate 357 e 393 e confronta l’implementazione della conversione di smallvec di PyO3. Il lavoro sarà completo quando sarà disponibile un approccio documentato e concordato per esporre automaticamente i campi delle struct ndarray tramite getter e setter, incluso il comportamento di conversione richiesto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
I tried to write Python bindings for a struct containing ndarray type fields, but it does not compile: (rust-numpy v0.22.0)
use pyo3::prelude::*;
use pyo3::{pymodule, Bound, PyResult};
use numpy::ndarray::Array2;
#[pyclass(get_all, set_all)]
#[derive(Debug, Clone)]
pub struct Foo {
vec: Array2<f64>,
}
#[pymodule]
fn my_module(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_class::<Foo>()?;
Ok(())
}
I read the existing discussions (this and this) and they suggests writing getters and setters manually for each field, which is unsatisfactory.
This currently greatly limits the ability to make existing APIs that contain ndarrays available to Python: We can only use free functions but not structs or classmethods.
Why is this limitation ? Could it be solved by simply implementing the IntoPy<Py<PyAny>> and FromPyObject traits for ndarray ?
I see that this is done for smallvec's and having smallvec's as fields just works as expected.
Note also that this feature is present in C++'s pybind11 (the getters return a read-only array).
I would greatly appreciate the ability to bind ndarray fields and automatically provide getters and setters in Python. This would allow to fully bind an existing Rust API to Python.
Thanks a lot!
- Lingua principale
- Rust
- Stelle
- 1.4k
- Fork
- 141
- Merge medio
- 16m
- PR unite (30g)
- 3
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di PyO3/rust-numpy
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
PyO3/rust-numpy#565 · 1 commento ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 58/100
PyO3/rust-numpy#563 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 56/100
PyO3/rust-numpy#557 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
PyO3/rust-numpy#547 · 2 commenti ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 20/100
PyO3/rust-numpy#535 ·
Tutte le issue di PyO3/rust-numpy
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
TheLarkInn/aipm#2413 ·
-
documentation
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
alexgorbatchev/simple-ptt#15 ·
-
tooling
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
todo:ticket
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
taikoxyz/taiko-mono#22168 · 1 commento ·