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

Commit

Permalink
simplify doctessts in polyhedron face lattice
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Kliem committed Sep 2, 2020
1 parent 41ed120 commit 1529987
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ cdef class PolyhedronFaceLattice:
cdef inline bint is_smaller(self, uint64_t *one, uint64_t *two)
cdef inline int is_equal(self, int dimension, size_t index,
uint64_t *face) except -1
cdef CombinatorialFace get_face(self, int dimension, size_t index)
cpdef CombinatorialFace get_face(self, int dimension, size_t index)
cdef size_t set_coatom_rep(self, int dimension, size_t index) except -1
cdef size_t set_atom_rep(self, int dimension, size_t index) except -1
cdef void incidence_init(self, int dimension_one, int dimension_two)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,30 @@ cdef class PolyhedronFaceLattice:
j += 1
counter += 1

def _find_face_from_combinatorial_face(self, CombinatorialFace face):
r"""
A method to test :meth:`find_face`.
``f`` must be a face in dual mode if and only if ``self`` is in dual mode.
TESTS::
sage: from sage.geometry.polyhedron.combinatorial_polyhedron.polyhedron_face_lattice \
....: import PolyhedronFaceLattice
sage: P = polytopes.hypercube(4)
sage: C = CombinatorialPolyhedron(P)
sage: F = PolyhedronFaceLattice(C)
sage: it = C.face_iter()
sage: face = next(it)
sage: F._find_face_from_combinatorial_face(face)
Traceback (most recent call last):
...
ValueError: cannot find a facet, as those are not sorted
"""
if not (self.dual == face._dual):
raise ValueError("iterator and allfaces not in same mode")
return self.find_face(face.dimension(), face.face)

cdef inline size_t find_face(self, int dimension, uint64_t *face) except -1:
r"""
Return the index of ``face``, if it is of dimension ``dimension``.
Expand All @@ -348,28 +372,13 @@ cdef class PolyhedronFaceLattice:
EXAMPLES::
sage: cython('''
....: from libc.stdint cimport uint64_t
....: from sage.geometry.polyhedron.combinatorial_polyhedron.base \
....: cimport CombinatorialPolyhedron, FaceIterator, PolyhedronFaceLattice
....:
....: def find_face_from_iterator(FaceIterator it, CombinatorialPolyhedron C):
....: C._record_all_faces()
....: cdef PolyhedronFaceLattice all_faces = C._all_faces
....: if not (all_faces.dual == it.dual):
....: raise ValueError("iterator and allfaces not in same mode")
....: return all_faces.find_face(it.structure.current_dimension, it.structure.face)
....: ''')
sage: from sage.geometry.polyhedron.combinatorial_polyhedron.polyhedron_face_lattice \
....: import PolyhedronFaceLattice
sage: P = polytopes.permutahedron(4)
sage: C = CombinatorialPolyhedron(P)
sage: it = C.face_iter()
sage: face = next(it)
sage: find_face_from_iterator(it, C)
Traceback (most recent call last):
...
ValueError: cannot find a facet, as those are not sorted
sage: F = PolyhedronFaceLattice(C)
sage: it = C.face_iter(dimension=1)
sage: S = set(find_face_from_iterator(it, C) for _ in it)
sage: S = set(F._find_face_from_combinatorial_face(f) for f in it)
sage: S == set(range(36))
True
"""
Expand Down Expand Up @@ -419,7 +428,7 @@ cdef class PolyhedronFaceLattice:
cdef size_t i
return (0 == memcmp(face, face2, self.face_length*8))

cdef CombinatorialFace get_face(self, int dimension, size_t index):
cpdef CombinatorialFace get_face(self, int dimension, size_t index):
r"""
Return the face of dimension ``dimension`` and index ``index``.
Expand All @@ -432,42 +441,36 @@ cdef class PolyhedronFaceLattice:
EXAMPLES::
sage: cython('''
....: from libc.stdint cimport uint64_t
....: from sage.geometry.polyhedron.combinatorial_polyhedron.base \
....: cimport CombinatorialPolyhedron, FaceIterator, PolyhedronFaceLattice
....:
....: def face_via_all_faces_from_iterator(FaceIterator it, CombinatorialPolyhedron C):
....: cdef int dimension = it.structure.current_dimension
....: C._record_all_faces()
....: cdef PolyhedronFaceLattice all_faces = C._all_faces
....: if not (all_faces.dual == it.dual):
....: raise ValueError("iterator and allfaces not in same mode")
....: index = all_faces.find_face(dimension, it.structure.face)
....: return all_faces.get_face(dimension, index)
....: ''')
sage: from sage.geometry.polyhedron.combinatorial_polyhedron.polyhedron_face_lattice \
....: import PolyhedronFaceLattice
sage: P = polytopes.permutahedron(4)
sage: C = CombinatorialPolyhedron(P)
sage: F = PolyhedronFaceLattice(C)
sage: it = C.face_iter(dimension=1)
sage: face = next(it)
sage: face_via_all_faces_from_iterator(it, C).ambient_Vrepresentation()
sage: index = F._find_face_from_combinatorial_face(face)
sage: F.get_face(face.dimension(), index).ambient_Vrepresentation()
(A vertex at (2, 1, 4, 3), A vertex at (1, 2, 4, 3))
sage: face.ambient_Vrepresentation()
(A vertex at (2, 1, 4, 3), A vertex at (1, 2, 4, 3))
sage: all(face_via_all_faces_from_iterator(it, C).ambient_Vrepresentation() ==
sage: all(F.get_face(face.dimension(),
....: F._find_face_from_combinatorial_face(face)).ambient_Vrepresentation() ==
....: face.ambient_Vrepresentation() for face in it)
True
sage: P = polytopes.twenty_four_cell()
sage: C = CombinatorialPolyhedron(P)
sage: F = PolyhedronFaceLattice(C)
sage: it = C.face_iter()
sage: face = next(it)
sage: while (face.dimension() == 3): face = next(it)
sage: face_via_all_faces_from_iterator(it, C).ambient_Vrepresentation()
sage: index = F._find_face_from_combinatorial_face(face)
sage: F.get_face(face.dimension(), index).ambient_Vrepresentation()
(A vertex at (-1/2, 1/2, -1/2, -1/2),
A vertex at (-1/2, 1/2, 1/2, -1/2),
A vertex at (0, 0, 0, -1))
sage: all(face_via_all_faces_from_iterator(it, C).ambient_V_indices() ==
sage: all(F.get_face(face.dimension(),
....: F._find_face_from_combinatorial_face(face)).ambient_V_indices() ==
....: face.ambient_V_indices() for face in it)
True
"""
Expand Down

0 comments on commit 1529987

Please sign in to comment.