[Numpy-discussion] copy on demand

Chris Barker Chris.Barker at noaa.gov
Fri Jun 14 16:20:03 EDT 2002


Konrad Hinsen wrote:
> Not necessarily. We could decide that
> 
>    array.view
> 
> is a view of the full array object, and that slicing views returns
> subviews.

Please don't!! Having two types of arrays around in a single program
that have the same behaviour except when they are sliced is begging for
confusion and hard to find bugs.

I agree with Perry, that I occasionaly use the view behaviour of
slicing, and it is very usefull when I do, but most of the time I would
be happier with copy symantics. All I want is a way to get at a view of
part of an array, I don't want two different kinds of array around with
different slicing behaviour.

> My main objection to changing the slicing behaviour is, like with some
> other proposed changes, compatibility. 

The switch from Numeric to Numarray is a substantial change. I think we
should view it like the mythical Py3k: an oportunity to make
incompatible changes that will really make it better.

By the way, as an old MATLAB user, I have to say that being able to get
views from a slice is one behaviour of NumPy that I really appreciate,
even though I only need it occasionally. MATLAB, howver is a whole
different ball of wax in a lot of ways. There has been a lot of
discussion about the copy on demand idea in MATLAB, but that is
primarily useful because MATLAB has call by value function semantics, so
without copy on demand, you would be making copies of large arrays
passed to functions that weren't even going to change them. I don't
think MATLAB impliments copy on demand for slices anyway, but I could be
wrong there.

Oh, and no function (ie ravel() ) should return a view in some cases,
and a copy in others, that is just asking for bugs!

-Chris



-- 
Christopher Barker, Ph.D.
Oceanographer
                                    		
NOAA/OR&R/HAZMAT         (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov




More information about the NumPy-Discussion mailing list