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

Commit

Permalink
simplified projection into affine_hull
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Kliem committed Mar 13, 2020
1 parent 6db1a26 commit f9e1283
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/sage/geometry/polyhedron/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9000,14 +9000,19 @@ def affine_hull(self, as_affine_map=False, orthogonal=False, orthonormal=False,
...
NotImplementedError: "orthogonal=True" and "orthonormal=True" work only for compact polyhedra
Setting ``as_affine_map`` to ``True`` only works in combination
with ``orthogonal`` or ``orthonormal`` set to ``True``::
Setting ``as_affine_map`` to ``True``
without ``orthogonal`` or ``orthonormal`` set to ``True``::
sage: S = polytopes.simplex()
sage: S.affine_hull(as_affine_map=True)
Traceback (most recent call last):
...
NotImplementedError: "as_affine_map=True" only works with "orthogonal=True" and "orthonormal=True"
(Vector space morphism represented by the matrix:
[1 0 0]
[0 1 0]
[0 0 1]
[0 0 0]
Domain: Vector space of dimension 4 over Rational Field
Codomain: Vector space of dimension 3 over Rational Field,
(0, 0, 0))
If the polyhedron is full-dimensional, it is returned::
Expand All @@ -9019,7 +9024,8 @@ def affine_hull(self, as_affine_map=False, orthogonal=False, orthonormal=False,
[0 1 0]
[0 0 1]
Domain: Vector space of dimension 3 over Rational Field
Codomain: Vector space of dimension 3 over Rational Field, (0, 0, 0))
Codomain: Vector space of dimension 3 over Rational Field,
(0, 0, 0))
TESTS:
Expand Down Expand Up @@ -9103,9 +9109,7 @@ def affine_hull(self, as_affine_map=False, orthogonal=False, orthonormal=False,
return linear_transformation(A, side='right'), -A*vector(A.base_ring(), affine_basis[0])

translate_vector = vector(A.base_ring(), affine_basis[0])
parent = self.parent().change_ring(A.base_ring(), ambient_dim=self.dim())
new_vertices = [A*(vector(A.base_ring(), w) - translate_vector) for w in self.vertices()]
return parent.element_class(parent, [new_vertices, [], []], None)
return A*(self.change_ring(A.base_ring()) - translate_vector)

# translate one vertex to the origin
v0 = self.vertices()[0].vector()
Expand All @@ -9120,15 +9124,11 @@ def affine_hull(self, as_affine_map=False, orthogonal=False, orthonormal=False,
# Pick subset of coordinates to coordinatize the affine span
pivots = matrix(gens).pivots()

def pivot(indexed):
return [indexed[i] for i in pivots]

vertices = [pivot(_) for _ in self.vertices()]
rays = [pivot(_) for _ in self.rays()]
lines = [pivot(_) for _ in self.lines()]
A = matrix([[1 if j == i else 0 for j in range(self.ambient_dim())] for i in pivots])
if as_affine_map:
raise NotImplementedError('"as_affine_map=True" only works with "orthogonal=True" and "orthonormal=True"')
return Polyhedron(vertices=vertices, rays=rays, lines=lines, base_ring=self.base_ring(), backend=self.backend())
return linear_transformation(A, side='right'), vector(self.base_ring(), self.dim())
else:
return A*self

def _polymake_init_(self):
"""
Expand Down

0 comments on commit f9e1283

Please sign in to comment.