Skip to content

Commit

Permalink
Trac #33645: Another improvement for face iterator of simple/simplici…
Browse files Browse the repository at this point in the history
…al polytopes

Follow up on #30040:

If we are in a lattice, such that all intervals `[F, G]` are boolean, if
`F` is not the lower bound, then any face except the lower bound, has a
unique representation as meet of coatoms.

This means that we do not need to mark a face as visited, when removing
it from the coatoms.

Before (benchmarks without parallelization):

{{{
sage: P = polytopes.cyclic_polytope(10, 22)
sage: %timeit C = CombinatorialPolyhedron(P); C.f_vector(1, 0)
43.2 ms ± 40 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
sage: P = polytopes.associahedron(['A', 8])
sage: %timeit C = CombinatorialPolyhedron(P); C.f_vector(1, 0)
20.1 ms ± 69.3 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
sage: P = polytopes.hypercube(12, backend='field')
sage: %timeit C = CombinatorialPolyhedron(P); C.f_vector(1, 0)
38.6 ms ± 464 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
sage: P = polytopes.Birkhoff_polytope(5)  # neither simple nor
simplicial
sage: %timeit C = CombinatorialPolyhedron(P); C.f_vector(1, 0)
275 ms ± 531 µs per loop (mean ± std. dev. of 7 runs, 1 loop each)
}}}

After (benchmarks without parallelization):
{{{
sage: P = polytopes.cyclic_polytope(10, 22)
sage: %timeit C = CombinatorialPolyhedron(P); C.f_vector(1, 0)
38.6 ms ± 1.07 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
sage: P = polytopes.associahedron(['A', 8])
sage: %timeit C = CombinatorialPolyhedron(P); C.f_vector(1, 0)
18.3 ms ± 23.7 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
sage: P = polytopes.hypercube(12, backend='field')
sage: %timeit C = CombinatorialPolyhedron(P); C.f_vector(1, 0)
30.9 ms ± 40 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
sage: P = polytopes.Birkhoff_polytope(5)  # neither simple nor
simplicial
sage: %timeit C = CombinatorialPolyhedron(P); C.f_vector(1, 0)
274 ms ± 410 µs per loop (mean ± std. dev. of 7 runs, 1 loop each)
}}}

URL: https://trac.sagemath.org/33645
Reported by: gh-kliem
Ticket author(s): Jonathan Kliem
Reviewer(s): Travis Scrimshaw
  • Loading branch information
Release Manager committed Apr 10, 2022
2 parents 34adbe3 + 04ca6fb commit 38b13ef
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1970,7 +1970,13 @@ cdef inline int next_face_loop(iter_t structure) nogil except -1:
# In this case there exists ``faces[0].faces[n_faces]``, of which we
# have visited all faces, but which was not added to
# ``visited_all`` yet.
add_face_shallow(visited_all[0], faces[0].faces[n_faces])

if not faces[0].polyhedron_is_simple:
# In case of a simple lattice, this step needs not to be applied:
# Every element, except the lower bound, has a unique representation of coatoms in this case.
# Hence, as the face is already removed from faces[0], any subfaces will not be visited.
# (If we manually ignore subfaces, faces will still be added to visited_all).
add_face_shallow(visited_all[0], faces[0].faces[n_faces])
else:
# Once we have visited all faces of ``faces[n_faces]``, we want
# to add it to ``visited_all``.
Expand Down Expand Up @@ -2193,7 +2199,14 @@ cdef inline int prepare_face_iterator_for_partial_job(

for i in range(job_id_c):
# Fast forwarding the jobs.
add_face_shallow(structure.visited_all[d], structure.new_faces[d].faces[structure.new_faces[d].n_faces -1])

if not structure.new_faces[d].polyhedron_is_simple:
# In case of a simple lattice, this step needs not to be applied:
# Every element, except the lower bound, has a unique representation of coatoms in this case.
# Hence, as the face is already removed from faces[0], any subfaces will not be visited.
# (If we manually ignore subfaces, faces will still be added to visited_all).
add_face_shallow(structure.visited_all[d], structure.new_faces[d].faces[structure.new_faces[d].n_faces -1])

structure.new_faces[d].n_faces -= 1

parallel_struct.current_job_id[current_depth -1] = job_id_c
Expand Down

0 comments on commit 38b13ef

Please sign in to comment.