-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello, I work on a 64bit machine with 64bits enable fedora on it. I just discovered that numpy.int on the python part are 64bits ints, while npy_int in the C api are 32bits ints. I can live with it, but it seems to be different on 32bit machines, hence I wonder what is the right way to do when retrieving an array from python to C. Here is what I use now: data_pyarray = (PyArrayObject *)PyArray_ContiguousFromObject(data_list, PyArray_INT, 1, 2); but that implies that I send np.int32 arrays to the C part. Should I use longs instead ? Regards, Martin -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/ iQEcBAEBAgAGBQJLoiuqAAoJEBdvyODiyJI4TikIAIUpnsIxxeYMlz8qEeZL/UUB 3UTGOCcrcIICPVRW/CLbOss5W4xe8BTxPslRXZfckSuMMgHHiD3rGC302gZgfvsb mS6fcDzTOboJ1da1xoczpJYVCwvC9aWAPEjEDa6jyI331pDAXABurmjzIQqjowDw 1cWX5swt9MeSn0yOa/a2EYQP8Xj+n0RQlSIutEDR5jktlK3yyHX8LAtZd0tAPgrd hr9RGwO09Hwcn7ke4B9SwHF7Zg/mBrHgdTdaufW+kjPleZ479lyMO8r/LsWbehVo usQ5wefnmnzhDhOoxff8aKUo8D+Ne8gqxI4BR5EOAdHfQ2uUPpBA91pJ0cNbzZI= =E0XH -----END PGP SIGNATURE-----
Martin Raspaud wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Hello,
I work on a 64bit machine with 64bits enable fedora on it.
I just discovered that numpy.int on the python part are 64bits ints, while npy_int in the C api are 32bits ints.
np.intc Dag Sverre
I can live with it, but it seems to be different on 32bit machines, hence I wonder what is the right way to do when retrieving an array from python to C.
Here is what I use now: data_pyarray = (PyArrayObject *)PyArray_ContiguousFromObject(data_list, PyArray_INT, 1, 2);
but that implies that I send np.int32 arrays to the C part.
Should I use longs instead ?
Regards, Martin -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/
iQEcBAEBAgAGBQJLoiuqAAoJEBdvyODiyJI4TikIAIUpnsIxxeYMlz8qEeZL/UUB 3UTGOCcrcIICPVRW/CLbOss5W4xe8BTxPslRXZfckSuMMgHHiD3rGC302gZgfvsb mS6fcDzTOboJ1da1xoczpJYVCwvC9aWAPEjEDa6jyI331pDAXABurmjzIQqjowDw 1cWX5swt9MeSn0yOa/a2EYQP8Xj+n0RQlSIutEDR5jktlK3yyHX8LAtZd0tAPgrd hr9RGwO09Hwcn7ke4B9SwHF7Zg/mBrHgdTdaufW+kjPleZ479lyMO8r/LsWbehVo usQ5wefnmnzhDhOoxff8aKUo8D+Ne8gqxI4BR5EOAdHfQ2uUPpBA91pJ0cNbzZI= =E0XH -----END PGP SIGNATURE-----
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Dag Sverre Seljebotn skrev:
Martin Raspaud wrote: Hello,
I work on a 64bit machine with 64bits enable fedora on it.
I just discovered that numpy.int on the python part are 64bits ints, while npy_int in the C api are 32bits ints.
np.intc
Thanks ! But I'm also wondering about the C side. How can I make sure my conversion to PyArray goes well ? Should I use PyArray_LONG ? or is this also platform dependent ? Regards, Martin
I can live with it, but it seems to be different on 32bit machines, hence I wonder what is the right way to do when retrieving an array from python to C.
Here is what I use now: data_pyarray = (PyArrayObject *)PyArray_ContiguousFromObject(data_list, PyArray_INT, 1, 2);
but that implies that I send np.int32 arrays to the C part.
Should I use longs instead ?
Regards, Martin
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/ iQEcBAEBAgAGBQJLokeGAAoJEBdvyODiyJI4tv0H/R+sUTIfvH2JejX85XHUGtOw mUwDkAD2ePj9qNc62RJJQg75B58useoe8zHSNj2NFG7U5fhFYviIQImugJ4dAESo z4WgrIRQE29apyCScRid8lXBHDL8kvJtpI+G/uFQ62jxSzheIDpEEzKUlDMYZeIA MLFhMWqzHVmuNEUVyUdPt+ryL6T23t/uzQEtpt+QKt5U2Vj/dYerRRjilMA5bvLn r+xGIFQqKOLW8MzwJ+zo0nkea7JvfDBbSZdU2oS5yuQ8rdXR/v9OeSfzTI5fuI7C erUTkEozZ+5jShZbmJbihJcjjw61KleF7QfiySOahqW/E/gKYWRSX5doB4rF35A= =MDuv -----END PGP SIGNATURE-----
On Thu, Mar 18, 2010 at 08:33, Martin Raspaud <martin.raspaud@smhi.se> wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Hello,
I work on a 64bit machine with 64bits enable fedora on it.
I just discovered that numpy.int on the python part are 64bits ints, while npy_int in the C api are 32bits ints.
Note that np.int is just Python's builtin int type (there only for historical reasons). It corresponds to a C long. npy_int corresponds to a C int.
I can live with it, but it seems to be different on 32bit machines, hence I wonder what is the right way to do when retrieving an array from python to C.
Here is what I use now: data_pyarray = (PyArrayObject *)PyArray_ContiguousFromObject(data_list, PyArray_INT, 1, 2);
but that implies that I send np.int32 arrays to the C part.
Should I use longs instead ?
Not necessarily; C longs are the cause of your problem. On some platforms they are 64-bit, some they are 32-bit. Technically speaking, C ints can vary from platform to platform, but they are typically 32-bits on all modern platforms running numpy. Of course, numpy defaults to using a C long for its integer arrays, just as Python does for its int type, so perhaps using a C long would work best for you. It's platform dependent, but it matches the platform dependent changes in numpy. It depends on what your needs are. If you need a consistent size (perhaps you are writing bytes out to a file), then always use the int32 or int64 specific types. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
participants (3)
-
Dag Sverre Seljebotn
-
Martin Raspaud
-
Robert Kern