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

Commit

Permalink
Merge #31821
Browse files Browse the repository at this point in the history
  • Loading branch information
mkoeppe committed May 16, 2021
2 parents ab9d41e + b285d95 commit db82c83
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 5 deletions.
42 changes: 40 additions & 2 deletions src/sage/geometry/polyhedron/backend_normaliz.py
Original file line number Diff line number Diff line change
Expand Up @@ -1272,12 +1272,28 @@ def __getstate__(self):
A vertex at (0, 0, 1, 0),
A vertex at (0, 1, 0, 0),
A vertex at (1, 0, 0, 0)),
'_normaliz_field': Rational Field})
'_normaliz_field': Rational Field,
'_pickle_equations': [(-1, 1, 1, 1, 1)],
'_pickle_inequalities': [(0, 0, 0, 0, 1),
(0, 0, 0, 1, 0),
(0, 0, 1, 0, 0),
(0, 1, 0, 0, 0)],
'_pickle_lines': [],
'_pickle_rays': [],
'_pickle_vertices': [(0, 0, 0, 1),
(0, 0, 1, 0),
(0, 1, 0, 0),
(1, 0, 0, 0)]})
"""
state = super(Polyhedron_normaliz, self).__getstate__()
state = (state[0], state[1].copy())
# Remove the unpicklable entries.
del state[1]['_normaliz_cone']
state[1]["_pickle_vertices"] = [v._vector for v in self.vertices()]
state[1]["_pickle_rays"] = [v._vector for v in self.rays()]
state[1]["_pickle_lines"] = [v._vector for v in self.lines()]
state[1]["_pickle_inequalities"] = [v._vector for v in self.inequalities()]
state[1]["_pickle_equations"] = [v._vector for v in self.equations()]
return state

def __setstate__(self, state):
Expand Down Expand Up @@ -1326,17 +1342,39 @@ def __setstate__(self, state):
sage: P2 = Polyhedron_normaliz(P1.parent(), None, None, P1._normaliz_cone, normaliz_field=P1._normaliz_field) # optional - pynormaliz
sage: P == P2 # optional - pynormaliz
True
Test that :trac:`31820` is fixed::
sage: P = polytopes.cube(backend='normaliz') # optional - pynormaliz
sage: v = P.Vrepresentation()[0] # optional - pynormaliz
sage: v1 = loads(v.dumps()) # optional - pynormaliz
"""
if "_pickle_vertices" in state[1]:
vertices = state[1].pop("_pickle_vertices")
rays = state[1].pop("_pickle_rays")
lines = state[1].pop("_pickle_lines")
inequalities = state[1].pop("_pickle_inequalities")
equations = state[1].pop("_pickle_equations")
else:
vertices = None

super(Polyhedron_normaliz, self).__setstate__(state)

if self.is_empty():
# Special case to avoid.
self._normaliz_cone = None
return

if vertices is None:
vertices = self.vertices()
rays = self.rays()
lines = self.lines()
inequalities = self.inequalities()
equations = self.equations()

self._normaliz_cone = \
self._cone_from_Vrepresentation_and_Hrepresentation(
self.vertices(), self.rays(), self.lines(), self.inequalities(), self.equations())
vertices, rays, lines, inequalities, equations)

def integral_hull(self):
r"""
Expand Down
16 changes: 16 additions & 0 deletions src/sage/geometry/polyhedron/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3537,6 +3537,22 @@ def combinatorial_polyhedron(self):
from sage.geometry.polyhedron.combinatorial_polyhedron.base import CombinatorialPolyhedron
return CombinatorialPolyhedron(self)

def _test_combinatorial_polyhedron(self, tester=None, **options):
"""
Run test suite of combinatorial polyhedron.
TESTS::
sage: polytopes.cross_polytope(3)._test_combinatorial_polyhedron()
"""
from sage.misc.sage_unittest import TestSuite

tester = self._tester(tester=tester, **options)
tester.info("\n Running the test suite of self.combinatorial_polyhedron()")
TestSuite(self.combinatorial_polyhedron()).run(verbose=tester._verbose,
prefix=tester._prefix+" ")
tester.info(tester._prefix+" ", newline = False)

def simplicity(self):
r"""
Return the largest integer `k` such that the polytope is `k`-simple.
Expand Down
21 changes: 18 additions & 3 deletions src/sage/geometry/polyhedron/combinatorial_polyhedron/base.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -652,11 +652,11 @@ cdef class CombinatorialPolyhedron(Element):
"""
# Give a constructor by list of facets.
if not self.is_bounded():
return (CombinatorialPolyhedron, (self.facets(),
return (CombinatorialPolyhedron, (self.incidence_matrix(),
self.Vrepresentation(), self.Hrepresentation(),
True, self.far_face_tuple()))
else:
return (CombinatorialPolyhedron, (self.facets(),
return (CombinatorialPolyhedron, (self.incidence_matrix(),
self.Vrepresentation(), self.Hrepresentation()))

def _test_bitsets(self, tester=None, **options):
Expand Down Expand Up @@ -1006,7 +1006,7 @@ cdef class CombinatorialPolyhedron(Element):
sage: C.facets()
()
"""
if unlikely(self.dimension() == 0):
if unlikely(self.dimension() <= 0):
# Special attention for this trivial case.
# Facets are defined to be nontrivial faces of codimension 1.
# The empty face is trivial.
Expand Down Expand Up @@ -2784,6 +2784,21 @@ cdef class CombinatorialPolyhedron(Element):
"""
return self._far_face_tuple

def __eq__(self, other):
r"""
Return whether ``self`` and ``other`` are equal.
"""
if not isinstance(other, CombinatorialPolyhedron):
return False
cdef CombinatorialPolyhedron other_C = other
return (self.n_facets() == other.n_facets()
and self.Vrepresentation() == other.Vrepresentation()
and self.facet_names() == other_C.facet_names()
and self.equalities() == other_C.equalities()
and self.dimension() == other.dimension()
and self.far_face_tuple() == other_C.far_face_tuple()
and self.incidence_matrix() == other.incidence_matrix())


# Methods to obtain a different combinatorial polyhedron.

Expand Down

0 comments on commit db82c83

Please sign in to comment.