[Numpy-discussion] array copy-to-self and views

Timothy Hochberg tim.hochberg at ieee.org
Thu Feb 1 14:24:04 EST 2007


On 2/1/07, Zachary Pincus <zpincus at stanford.edu> wrote:

[CHOP]

I think that this is is unquestionably a bug


It's not a bug. It's a design decision. It has certain consequences. Many
good, some bad and some that just take some getting used to.


-- isn't the point of
> views that the user shouldn't need to care if a particular array
> object is a view or not?


As you state elsewhere, the issue isn't whether a given object is a view per
se, it's whether the objects that you are operating on refer to the same
block of memory. They could both be views, even of the same object, and as
long as they're disjoint, it's not a problem.

Given the lack of methods to query whether
> an array is a view, or what it might be a view on, this seems like a
> reasonable perspective... I mean, if certain operations produce
> completely different results when one of the operands is a view, that
> *seems* like a bug. It might not be worth fixing, but I can't see how
> that behavior would be considered a feature.


View semantics are a feature. A powerful and sometime dangerous feature.
Sometimes the consequences of these semantics can bite people, but that
doesn't make them a bug.

 [CHOP]

>
>
> Good question. As I mentioned above, I assume that this information
> is tracked internally to prevent the 'original' array data from being
> deleted before any views have; however I really don't know how it is
> exposed.


I believe that a reference is held to the original array, so the array
itself won't be deleted even if all of the references to it go away. The
details may be different, but that's the gist of it. Even ifyou could access
this, it wouldn't really tell you anything useful since two slices could
refer to pieces of the original chunk of data, yet still be disjoint.

If you wanted to be able to figure this out, probably the thing to do is
just to actually look at the block of data occupied by each array and see if
they overlap. I think you could even do this without resorting to C by using
the array interface.

However, I'd like to repeat what my doctor said as a kid when I complained
that "it hurts when I do this":
    "Don't do that!" -- Some Radom Doctor
In other words, I think you'd be better off restructuring your code so that
this isn't an issue. I've been using Numeric/numarray/numpy for over ten
years now this has never been a significant issue for me.


-- 

//=][=\\

tim.hochberg at ieee.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20070201/5f5a92e7/attachment.html>


More information about the NumPy-Discussion mailing list