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

Matthew Brett matthew.brett at gmail.com
Tue Apr 2 20:56:42 EDT 2013


On Tue, Apr 2, 2013 at 5:52 PM, Nathaniel Smith <njs at pobox.com> 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.

Thanks - but I guess we all agree that

np.array(a, order='C')


np.ravel(a, order='F')

are using the term 'order' in two different and orthogonal senses, and
the discussion is about whether it is possible to get confused about
these two senses and, if so, what we should do about it.

Just to repeat what you're suggesting

np.array(a, memory_order='C')
np.ravel(a, index_order='C')
np.ravel(a, index_order='K')

That makes sense to me.  I guess we'd have to do something like:

def ravel(a, index_order='C', **kwargs):

Where kwargs must be empty if the second arg is specified, otherwise
it can contain only one key, 'order' and 'index_order'.  Thus:

np.ravel(a, index_order='C')

will work for the forseeable future.



More information about the NumPy-Discussion mailing list