Cython C ++ shell operator overload error ()

Linked to my previous question. Using Cython to port a C ++ class using OpenCV types as parameters

Now I am stuck with another error. My cython shell code like OpenCV Matx33d looks like this:

cdef extern from "opencv2/core/core.hpp" namespace "cv":
    cdef cppclass Matx33d "cv::Matx<double, 3, 3>":
        Matx33d()
        Matx33d(double v0, double v1, double v2, double v3, double v4, double v5, double v6, double v7, double v8)
        double& operator()(int i, int j)

      

Then I define a function to copy Matx33d into a numpy array.

cdef Matx33d2numpy(Matx33d &m):
    cdef np.ndarray[np.double_t, ndim=2] np_m = np.empty((3,3), dtype=np.float64)  
    np_m[0,0]= m(0,0); np_m[0,1]= m(0,1); np_m[0,2]= m(0,2)
    np_m[1,0]= m(1,0); np_m[1,1]= m(1,1); np_m[1,2]= m(1,2)
    np_m[2,0]= m(2,0); np_m[2,1]= m(2,1); np_m[2,2]= m(2,2)    
    return np_m

      

When I compile the cython shell I get this error

geom_gateway.cpp(2528) error C3861: '()': identifier not found

      

This corresponds to the first use of Matx33d :: operator (), which is when accessing m (0,0) in the code above. If I look at the generated line 2528 geom_gateway.cpp I get:

  *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_pybuffernd_np_m.rcbuffer->pybuffer.buf, __pyx_t_6, __pyx_pybuffernd_np_m.diminfo[0].strides, __pyx_t_7, __pyx_pybuffernd_np_m.diminfo[1].strides) = operator()(0, 0);

      

I don't understand that this operator () (0, 0) is there alone at the end of the line without any object !! How is this possible? Is this a Cython bug? or is the syntax I'm using for the () operator wrong? Any help is appreciated!

+2


source to share


1 answer


Ok, I don't know why this error happened, to me it looks like the syntax

double& operator()(int i, int j)

      

should work, but it doesn't. This syntax works for other operators like +, -, /, *



An alternative syntax that works is the following:

double& get "operator()"(int i, int j)

      

then in cython code when we want to use operator () (i, j) we will call get (i, j) instead

+7


source







All Articles