The NumPy Fortran-ordering quiz

Charles R Harris charlesr.harris at gmail.com
Tue Oct 17 23:26:17 CDT 2006


On 10/17/06, A. M. Archibald <peridot.faceted at gmail.com> wrote:
>
> On 17/10/06, Charles R Harris <charlesr.harris at gmail.com> wrote:
> >
> >
> > On 10/17/06, Travis Oliphant <oliphant.travis at ieee.org> wrote:
>
> > > Thus, reshape does the equivalent of a Fortran ravel to [1,4,2,5,3,6]
> > > and then a Fortran-order based fill of an empty (3,2) array:  giving
> you
> > > the result.
> >
> > Why a Fortran ravel? I am thinking of it as preserving the memory
> layout,
> > just messing with how it is addressed.
>
> Because, to first order, the memory layout is totally irrelevant to a
> python user.
>
> array([[1,2,3],[4,5,6]],order='C')
> array([[1,2,3],[4,5,6]],order='F')
>
> should be nearly identical to the python user.


So what is the point of having a fortran layout if things are not actually
layed out in fortran order? As far as I can see, memory layout is the only
reason for fortran ordering. Now I can sort of see where the fortran ravel
comes from, because the result can be passed to a fortran routine. And it
does look like a.ravel('F') is the same as a.T.ravel(). Hmmm. Now I wonder
about this:

In [62]: array([[1,2,3],[4,5,6]], dtype=int8, order='F').flags
Out[62]:
  CONTIGUOUS : False
  FORTRAN : True
  OWNDATA : True
  WRITEABLE : True
  ALIGNED : True
  UPDATEIFCOPY : False

Now, either CONTIGUOUS is in error, because it really *is* fortran
contiguous (but not c contiguous), or the array cannot be passed to a
fortran routine that expects fortran ordering, or CONTIGUOUS refers to C
addressing, which we already know is not contiguous, in which case we feel
uncertain. Note that knowing the answer matters if I want to call a fortran
routine with this by pulling out the data pointer. The fortran routine could
be in a library, or maybe in the LaPack wrapper, but whatever, it hasn't
been wrapped by f2py that takes care of such details.

This also looks fishy:

In [93]: asfortranarray(array([[1,2,3],[4,5,6]], dtype=int8))
Out[93]:
array([[1, 2, 3],
       [4, 5, 6]], dtype=int8)

In [96]: asfortranarray(array([[1,2,3],[4,5,6]], dtype=int8)).flags
Out[96]:
  CONTIGUOUS : False
  FORTRAN : True
  OWNDATA : True
  WRITEABLE : True
  ALIGNED : True
  UPDATEIFCOPY : False

because the docstring says:

asfortranarray(a, dtype=None)
    Return 'a' as an array laid out in Fortran-order in memory.


Which doesn't seem to be the case here. I am beginning to wonder if we
really need fortran order, seems that a few well chosen interface routines
would fill the need and avoid much confusion.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20061017/b2fc57aa/attachment.html 
-------------- next part --------------
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
-------------- next part --------------
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/numpy-discussion


More information about the Numpy-discussion mailing list