带有scipy.weave.inline的SyntaxError [英] SyntaxError with scipy.weave.inline

查看:382
本文介绍了带有scipy.weave.inline的SyntaxError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近升级到了最新版本的 brian2 ,并且在运行神经模拟时开始看到以下警告:

 警告brian2.codegen.runtime.weave_rt.weave_rt.failed_compile_test:无法使用编织,测试编译失败:无效语法(< string> ;,第1行)(SyntaxError)

经过一番挖掘,我发现这个警告是由于这些行在 brian2 的模块:

 编译器,extra_compile_args = get_compiler_and_args()
weave.inline('int x = 0;',[],
compiler = compiler,
headers = ['< algorithm>','< limits>]],
extra_compile_args = extra_compile_args,
verbose = 0)

运行此代码,我得到以下内容:

 在[11]中:from scipy import weave 

在[12]中:compiler
出[12]:' gcc'

在[13]中:extra_compile_args
Out [13]:['-w','-O3']

在[14] .inline('int x = 0;',[],compiler = compiler,headers = ['< algorithm>','< limits>],extra_compile_args = extra_compile_args,verbose = 0)
File < string>,line 1
'\t\t\t\t // SUPPORT CODE \\\
\t // static py :: object _namespace_numpy_rand; \\\
\t //#define BUFFER_SIZE 1024 \\\
\t ////一个rand()函数,返回一个随机数。内部////它一次向BUFFER_SIZE \\\
\t // //随机数询问numpy的rand函数,然后从这里返回一个数字\\\\ //// buffer.\\\
\t ////它需要引用numpy_rand对象(原始numpy \\\
\t ////函数),因为否则它只能在n\t //// compiled_function(其中is自动处理).\\\
\t //// \\\
\t // double _rand(const int _vectorisation_idx){\\\
\ t // // _vectorisation_idx参数现在未被使用,它可以在使用\\\\ // // OpenMP等时使用\\\\ // //原理来获得可重复的随机数。 //静态PyArrayObject * rand_buffer = NULL; \\\
\t // static double * buf_pointer = NULL; \\\
\t // static npy_int curbuffer = 0; \\\
\t / / if(curbuffer == 0)\\\
\t // {\\\
\t // if(rand_buffer)Py_DECREF(rand_buffer); \\ /// py :: tuple args(1); \\\
\t // args [0] = BUFFER_SIZE; \\\
\t // rand_buffer =(PyArrayObject *)PyArray_FromAny(_namespace_numpy_rand.call args),\\\
\t // NULL,1,1,0,NULL); \\\
\t // buf_pointer =(double *)PyArray_GETPTR1(rand_buffer,0); \\\
\t / /} \\\
\t // double number = buf_pointer [curbuffer]; \\\
\t // curbuffer = curbuffer + 1; \\\
\t // if(curbuffer == BUFFER_SIZE)\\\
\t // //使用(curbuffer + 1)%BUFFER_SIZE似乎更安全,我们可能会碰到\\\
\t // //大网络的整数溢出,否则。\\\ t // curbuffer = 0; \\\
\t //返回数字; \\\
\t //} \\\
\\\
\\\
\t\t\t //// HANDLE纪元//// \\\\\\\\\\\\\\\\\\\\\\\\\\\ n\\\
\t\t \\ t //// POINTERS //// \ n\tint * __restrict _ptr_array_synapses_4_N_incoming = _array_synapses_4_N_incoming; \\\
\tint * __restrict _ptr_array_poissongroup_i = _array_poissongroup_i; \\\
\tint * __restrict _ptr_array_neurongroup_i = _array_neurongroup_i; \\\
\tint * __restrict _ptr_array_synapses_4__synaptic_post = _array_synapses_4__synaptic_post; \\\
\tint * __restrict _ptr_array_synapses_4_N_outgoing = _array_synapses_4_N_outgoing; \\\
\tint * __restrict _ptr_array_synapses_4__synaptic_pre = _array_synapses_4__synaptic_pre; \\\
\t_namespace_numpy_rand = _numpy_rand; \\\
\\\
\ n == srand((unsigned int)time(NULL)); \\\
const int _buffer_size = 1024; \\\
int * const _prebuf = new int [_buffer_size]; \\\
int * const _postbuf = new int [ _buffer_size]; \\\
int * const _synprebuf = new int [1]; \\\
int * const _synpostbuf = new int [1]; \\\
int _curbuf = 0; \\\
\\\
//标量代码\\ n\tconst intrray_neurongroup_1_s_ext; \\\
\tdouble * __restrict _ptr_array_neurongroup_1_s_gaba = _array_neurongroup_1_s_gaba; \\\
\tdouble * __restrict _ptr_array_neurongroup_1_v = _array_neurongroup_1_v; \\\
\tdouble * __restrict _ptr_array_neurongroup_1_s_tot_ampa = _array_neurongroup_1_s_tot_ampa; \\\
\\\
\主要代码//////////// \\ n\\\
\t //标量代码\\\
\tconst int _vectorisation_idx = 1; \\ n \\ n \ t\\\
const double _lio_const_1 = - dt; \\\
const double _lio_const_2 = - G_ampa; \\\
const double _lio_const_3 = - E_ampa; \\\
const double _lio_const_4 = - E_gaba; \\\
const double _lio_const_5 = - E_nmda; \\\
const double _lio_const_6 = - a; \\\
const double _lio_const_7 = - El_i; \\\
\\\
\\\
\tfor(int _idx = 0; _idx< N; _idx ++)\\\
\t {\\\
\t // vector code\\\
\t\tconst int _vectorisation_idx = _idx; \\\
\t\t \\\
const double s_tot_ampa = _ptr_array_neurongroup_1_s_tot_ampa [_idx]; \\\
double s_ext = _ptr_array_neurongroup_1_s_ext [_idx]; \\\
double s_gaba = _ptr_array_neurongroup_1_s_gaba [_idx]; \\\
const double s_tot_nmda = _ptr_array_neurongroup_1_s_tot_nmda [_idx]; \\\
double v = _ptr_array_neurongroup_1_v [_idx];; \\ n const double lastspike = _ptr_array_neurongroup_1_lastspike [_idx]; \\\
bool not_refractory = _ptr_array_neurongroup_1_not_refractory [_idx]; \\\
not_refractory =(t - lastspike)> tr_i; \\\
const double __k_s_ext =(_lio_const_1 * s_ext)/ t_ampa; \\\
const double __k_s_gaba =(_lio_const_1 * s_gaba)/ t_gaba; \\\
const double __k_v =((dt *((((((_lio_const_2 *(_lio_const_3 + v)) - ((G_ext * s_ext)*(_lio_const_3 + v))) - ((G_gaba * s_gaba)*(_lio_const_4 + v))) - (((G_nmda * s_tot_nmda)*( _lio_const_5 + v))/((b * exp(_lio_const_6 * v))+ 1.0))) - (gl_i *(_lio_const_7 + v))))* int_(not_refractory))/ C_m; \\\
const double _s_ext = ((_lio_const_1 *((0.5 * __k_s_ext)+ s_ext))/ t_ampa)+ s_ext; \\\
const double _s_gaba =((_lio_const_1 *((0.5 * __k_s_gaba)+ s_gaba))/ t_gaba)+ s_gaba; \\\
const double _v = v +(((((_lio_const_2 * s_tot_ampa)*((_lio_const_3 +(0.5 * __k_v))+ v)) - ((G_ext *((0.5 * __k_s_ext)+ s_ext) )((G_gaba *((0.5 * _k_s_gaba)+ s_gaba))*((_lio_const_4 +(0.5 * __k_v))+(v *))) - ( (((G_nmda * s_tot_nmda)*((_lio_c (()* /())/((b * exp(_lio_const_6 *((0.5 * __k_v)+ v)))+(1.0 * __k_v) )+ v))))* int_(not_refractory))/ C_m); \ n s_ext = _s_ext; \ n s_gaba = _s_gaba; \\\
if(not_refractory)\\\
v = _v; \\\
_ptr_array_neurongroup_1_s_gaba [_idx ] = s_gaba; \\\
_ptr_array_neurongroup_1_v [_idx] = v; \\\
_ptr_array_neurongroup_1_s_ext [_idx] = s_ext; \\\
_ptr_array_neurongroup_1_not_refractory [_idx] = not_refractory; \\\
\\\
\\\
\t} \\\
\\\
/ * \\\
下面的代码只是编译器选项,用于调用weave.inline.\\\
By在这里包括它们,如果编译器选项发生变化,我们强制重新编译,\ñ这是一件好事(例如切换-ffast-math on和off).\\\
\\\
support_code:\\\
\t\t\\\
int int_(const bool value)\\\
{\ n return value? 1:0; \\\
} \\\
\\\
\\\
\\\
\\\
编译器:\\\
gcc\\\
\\\
extra_compile_args:\\\
[' - w','-O3'] \ n \ ninclude_dirs:\\\
['/ usr / local / anaconda / include'] \\\
* / \\\
,(119808,66)
^
SyntaxError:无效语法

我注意到 inline code> outputs是我运行过的前一个模拟的变量:例如 s_gaba 。 (在调用 inline 时会引发错误,因此不会涉及任何模拟。)是否应该删除某些应该删除的数据存储的问题仍然存在?我怎样才能避免这个错误?

解决方案

我在官方 编织教程。特别是,


我有时使用verbose进行调试。设置为2时,它将输出您希望运行make文件所需的所有信息(包括.cpp文件的名称)。这很好,如果你需要检查生成的代码,看看事情发生了什么。请注意,即使verbose设置为0,编译失败的错误消息也会显示在屏幕上。

下面的示例演示如何在Windows上使用gcc而不是标准msvc编译器与上面相同的代码片段。因为这个例子已经被编译过了,所以需要force = 1标志来使inline()忽略之前编译的版本并使用gcc重新编译。

设置 verbose = 2 force = 1 ,我得到了以下内容:

  In [3]:weave.inline('int x = 0;',[],compiler ='gcc',headers = 

['<算法>','< limits>],extra_compile_args = [' - w','-03 '],verbose = 2,force = 1)
< weave:compiling>
正在创建/ tmp / scipy-dbliss -wzdMj_ / python27_intermediate / compiler_0129f738e3db7528dd918ff316c8b91b
正在运行build_ext
正在运行build_src
build_src
正在建立扩展sc_302644cc5257b9feebbfde0f5856848e1源
build_src:建筑NPY-PKG配置文件
定制UnixCCompiler
UnixCCompiler使用build_ext
定制UnixCCompiler
。使用build_ext
栋 'sc_302644cc5257b9feebbfde0f5856848e1' 扩展
编译C ++源代码定制UnixCCompiler定制
C编译器:g ++ -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -fPIC

创建/ tmp / scipy-dbliss-wzdMj_ / python27_intermediate / compiler_0129f738e3db7528dd918ff316c8b91b /家庭
创建的/ tmp / SciPy的-dbliss-wzdMj_ / python27_intermediate / compiler_0129f738e3db7528dd918ff316c8b91b /家庭/ despo
创建的/ tmp / SciPy的-dbliss-wzdMj_ / python27_intermediate / compiler_0129f738e3db7528dd918ff316c8b91b /家庭/ despo / dbliss
创建/ tmp / scipy-dbliss-wz dMj_ / python27_intermediate / compiler_0129f738e3db7528dd918ff316c8b91b / home / despo / dbliss / .cache
正在创建/tmp/scipy-dbliss-wzdMj_/python27_intermediate/compiler_0129f738e3db7528dd918ff316c8b91b/home/despo/dbliss/.cache/scipy
正在创建/ tmp / scipy-dbliss -wzdMj_ / python27_intermediate / compiler_0129f738e3db7528dd918ff316c8b91b / home / despo / dbliss / .cache / scipy / python27_compiled $ b $创建/ tmp / scipy-dbliss-wzdMj_ / python27_intermediate / compiler_0129f738e3db7528dd918ff316c8b91b / usr
创建/ tmp / scipy -dbliss -wzdMj_ / python27_intermediate / compiler_0129f738e3db7528dd918ff316c8b91b / usr / local
创建/ tmp / scipy -dbliss -wzdMj_ / python27_intermediate / compiler_0129f738e3db7528dd918ff316c8b91b / usr / local / anaconda
创建/ tmp / scipy-dbliss-wzdMj_ / python27_intermediate / compiler_0129f738e3db7528dd918ff316c8b91b / usr / local / anaconda / lib
创建/tmp/scipy-dbliss-wzdMj_/python27_intermediate/compiler_0129f738e3db7528dd918ff316c8b91b/usr/local/anaconda/lib/python2.7
创建/ t mp / scipy-dbliss -wzdMj_ / python27_intermediate / compiler_0129f738e3db7528dd918ff316c8b91b / usr / local / anaconda / lib / python2.7 / site-packages $ b $创建/ tmp / scipy-dbliss -wzdMj_ / python27_intermediate / compiler_0129f738e3db7528dd918ff316c8b91b / usr / local / anaconda /lib/python2.7/site-packages/scipy
创建/tmp/scipy-dbliss-wzdMj_/python27_intermediate/compiler_0129f738e3db7528dd918ff316c8b91b/usr/local/anaconda/lib/python2.7/site-packages/scipy/weave
。建立/tmp/scipy-dbliss-wzdMj_/python27_intermediate/compiler_0129f738e3db7528dd918ff316c8b91b/usr/local/anaconda/lib/python2.7/site-packages/scipy/weave/scxx
编译选项:-I / USR /local/anaconda/lib/python2.7/site-packages/scipy/weave -I / usr / local / anaconda / lib / python2.7 / site-packages / scipy / weave / scxx -I / usr / local / anaconda /lib/python2.7/site-packages/numpy/core/include -I / usr / local / anaconda-1.9.2 / include / python2.7 -c'
extra options:'-w -03'
g ++:/home/despo/dbliss/.cache/scipy/python27_compiled/sc_302644cc52 57b9feebbfde0f5856848e1.cpp
g ++:无法识别的选项'-03'
g ++:/usr/local/anaconda/lib/python2.7/site-packages/scipy/weave/scxx/weave_imp.cpp
g ++:无法识别的选项'-03'
g ++ -pthread -shared /tmp/scipy-dbliss-wzdMj_/python27_intermediate/compiler_0129f738e3db7528dd918ff316c8b91b/home/despo/dbliss/.cache/scipy/python27_compiled/sc_302644cc5257b9feebbfde0f5856848e1.o / tmp / SciPy的-dbliss-wzdMj_ / python27_intermediate / compiler_0129f738e3db7528dd918ff316c8b91b在/ usr /本地/蟒蛇/ lib目录/ python2.7 /站点包/ SciPy的/组织/ scxx / weave_imp.o -L在/ usr /本地/蟒蛇-1.9.2 / lib目录 - lpython2.7 -o /home/despo/dbliss/.cache/scipy/python27_compiled/sc_302644cc5257b9feebbfde0f5856848e1.so
文件< string>,第1行
'\ t\t\t \t //支持代码\\\\\ //静态py :: object_namespace_numpy_rand; \\\
\t //定义BUFFER_SIZE 1024\\\
\t //// rand()函数返回一个随机数。内部////它一次向BUFFER_SIZE \\\
\t // //随机数询问numpy的rand函数,然后从这个返回一个数字\\\
\t //// buffer.\\\
\t ////它需要引用numpy_rand对象(原始numpy \\\
\t ////函数),因为否则它只能在n\t //// compiled_function(其中is自动处理).\\\
\t //// \\\
\t // double _rand(const int _vectorisation_idx){\\\
\ t // // _vectorisation_idx参数现在未被使用,它可以在使用\\\\ // // OpenMP等时使用\\\\ // //原理来获得可重复的随机数。 //静态PyArrayObject * rand_buffer = NULL; \\\
\t // static double * buf_pointer = NULL; \\\
\t // static npy_int curbuffer = 0; \\\
\t / / if(curbuffer == 0)\\\
\t // {\\\
\t // if(rand_buffer)Py_DECREF(rand_buffer); \\ /// py :: tuple args(1); \\\
\t // args [0] = BUFFER_SIZE; \\\
\t // rand_buffer =(PyArrayObject *)PyArray_FromAny(_namespace_numpy_rand.call args),\\\
\t // NULL,1,1,0,NULL); \\\
\t // buf_pointer =(double *)PyArray_GETPTR1(rand_buffer,0); \\\
\t / /} \\\
\t // double number = buf_pointer [curbuffer]; \\\
\t // curbuffer = curbuffer + 1; \\\
\t // if(curbuffer == BUFFER_SIZE)\\\
\t // //使用(curbuffer + 1)%BUFFER_SIZE似乎更安全,我们可能会碰到\\\
\t // //大网络的整数溢出,否则。\\\ t // curbuffer = 0; \\\
\t //返回数字; \\\
\t //} \\\
\\\
\\\
\t\t\t //// HANDLE DORMORMALS //// \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ n\\\
\t\t \\ t //// POINTERS //// \ n\tint * __restrict _ptr_array_synapses_4_N_incoming = _array_synapses_4_N_incoming; \\\
\tint * __restrict _ptr_array_poissongroup_i = _array_poissongroup_i; \\\
\tint * __restrict _ptr_array_neurongroup_i = _array_neurongroup_i; \\\
\tint * __restrict _ptr_array_synapses_4__synaptic_post = _array_synapses_4__synaptic_post; \\\
\tint * __restrict _ptr_array_synapses_4_N_outgoing = _array_synapses_4_N_outgoing; \\\
\tint * __restrict _ptr_array_synapses_4__synaptic_pre = _array_synapses_4__synaptic_pre; \\\
\t_namespace_numpy_rand = _numpy_rand; \\\
\\\
\ n == srand((unsigned int)time(NULL)); \\\
const int _buffer_size = 1024; \\\
int * const _prebuf = new int [_buffer_size]; \\\
int * const _postbuf = new int [ _buffer_size]; \\\
int * const _synprebuf = new int [1]; \\\
int * const _synpostbuf = new int [1]; \\\
int _curbuf = 0; \\\
\\\
//标量代码\\ n\tconst intrray_neurongroup_1_s_ext; \\\
\tdouble * __restrict _ptr_array_neurongroup_1_s_gaba = _array_neurongroup_1_s_gaba; \\\
\tdouble * __restrict _ptr_array_neurongroup_1_v = _array_neurongroup_1_v; \\\
\tdouble * __restrict _ptr_array_neurongroup_1_s_tot_ampa = _array_neurongroup_1_s_tot_ampa; \\\
\\\
\主要代码//////////// \\ n\\\
\t //标量代码\\\
\tconst int _vectorisation_idx = 1; \\ n \\ n \ t\\\
const double _lio_const_1 = - dt; \\\
const double _lio_const_2 = - G_ampa; \\\
const double _lio_const_3 = - E_ampa; \\\
const double _lio_const_4 = - E_gaba; \\\
const double _lio_const_5 = - E_nmda; \\\
const double _lio_const_6 = - a; \\\
const double _lio_const_7 = - El_i; \\\
\\\
\\\
\tfor(int _idx = 0; _idx< N; _idx ++)\\\
\t {\\\
\t // vector code\\\
\t\tconst int _vectorisation_idx = _idx; \\\
\t\t \\\
const double s_tot_ampa = _ptr_array_neurongroup_1_s_tot_ampa [_idx]; \\\
double s_ext = _ptr_array_neurongroup_1_s_ext [_idx]; \\\
double s_gaba = _ptr_array_neurongroup_1_s_gaba [_idx]; \\\
const double s_tot_nmda = _ptr_array_neurongroup_1_s_tot_nmda [_idx]; \\\
double v = _ptr_array_neurongroup_1_v [_idx];; \\ n const double lastspike = _ptr_array_neurongroup_1_lastspike [_idx]; \\\
bool not_refractory = _ptr_array_neurongroup_1_not_refractory [_idx]; \\\
not_refractory =(t - lastspike)> tr_i; \\\
const double __k_s_ext =(_lio_const_1 * s_ext)/ t_ampa; \\\
const double __k_s_gaba =(_lio_const_1 * s_gaba)/ t_gaba; \\\
const double __k_v =((dt *((((((_lio_const_2 *(_lio_const_3 + v)) - ((G_ext * s_ext)*(_lio_const_3 + v))) - ((G_gaba * s_gaba)*(_lio_const_4 + v))) - (((G_nmda * s_tot_nmda)*( _lio_const_5 + v))/((b * exp(_lio_const_6 * v))+ 1.0))) - (gl_i *(_lio_const_7 + v))))* int_(not_refractory))/ C_m; \\\
const double _s_ext = ((_lio_const_1 *((0.5 * __k_s_ext)+ s_ext))/ t_ampa)+ s_ext; \\\
const double _s_gaba =((_lio_const_1 *((0.5 * __k_s_gaba)+ s_gaba))/ t_gaba)+ s_gaba; \\\
const double _v = v +(((((_lio_const_2 * s_tot_ampa)*((_lio_const_3 +(0.5 * __k_v))+ v)) - ((G_ext *((0.5 * __k_s_ext)+ s_ext) )((G_gaba *((0.5 * _k_s_gaba)+ s_gaba))*((_lio_const_4 +(0.5 * __k_v))+(v *))) - ( (((G_nmda * s_tot_nmda)*((_lio_c (()* /())/((b * exp(_lio_const_6 *((0.5 * __k_v)+ v)))+(1.0 * __k_v) )+ v))))* int_(not_refractory))/ C_m); \ n s_ext = _s_ext; \ n s_gaba = _s_gaba; \\\
if(not_refractory)\\\
v = _v; \\\
_ptr_array_neurongroup_1_s_gaba [_idx ] = s_gaba; \\\
_ptr_array_neurongroup_1_v [_idx] = v; \\\
_ptr_array_neurongroup_1_s_ext [_idx] = s_ext; \\\
_ptr_array_neurongroup_1_not_refractory [_idx] = not_refractory; \\\
\\\
\\\
\t} \\\
\\\
/ * \\\
下面的代码只是编译器选项,用于调用weave.inline.\\\
By在这里包括它们,如果编译器选项发生变化,我们强制重新编译,\ñ这是一件好事(例如切换-ffast-math on和off).\\\
\\\
support_code:\\\
\t\t\\\
int int_(const bool value)\\\
{\ n return value? 1:0; \\\
} \\\
\\\
\\\
\\\
\\\
编译器:\\\
gcc\\\
\\\
extra_compile_args:\\\
[' - w','-O3'] \ n \ ninclude_dirs:\\\
['/ usr / local / anaconda / include'] \\\
* / \\\
,(119808,66)
^
SyntaxError:无效的语法

我在这里跳出的是在我的主目录中存在一个缓存: /home/despo/dbliss/.cache/scipy/python27_compiled/sc_302644cc5257b9feebbfde0f5856848e1.cpp



删除此内容缓存 - 即 $ rm -r〜/ .cache / scipy - 解决了这个问题。不再有 SyntaxError


I recently upgraded to the newest version of brian2, and began to see the following warning when running neural simulations:

WARNING  brian2.codegen.runtime.weave_rt.weave_rt.failed_compile_test: Cannot use weave, a test compilation failed: invalid syntax (<string>, line 1) (SyntaxError)

After some digging, I found that this warning is due to an error raised by these lines in one of brian2's modules:

compiler, extra_compile_args = get_compiler_and_args()
weave.inline('int x=0;', [],
             compiler=compiler,
             headers=['<algorithm>', '<limits>'],
             extra_compile_args=extra_compile_args,
             verbose=0)

Running this code, I get the following:

In [11]: from scipy import weave

In [12]: compiler
Out[12]: 'gcc'

In [13]: extra_compile_args 
Out[13]: ['-w', '-O3']

In [14]: weave.inline('int x=0;', [], compiler=compiler, headers=['<algorithm>', '<limits>'], extra_compile_args=extra_compile_args, verbose=0)
  File "<string>", line 1
    '\t\t\t\t// SUPPORT CODE\n\t//static py::object _namespace_numpy_rand;\n\t//#define BUFFER_SIZE 1024\n\t//// A rand() function that returns a single random number. Internally\n\t//// it asks numpy\'s rand function for BUFFER_SIZE\n\t//// random numbers at a time and then returns one number from this\n\t//// buffer.\n\t//// It needs a reference to the numpy_rand object (the original numpy\n\t//// function), because this is otherwise only available in\n\t//// compiled_function (where is is automatically handled by weave).\n\t////\n\t//double _rand(const int _vectorisation_idx) {\n\t//    // the _vectorisation_idx argument is unused for now, it could in\n\t//    // principle be used to get reproducible random numbers when using\n\t//    // OpenMP etc.\n\t//    static PyArrayObject *rand_buffer = NULL;\n\t//    static double *buf_pointer = NULL;\n\t//    static npy_int curbuffer = 0;\n\t//    if(curbuffer==0)\n\t//    {\n\t//        if(rand_buffer) Py_DECREF(rand_buffer);\n\t//        py::tuple args(1);\n\t//        args[0] = BUFFER_SIZE;\n\t//        rand_buffer = (PyArrayObject *)PyArray_FromAny(_namespace_numpy_rand.call(args),\n\t//                                                       NULL, 1, 1, 0, NULL);\n\t//        buf_pointer = (double*)PyArray_GETPTR1(rand_buffer, 0);\n\t//    }\n\t//    double number = buf_pointer[curbuffer];\n\t//    curbuffer = curbuffer+1;\n\t//    if (curbuffer == BUFFER_SIZE)\n\t//        // This seems to be safer then using (curbuffer + 1) % BUFFER_SIZE, we might run into\n\t//        // an integer overflow for big networks, otherwise.\n\t//        curbuffer = 0;\n\t//    return number;\n\t//}\n\n\n\t\t\t//// HANDLE DENORMALS ////\n\t\n\n\n\t\t\t//// HASH DEFINES ////\n\t\n\n\n\t\t\t//// POINTERS ////\n\tint* __restrict  _ptr_array_synapses_4_N_incoming = _array_synapses_4_N_incoming;\n\tint* __restrict  _ptr_array_poissongroup_i = _array_poissongroup_i;\n\tint* __restrict  _ptr_array_neurongroup_i = _array_neurongroup_i;\n\tint* __restrict  _ptr_array_synapses_4__synaptic_post = _array_synapses_4__synaptic_post;\n\tint* __restrict  _ptr_array_synapses_4_N_outgoing = _array_synapses_4_N_outgoing;\n\tint* __restrict  _ptr_array_synapses_4__synaptic_pre = _array_synapses_4__synaptic_pre;\n\t_namespace_numpy_rand = _numpy_rand;\n\n\n\n    srand((unsigned int)time(NULL));\n    const int _buffer_size = 1024;\n    int *const _prebuf = new int[_buffer_size];\n    int *const _postbuf = new int[_buffer_size];\n    int *const _synprebuf = new int[1];\n    int *const _synpostbuf = new int[1];\n    int _curbuf = 0;\n\n    // scalar code\n\tconst intrray_neurongroup_1_s_ext;\n\tdouble* __restrict  _ptr_array_neurongroup_1_s_gaba = _array_neurongroup_1_s_gaba;\n\tdouble* __restrict  _ptr_array_neurongroup_1_v = _array_neurongroup_1_v;\n\tdouble* __restrict  _ptr_array_neurongroup_1_s_tot_ampa = _array_neurongroup_1_s_tot_ampa;\n\n\n\n\t//// MAIN CODE ////////////\n\n\t// scalar code\n\tconst int _vectorisation_idx = 1;\n \t\n const double _lio_const_1 = - dt;\n const double _lio_const_2 = - G_ampa;\n const double _lio_const_3 = - E_ampa;\n const double _lio_const_4 = - E_gaba;\n const double _lio_const_5 = - E_nmda;\n const double _lio_const_6 = - a;\n const double _lio_const_7 = - El_i;\n\n\n\tfor(int _idx=0; _idx<N; _idx++)\n\t{\n\t    // vector code\n\t\tconst int _vectorisation_idx = _idx;\n      \t\t    \n      const double s_tot_ampa = _ptr_array_neurongroup_1_s_tot_ampa[_idx];\n      double s_ext = _ptr_array_neurongroup_1_s_ext[_idx];\n      double s_gaba = _ptr_array_neurongroup_1_s_gaba[_idx];\n      const double s_tot_nmda = _ptr_array_neurongroup_1_s_tot_nmda[_idx];\n      double v = _ptr_array_neurongroup_1_v[_idx];\n      const double lastspike = _ptr_array_neurongroup_1_lastspike[_idx];\n      bool not_refractory = _ptr_array_neurongroup_1_not_refractory[_idx];\n      not_refractory = (t - lastspike) > tr_i;\n      const double __k_s_ext = (_lio_const_1 * s_ext) / t_ampa;\n      const double __k_s_gaba = (_lio_const_1 * s_gaba) / t_gaba;\n      const double __k_v = ((dt * ((((((_lio_const_2 * s_tot_ampa) * (_lio_const_3 + v)) - ((G_ext * s_ext) * (_lio_const_3 + v))) - ((G_gaba * s_gaba) * (_lio_const_4 + v))) - (((G_nmda * s_tot_nmda) * (_lio_const_5 + v)) / ((b * exp(_lio_const_6 * v)) + 1.0))) - (gl_i * (_lio_const_7 + v)))) * int_(not_refractory)) / C_m;\n      const double _s_ext = ((_lio_const_1 * ((0.5 * __k_s_ext) + s_ext)) / t_ampa) + s_ext;\n      const double _s_gaba = ((_lio_const_1 * ((0.5 * __k_s_gaba) + s_gaba)) / t_gaba) + s_gaba;\n      const double _v = v + (((dt * ((((((_lio_const_2 * s_tot_ampa) * ((_lio_const_3 + (0.5 * __k_v)) + v)) - ((G_ext * ((0.5 * __k_s_ext) + s_ext)) * ((_lio_const_3 + (0.5 * __k_v)) + v))) - ((G_gaba * ((0.5 * __k_s_gaba) + s_gaba)) * ((_lio_const_4 + (0.5 * __k_v)) + v))) - (((G_nmda * s_tot_nmda) * ((_lio_const_5 + (0.5 * __k_v)) + v)) / ((b * exp(_lio_const_6 * ((0.5 * __k_v) + v))) + 1.0))) - (gl_i * ((_lio_const_7 + (0.5 * __k_v)) + v)))) * int_(not_refractory)) / C_m);\n      s_ext = _s_ext;\n      s_gaba = _s_gaba;\n      if(not_refractory)\n          v = _v;\n      _ptr_array_neurongroup_1_s_gaba[_idx] = s_gaba;\n      _ptr_array_neurongroup_1_v[_idx] = v;\n      _ptr_array_neurongroup_1_s_ext[_idx] = s_ext;\n      _ptr_array_neurongroup_1_not_refractory[_idx] = not_refractory;\n\n\n\t}\n\n/*\nThe following code is just compiler options for the call to weave.inline.\nBy including them here, we force a recompile if the compiler options change,\nwhich is a good thing (e.g. switching -ffast-math on and off).\n\nsupport_code:\n  \t\t\n  int int_(const bool value)\n  {\n      return value ? 1 : 0;\n  }\n\n\n\n\ncompiler:\ngcc\n\nextra_compile_args:\n['-w', '-O3']\n\ninclude_dirs:\n['/usr/local/anaconda/include']\n*/\n        ", (119808, 66)
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    ^
SyntaxError: invalid syntax

What I notice in that crazy string that inline outputs are variables from a previous simulation I've run: e.g., s_gaba. (No simulation is involved in the call to inline that raises the error.) Is the problem that some store of these data that should have been deleted is still hanging around? How might I avoid this error?

解决方案

I found some tips in the official weave tutorial. Specifically,

I use verbose sometimes for debugging. When set to 2, it’ll output all the information (including the name of the .cpp file) that you’d expect from running a make file. This is nice if you need to examine the generated code to see where things are going haywire. Note that error messages from failed compiles are printed to the screen even if verbose is set to 0.

The following example demonstrates using gcc instead of the standard msvc compiler on windows using same code fragment as above. Because the example has already been compiled, the force=1 flag is needed to make inline() ignore the previously compiled version and recompile using gcc.

Setting verbose=2 and force=1, I got the following:

In [3]: weave.inline('int x=0;', [], compiler='gcc', headers=

['<algorithm>', '<limits>'], extra_compile_args=['-w', '-03'], verbose=2, force=1)
<weave: compiling>
creating /tmp/scipy-dbliss-wzdMj_/python27_intermediate/compiler_0129f738e3db7528dd918ff316c8b91b
running build_ext
running build_src
build_src
building extension "sc_302644cc5257b9feebbfde0f5856848e1" sources
build_src: building npy-pkg config files
customize UnixCCompiler
customize UnixCCompiler using build_ext
customize UnixCCompiler
customize UnixCCompiler using build_ext
building 'sc_302644cc5257b9feebbfde0f5856848e1' extension
compiling C++ sources
C compiler: g++ -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -fPIC

creating /tmp/scipy-dbliss-wzdMj_/python27_intermediate/compiler_0129f738e3db7528dd918ff316c8b91b/home
creating /tmp/scipy-dbliss-wzdMj_/python27_intermediate/compiler_0129f738e3db7528dd918ff316c8b91b/home/despo
creating /tmp/scipy-dbliss-wzdMj_/python27_intermediate/compiler_0129f738e3db7528dd918ff316c8b91b/home/despo/dbliss
creating /tmp/scipy-dbliss-wzdMj_/python27_intermediate/compiler_0129f738e3db7528dd918ff316c8b91b/home/despo/dbliss/.cache
creating /tmp/scipy-dbliss-wzdMj_/python27_intermediate/compiler_0129f738e3db7528dd918ff316c8b91b/home/despo/dbliss/.cache/scipy
creating /tmp/scipy-dbliss-wzdMj_/python27_intermediate/compiler_0129f738e3db7528dd918ff316c8b91b/home/despo/dbliss/.cache/scipy/python27_compiled
creating /tmp/scipy-dbliss-wzdMj_/python27_intermediate/compiler_0129f738e3db7528dd918ff316c8b91b/usr
creating /tmp/scipy-dbliss-wzdMj_/python27_intermediate/compiler_0129f738e3db7528dd918ff316c8b91b/usr/local
creating /tmp/scipy-dbliss-wzdMj_/python27_intermediate/compiler_0129f738e3db7528dd918ff316c8b91b/usr/local/anaconda
creating /tmp/scipy-dbliss-wzdMj_/python27_intermediate/compiler_0129f738e3db7528dd918ff316c8b91b/usr/local/anaconda/lib
creating /tmp/scipy-dbliss-wzdMj_/python27_intermediate/compiler_0129f738e3db7528dd918ff316c8b91b/usr/local/anaconda/lib/python2.7
creating /tmp/scipy-dbliss-wzdMj_/python27_intermediate/compiler_0129f738e3db7528dd918ff316c8b91b/usr/local/anaconda/lib/python2.7/site-packages
creating /tmp/scipy-dbliss-wzdMj_/python27_intermediate/compiler_0129f738e3db7528dd918ff316c8b91b/usr/local/anaconda/lib/python2.7/site-packages/scipy
creating /tmp/scipy-dbliss-wzdMj_/python27_intermediate/compiler_0129f738e3db7528dd918ff316c8b91b/usr/local/anaconda/lib/python2.7/site-packages/scipy/weave
creating /tmp/scipy-dbliss-wzdMj_/python27_intermediate/compiler_0129f738e3db7528dd918ff316c8b91b/usr/local/anaconda/lib/python2.7/site-packages/scipy/weave/scxx
compile options: '-I/usr/local/anaconda/lib/python2.7/site-packages/scipy/weave -I/usr/local/anaconda/lib/python2.7/site-packages/scipy/weave/scxx -I/usr/local/anaconda/lib/python2.7/site-packages/numpy/core/include -I/usr/local/anaconda-1.9.2/include/python2.7 -c'
extra options: '-w -03'
g++: /home/despo/dbliss/.cache/scipy/python27_compiled/sc_302644cc5257b9feebbfde0f5856848e1.cpp
g++: unrecognized option '-03'
g++: /usr/local/anaconda/lib/python2.7/site-packages/scipy/weave/scxx/weave_imp.cpp
g++: unrecognized option '-03'
g++ -pthread -shared /tmp/scipy-dbliss-wzdMj_/python27_intermediate/compiler_0129f738e3db7528dd918ff316c8b91b/home/despo/dbliss/.cache/scipy/python27_compiled/sc_302644cc5257b9feebbfde0f5856848e1.o /tmp/scipy-dbliss-wzdMj_/python27_intermediate/compiler_0129f738e3db7528dd918ff316c8b91b/usr/local/anaconda/lib/python2.7/site-packages/scipy/weave/scxx/weave_imp.o -L/usr/local/anaconda-1.9.2/lib -lpython2.7 -o /home/despo/dbliss/.cache/scipy/python27_compiled/sc_302644cc5257b9feebbfde0f5856848e1.so
  File "<string>", line 1
    '\t\t\t\t// SUPPORT CODE\n\t//static py::object _namespace_numpy_rand;\n\t//#define BUFFER_SIZE 1024\n\t//// A rand() function that returns a single random number. Internally\n\t//// it asks numpy\'s rand function for BUFFER_SIZE\n\t//// random numbers at a time and then returns one number from this\n\t//// buffer.\n\t//// It needs a reference to the numpy_rand object (the original numpy\n\t//// function), because this is otherwise only available in\n\t//// compiled_function (where is is automatically handled by weave).\n\t////\n\t//double _rand(const int _vectorisation_idx) {\n\t//    // the _vectorisation_idx argument is unused for now, it could in\n\t//    // principle be used to get reproducible random numbers when using\n\t//    // OpenMP etc.\n\t//    static PyArrayObject *rand_buffer = NULL;\n\t//    static double *buf_pointer = NULL;\n\t//    static npy_int curbuffer = 0;\n\t//    if(curbuffer==0)\n\t//    {\n\t//        if(rand_buffer) Py_DECREF(rand_buffer);\n\t//        py::tuple args(1);\n\t//        args[0] = BUFFER_SIZE;\n\t//        rand_buffer = (PyArrayObject *)PyArray_FromAny(_namespace_numpy_rand.call(args),\n\t//                                                       NULL, 1, 1, 0, NULL);\n\t//        buf_pointer = (double*)PyArray_GETPTR1(rand_buffer, 0);\n\t//    }\n\t//    double number = buf_pointer[curbuffer];\n\t//    curbuffer = curbuffer+1;\n\t//    if (curbuffer == BUFFER_SIZE)\n\t//        // This seems to be safer then using (curbuffer + 1) % BUFFER_SIZE, we might run into\n\t//        // an integer overflow for big networks, otherwise.\n\t//        curbuffer = 0;\n\t//    return number;\n\t//}\n\n\n\t\t\t//// HANDLE DENORMALS ////\n\t\n\n\n\t\t\t//// HASH DEFINES ////\n\t\n\n\n\t\t\t//// POINTERS ////\n\tint* __restrict  _ptr_array_synapses_4_N_incoming = _array_synapses_4_N_incoming;\n\tint* __restrict  _ptr_array_poissongroup_i = _array_poissongroup_i;\n\tint* __restrict  _ptr_array_neurongroup_i = _array_neurongroup_i;\n\tint* __restrict  _ptr_array_synapses_4__synaptic_post = _array_synapses_4__synaptic_post;\n\tint* __restrict  _ptr_array_synapses_4_N_outgoing = _array_synapses_4_N_outgoing;\n\tint* __restrict  _ptr_array_synapses_4__synaptic_pre = _array_synapses_4__synaptic_pre;\n\t_namespace_numpy_rand = _numpy_rand;\n\n\n\n    srand((unsigned int)time(NULL));\n    const int _buffer_size = 1024;\n    int *const _prebuf = new int[_buffer_size];\n    int *const _postbuf = new int[_buffer_size];\n    int *const _synprebuf = new int[1];\n    int *const _synpostbuf = new int[1];\n    int _curbuf = 0;\n\n    // scalar code\n\tconst intrray_neurongroup_1_s_ext;\n\tdouble* __restrict  _ptr_array_neurongroup_1_s_gaba = _array_neurongroup_1_s_gaba;\n\tdouble* __restrict  _ptr_array_neurongroup_1_v = _array_neurongroup_1_v;\n\tdouble* __restrict  _ptr_array_neurongroup_1_s_tot_ampa = _array_neurongroup_1_s_tot_ampa;\n\n\n\n\t//// MAIN CODE ////////////\n\n\t// scalar code\n\tconst int _vectorisation_idx = 1;\n \t\n const double _lio_const_1 = - dt;\n const double _lio_const_2 = - G_ampa;\n const double _lio_const_3 = - E_ampa;\n const double _lio_const_4 = - E_gaba;\n const double _lio_const_5 = - E_nmda;\n const double _lio_const_6 = - a;\n const double _lio_const_7 = - El_i;\n\n\n\tfor(int _idx=0; _idx<N; _idx++)\n\t{\n\t    // vector code\n\t\tconst int _vectorisation_idx = _idx;\n      \t\t    \n      const double s_tot_ampa = _ptr_array_neurongroup_1_s_tot_ampa[_idx];\n      double s_ext = _ptr_array_neurongroup_1_s_ext[_idx];\n      double s_gaba = _ptr_array_neurongroup_1_s_gaba[_idx];\n      const double s_tot_nmda = _ptr_array_neurongroup_1_s_tot_nmda[_idx];\n      double v = _ptr_array_neurongroup_1_v[_idx];\n      const double lastspike = _ptr_array_neurongroup_1_lastspike[_idx];\n      bool not_refractory = _ptr_array_neurongroup_1_not_refractory[_idx];\n      not_refractory = (t - lastspike) > tr_i;\n      const double __k_s_ext = (_lio_const_1 * s_ext) / t_ampa;\n      const double __k_s_gaba = (_lio_const_1 * s_gaba) / t_gaba;\n      const double __k_v = ((dt * ((((((_lio_const_2 * s_tot_ampa) * (_lio_const_3 + v)) - ((G_ext * s_ext) * (_lio_const_3 + v))) - ((G_gaba * s_gaba) * (_lio_const_4 + v))) - (((G_nmda * s_tot_nmda) * (_lio_const_5 + v)) / ((b * exp(_lio_const_6 * v)) + 1.0))) - (gl_i * (_lio_const_7 + v)))) * int_(not_refractory)) / C_m;\n      const double _s_ext = ((_lio_const_1 * ((0.5 * __k_s_ext) + s_ext)) / t_ampa) + s_ext;\n      const double _s_gaba = ((_lio_const_1 * ((0.5 * __k_s_gaba) + s_gaba)) / t_gaba) + s_gaba;\n      const double _v = v + (((dt * ((((((_lio_const_2 * s_tot_ampa) * ((_lio_const_3 + (0.5 * __k_v)) + v)) - ((G_ext * ((0.5 * __k_s_ext) + s_ext)) * ((_lio_const_3 + (0.5 * __k_v)) + v))) - ((G_gaba * ((0.5 * __k_s_gaba) + s_gaba)) * ((_lio_const_4 + (0.5 * __k_v)) + v))) - (((G_nmda * s_tot_nmda) * ((_lio_const_5 + (0.5 * __k_v)) + v)) / ((b * exp(_lio_const_6 * ((0.5 * __k_v) + v))) + 1.0))) - (gl_i * ((_lio_const_7 + (0.5 * __k_v)) + v)))) * int_(not_refractory)) / C_m);\n      s_ext = _s_ext;\n      s_gaba = _s_gaba;\n      if(not_refractory)\n          v = _v;\n      _ptr_array_neurongroup_1_s_gaba[_idx] = s_gaba;\n      _ptr_array_neurongroup_1_v[_idx] = v;\n      _ptr_array_neurongroup_1_s_ext[_idx] = s_ext;\n      _ptr_array_neurongroup_1_not_refractory[_idx] = not_refractory;\n\n\n\t}\n\n/*\nThe following code is just compiler options for the call to weave.inline.\nBy including them here, we force a recompile if the compiler options change,\nwhich is a good thing (e.g. switching -ffast-math on and off).\n\nsupport_code:\n  \t\t\n  int int_(const bool value)\n  {\n      return value ? 1 : 0;\n  }\n\n\n\n\ncompiler:\ngcc\n\nextra_compile_args:\n['-w', '-O3']\n\ninclude_dirs:\n['/usr/local/anaconda/include']\n*/\n        ", (119808, 66)
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    ^
SyntaxError: invalid syntax

What jumps out at me here is the existence of a cache in my home directory: /home/despo/dbliss/.cache/scipy/python27_compiled/sc_302644cc5257b9feebbfde0f5856848e1.cpp.

Removing everything in this cache -- i.e., $ rm -r ~/.cache/scipy -- resolves the issue. No more SyntaxError!

这篇关于带有scipy.weave.inline的SyntaxError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆