[Numpy-discussion] order flag again

Tim Hochberg tim.hochberg at cox.net
Mon Mar 27 11:08:03 CST 2006


I notice that some methods of the array object, notably reshape, take 
the order flag. I think this is a mistake. At this point, x.reshape() 
should always be returning a view. That means it's a cheap operation. 
Similarly, setting the order flag is also a cheap operation[*]. For that 
reason there's not a pressing efficiency reason to combine to the two 
operations and I feel that they should be broken apart. Thus we'd gain 
an operation  'setorder' or similar and lose the order flag everywhere 
but array and the various asXXXarray[**] functions since they need it to 
efficiently construct a correctly ordered array. Thus:

    b = a.reshape(newshape, order=neworder)

would become:

    b = a.reshape(newshape).setorder(neworder)

That doesn't look substantially better in that form, but compare:

    b = a.reshape(weeble, order=wobble)

with:

    b = a.reshape(weeble).setorder(wobble)

And the superiority of the second form begins to becomes apparent. The 
requirement that order be keyword parameter helps, but not enough IMO. 
The second form is orthogonal and self documenting and just all around 
more swell ;)

Regards,

-tim


[*] I know this even though I haven't thought through what reshape plus 
the order flag is doing because reshape isn't allowed to return a copy. 
Thus setting the order flag in this context must amount to just 
rejiggering shape and strides.

[**] And I suppose, maybe, ravel. However, ravel is yet another evil 
function, or rather method in this case, that sometimes returns a view 
and sometimes a copy. Ravels is really unnecessary, and I don't have the 
energy to wage a campaign against its evil ways (much to everyones 
relief I imagine), so I plan to just ignore it and recomend that no one 
use it . Ever.






More information about the Numpy-discussion mailing list