[Numpy-discussion] Ransom Proposals
Tim Hochberg
tim.hochberg at cox.net
Tue Mar 28 07:36:18 CST 2006
Travis Oliphant wrote:
> Charles R Harris wrote:
>
>> Tim,
>>
>>
>> That being said I have a suggestion that *might* satisfy
>> everyone. Set
>> the WRITEABLE flag to false if reshape creates a new array:
>>
>> I think this will cause problems as I myself usually want to modify
>> the contents after a reshape. Why not in this case have
>> a.reshape(...) return a view when possible and raise an error
>> otherwise, and have the functional form make a copy. Reshape the
>> method then provides a path to efficient computing, while reshape the
>> function promotes safe computing. I like to write classes in C++
>> where I can do things like
>> b.mul(c).add(d).div(e) all inplace for efficiency and the current
>> situation strikes me as similar.
>>
> This is the direction I could support. If we did this, then the
> ravel method would also have to change to be consistent.
>
> The functions would be copy-if-necessary and would *not* be deprecated.
>
> To summarize
>
> on making methods that return views raise an error when impossible and
> not changing and/or deprecating functions (i.e. the functions are
> simple wrappers around the methods).
>
> -1
>
> on making methods that return views raise an error when impossible and
> changing the function to make a copy
>
> +0
+1 Assuming I understand all of the implications.
* When doing automated conversion from Numeric/numarray to numpy,
"reshape(obj) => asarray(obj).reshape()". Doing anything else is going
to cause breakage and/or massive slowdowns. Can the conversion tool
handle this? I would guess yes, but that's just a guess.
* This means that "somenoncontiguousarray.reshape(newshape)" will oftern
raise an error. That's a good thing, but I figured I'd get it out in the
open now so no one is suprised.
* Since x.reshape would no longer return copies, the order flag is
unnecessary.
* numpy.reshape(obj, newshape) on the other hand, always copies, so it
*could* grow an order flag. I think that I'd prefer that it didn't; if
you need that kind of control of the resulting arrays you should be
using array to copy your matrices.
* What does fixing ravel to be consistent mean? Always return a view? Or
always return a copy? The latter seems more useful, as the first is
already covered by both obj.reshape(-1) and obj.flat.
Regards,
-tim
More information about the Numpy-discussion
mailing list