[Numpy-discussion] Preserving NumPy views when pickling
robert.kern at gmail.com
Tue Oct 25 22:39:14 EDT 2016
On Tue, Oct 25, 2016 at 7:05 PM, Feng Yu <rainwoodman at gmail.com> wrote:
> Just another perspective. base' and 'data' in PyArrayObject are two
> separate variables.
> base can point to any PyObject, but it is `data` that defines where
> data is accessed in memory.
> 1. There is no clear way to pickle a pointer (`data`) in a meaningful
> way. In order for `data` member to make sense we still need to
> 'readout' the values stored at `data` pointer in the pickle.
> 2. By definition base is not necessary a numpy array but it is just
> some other object for managing the memory.
In general, yes, but most often it's another ndarray, and the child is
related to the parent by a slice operation that could be computed by
comparing the `data` tuples. The exercise here isn't to always represent
the general case in this way, but to see what can be done opportunistically
and if that actually helps solve a practical problem.
> 3. One can surely pickle the `base` object as a reference, but it is
> useless if the data memory has been reconstructed independently during
> 4. Unless there is clear way to notify the referencing numpy array of
> the new data pointer. There probably isn't.
> BTW, is the stride information is lost during pickling, too? The
> behavior shall probably be documented if not yet.
The stride information may be lost, yes. We reserve the right to retain it,
though (for example, if .T is contiguous then we might well serialize the
transposed data linearly and return a view on that data upon
deserialization). I don't believe that we guarantee that the unpickled
result is contiguous.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion