[Numpy-discussion] is ndarray.base the closest base or the ultimate base?
Wed Sep 23 12:05:01 CDT 2009
On Tue, Sep 22, 2009 at 17:14, Citi, Luca <firstname.lastname@example.org> wrote:
> My vote (if I am entitled to) goes to "change the code".
> Whether or not the addressee of .base is an array, it should be "the object that has to be kept alive such that the data does not get deallocated" rather "one object which will keep alive another object, which will keep alive another object, ...., which will keep alive the object with the data".
> On creation of a new view B of object A, if A has ONWDATA true then B.base = A, else B.base = A.base.
> When working on
> I had to walk the chain of bases to establish whether any of the inputs and the outputs were views of the same data.
> If "base" were the ultimate base, one would only need to check whether any of the inputs have the same base of any of the outputs.
This is not reliable. You need to check memory addresses and extents
for overlap (unfortunately, slices complicate this;
numpy.may_share_memory() is a good heuristic, though). When
interfacing with other systems using __array_interface__ or similar
APIs, the other system may have multiple objects that point to the
same data. If you create ndarrays from each of these objects, their
.base attributes would all be different although they all point to the
> I tried to modify the code to change the behaviour.
> I have opened a ticket for this http://projects.scipy.org/numpy/ticket/1232
> and attached a patch but I am not 100% sure.
> I changed PyArray_View in convert.c and a few places in mapping.c and sequence.c.
> But if there is any reason why the current behaviour should be kept, just ignore the ticket.
Lacking a robust use case, I would prefer to keep the current
behavior. It is likely that nothing would break if we changed it, but
without a use case, I would prefer to be conservative.
"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
-- Umberto Eco
More information about the NumPy-Discussion