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@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@scipy.org [numpy-discussion-bounces@scipy.org] On Behalf Of Rich E [reakinator@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@scipy.org>http://projects.scipy.org/mailman/listinfo/numpy-discussion> _______________________________________________
> Numpy-discussion mailing list
>Numpy-discussion@scipy.org>http://projects.scipy.org/mailman/listinfo/numpy-discussion>