[Cython] calling gmp automatically

Dag Sverre Seljebotn dagss at student.matnat.uio.no
Tue Dec 23 14:46:11 CET 2008


Ondrej Certik wrote:
> Preferably one could use it like this:
>
> cdef mpz tmp
> tmp = den/f.v[i]
> vec[0][i] = f.v[i]*tmp
>
> or something like that and leave it to Cython to call the correct
> methods. I don't like the fact that Cython would have to be gmp aware
> --- maybe there is some way to just implement a cdef class mpz that
> would support __add__, __mull__ and things like that, so as to behave
> just like python integer, but still be as fast as the explicit code
> above.

Yep. Operator overloading using inline cdef functions should be a very
non-controversial feature to add to Cython, and not very difficult to add
either (transform from eg. BinopNode to SimpleCallNode in the right
circumstances), and that would solve this problem in a much more generic
way. At first that would require one to create a "cdef class" wrapper
class containing the struct as a member and the overloaded operators, but
when that is all working one could discuss allowing such overloads in
structs as well?

Dag Sverre



More information about the Cython-dev mailing list