[Numpy-discussion] Raveling, reshape order keyword unnecessarily confuses index and memory ordering

Sebastian Berg sebastian at sipsolutions.net
Wed Apr 3 09:24:48 EDT 2013

On Tue, 2013-04-02 at 22:52 +0100, Nathaniel Smith wrote:
> On Tue, Apr 2, 2013 at 10:21 PM, Matthew Brett <matthew.brett at gmail.com> wrote:
> >> This is like observing that if I say "go North" then it's ambiguous
> >> about whether I want you to drive or walk, and concluding that we need
> >> new words for the directions depending on what sort of vehicle you
> >> use. So "go North" means drive North, "go htuoS" means walk North,
> >> etc. Totally silly. Makes much more sense to have one set of words for
> >> directions, and then make clear from context what the directions are
> >> used for -- "drive North", "walk North". Or "iterate C-wards", "store
> >> F-wards".
> >>
> >> "C" and "Z" mean exactly the same thing -- they describe a way of
> >> unraveling a cube into a straight line. The difference is what we do
> >> with the resulting straight line. That's why I'm suggesting that the
> >> distinction should be made in the name of the argument.
> >
> > Could you unpack that for the 'ravel' docstring?  Because these
> > options all refer to the way of unraveling and not the memory layout
> > that results.
> Z/C/column-major/whatever-you-want-to-call-it is a general strategy
> for converting between a 1-dim representation and a n-dim
> representation. In the case of memory storage, the 1-dim
> representation is the flat space of pointer arithmetic. In the case of
> ravel, the 1-dim representation is the flat space of a 1-dim indexed
> array. But the 1-dim-to-n-dim part is the same in both cases.
> I think that's why you're seeing people baffled by your proposal -- to
> them the "C" refers to this general strategy, and what's different is
> the context where it gets applied. So giving the same strategy two
> different names is silly; if anything it's the contexts that should
> have different names.

Yup, thats how I think about it too... So I am against different values
for the order argument. I am somewhat fine with a new name, but it seems
like that may get clumsy.
But I would really love if someone would try to make the documentation
simpler! There is also never a mention of "contiguity", even though when
we refer to "memory order", then having a C/F contiguous array is often
the reason why (in np.asarray "contiguous='C'" would make as much sense
as "order", maybe even more so). Also 'A' seems often explained not
quite correctly (though that does not matter (except for reshape, where
its explanation is fuzzy), it will matter more in the future -- even if
I don't expect 'A' to be actually used).

If there is not yet, there should maybe be an overview in the
user/reference guide of what order means and how application to new
memory is different to reshape, etc. use it... Then the functions using
order, can also reference that, plus maybe we have some place to look up
what C and F is for all of us who like to forget it...

- Sebastian

> -n
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion

More information about the NumPy-Discussion mailing list