0

I am doing a project that needs this library (pylibol). link: https://github.com/billhhh/pylibol. When i build setup.py,it shows C method 'get_weight' not previously declared in definition part of extension type 'SOL'.

> Error compiling Cython file:
> ------------------------------------------------------------ ...
>         dict: mapping of string to string
>         """
>         params = dict()
>         sol_GetModelParameters(self._c_model, get_parameter, <void*>params)
>         return params
>     cpdef np.ndarray[float, ndim=1, mode="c"] get_weight(self, cls_id=0):
>          ^
> ------------------------------------------------------------
> 
> python/pysol.pyx:141:10: C method 'get_weight' not previously declared
> in definition part of extension type 'SOL'

The problem is happened in pysol.pyx. So i checked pysol.pyx and add cdef get_weight in pysol.pdx.

pysol.pyx:

def get_params(self):
        """Get Model Parameters

        Returns
        -------
        dict: mapping of string to string
        """
        params = dict()
        sol_GetModelParameters(self._c_model, get_parameter, <void*>params)
        return params
    cpdef np.ndarray[float, ndim=1, mode="c"] get_weight(self, cls_id=0):
        """Get Model Weight,
        input cls_id: the id of classifier, in range 0 to cls_num-1
        output an numpy array of classifier for the cls_id 's class.
        for binary classifier, cls_id is 0 and cls_num=1
        """
        d=sol_Getw_dime(self._c_model, cls_id)
        cdef np.ndarray[float, ndim=1, mode="c"] w = np.zeros((d,),dtype=np.float32)
        sol_Getw(self._c_model, cls_id,&w[0])
        return w

pysol.pdx:

cdef class SOL:
    cdef void* _c_model
    cdef void* _c_data_iter
    cdef const char* algo
    cdef int class_num
    cdef bint verbose
    cdef get_weight

But this is happened:

AttributeError: 'PyObjectType' object has no attribute 'exception_check'

any idea why this happened? I'm working on ubuntu and using python 2.7.

0

1 Answer 1

1

The easiest way to proceed would probably be to go back to a 2017 version of Cython. It looks like it was originally built in with Cython 0.25.2.


If you don't want to do that then you need to look at the lines you're adding:

cdef get_weight

says that the class has an attribute called get_weight which is typed as a Python object (by default). Instead you want to match the function signature of get_weight

cpdef np.ndarray[float, ndim=1, mode="c"] get_weight(self, cls_id=0)

(I can't remember exactly what you do with default arguments off the top of my head - you may need to remove the =0 from the .pyx file).


Alternatively you could just change cpdef to def in the ".pyx" files. A def function doesn't need declaring in advance (and in my opinion cpdef functions are usually the wrong choice).

Sign up to request clarification or add additional context in comments.

6 Comments

Changing into Cython 0.25.2 and change cdef get_weight into cpdef get_weight doesn't work. For the last solution, do you mean like this? def np.ndarray[float, ndim=1, mode="c"] get_weight(self, cls_id=0): but it's still raise error.
For the last solution just do def get_weight(self, cls_id=0). Don't specify the output type. If you change back to Cython 0.25.2 then you should put everything back as it originally was. It looks like an unmaintained broken package though - there may be a huge list of problems to fix before you get it working though.
Changing version to Cython 0.25.2 without changing anything in the program(using original program) or using the modified program def get_weight(self, cls_id=0) raised an error. Both suggession raised error command 'gcc' failed with exit status 1 . I've tried sudo apt-get install python-dev but still error. is it because my g++ version? but I've fulfilled prequisites (my g++ = 10.2.0). Any idea? I'm sorry this slightly out of topic, but I badly need this library work because sadly there's no alternative library that i can use.
The "exit status 1" error tells you very little. There will be a more useful message before it that will tell you why it's failing. I doubt that your GCC version is the problem. You are making progress though - you've got further on in building it.
The only error that I see is: In file included from src/sol/model/model.cc:9: include/sol/model/model.h:87:25: error: extra qualification ‘sol::model::Model::’ on member ‘Get’ [-fpermissive] 87 | math::Vector<real_t>* Model::Get() const; | ^~~~~ what does it means? Aside that that there's a lot of warning. Do warnings count as clues?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.