On Fri, Jul 23, 2010 at 8:30 PM, Ronan Lamy <ronan.l...@gmail.com> wrote: > Le vendredi 23 juillet 2010 à 17:41 -0700, Brian Granger a écrit : >> On Wed, Jul 21, 2010 at 1:15 PM, Aaron S. Meurer <asmeu...@gmail.com> wrote: >> > First off, pragmatically speaking, is there a reason why you need to use >> > the core Mul instead of writing your own custom Mul for the quantum stuff? >> > I am just saying this because even though I agree that we need this >> > change, changing anything in the core is very difficult and time >> > consuming, because the code is so fragile, and you also have to pay close >> > attention to speed concerns. >> >> I would very much like the option of using a custom Mul subclass, but >> that is currently impossible in sympy. The reason is that my >> expressions also have sympy scalars. Anytime one of those appears on >> the left of a multiplication its __mul__ gets called and everything >> becomes a Mul. To use custom Mul classes for anything, we need to >> have something like the __array_priority that numpy has built into the >> core. > > I think this can be done with a careful implementation of double > dispatch in __mul__ and __rmul__, so I don't see the point of this > __array_priority. Though this implementation would require some sort of > complete ordering of the classes, which is conceptually similar to an > __array_priority, it doesn't have to appear explicitly in the code.
The nice thing about the __array_priority is that it is easily extensible. You can add new sympy types and fine tune their priority without touching the core. Also, like numpy, the priority should be used in all special methods like __add__, __mul__, __pow__, etc. Cheers, Brian > Ronan > > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To post to this group, send email to sy...@googlegroups.com. > To unsubscribe from this group, send email to > sympy+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/sympy?hl=en. > > -- Brian E. Granger, Ph.D. Assistant Professor of Physics Cal Poly State University, San Luis Obispo bgran...@calpoly.edu elliso...@gmail.com -- You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to sy...@googlegroups.com. To unsubscribe from this group, send email to sympy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sympy?hl=en.