LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 2699|回复: 2

scipy inline 问题

[复制链接]
发表于 2010-10-2 16:33:38 | 显示全部楼层 |阅读模式
  1. from scipy.weave import inline

  2. vec = 100
  3. code = """
  4. double sum = 0.0;
  5. int npts = Nvec[0];
  6. for (int i=0;i<npts;++i) {
  7.     sum += vec[i];
  8. }
  9. return_val = sum;
  10. """
  11. print inline(code,['vec'])
  12. print vec.sum()

复制代码
/home/shihyu/.python26_compiled/sc_d6f219b85e9586396248b98781b97fd25.cpp: In function ‘PyObject* compiled_func(PyObject*, PyObject*)’:
/home/shihyu/.python26_compiled/sc_d6f219b85e9586396248b98781b97fd25.cpp:667: error: ‘Nvec’ was not declared in this scope
/home/shihyu/.python26_compiled/sc_d6f219b85e9586396248b98781b97fd25.cpp:669: error: invalid types ‘int[int]’ for array subscript
/home/shihyu/.python26_compiled/sc_d6f219b85e9586396248b98781b97fd25.cpp: In function ‘PyObject* compiled_func(PyObject*, PyObject*)’:
/home/shihyu/.python26_compiled/sc_d6f219b85e9586396248b98781b97fd25.cpp:667: error: ‘Nvec’ was not declared in this scope
/home/shihyu/.python26_compiled/sc_d6f219b85e9586396248b98781b97fd25.cpp:669: error: invalid types ‘int[int]’ for array subscript
Traceback (most recent call last):
  File "test.py", line 12, in <module>
    print inline(code,['vec'])
  File "/usr/lib/python2.6/dist-packages/scipy/weave/inline_tools.py", line 335, in inline
    **kw)
  File "/usr/lib/python2.6/dist-packages/scipy/weave/inline_tools.py", line 462, in compile_function
    verbose=verbose, **kw)
  File "/usr/lib/python2.6/dist-packages/scipy/weave/ext_tools.py", line 365, in compile
    verbose = verbose, **kw)
  File "/usr/lib/python2.6/dist-packages/scipy/weave/build_tools.py", line 272, in build_extension
    setup(name = module_name, ext_modules = [ext],verbose=verb)
  File "/usr/lib/python2.6/dist-packages/numpy/distutils/core.py", line 184, in setup
    return old_setup(**new_attr)
  File "/usr/lib/python2.6/distutils/core.py", line 169, in setup
    raise SystemExit, "error: " + str(msg)
scipy.weave.build_tools.CompileError: error: Command "g++ -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -fPIC -I/usr/lib/python2.6/dist-packages/scipy/weave -I/usr/lib/python2.6/dist-packages/scipy/weave/scxx -I/usr/lib/python2.6/dist-packages/numpy/core/include -I/usr/include/python2.6 -c /home/shihyu/.python26_compiled/sc_d6f219b85e9586396248b98781b97fd25.cpp -o /tmp/shihyu/python26_intermediate/compiler_2da6387b1d12110fba46fe47fea9326a/home/shihyu/.python26_compiled/sc_d6f219b85e9586396248b98781b97fd25.o" failed with exit status 1


請問是什麼原因造成?
謝謝
发表于 2010-10-7 11:28:31 | 显示全部楼层
没用过scipy.但从错误消息看,应该是你内嵌的那段c/c++代码包含错误(比如Nvec没有声明……)。
你可以试着直接写一段c代码,单独编译,看看有没问题,没问题了再继续inline.
回复 支持 反对

使用道具 举报

发表于 2010-10-14 09:24:42 | 显示全部楼层
还没有学到这里。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表