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

Commit

Permalink
prefer face_generator over face_iter and algorithm= over dual=
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Kliem committed Apr 5, 2022
1 parent 3e8dd25 commit f638686
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 100 deletions.
68 changes: 41 additions & 27 deletions src/sage/geometry/polyhedron/combinatorial_polyhedron/base.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ Face lattice::
Face iterator::
sage: C.face_iter()
sage: C.face_generator()
Iterator over the proper faces of a 4-dimensional combinatorial polyhedron
sage: C.face_iter(2)
sage: C.face_generator(2)
Iterator over the 2-faces of a 4-dimensional combinatorial polyhedron
AUTHOR:
Expand Down Expand Up @@ -334,7 +334,7 @@ cdef class CombinatorialPolyhedron(SageObject):
Traceback (most recent call last):
...
ValueError: the combinatorial polyhedron was not initialized
sage: C.face_iter()
sage: C.face_generator()
Traceback (most recent call last):
...
ValueError: the combinatorial polyhedron was not initialized
Expand Down Expand Up @@ -629,8 +629,8 @@ cdef class CombinatorialPolyhedron(SageObject):
sage: P = polytopes.permutahedron(4) # optional - sage.combinat
sage: C = CombinatorialPolyhedron(P) # optional - sage.combinat
sage: C1 = loads(C.dumps()) # optional - sage.combinat
sage: it = C.face_iter() # optional - sage.combinat
sage: it1 = C1.face_iter() # optional - sage.combinat
sage: it = C.face_generator() # optional - sage.combinat
sage: it1 = C1.face_generator() # optional - sage.combinat
sage: tup = tuple((face.ambient_Vrepresentation(), # optional - sage.combinat
....: face.ambient_Hrepresentation()) for face in it)
sage: tup1 = tuple((face.ambient_Vrepresentation(), # optional - sage.combinat
Expand All @@ -641,8 +641,8 @@ cdef class CombinatorialPolyhedron(SageObject):
sage: P = polytopes.cyclic_polytope(4,10)
sage: C = CombinatorialPolyhedron(P)
sage: C1 = loads(C.dumps())
sage: it = C.face_iter()
sage: it1 = C1.face_iter()
sage: it = C.face_generator()
sage: it1 = C1.face_generator()
sage: tup = tuple((face.ambient_Vrepresentation(), face.ambient_Hrepresentation()) for face in it)
sage: tup1 = tuple((face.ambient_Vrepresentation(), face.ambient_Hrepresentation()) for face in it1)
sage: tup == tup1
Expand All @@ -651,8 +651,8 @@ cdef class CombinatorialPolyhedron(SageObject):
sage: P = Polyhedron(rays=[[1,0,0], [-1,0,0], [0,-1,0]])
sage: C = CombinatorialPolyhedron(P)
sage: C1 = loads(C.dumps())
sage: it = C.face_iter()
sage: it1 = C1.face_iter()
sage: it = C.face_generator()
sage: it1 = C1.face_generator()
sage: tup = tuple((face.ambient_Vrepresentation(), face.ambient_Hrepresentation()) for face in it)
sage: tup1 = tuple((face.ambient_Vrepresentation(), face.ambient_Hrepresentation()) for face in it1)
sage: tup == tup1
Expand All @@ -662,8 +662,8 @@ cdef class CombinatorialPolyhedron(SageObject):
....: [0,-1,0], [0,1,0]])
sage: C = CombinatorialPolyhedron(P)
sage: C1 = loads(C.dumps())
sage: it = C.face_iter()
sage: it1 = C1.face_iter()
sage: it = C.face_generator()
sage: it1 = C1.face_generator()
sage: tup = tuple((face.ambient_Vrepresentation(), face.ambient_Hrepresentation()) for face in it)
sage: tup1 = tuple((face.ambient_Vrepresentation(), face.ambient_Hrepresentation()) for face in it1)
sage: tup == tup1
Expand Down Expand Up @@ -1320,7 +1320,7 @@ cdef class CombinatorialPolyhedron(SageObject):
contained in exactly two facets.
To obtain all faces of codimension 1 use
:meth:`CombinatorialPolyhedron.face_iter` instead.
:meth:`CombinatorialPolyhedron.face_generator` instead.
The ridges will be given by the facets, they are contained in.
Expand Down Expand Up @@ -1387,7 +1387,7 @@ cdef class CombinatorialPolyhedron(SageObject):
A 1-dimensional combinatorial polyhedron with 1 facet
sage: C.ridges()
()
sage: it = C.face_iter(0)
sage: it = C.face_generator(0)
sage: for face in it: face.ambient_Hrepresentation()
(An inequality (1, 0) x + 0 >= 0, An equation (0, 1) x + 0 == 0)
Expand Down Expand Up @@ -2566,7 +2566,7 @@ cdef class CombinatorialPolyhedron(SageObject):
sage: C.join_of_Vrep().ambient_V_indices() # optional - sage.combinat
()
"""
return self.face_iter().join_of_Vrep(*indices)
return self.face_generator().join_of_Vrep(*indices)

def meet_of_Hrep(self, *indices):
r"""
Expand All @@ -2593,18 +2593,23 @@ cdef class CombinatorialPolyhedron(SageObject):
sage: C.meet_of_Hrep().ambient_H_indices() # optional - sage.rings.number_field
()
"""
return self.face_iter().meet_of_Hrep(*indices)
return self.face_generator().meet_of_Hrep(*indices)

def face_iter(self, dimension=None, dual=None):
def face_generator(self, dimension=None, dual=None, algorithm=None):
r"""
Iterator over all proper faces of specified dimension.
INPUT:
- ``dimension`` -- if specified, then iterate over only this dimension
- ``dual`` -- if ``True``, iterate starting with the vertices,
if ``False``, iterate starting with the facets,
if ``None``, choose ``True`` or ``False`` for speed
- ``dual`` -- boolean (default ``None``);
if ``True``, pick dual algorithm
if ``False``, pick primal algorithm
- ``algorithm`` -- string (optional);
specify whether to start with facets or vertices:
* ``'primal'`` -- start with the facets
* ``'dual'`` -- start with the vertices
* ``None`` -- choose automatically
OUTPUT:
Expand All @@ -2619,7 +2624,7 @@ cdef class CombinatorialPolyhedron(SageObject):
sage: P = polytopes.permutahedron(5) # optional - sage.combinat
sage: C = CombinatorialPolyhedron(P) # optional - sage.combinat
sage: it = C.face_iter(dimension=2) # optional - sage.combinat
sage: it = C.face_generator(dimension=2) # optional - sage.combinat
sage: face = next(it); face # optional - sage.combinat
A 2-dimensional face of a 4-dimensional combinatorial polyhedron
sage: face.ambient_Vrepresentation() # optional - sage.combinat
Expand Down Expand Up @@ -2652,7 +2657,7 @@ cdef class CombinatorialPolyhedron(SageObject):
(32, 89, 90, 94)
sage: C = CombinatorialPolyhedron([[0,1,2],[0,1,3],[0,2,3],[1,2,3]])
sage: it = C.face_iter()
sage: it = C.face_generator()
sage: for face in it: face.ambient_Vrepresentation()
(1, 2, 3)
(0, 2, 3)
Expand All @@ -2671,7 +2676,7 @@ cdef class CombinatorialPolyhedron(SageObject):
sage: P = Polyhedron(rays=[[1,0],[0,1]], vertices=[[1,0],[0,1]])
sage: C = CombinatorialPolyhedron(P)
sage: it = C.face_iter(1)
sage: it = C.face_generator(1)
sage: for face in it: face.ambient_Vrepresentation()
(A vertex at (0, 1), A vertex at (1, 0))
(A ray in the direction (1, 0), A vertex at (1, 0))
Expand All @@ -2682,6 +2687,13 @@ cdef class CombinatorialPolyhedron(SageObject):
:class:`~sage.geometry.polyhedron.combinatorial_polyhedron.face_iterator.FaceIterator`,
:class:`~sage.geometry.polyhedron.combinatorial_polyhedron.combinatorial_face.CombinatorialFace`.
"""
if algorithm == 'primal':
dual = False
elif algorithm == 'dual':
dual = True
elif algorithm is not None:
raise ValueError("algorithm must be 'primal', 'dual' or None")

cdef FaceIterator face_iter
if dual is None:
# Determine the faster way, to iterate through all faces.
Expand All @@ -2692,6 +2704,8 @@ cdef class CombinatorialPolyhedron(SageObject):

return FaceIterator(self, dual, output_dimension=dimension)

face_iter = face_generator

cdef FaceIterator _face_iter(self, bint dual, int dimension):
r"""
A method to obtain the FaceIterator as Cython object.
Expand Down Expand Up @@ -3059,7 +3073,7 @@ cdef class CombinatorialPolyhedron(SageObject):
# We take a face iterator and do one depth-search.
# Depending on whether it is dual or not,
# the search will be from the top or bottom.
cdef FaceIterator it = self.face_iter()
cdef FaceIterator it = self.face_generator()
chain = [None]*(self.dimension())
dual = it.dual
final_dim = 0 if not dual else self.dimension()-1
Expand Down Expand Up @@ -3782,7 +3796,7 @@ cdef class CombinatorialPolyhedron(SageObject):
sage: P = polytopes.permutahedron(4) # optional - sage.combinat
sage: C = CombinatorialPolyhedron(P) # optional - sage.combinat
sage: it = C.face_iter() # optional - sage.combinat
sage: it = C.face_generator() # optional - sage.combinat
sage: tup = tuple((face.ambient_Vrepresentation(), # optional - sage.combinat
....: face.ambient_Hrepresentation()) for face in it)
sage: rg = range(1,sum(C.f_vector()) - 1) # optional - sage.combinat
Expand All @@ -3793,7 +3807,7 @@ cdef class CombinatorialPolyhedron(SageObject):
sage: P = polytopes.cyclic_polytope(4,10)
sage: C = CombinatorialPolyhedron(P)
sage: it = C.face_iter()
sage: it = C.face_generator()
sage: tup = tuple((face.ambient_Vrepresentation(),face.ambient_Hrepresentation()) for face in it)
sage: rg = range(1,sum(C.f_vector()) - 1)
sage: tup2 = tuple((C.face_by_face_lattice_index(i).ambient_Vrepresentation(),
Expand All @@ -3803,7 +3817,7 @@ cdef class CombinatorialPolyhedron(SageObject):
sage: P = Polyhedron(rays=[[1,0,0], [-1,0,0], [0,-1,0]])
sage: C = CombinatorialPolyhedron(P)
sage: it = C.face_iter()
sage: it = C.face_generator()
sage: tup = tuple((face.ambient_Vrepresentation(),face.ambient_Hrepresentation()) for face in it)
sage: rg = range(1,sum(C.f_vector()) - 1)
sage: tup2 = tuple((C.face_by_face_lattice_index(i).ambient_Vrepresentation(),
Expand All @@ -3814,7 +3828,7 @@ cdef class CombinatorialPolyhedron(SageObject):
sage: P = Polyhedron(rays=[[1,0,0], [-1,0,0],
....: [0,-1,0], [0,1,0]])
sage: C = CombinatorialPolyhedron(P)
sage: it = C.face_iter()
sage: it = C.face_generator()
sage: tup = tuple((face.ambient_Vrepresentation(),face.ambient_Hrepresentation()) for face in it)
sage: rg = range(1,sum(C.f_vector()) - 1)
sage: tup2 = tuple((C.face_by_face_lattice_index(i).ambient_Vrepresentation(),
Expand Down
Loading

0 comments on commit f638686

Please sign in to comment.