On Tue, Feb 10, 2015 at 2:34 PM, Volker Braun <vbraun.n...@gmail.com> wrote: > My advice would be to implement the parent in Python and benchnmark it. If > you are doing something in _element_constructor_ that would benefit greatly > by Cython then you can just move that part to Cython.
+1 > On Tuesday, February 10, 2015 at 8:20:08 PM UTC+1, Marc Mezzarobba wrote: >> >> Hi, >> >> What is the recommended way to implement a parent that needs a fast >> element constructor but otherwise can be expected not to be queried too >> often once the coercion maps involving it are set up ? (I would like >> MyParent(obj) to have as little overhead as possible, not just >> coercions.) >> >> I can think of two main options: >> >> (1) Implement the parent as a Cython extension class. Tell users not >> to construct instances directly, and provide a (weakly) cached factory >> function or a UniqueFactory to be used instead. This appears to be the >> most common approach in Sage. >> >> (2) Implement the parent as a Python class. A benefit is that we can >> inherit from Singleton or UniqueRepresentation (and perhaps other >> similar utility classes?) as appropriate. I also seem to remember that >> having a true Python class avoids at least some getattr hackery related >> to categories, but I don't remember to what extent. Provide the element >> constructor as a cpdef function outside, as a direct call to the >> (Cython) element class, or perhaps even as a method of a Cython "shadow >> class" storing any necessary parameters. This does not seem to be widely >> used, a notable exception being QQ. The version with parameters is not >> used at all as far as I can tell. >> >> Any advice? >> >> Thanks, >> >> -- >> Marc >> > -- > You received this message because you are subscribed to the Google Groups > "sage-devel" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sage-devel+unsubscr...@googlegroups.com. > To post to this group, send email to sage-devel@googlegroups.com. > Visit this group at http://groups.google.com/group/sage-devel. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at http://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.