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

Commit 192efaf

Browse files
author
Release Manager
committed
Trac #29455: Bug in incidence_matrix of CombinatorialPolyhedron
The `incidence_matrix` method of a 0-dimensional `CombinatorialPolyhedron` returns an error: {{{ sage: P = Polyhedron([[0]]); P A 0-dimensional polyhedron in ZZ^1 defined as the convex hull of 1 vertex sage: C = P.combinatorial_polyhedron() sage: C.incidence_matrix() ------------------------------------------------------------------------ --- ValueError Traceback (most recent call last) <ipython-input-7-dab311ba238f> in <module>() ----> 1 C.incidence_matrix() ... ValueError: ``output_dimension`` must be the dimension of proper faces }}} We fix this and make the `0`-dimensional case consistent with `Polyhedron_base`. Also we make `incidence_matrix` a `chached_method`. URL: https://trac.sagemath.org/29455 Reported by: gh-LaisRast Ticket author(s): Jonathan Kliem Reviewer(s): Laith Rastanawi
2 parents e8117be + 34f3254 commit 192efaf

File tree

1 file changed

+32
-0
lines changed
  • src/sage/geometry/polyhedron/combinatorial_polyhedron

1 file changed

+32
-0
lines changed

src/sage/geometry/polyhedron/combinatorial_polyhedron/base.pyx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,7 @@ cdef class CombinatorialPolyhedron(SageObject):
955955

956956
return tuple(facets)
957957

958+
@cached_method
958959
def incidence_matrix(self):
959960
"""
960961
Return the incidence matrix.
@@ -990,12 +991,41 @@ cdef class CombinatorialPolyhedron(SageObject):
990991
sage: C = P.combinatorial_polyhedron()
991992
sage: C.incidence_matrix() == P.incidence_matrix()
992993
True
994+
995+
The incidence matrix is consistent with
996+
:meth:`~sage.geometry.polyhedron.base.Polyhedron_base.incidence_matrix`::
997+
998+
sage: P = Polyhedron([[0,0]])
999+
sage: P.incidence_matrix()
1000+
[1 1]
1001+
sage: P.combinatorial_polyhedron().incidence_matrix()
1002+
[1 1]
1003+
1004+
TESTS:
1005+
1006+
Check that :trac:`29455` is fixed::
1007+
1008+
sage: C = Polyhedron([[0]]).combinatorial_polyhedron()
1009+
sage: C.incidence_matrix()
1010+
[1]
1011+
sage: C = CombinatorialPolyhedron(-1)
1012+
sage: C.incidence_matrix()
1013+
[]
9931014
"""
9941015
from sage.rings.all import ZZ
9951016
from sage.matrix.constructor import matrix
9961017
incidence_matrix = matrix(ZZ, self.n_Vrepresentation(),
9971018
self.n_Hrepresentation(), 0)
9981019

1020+
if self.dim() < 1:
1021+
# Small cases.
1022+
if self.dim() == 0:
1023+
# To be consistent with ``Polyhedron_base``,
1024+
for i in range(self.n_Hrepresentation()):
1025+
incidence_matrix[0,i] = 1
1026+
incidence_matrix.set_immutable()
1027+
return incidence_matrix
1028+
9991029
# If equalities are present, we add them as first columns.
10001030
n_equalities = 0
10011031
if self.facet_names() is not None:
@@ -1010,6 +1040,8 @@ cdef class CombinatorialPolyhedron(SageObject):
10101040
for Vindex in facet.ambient_V_indices():
10111041
incidence_matrix[Vindex, Hindex] = 1
10121042

1043+
incidence_matrix.set_immutable()
1044+
10131045
return incidence_matrix
10141046

10151047
def edges(self, names=True):

0 commit comments

Comments
 (0)