On Wed, May 30, 2018 at 8:38 AM, Travis Scrimshaw <tsc...@ucdavis.edu> wrote: > Hi Martin, > >> I am frustrated with the following and would like to fix it: >> >> >> Is "Set" supposed to be slow? Replacing "Set" with "set" in >> "SetPartition.__init__" is a huge improvement, we go down to about 5.5 ms >> per loop, but "Set" has bitten me performance >> (https://trac.sagemath.org/ticket/23877) and featurewise >> (https://trac.sagemath.org/ticket/23324) already so often, that I'd rather >> get rid of it altogether. Is there any point at all in having "Set"? > > > I can certainly hear your frustration, but these kinds of comments make me > far less willing to help you as it makes me feel like it is flamebait and > you are too narrowly focused on your issues. > > Yes, there are a number of reasons to have Set. It allows you to work within > Sage's Parent/Element framework, the nice output representations, it is > hashable when the input objects are hashable, and the code can be easier to > understand (e.g., you cannot do X + Y with (frozen)sets and it doesn't have > a method to get subsets). However, as Sébastien said, it is better to use > frozenset internally, but there is a caveat, this only works whenever you > want to assume your objects are hashable. Now for SetPartition, I think that > is a reasonable assumption and should be changed. However, it might require > a fairly substantial overhaul of that code and a number of other places > where that code is used to build iterators. +1 for you making such > improvements to SetPartitions.
The way I see it, Set is a high-level object representing a mathematical Set in the sense needed to fit in with Sage's categorical framework. It has many more features than the set built-in. Comparing it performance to the set built-in is unfair because they serve different purposes (that said, I'm sure the performance of Set could be improved). The set built-in is just a low-level data structure. Saying it's slow is like saying that a list of lists is slower than a matrix type. Yes they're effectively able to represent the same data structure, but were designed for different use cases. I'd say for implementation details of some code just use set or frozenset (if you want immutability/hashability) and only use Sage's Set for when it's explicitly needed. -- 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 https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.