[Numpy-discussion] C vs. Fortran order -- misleading documentation?

David Goldsmith d.l.goldsmith at gmail.com
Tue Jun 8 22:33:37 EDT 2010


On Tue, Jun 8, 2010 at 3:49 PM, Friedrich Romstedt <
friedrichromstedt at gmail.com> wrot

> 2010/6/8 Anne Archibald <aarchiba at physics.mcgill.ca>:
> > Numpy arrays can have any configuration of memory strides, including
> > some that are zero; C and Fortran contiguous arrays are simply those
> > that have special arrangements of the strides. The actual stride
> > values is normally almost irrelevant to python code.
>
> First, I don't see the point why this text made it's way to this doc
> page at all - it's all abstract Python numpy indexing on that page as
> far as I can see - I don't know why a beginner should worry about
> strides and how the linear memory is actually organised - from my
> point of view I never did that.
>

Friedrich's perspective occurred to me also (at least I think mine's the
same) since my last post: the document in question is basics.indexing -
given the complexity and rather advanced nature of this issue, seems to me
that both the easiest _and_ most logical solution is to simply remove
discussion of the issue from this document altogether, and place it in, say,
docs/numpy-docs/user/c-info.beyond-basics.rst/ or
docs/numpy-docs/user/misc.rst/ (the latter of which, I note, already
discusses interfacing to C and interfacing to Fortran; not that the
row-major/col-major issue is an interfacing issue, but at least there's
already precedent for discussing these types of differences in the
document).

DG

To resolve the problem, and to avoid the confusion about the "fast"
> and "slow", why not using directly the concept of strides as Anne
> pointed out.  Simply saying that:
>
> When an array is indiced with indices (i1, i2, i3, ... in) and the
> array has strides (s1, s2, s3, ..., sn), the memory location addressed
> is:
>    i1 * s1 + i2 * s2 + ... + in * sn
> relative to the base point (and up to dtype).  I hope I'm not wrong here.
> For C order,
>    s1 >= s2 >= ... >= sn = 1 ,
> for fortran order the other way round.
>
> Friedrich
>
>
> In fact it holds:
>    s(k-1) = sk * Nk for C order,
>    s(k+1) = sk * Nk for fortran order,
> where Nk is the length of dimension k.
> If I'm not mistaken, it's late at night.
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>



-- 
Mathematician: noun, someone who disavows certainty when their uncertainty
set is non-empty, even if that set has measure zero.

Hope: noun, that delusive spirit which escaped Pandora's jar and, with her
lies, prevents mankind from committing a general suicide.  (As interpreted
by Robert Graves)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20100608/7c7bca4b/attachment.html>


More information about the NumPy-Discussion mailing list