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

Commit

Permalink
fix incidence matrix for small combinatorial polyhedra
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Kliem committed Apr 3, 2020
1 parent 6a45805 commit 4aa8b28
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/sage/geometry/polyhedron/combinatorial_polyhedron/base.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,7 @@ cdef class CombinatorialPolyhedron(SageObject):

return tuple(facets)

@cached_method
def incidence_matrix(self):
"""
Return the incidence matrix.
Expand Down Expand Up @@ -904,12 +905,41 @@ cdef class CombinatorialPolyhedron(SageObject):
sage: C = P.combinatorial_polyhedron()
sage: C.incidence_matrix() == P.incidence_matrix()
True
The incidence matrix is consistent with
:meth:`~sage.geometry.polyhedron.base.Polyhedron_base.incidence_matrix`::
sage: P = Polyhedron([[0,0]])
sage: P.incidence_matrix()
[1, 1]
sage: P.combinatorial_polyehdron().incidence_matrix()
[1, 1]
TESTS:
Check that :trac:`29455` is fixed::
sage: C = Polyhedron([[0]]).combinatorial_polyhedron()
sage: C.incidence_matrix()
[1]
sage: C = CombinatorialPolyhedron(-1)
sage: C.incidence_matrix()
[]
"""
from sage.rings.all import ZZ
from sage.matrix.constructor import matrix
incidence_matrix = matrix(ZZ, self.n_Vrepresentation(),
self.n_Hrepresentation(), 0)

if self.dim() < 1:
# Small cases.
if self.dim() == 0:
# To be consistent with ``Polyhedron_base``,
for i in range(self.n_Hrepresentation()):
incidence_matrix[0,i] = 1
incidence_matrix.set_immutable()
return incidence_matrix

# If equalities are present, we add them as first columns.
n_equalities = 0
if self.facet_names() is not None:
Expand All @@ -924,6 +954,8 @@ cdef class CombinatorialPolyhedron(SageObject):
for Vindex in facet.ambient_V_indices():
incidence_matrix[Vindex, Hindex] = 1

incidence_matrix.set_immutable()

return incidence_matrix

def edges(self, names=True):
Expand Down

0 comments on commit 4aa8b28

Please sign in to comment.