小编use*_*720的帖子

导出函数时boost python模板参数推导/替换失败

我正在尝试将两个重载函数导出到 Python。因此,我首先定义指向这些函数的指针,然后使用它们将函数公开给 Python。

BOOST_PYTHON_MODULE(mylib){

    // First define pointers to overloaded function
    double (*expt_pseudopot02_v1)(double,double,double,const VECTOR&,
                                  int,int,int,double,const VECTOR&,
                                  int,int,int,double,const VECTOR& ) = &pseudopot02;

    boost::python::list (*expt_pseudopot02_v2)(double, double, double, const VECTOR&,
                            int,int,int,double, const VECTOR&,
                            int,int,int,double, const VECTOR&,  int, int ) = &pseudopot02;

    // Now export 
    def("pseudopot02", expt_pseudopot02_v1); // this works fine!
    //def("pseudopot02", expt_pseudopot02_v2); // this one gives the problem!

}
Run Code Online (Sandbox Code Playgroud)

第一个导出功能工作正常。第二个(目前评论)失败,给出错误:

template argument deduction/substitution failed
Run Code Online (Sandbox Code Playgroud)

它还打印了这个解释:

...../boost_1_50_0/boost/python/make_function.hpp:104:59: note:   mismatched types ‘RT (ClassT::*)(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, …
Run Code Online (Sandbox Code Playgroud)

c++ python boost boost-python

2
推荐指数
1
解决办法
857
查看次数

为什么内存访问速度如此之慢?

我有一个非常奇怪的性能问题,与访问内存有关.代码段是:

#include <vector>
using namespace std;

vector<int> arrx(M,-1); 
vector< vector<int> > arr(N,arrx);

...
for(i=0;i<N;i++){
  for(j=0;j<M;j++){
    //>>>>>>>>>>>> Part 1 <<<<<<<<<<<<<<
    // Simple arithmetic operations
    int n1 = 1 + 2;  // does not matter what (actually more complicated)
    // Integer assignment, without access to array
    int n2 = n1;

    //>>>>>>>>>>>> Part 2 <<<<<<<<<<<<<<
    // This turns out to be most expensive part
    arr[i][j] = n1;
  }
}
Run Code Online (Sandbox Code Playgroud)

N和M - 是一些大约1000 - 10000左右的常数.当我编译此代码(发布版本)时,如果第2部分被评论,则需要大约15个时钟才能完成.使用这部分,执行时间可达100多个时钟,因此几乎慢了10倍.我期望赋值操作比简单的算术运算便宜得多.如果我们不使用数组,这实际上是正确的.但是使用该阵列,分配似乎要贵得多.我也尝试过1-D阵列而不是2-D - 相同的结果(对于2D显然更慢).我也使用int**或int*而不是vector <vector <int >>>或vector <int> - 结果再次相同.

为什么我在数组赋值中表现不佳,我可以修复它吗? …

c++ memory arrays performance vector

1
推荐指数
2
解决办法
1510
查看次数

标签 统计

c++ ×2

arrays ×1

boost ×1

boost-python ×1

memory ×1

performance ×1

python ×1

vector ×1