From 5d1a52e4c73c33f69aeae6ad9e42265750394adb Mon Sep 17 00:00:00 2001 From: Jonathan Kliem Date: Fri, 24 Apr 2020 11:41:19 +0200 Subject: [PATCH] store incidence matrix, if initialized from it --- .../combinatorial_polyhedron/base.pyx | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/sage/geometry/polyhedron/combinatorial_polyhedron/base.pyx b/src/sage/geometry/polyhedron/combinatorial_polyhedron/base.pyx index 969c9f86db1..ab431210731 100644 --- a/src/sage/geometry/polyhedron/combinatorial_polyhedron/base.pyx +++ b/src/sage/geometry/polyhedron/combinatorial_polyhedron/base.pyx @@ -427,6 +427,12 @@ cdef class CombinatorialPolyhedron(SageObject): self._n_Hrepresentation = data.ncols() self._n_Vrepresentation = data.nrows() + # Store the incidence matrix. + if not data.is_immutable(): + data = data.__copy__() + data.set_immutable() + self.incidence_matrix.set_cache(data) + # Initializing the facets in their Bit-representation. self._bitrep_facets = incidence_matrix_to_bit_rep_of_facets(data) @@ -984,11 +990,22 @@ cdef class CombinatorialPolyhedron(SageObject): [0 0 0 1 1 1] [0 1 0 1 1 0] [0 1 1 1 0 0] - sage: P.incidence_matrix() == C.incidence_matrix() + + In this case the incidence matrix is only computed once:: + + sage: P.incidence_matrix() is C.incidence_matrix() + True + sage: C.incidence_matrix.clear_cache() + sage: C.incidence_matrix() is P.incidence_matrix() + False + sage: C.incidence_matrix() == P.incidence_matrix() True + :: + sage: P = polytopes.permutahedron(5) sage: C = P.combinatorial_polyhedron() + sage: C.incidence_matrix.clear_cache() sage: C.incidence_matrix() == P.incidence_matrix() True @@ -998,6 +1015,8 @@ cdef class CombinatorialPolyhedron(SageObject): sage: P = Polyhedron([[0,0]]) sage: P.incidence_matrix() [1 1] + sage: C = P.combinatorial_polyhedron() + sage: C.incidence_matrix.clear_cache() sage: P.combinatorial_polyhedron().incidence_matrix() [1 1] @@ -1006,9 +1025,11 @@ cdef class CombinatorialPolyhedron(SageObject): Check that :trac:`29455` is fixed:: sage: C = Polyhedron([[0]]).combinatorial_polyhedron() + sage: C.incidence_matrix.clear_cache() sage: C.incidence_matrix() [1] sage: C = CombinatorialPolyhedron(-1) + sage: C.incidence_matrix.clear_cache() sage: C.incidence_matrix() [] """