Hi Nathann,

On 2014-11-28, Nathann Cohen <nathann.co...@gmail.com> wrote:
> sage: g = posets.BooleanLattice(5).hasse_diagram().transitive_closure();
> sage: g = g.cartesian_product(g)
> sage: %time Poset(g)
> CPU times: user 284 ms, sys: 32 ms, total: 316 ms
> Wall time: 278 ms
> Finite poset containing 1024 elements
> sage: %time Poset(g)
> CPU times: user 1.63 s, sys: 44 ms, total: 1.68 s
> Wall time: 1.61 s
> Finite poset containing 1024 elements
>
> Even without my optimisations you see this effect, and I am pretty sure
> that the huge time penalty here is because Poset inherits from
> UniqueRepresentation. Profiling shows that most of the time is spent
> testing equality of posets, which is part of the UniqueRepresentation
> initialization.

You mean the comparison of g with itself takes so much time? Hard to
believe, but it really seems to be the case:
  sage: g =
  posets.BooleanLattice(5).hasse_diagram().transitive_closure()
  sage: g = g.cartesian_product(g)
  sage: %timeit g==g
  1 loops, best of 3: 10.3 s per loop

How can that be? Isn't generally the test by "==" first checking whether
the two arguments are identical, before calling `.__eq__`?

If python does not do it automatically, then at least in your example it
would be good to make g.__eq__ use the "self is other" test, before
doing anything expensive. Probably the problem would also be solved by
implementing rich comparison via __richcmp__ (not sure though).

In any case, if there is a reason to have unique representation, then
ideally the defining data should be easy to compare. Evidently, a
dictionary lookup has to be involved for any kind of unique
represenation.

Best regards,
Simon


-- 
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.

Reply via email to