Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Do not iterate twice for CombinatorialPolyhedron.facets()
Browse files Browse the repository at this point in the history
  • Loading branch information
videlec committed Apr 18, 2019
1 parent 72ac3b0 commit 611099f
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/sage/geometry/polyhedron/combinatorial_polyhedron/base.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -786,19 +786,17 @@ cdef class CombinatorialPolyhedron(SageObject):
# There is actually one facet, but we have not initialized it.
return ((),)

# Get all facets from :meth:`face_iter`.
face_iter = self.face_iter(self.dimension() - 1, dual=False)
tup = tuple(face_iter.vertex_repr(names=names) for _ in face_iter)

# It is important to have the facets in the exact same order as
# It is essential to have the facets in the exact same order as
# on input, so that pickle/unpickle by :meth:`reduce` works.
# Every facet knows its index by the facet-representation.
# Every facet knows its index by the facet representation.
face_iter = self.face_iter(self.dimension() - 1, dual=False)
indices = tuple(face_iter.facet_repr(names=False)[0] for _ in face_iter)
dic = {}
for i in range(len(tup)):
dic[indices[i]] = tup[i]
return tuple(dic[i] for i in range(len(tup)))
facets = [None] * self._nr_facets
for _ in face_iter:
index = face_iter.facet_repr(names=False)[0]
verts = face_iter.vertex_repr(names=names)
facets[index] = verts

return tuple(facets)

def edges(self, names=True):
r"""
Expand Down

0 comments on commit 611099f

Please sign in to comment.