[Numpy-discussion] default float type of array not accepted by SWIG wrapped C functions

Rich E reakinator at gmail.com
Fri Feb 6 11:29:52 EST 2009


I ended up solving my problem in SWIG, so I might as well post it
here.  I just made my own 'array' and 'zeros' functions with floating
point precision as follows:

%pythoncode %{

from numpy import array as np_array
def array (n, type='float32'):
        return(np_array(n, type))

from numpy import zeros as np_zeros
def zeros (n, type='float32'):
        return(np_zeros(n, type))
%}

Pretty basic, I know.  But it cuts down on alot of unnecessary code.

- Rich


On Thu, Jan 22, 2009 at 6:09 PM, Spotz, William F <wfspotz at sandia.gov> wrote:
> Rich,
>
> Basic python only supports double precision floats, so that is not an option.
>
> NumPy does not have, as far as I know, a way to set the default precision, although it might be a reasonable request.
>
> As for the SWIG interface file, almost anything is possible.  Can you give an example of a function prototype you are wrapping, the %apply directive you use and and example of python code accessing it?
>
> -Bill
> ________________________________________
> From: numpy-discussion-bounces at scipy.org [numpy-discussion-bounces at scipy.org] On Behalf Of Rich E [reakinator at gmail.com]
> Sent: Thursday, January 22, 2009 11:45 AM
> To: Discussion of Numerical Python
> Subject: [Numpy-discussion] default float type of array not accepted by SWIG wrapped C functions
>
> Hi all,
>
> I have a SWIG wrapped C library that uses 32bit floating point arrays,
> using the numpy.i typemapping system for passing the arrays.  For
> every array that I make, I have to convert it using astype('float32'),
> else python complains that I tried to pass a double-precision array.
>
> Is there any way to set the default floating point precision to 32bit,
> in python or in the SWIG interface file?
>
> regards,
> Rich
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>



More information about the NumPy-Discussion mailing list