c++ template trouble

13 views
Skip to first unread message

Bayle Shanks

unread,
Feb 11, 2012, 8:03:14 PM2/11/12
to cython-users
Hello all,

i'm having trouble compiling https://github.com/bshanks/kf . The exact
error message is at the bottom of that webpage (at the bottom of the
README). In summary,

1) The C++ code i am wrapping is used like this:

KF<> kf;
vector<double> x(1);
x(0) = 1.0;
kf(0.0, x);

The template parameter is a size_t of the vector, e.g. for a length
2 vector:

KF<2> kf(.999, vector<double>(2, .999));

2) Here's an excerpt from the underlying C++ code (written by Max
Dama, not by me):


template <std::size_t p = 1>
class KF
{
public:
KF(double beta = .99, const vector<double>& Delta = vector<double>
(p, .99))

3) Here's an excerpt from my Cython wrapper (the whole thing can be
found at https://github.com/bshanks/kf ):

cdef extern from "kf.cpp":
cdef cppclass KF[size_t]:
KF(double, vector[double])

cdef class PyKf:
cdef KF[size_t] *kf

def __cinit__(self, double beta = 0.99, delta = [.99]):
cdef vector[double] delta_vec

for i in range(len(delta)):
delta_vec.push_back(delta[i])
self.kf = new KF(beta, delta_vec)


4) Here's an excerpt from the error message:

PyKf.cpp:318:12: error: type/value mismatch at argument 1 in
template parameter list for ‘template<long unsigned int p> class KF’
PyKf.cpp:318:12: error: expected a constant of type ‘long unsigned
int’, got ‘size_t {aka long unsigned int}’

thanks,
bayle
Reply all
Reply to author
Forward
0 new messages