[f2py] column major versus row major storage question...
pearu at cens.ioc.ee
pearu at cens.ioc.ee
Wed Feb 9 10:53:23 EET 2005
On Tue, 8 Feb 2005, Louis Wicker wrote:
> All:
>
> this is probably another one of my silly questions.....
>
> If you create an array in Python, such as
>
> sC = array([[1,2,3],[4,5,6]])
>
> and print it out it shows
>
> [[1 2 3]
> [4 5 6]]
>
> now, suppose I try and convert that array to a column major storage via
>
> sF = fortran.as_column_major_storage(sC)
>
> and if the data transposition is done, then should not the print out of
> sF be
>
> [[1 3 5]
> [2 4 6]] ???
>
> its not...
And should not be. The argument of as_column_major_storage and its return
value are equivalent when accessing from Pyhton side. Just when argument
is C contiguous then the return value will be Fortran contiguous. So, the
following behaviour is correct:
In [4]: a=array([[1,2,3],[4,5,6]])
In [5]: a
Out[5]:
array([[1, 2, 3],
[4, 5, 6]])
In [6]: b=as_column_major_storage(a)
In [7]: b
Out[7]:
array([[1, 2, 3],
[4, 5, 6]])
In [8]: transpose(a)
Out[8]:
array([[1, 4],
[2, 5],
[3, 6]])
In [9]: transpose(b)
Out[9]:
array([[1, 4],
[2, 5],
[3, 6]])
In [11]: a.iscontiguous()
Out[11]: 1
In [12]: b.iscontiguous()
Out[12]: 0
In [13]: transpose(b).iscontiguous()
Out[13]: 1
Pearu
More information about the f2py-users
mailing list