--
I strongly think that multipledispatch should be a separate project.
There is a good chance we would use this over time in IPython and I
definitely plan on using in various codes I write outside of SymPy.
--
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 sympy+unsubscribe@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/533BC8B9.1080002%40durchholz.org.
What are your plans for multiple dispatch as a project?
Why can't this just be included in SymPy?
Do any other projects use multipledispatch, to your knowledge?
How stable is the API? Will we need to worry about compatibility breaks no version mismatches?
Yup, that's a valid concern. On the flip side once multipledispatch has users it's much harder for me to experiment and change things.
However, in this particular case there are a couple of things we can do.
singledispatch in Python 3.4 functools. It's safe to say that this interface is pretty stableFinally, multipledispatch has a very small scope. I consider it to be fairly complete now. I mostly expect only performance tweaks and some Python 3 sugar in the future.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAH4pYpScS99k9X0j6B2GHZW-WM%3DoUquwcp71dkBiX8w9DE3ZEg%40mail.gmail.com.
By the way, what about using the test cases to tag the types of all of SymPy's methods by the @dispatch decorator?
That can be useful to try an automated translation to C++ or some other language.
--
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 sympy+un...@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/32d9fa46-eb9f-494e-bc04-dbaca317f2ad%40googlegroups.com.
1) On multidispatch itself: You can have either modularity or freeness from surprises (this has been discussed before - essentially, if you have modularity, adding a module with new MD definitions can change dispatch decisions for related combinations of types).
This isn't a problem inside SymPy where we do not expect average users to develop subclasses of existing, multi-dispatching SymPy object classes. It might become a problem if multi-dispatch is made an independent module.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAP7f1AjF6snYpEx_Kc-JPG%2B_Jpan4j-kjCFuOvEJLf%3DQCUkkrg%40mail.gmail.com.
As far as performance goes --- what are the bottlenecks? Is Julia's
multipledispatch the same fast?
If it is faster, can multipledispatch be made faster too?
--
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 sympy+un...@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CADDwiVBEH9WsnY7jOLDE1DYGnMcNSGVG4gfgpFyHnMrxt88v5w%40mail.gmail.com.
As far as performance goes --- what are the bottlenecks? Is Julia's
multipledispatch the same fast?
If it is faster, can multipledispatch be made faster too?
Ondrej
--
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 sympy+un...@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CADDwiVAcWAJ02iQwnaLA_VVzB9M%3DafmvGqOOr3A1nL50yMMSMw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CADDwiVAuJX7994N6tvZ8TYrrfbYNkNpGkzQ2NBkgdDPRgUXDyQ%40mail.gmail.com.
--
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 sympy+unsubscribe@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/533C4E2F.2050804%40durchholz.org.
--
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 sympy+un...@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAJ8oX-HUeYyeA%2BDEj7YwmftmrkFOQ1L5yReDNHOXZ59tEDKAmQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAKgW%3D6K2pwZC7xnXee7mQdiH_xDHKKWSCxfmjnNFf3rv7BZ47g%40mail.gmail.com.
--
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 sympy+un...@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CADDwiVBEH9WsnY7jOLDE1DYGnMcNSGVG4gfgpFyHnMrxt88v5w%40mail.gmail.com.
--
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 sympy+unsubscribe@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/533C7975.5020409%40durchholz.org.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAJ8oX-GcPt3YDJbBX4x1EUzpOM048_cKFpGqSeaTK2BpVShJUQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAKgW%3D6LQSuncEudUNVEp5L-55d_3y%2By7GA5fw7K2gHOdoZ9-GQ%40mail.gmail.com.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAJ8oX-G%2BpUOCgProjgj1Am4LB2JXrb4mzNYaP%2BjiOvzX0wNa3g%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAJ8oX-Gkfd9-tN0UUCGn0tMFzULzDQ8kpj2318x0ec0qjWRV4Q%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAKgW%3D6Khj_EkCo-YZHGDHCJ8JDEkDf_bGXF9ipE-2yOiyEjNnA%40mail.gmail.com.
Not all of the ties result from ambiguities. For example the signatures (int,) and (float,) tie. Which should come first in the toposort?
Regarding API breaks I recommend that SymPy not inject any ambiguities. These can be avoided just by adding extra function definitions. E.g.@dispatch(object, float)def f(x, y):return 1@dispatch(float, object)def f(x, y):return 2f(1.0, 2.0) # oh no! which do we choose?
In this case multipledispatch gives you a warning when you register the second implementation
multipledispatch/core.py:52: AmbiguityWarning:Ambiguities exist in dispatched function fThe following signatures may result in ambiguous behavior:[float, object], [object, float]Consider making the following additions:
@dispatch(float, float)def f(...)My answer to this problem is that we just follow the instructions and define functions to cover all ambiguities.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAJ8oX-GwWyF4NtXKv%3DD8GGTr0EgzH777a%3Dne%3DZTsMyZ0FXciBg%40mail.gmail.com.
Not all of the ties result from ambiguities. For example the signatures (int,) and (float,) tie. Which should come first in the toposort?For what input?
I would definitely raise an exception here. You can maybe play with ways for people to tell the dispatcher how they want it to break ties, but the default implementation shouldn't take sides.
Couldn't you resolve the ambiguity by adding additional dispatch against (float, float)?
I don't think it's right to do this check at registry time.
I already asked this, but didn't get a reply: I really think it should raise an exception on ambiguity by default. You can allow the user to explicitly override this behavior if you know what you are doing.
Sent from my mobile phone.
--
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 sympy+un...@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAJ8oX-FZ%3DPFqaiePYfu%3Db8MpNdYEAxeuXFfMwpCJawh0SXwzgQ%40mail.gmail.com.
Ah, must have missed it, fortunately Aaron bright up the same point. My response:
I can see the reasoning here but slightly disagree. Both implementations are presumably valid and you should just pick one. This is also consistent with the standard set out by the Julia Language, from which I'm stealing a good amount of inspiration.
Perhaps it would make sense to reach out to the Julia folks and ask about their experiences.
And then I suggest that sympy could catch warnings and throw errors. In my PRs I use a small module sympy. dispatch rather than the raw dispatch in multipledispatch
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CADDwiVATGaBzjoOzw2CiuTjQrC1fkt%2B-M-hkiON8qO35J6uKcg%40mail.gmail.com.
Not all of the ties result from ambiguities. For example the signatures (int,) and (float,) tie. Which should come first in the toposort?For what input?How MD operates now is that it forms a graph of signatures with an edge between two signatures if one is more specific than the other. It then topologically sorts this graph to form a linear ordering. When inputs come in we get their types and then compare those types against each of the type signatures in the linear ordering from most to least specific (by the topological sort). Once we find a match we return the function that was registered with the matching signature. In this way we get to use issubclass and are also assured that we aren't missing a more specific signature.
So, in the float/int case our graph is just two disconnected nodes and our ordering might look like[(int,), (float,)]When an input comes in, like 1.0, we get it's types, (float,), and then ask issubclass(float, int), get no, and move on to ask if issubclass(float, float). This works so we return the function associated with (float,).(Although actually we first just check in a dict to see if we have the type signature exactly, which we do in this case, so we return in constant time)
I would definitely raise an exception here. You can maybe play with ways for people to tell the dispatcher how they want it to break ties, but the default implementation shouldn't take sides.I can see the reasoning here but slightly disagree. Often both implementations are perfectly valid and you should just pick one. This is also consistent with the standard set out by the Julia Language, from which I'm stealing a good amount of inspiration.
Couldn't you resolve the ambiguity by adding additional dispatch against (float, float)?Yes, this is what is suggested automatically by MD. Perhaps I don't understand your comment.
I don't think it's right to do this check at registry time.I'm not sure that I understand this either. When would you do the check?
--
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 sympy+un...@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAJ8oX-EXLpUGxJXK5Zm8PT%2B27OC6O42pCYP2vvXWVPv_qM5E4g%40mail.gmail.com.
--
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 sympy+un...@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAJ8oX-FZ%3DPFqaiePYfu%3Db8MpNdYEAxeuXFfMwpCJawh0SXwzgQ%40mail.gmail.com.
Ok. I am installing Julia and I play with it more. Julia argument is a good argument because Julia is a solid iterative improvement over Python. I think in the next 5 years Python will be used a lot more than Julia and it's hard to predict what will happen after that. But I think that Julia is going to be used a lot, so we should try to be compatible if it makes sense.
Sent from my mobile phone.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAJ8oX-ECk%2BzUkDpMG4V72PEUntTdZJ-%3DJp8mXq0NgizP92zGgw%40mail.gmail.com.
My point is, the order comes from the input itself, not from the registry. AKA, you should use MRO. MRO satisfied monotonicity, which I think for multiple dispatch basically says that if you subclass a class, it won't change which function it will dispatch to (see https://www.python.org/download/releases/2.2.3/descrintro).
I would definitely raise an exception here. You can maybe play with ways for people to tell the dispatcher how they want it to break ties, but the default implementation shouldn't take sides.I can see the reasoning here but slightly disagree. Often both implementations are perfectly valid and you should just pick one. This is also consistent with the standard set out by the Julia Language, from which I'm stealing a good amount of inspiration.I think Julia only has one use-case in mind, which is that a function is going to compute something, dispatched against some algorithm, and return the result. But I think there are other possibilities.
I'll think about some concrete examples, but my gut tells me that there are going to be different ways that people might want to break or not break ties. Multipledispatch should allow that via subclassing the Dispatch class, and the default implementation should not do it. I also reiterateIn the face of ambiguity, refuse the temptation to guess.
Couldn't you resolve the ambiguity by adding additional dispatch against (float, float)?Yes, this is what is suggested automatically by MD. Perhaps I don't understand your comment.
The point is, you are warning when the function is registered. If you have@dispatch(float, object)def add(a, b):...@dispatch(object, float)def add(a, b):...@dispatch(float, float)def add(a, b):...it will raise a warning telling you to do something that you have already done. Since there's no way to "finalize" the dispatcher (nor should there be), it should just do this at run time. You can cache the state of the Dispatch object if performance is a concern.
I haven't yet actually read the code, only the documentation and what you wrote here, so if I wrote something stupid above, pardon it.
MRO is a reaonably good solution for 99% of the cases. 100% solutions do
exist but Python did not choose them (nor did any other language that
I'm aware of).
--
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 sympy+unsubscribe@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/533D13C9.60207%40durchholz.org.