[Cython] calling gmp automatically
Robert Bradshaw
robertwb at math.washington.edu
Tue Dec 23 19:58:27 CET 2008
On Dec 23, 2008, at 5:46 AM, Dag Sverre Seljebotn wrote:
> 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?
Yes, this has been on my want-to-do list for a long time. In fact,
I've been thinking about this in terms of adding support for native
(double) complex types. One question is weather/how to handle memory
allocation if we implemented gmp integers in a more native way.
- Robert
More information about the Cython-dev
mailing list