[SciPy-user] weave doesn't recognise complex?
eric jones
eric@enthought....
Fri Sep 7 17:47:30 CDT 2007
Here is the issue. This one isn't detected correctly by weave.
In [23]: a = sqrt(2) - 1j
In [24]: type(a)
Out[24]: <type 'numpy.complex128'>
While this one is:
In [25]: a=1+1j
In [26]: type(a)
Out[26]: <type 'complex'>
In [27]: weave.inline("return_val = 1.0/a; ", ['a'])
<weave: compiling>
/home/eric/.python25_compiled/sc_76f8a7fbb0d61e690b0da4302d274e260.cpp:5:
warning: ignoring #pragma warning
/home/eric/.python25_compiled/sc_76f8a7fbb0d61e690b0da4302d274e260.cpp:6:
warning: ignoring #pragma warning
/home/eric/.python25_compiled/sc_76f8a7fbb0d61e690b0da4302d274e260.cpp:
In function âPyObject* file_to_py(FILE*, char*, char*)â:
/home/eric/.python25_compiled/sc_76f8a7fbb0d61e690b0da4302d274e260.cpp:403:
warning: unused variable âpy_objâ
Out[27]: (0.5-0.5j)
Notice the types are different because sqrt returns a numpy scalar
type. So, it looks like weave isn't detecting and converting the numpy
types correctly.
A ticket has been created. http://scipy.org/scipy/scipy/ticket/496
As a stop gap until this is fixed, you can cast the value back to a
complex before calling weave.
eric
Peter Bienstman wrote:
> Consider the following script:
>
> ------------------
> from numpy import *
> from scipy.weave import inline
>
> alpha = sqrt(2) - 1j
>
> inline("1.0 / alpha;", ['alpha'])
> -------------------
>
> This doesn't compile:
> /home/pbienst/.python24_compiled/sc_f7fc5c122cc2b740c6482ea58b8bdeb10.cpp:663:
> error: ambiguous overload for 'operator/' in '1.0e+0 / alpha'
>
> Looking in the generated code, it seems weave hasn't detected that alpha is a
> complex:
>
> py::object alpha = convert_to_catchall(py_alpha,"alpha");
>
> What does work is changing sqrt(2) by 1.41 or replacing 'from numpy import *'
> by 'from math import *'
>
> Cheers,
>
> Peter
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
>
More information about the SciPy-user
mailing list