[Numpy-discussion] Should arr.diagonal() return a copy or a view? (1.7 compatibility issue)

Fernando Perez fperez.net at gmail.com
Thu May 17 01:43:58 EDT 2012


On Fri, May 11, 2012 at 4:54 PM, Nathaniel Smith <njs at pobox.com> wrote:
> I
> have lying around my homedir that it would generally be a free speed
> win

Don't forget the case where the copy semantics may actually provide an
*improvement* in performance by allowing a potentially large array to
get deallocated if it was local.  People often forget that a *single
element* that is a view can 'pin' a huge array to memory by INCREF-ing
it.  If that large array trashes your cache (or worse, makes you go
into swapping), the time savings of using a view will be quickly
obliterated.

There are cases where a copy can be the fast solution...

Cheers,

f



More information about the NumPy-Discussion mailing list