On May 23, 2008, at 10:14 AM, Carl Witty wrote:

> On Thu, May 22, 2008 at 11:35 AM, Dag Sverre Seljebotn
> <[EMAIL PROTECTED]> wrote:
>> Stefan wrote:
>>> Hi,
>>>
>>> Dag Sverre Seljebotn wrote:
>>>> http://wiki.cython.org/enhancements/compiledducktyping
>>>
>>> Isn't the overloading stuff what PEP 3124 is heading for?
>>>
>>> http://www.python.org/dev/peps/pep-3124/
>>>
>>> I think parameter annotations would make sense here.
>>
>> Compile-time duck typing is not really just overloading, it is  
>> overloaded
>> template methods, i.e. like this in C++:
>>
>> template <typename A, typename B>
>> A max(A a, B b) {...}
>>
>> (Unlike overloading, compile-time ducktyping has no Java equivalent).
>
> I was hoping this would be powerful enough to write generic optimized
> mathematics code for Sage, but it doesn't do enough for that.
>
> For Sage, a function that takes "double" arguments might include:
>   a = b + c
> the corresponding function that takes "mpz_t" arguments would have:
>   mpz_add(a, b, c)
> the corresponding function with "mpfr_t" arguments would have:
>   mpfr_add(a, b, c, GMP_RNDN)
> for integers mod p (for sufficiently small p), it would be:
>   a = (b + c) % p
>
> On the other hand, different subclasses of object (like Integer and
> RealNumber) should probably not have separate versions of the function
> compiled for them.
>
> Maybe it's not worth even trying to think about supporting this use
> case with this proposal--anything that works would end up being
> significantly more complicated than what you're talking about,
> probably.  But it would be nice to at least avoid making it harder to
> implement this complicated thing in the future.

Yes, implementing such a thing would be much more complicated to do.  
However, one can sort of do it now by making a .pxi file that has all  
the algorithms, then including it in pyx files that would define the  
types, (inline) arithmetic functions, etc.

- Robert



_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to