On Thu, Apr 20, 2017 at 6:12 AM, Francesco Bonazzi <[email protected]> wrote: > > > On Wednesday, 19 April 2017 21:51:08 UTC+2, Aaron Meurer wrote: >> >> Performance is a valid concern. We should definitely check that. >> >> The __slots__ part I don't know. That could probably be done differently. >> > > I didn't like that part too. Has anyone a better idea? > >> Regarding the implementation itself, how would you do it? The ability >> to make Mul or Add do custom stuff for custom objects is a very >> commonly requested feature. Would you keep it unimplemented, or do it >> some other way? > > > Yes, we really need this feature. > > Ideally we want to extend such mechanism to functions as well.
For functions, dispatch works nicely. In fact, most functions are single-argument, so you only need single dispatch, which is basically SymPy's _eval_*thing* mechanism. We could extend Function so that it dispatches before eval() is called on the subclass (say, sin(x) could call x._eval_function(sin)). At least, that should work when nargs = 1. For nargs > 1, you need something more complicated. The problem with Add and Mul is that they not only take multiple arguments, but an arbitrary number, so a true multiple dispatch system becomes unwieldy. Francesco's solution maybe isn't the most general, but it seems simple, and capable of handling the use-cases I know of. Aaron Meurer > > >> >> Aaron Meurer >> >> On Wed, Apr 19, 2017 at 3:46 PM, Ronan Lamy <[email protected]> wrote: >> > Le 19/04/17 à 19:00, Francesco Bonazzi a écrit : >> >> >> >> >> >> >> >> On Wednesday, 19 April 2017 17:05:08 UTC+2, Ronan Lamy wrote: >> >> >> >> Le 18/04/17 à 21:28, Francesco Bonazzi a écrit : >> >> > I'm gonna merge this PR soon: >> >> > >> >> > https://github.com/sympy/sympy/pull/12508 >> >> <https://github.com/sympy/sympy/pull/12508> >> >> >> >> Wow, that's horrifying! Good luck maintaining it! >> >> >> >> >> >> Why is it horrifying? >> > >> > >> > Well, using __new__ in the first place is a big WTF (and yes, I know >> > that >> > sympy is pretty much stuck with it forever), but layering a hook to a >> > whole >> > new programming paradigm inside it is evil genius. Bonus horror points >> > for >> > introspecting __slots__ and doing such fundamental changes to solve a >> > minor >> > issue. >> > >> > And BTW, has anybody checked the impact on performance? IIUC, that adds >> > a >> > non-trivial amount of work to every Add or Mul instantiation. >> > >> > That being said, don't mind me. As long as I don't have to debug it, >> > that >> > code won't bother me. >> > >> > -- >> > You received this message because you are subscribed to the Google >> > Groups >> > "sympy" group. >> > To unsubscribe from this group and stop receiving emails from it, send >> > an >> > email to [email protected]. >> > To post to this group, send email to [email protected]. >> > Visit this group at https://groups.google.com/group/sympy. >> > To view this discussion on the web visit >> > >> > https://groups.google.com/d/msgid/sympy/086034c8-3ad1-4059-7424-d358f3de9b92%40gmail.com . >> > >> > For more options, visit https://groups.google.com/d/optout. > > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/sympy. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sympy/03cf6d1f-83f6-4844-9b5c-753e947f90ce%40googlegroups.com . > > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/sympy. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAKgW%3D6JE_1tF9GnYv6eJY8enBnLBT5K82dBKx0FHhvC%2BxKOzOg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
