[Numpy-discussion] int16 or int32 for C int ?
Todd Miller
jmiller at stsci.edu
Mon Jun 27 03:18:00 EDT 2005
On Mon, 2005-06-27 at 09:36 +0200, Nicolas Pernetty wrote:
> On Sun, 26 Jun 2005 21:28:25 -0400, Todd Miller <jmiller at stsci.edu>
> wrote :
>
> > >
> > > I would like to create a numarray array from a C buffer of 'int' but
> > > I don't quite know how to handle different 'int' representation (16
> > > or 32 bits).
> >
> > On the platforms we test on at least, int == Int32. This is even
> > true for the 64-bit platforms I've seen.
> >
> > > For instante should I use :
> > >
> > > int a[10][20];
> > > x = NA_NewArray(a, tInt16, 2, 10, 20);
> > >
> > > or :
> > > int a[10][20];
> > > x = NA_NewArray(a, tInt32, 2, 10, 20);
> > >
> > > Should I use some macro to determine size of int ?
> >
> > You can do that with: sizeof(int)
> >
>
> Ok so If I want to make a really multiplatforms program, I should type :
>
> int a[10][20];
> if (sizeof(**a)==4)
> x = NA_NewArray(a, tInt32, 2, 10, 20);
> else
> x = NA_NewArray(a, tInt16, 2, 10, 20);
>
> This is the recommended way ?
I think this would be better:
Int32 a[10][20];
x = NA_NewArray(a, tInt32, 2, 10, 20);
Or, just do:
x = NA_NewArray(NULL, tInt32, 2, 10, 20)
and numarray will allocate the array storage which is then pointed to by
x->data.
Regards,
Todd
More information about the NumPy-Discussion
mailing list