[Numpy-discussion] Fortran ordering
Paul Northug
pnorthug@gmail....
Sat Apr 17 19:25:41 CDT 2010
Stéfan van der Walt <stefan <at> sun.ac.za> writes:
>
> On 16 April 2010 21:35, Paul Northug <pnorthug <at> gmail.com> wrote:
> > how is it stored in memory, as [1, 2, 3, 4] or [1, 3, 2, 4]?
>
> The latter:
>
> In [22]: np.fromstring(str(x.data))
> Out[22]: array([ 1., 3., 2., 4.])
>
> > But when I call external libraries through ctypes with a.ctypes.data
> > as argument, the external function gets [1, 2, 3, 4] (I think).
>
> That should not be the case. Please see the attached code as a
> demonstration, which has the following output:
>
> Printing values as in memory:
> 1 3 2 4
> Let's assign values 0, 1, 2 and 3 to consecutive memory
> addresses. The result is:
> [[ 0. 2.]
> [ 1. 3.]]
>
> Regards
> Stéfan
Thanks for the explanation and especially the code example. That clears it up
for me.
I also implemented it in cython as Dag suggested (wrapping cuda sgemm).
The confusion was due to how pycuda maps arrays to and from cuda device memory
using pycuda.gpuarray.
More information about the NumPy-Discussion
mailing list