Closed cschwan closed 1 year ago
I agree it would be desirable, and, for FkTable in general, you want only to read them. But are you sure it is supported by rust-numpy
?
I.e.: are you sure that rust-numpy
won't generate an actual Python object with its own memory anyhow?
I'm certain that in PyGrid::evolve
the method calls to into_owned()
and to_vec()
make copies, and we can easily avoid them.
Oh yes, I was reading right now the code, before I stopped to the comment. Essentially, it is the "opposite" problem of what I thought: you really have Python arrays, and don't want the copy to be done in Rust.
It might be that is also the third copy, if a copy is already done when passing the object from Python down to Rust, I'm not sure of this, but for sure you can avoid at least this (and I would expect to be the only one, but we can always profile it).
However, I started reading rust-numpy
docs in the meanwhile:
https://docs.rs/numpy/latest/numpy/borrow/index.html
and we are already using PyReadonlyArray
, so this supports my hypothesis that there is no further copy.
This PR changes the Rust interface to use
ArrayView5
instead ofArray5
, which has the advantage of avoiding a full copy of the operator inPyGrid::evolve
.