bsc-quantic/rosnet

Fix inplace alternative methods

Closed this issue · 3 comments

There are some methods in the NumPy API that are not in-place but that a in-place version would be desired; e.g. transpose, reshape. In-place versions of these methods would decrease the storage footprint, although the (de)serialization size would probably remain invariant.

Current implementations task.transpose_inplace, task.reshape_inplace are broken (or are terribly unsafe) and are temporarily deprecated until we get a solution.

In my experience, these methods are imposible to implement just in Python, due to the fact that changing the shape or data attributes of a numpy.ndarray from Python doesn't seem to always get the desired result (apart of being extremely unsafe and that we might be breaking stuff). Solution seems to implement them using CPython and making calls to NumPy internal API.

References for implementation:

I think this is a good technical issue to start with @HerManNav

If you fill more comfortable with Rust, it could also be done with the pyo3 and numpy crates. The increase in FFI overhead and the limitation of compilation targets is not critical for us yet.

Fixed in #32

Note

An in-place reshape is not achievable if it requires a copy. In that case, the reshape fails.
https://numpy.org/doc/stable/reference/generated/numpy.reshape.html#numpy.reshape

As a COMPSs is self-contained (no views of array, task runs in isolated process), it should never require a copy and thus there would be no problem. Documentation does not clearly state when a copy is required, but stated earlier, it should run in our case.