[SciPy-user] Problems with porting code using weave

Lars Bittrich lars.bittrich at googlemail.com
Mon Mar 27 05:14:25 EST 2006


Hi again,

On Friday 24 March 2006 20:22, Travis Oliphant wrote:
[...]
> Please let us know what trouble you are having.

finally I have isolated a very strange behavior. Sorry about the delay but I 
was not able to answer during the weekend. My code example looks as follows:

------------------------------------------------------------------------------

from scipy import *
from scipy.weave import inline,converters

N = 10
arr = zeros(N, Float)

factor = sqrt(1./pi)
#factor = pi

code= \
"""
double tmp = 1.0;

for (int i=0; i < N; i++) {
    arr(i) = tmp*factor;
}
"""
inline(code, ['arr', 'N', 'factor'], type_converters = converters.blitz)

print arr

------------------------------------------------------------------------------

When I run that file I get:

------------------------------------------------------------------------------
<weave: compiling>
/home/bittrich/.python23_compiled/sc_42e1646ad2085e8e2fc33f53a826fe5a0.cpp: In
   function `PyObject* compiled_func(PyObject*, PyObject*)':
/home/bittrich/.python23_compiled/sc_42e1646ad2085e8e2fc33f53a826fe5a0.cpp:715: 
error: ambiguous
   overload for 'operator*' in 'tmp * factor'
/home/bittrich/.python23_compiled/sc_42e1646ad2085e8e2fc33f53a826fe5a0.cpp:715: 
error: candidates
   are: operator*(double, double) <built-in>
/home/bittrich/.python23_compiled/sc_42e1646ad2085e8e2fc33f53a826fe5a0.cpp:715: 
error:
                  operator*(double, float) <built-in>
/home/bittrich/.python23_compiled/sc_42e1646ad2085e8e2fc33f53a826fe5a0.cpp:715: 
error:
                  operator*(double, int) <built-in>
/home/bittrich/.python23_compiled/sc_42e1646ad2085e8e2fc33f53a826fe5a0.cpp: In
   function `PyObject* compiled_func(PyObject*, PyObject*)':
/home/bittrich/.python23_compiled/sc_42e1646ad2085e8e2fc33f53a826fe5a0.cpp:715: 
error: ambiguous
   overload for 'operator*' in 'tmp * factor'
/home/bittrich/.python23_compiled/sc_42e1646ad2085e8e2fc33f53a826fe5a0.cpp:715: 
error: candidates
   are: operator*(double, double) <built-in>
/home/bittrich/.python23_compiled/sc_42e1646ad2085e8e2fc33f53a826fe5a0.cpp:715: 
error:
                  operator*(double, float) <built-in>
/home/bittrich/.python23_compiled/sc_42e1646ad2085e8e2fc33f53a826fe5a0.cpp:715: 
error:
                  operator*(double, int) <built-in>
Traceback (most recent call last):
  File "test.py", line 18, in ?
    inline(code, ['arr', 'N', 'factor'], type_converters = converters.blitz)
  File "/opt/cp/lib/python2.3/site-packages/scipy/weave/inline_tools.py", line 
334, in inline
    auto_downcast = auto_downcast,
  File "/opt/cp/lib/python2.3/site-packages/scipy/weave/inline_tools.py", line 
442, in compile_function
    verbose=verbose, **kw)
  File "/opt/cp/lib/python2.3/site-packages/scipy/weave/ext_tools.py", line 
353, in compile
    verbose = verbose, **kw)
  File "/opt/cp/lib/python2.3/site-packages/scipy/weave/build_tools.py", line 
274, in build_extension
    setup(name = module_name, ext_modules = [ext],verbose=verb)
  File "/opt/cp/lib/python2.3/site-packages/numpy/distutils/core.py", line 85, 
in setup
    return old_setup(**new_attr)
  File "/usr/lib/python2.3/distutils/core.py", line 166, in setup
    raise SystemExit, "error: " + str(msg)
scipy.weave.build_tools.CompileError: error: Command "g++ -pthread 
-fno-strict-aliasing -DNDEBUG -g -O3 -Wstrict-prototypes -fPIC 
-I/opt/cp/lib/python2.3/site-packages/scipy/weave 
-I/opt/cp/lib/python2.3/site-packages/scipy/weave/scxx 
-I/opt/cp/lib/python2.3/site-packages/scipy/weave/blitz 
-I/opt/cp/lib/python2.3/site-packages/numpy/core/include 
-I/usr/include/python2.3 
-c /home/bittrich/.python23_compiled/sc_42e1646ad2085e8e2fc33f53a826fe5a0.cpp 
-o /tmp/bittrich/python23_intermediate/compiler_cae5f1e251cd037a19f0234c558d6f0e/home/bittrich/.python23_compiled/sc_42e1646ad2085e8e2fc33f53a826fe5a0.o" 
failed with exit status 1

------------------------------------------------------------------------------

Uncommenting 'factor = pi' it simply works fine. Even if I remove that line 
once again and leave the c part unchanged so that there is no recompile 
needed, the program just works. Now I have found a solution for me. I just 
have to add some line like:

double tmpfactor = factor;

and do not use 'factor' again in the code. But that behavior remains odd in my 
eyes. Maybe it has something to do with my compiler. Maybe I can try the 
newest svn-version of scipy during the next few days. I will keep reporting 
anything alike. Thank you for your help.

Best regards,
Lars




More information about the SciPy-User mailing list