Closed mofeing closed 2 years ago
I think this is a good technical issue to start with @HerManNav
Fixed in #32
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.
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
ordata
attributes of anumpy.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:
fastremap.reshape
works inplace if the array is contiguous.fastremap.transpose
works inplace if the array is contiguous and.ndim
is up to 4.hptt.tensorTransposeAndUpdate
seems to be capable of inplace transposition ofndarray
s but it is limited to float and complex types.