Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faster meet() for lattice #21109

Closed
jm58660 mannequin opened this issue Jul 28, 2016 · 16 comments
Closed

Faster meet() for lattice #21109

jm58660 mannequin opened this issue Jul 28, 2016 · 16 comments

Comments

@jm58660
Copy link
Mannequin

jm58660 mannequin commented Jul 28, 2016

This trivial patch will speed up computation of meet matrix in lattices. Before:

sage: P = Posets.BooleanLattice(10)
sage: timeit("_ = P._hasse_diagram._meet", repeat=1, number=1)
1 loops, best of 1: 2.24 s per loop

After:

sage: P = Posets.BooleanLattice(10)
sage: timeit("_ = P._hasse_diagram._meet", repeat=1, number=1)
1 loops, best of 1: 917 ms per loop

And for small lattices:

sage: P10 = [P.with_bounds() for P in Posets(8)]
sage: timeit("len([P for P in P10 if P.is_meet_semilattice()])", repeat=1, number=1)

Without this patch it took 5.46 seconds, after the patch 1.54 seconds.

CC: @fchapoton

Component: combinatorics

Keywords: lattice poset

Author: Jori Mäntysalo

Branch/Commit: 965b8ab

Reviewer: Frédéric Chapoton

Issue created by migration from https://trac.sagemath.org/ticket/21109

@jm58660 jm58660 mannequin added this to the sage-7.3 milestone Jul 28, 2016
@jm58660 jm58660 mannequin added c: combinatorics labels Jul 28, 2016
@jm58660
Copy link
Mannequin Author

jm58660 mannequin commented Jul 28, 2016

Branch: u/jmantysalo/faster-meet

@jm58660
Copy link
Mannequin Author

jm58660 mannequin commented Jul 28, 2016

Commit: b679b3d

@jm58660
Copy link
Mannequin Author

jm58660 mannequin commented Jul 28, 2016

New commits:

b679b3dTrivial speedup for meet().

@jm58660 jm58660 mannequin added the s: needs review label Jul 28, 2016
@fchapoton
Copy link
Contributor

comment:3

I have some questions:

I do not understand the comment # T = {x_i \wedge z : z>-x_k}
What is the meaning of >- ?

Does lc stands for "lower covers" ? if yes, that would be worth to say in a comment

Could you take the opportunity to make the method fully pep8 compliant ? only the line

raise ValueError("No meet for x=%s y=%s"%(x,y))

must be changed to

raise ValueError("No meet for x=%s y=%s" % (x, y))

@tscrim
Copy link
Collaborator

tscrim commented Jul 28, 2016

comment:4

Have you run tests on smaller and larger lattices? Does the about 2x speedup still hold in those cases?

@tscrim
Copy link
Collaborator

tscrim commented Jul 29, 2016

Changed keywords from latticeposet to lattice poset

@tscrim
Copy link
Collaborator

tscrim commented Jul 29, 2016

comment:5

If you haven't, just let me know, and I can run the tests.

@jm58660

This comment has been minimized.

@jm58660 jm58660 mannequin added s: needs work and removed s: needs review labels Jul 29, 2016
@jm58660
Copy link
Mannequin Author

jm58660 mannequin commented Jul 29, 2016

comment:7

Replying to @tscrim:

Have you run tests on smaller and larger lattices? Does the about 2x speedup still hold in those cases?

It is very hard to think an example where my code would be slower. This references to a python dict, whereas current code references to a matrix; referencing to matrix elements in a loop is slow. And that matrix must be precomputed first. You can test what happens if you compute le-matrix first (assuming that the user has, say, computed Möbius function matrix), but there will still be speedup.

I added another example to description.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 29, 2016

Branch pushed to git repo; I updated commit sha1. New commits:

965b8abReviewer's comments.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 29, 2016

Changed commit from b679b3d to 965b8ab

@jm58660
Copy link
Mannequin Author

jm58660 mannequin commented Jul 29, 2016

comment:9

Replying to @fchapoton:

Could you take the opportunity to make the method fully pep8 compliant ? only the line

raise ValueError("No meet for x=%s y=%s"%(x,y))

must be changed to

raise ValueError("No meet for x=%s y=%s" % (x, y))

Changed. Then there is the error message formatting question... Python exceptions start with lowercase and do not end to a period. But this has been discussed in sage-devel without clear conclusion.

I do not understand the comment # T = {x_i \wedge z : z>-x_k}
What is the meaning of >- ?

I guess it has meant covering. I removed it.

Does lc stands for "lower covers" ? if yes, that would be worth to say in a comment

Done.

@jm58660 jm58660 mannequin added s: needs review and removed s: needs work labels Jul 29, 2016
@jm58660
Copy link
Mannequin Author

jm58660 mannequin commented Jul 29, 2016

comment:10

rc0 is out.

@jm58660 jm58660 mannequin modified the milestones: sage-7.3, sage-7.4 Jul 29, 2016
@fchapoton
Copy link
Contributor

Reviewer: Frédéric Chapoton

@fchapoton
Copy link
Contributor

comment:11

ok, looks good enough. Thanks

@vbraun
Copy link
Member

vbraun commented Aug 10, 2016

Changed branch from u/jmantysalo/faster-meet to 965b8ab

@vbraun vbraun closed this as completed in 083fc58 Aug 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants