On Oct 28, 2006, at 9:28 PM, Martin Albrecht wrote:

> To elaborate this, this is how the suggestion translates into  
> Python/Pyrex
> code. Please remember the idea is to avoid Python calls (at all  
> costs).
>
> Pyrex:
> -----------------------------------
> cdef class RingElement:
>
>     def __add__(self,other):
>         # Python calling convention
>         return RingElement._add_dispatch(self,other)
>
>     cdef _add_dispatch(self,other):
>         if hasattr(self,"__dict__"):
>             return type(self)._add_(self,other)
>         else:
>             return self._add_cdef(other)
>
>     cdef _add_(self,other):
>         return self._add_cdef(other)
>
>     cdef _add_cdef(self,other):
>         raise NotImplementedError
>
> cdef class Integer(RingElement):
>     cdef _add_cdef(self,other):
>         # C calling convention
>         # todo: type checks!
>         print "Integer"
>
> cdef class CInteger(Integer):
>     cdef _add_cdef(self,other):
>         # C calling convention
>         # todo: type checks!
>         print "CInteger"
>
>
> Python:
> ------------------------------------
> class PInteger(Integer):
>     def _add_(self,other):
>         # python calling convention
>         # todo: type checks!
>         print "PInteger"
>
> ------------------------------------


Yes, the "call graph" is correct in your code, although obviously the  
real code is more complicated.

I'm now starting to think "_add_sibling_pyrex" is a better name than  
"_add_sibling_cdef". Also I still don't like "_add_sibling_dispatch".

David


--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/
-~----------~----~----~----~------~----~------~--~---

Reply via email to