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

Commit

Permalink
test suite for gale transform
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Kliem committed Jun 20, 2020
1 parent d62124f commit c17428a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 14 deletions.
35 changes: 35 additions & 0 deletions src/sage/geometry/polyhedron/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3748,6 +3748,41 @@ def gale_transform(self):
A_ker = A.right_kernel_matrix(basis='computed')
return tuple(A_ker.columns())

def _test_gale_transform(self, tester=None, **options):
"""
Run tests on the method :meth:`.gale_transform` and its inverse
:meth:`~sage.geometry.polyhedron.library.gale_transform_to_polytope`.
TESTS::
sage: polytopes.cross_polytope(3)._test_gale_transform()
"""
if tester is None:
tester = self._tester(**options)

if not self.is_compact():
with tester.assertRaises(ValueError):
self.gale_transform()
return

# Check :trac:`29073`.
if not self.base_ring().is_exact():
g = self.gale_transform()
tester.assertTrue(sum(g).norm() < 1e-10 or sum(g).norm()/matrix(g).norm() < 1e-13)
return

# Prevent very long doctests.
if self.n_vertices() + self.n_rays() > 50 or self.n_facets() > 50:
return

if not self.is_empty():
# ``gale_transform_to_polytope`` needs at least one vertex to work.
from sage.geometry.polyhedron.library import gale_transform_to_polytope
g = self.gale_transform()
P = gale_transform_to_polytope(g, base_ring=self.base_ring(), backend=self.backend())

tester.assertTrue(self.is_combinatorially_isomorphic(P))

@cached_method
def normal_fan(self, direction='inner'):
r"""
Expand Down
14 changes: 0 additions & 14 deletions src/sage/geometry/polyhedron/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,20 +303,6 @@ def gale_transform_to_polytope(vectors, base_ring=None, backend=None):
Traceback (most recent call last):
...
ValueError: the gale transform does not correspond to a polytope
TESTS::
sage: def test(P):
....: P1 = gale_transform_to_polytope(
....: P.gale_transform(), base_ring=P.base_ring(),
....: backend=P.backend())
....: assert P1.is_combinatorially_isomorphic(P)
sage: test(polytopes.cube())
sage: test(polytopes.permutahedron(4))
sage: test(polytopes.regular_polygon(5))
sage: test(polytopes.regular_polygon(7, exact=False))
sage: test(polytopes.snub_cube(exact=True, backend='normaliz')) # optional - pynormaliz
"""
vertices = gale_transform_to_primal(vectors, base_ring, backend)
P = Polyhedron(vertices=vertices, base_ring=base_ring, backend=backend)
Expand Down

0 comments on commit c17428a

Please sign in to comment.