[Scipy-tickets] [SciPy] #496: weave not detecting numpy complex scalar (and perhaps other numpy) data types.

SciPy scipy-tickets@scipy....
Mon Nov 24 05:52:21 CST 2008


#496: weave not detecting numpy complex scalar (and perhaps other numpy) data
types.
-------------------------+--------------------------------------------------
 Reporter:  eric         |        Owner:  eric 
     Type:  defect       |       Status:  new  
 Priority:  normal       |    Milestone:  0.7.0
Component:  scipy.weave  |      Version:       
 Severity:  normal       |   Resolution:       
 Keywords:               |  
-------------------------+--------------------------------------------------
Old description:

> 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.
>
> 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

New description:

 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.

 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

-- 
Ticket URL: <http://scipy.org/scipy/scipy/ticket/496#comment:2>
SciPy <http://www.scipy.org/>
SciPy is open-source software for mathematics, science, and engineering.


More information about the Scipy-tickets mailing list