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

Commit

Permalink
Merge #31919
Browse files Browse the repository at this point in the history
  • Loading branch information
mkoeppe committed Jun 12, 2021
2 parents 1f7826d + 686d0af commit 2b1d108
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 5 deletions.
79 changes: 76 additions & 3 deletions src/sage/geometry/convex_set.py
Expand Up @@ -44,6 +44,15 @@ def is_universe(self):
OUTPUT:
Boolean.
TESTS::
sage: from sage.geometry.convex_set import ConvexSet_base
sage: C = ConvexSet_base()
sage: C.is_universe()
Traceback (most recent call last):
...
NotImplementedError: <abstract method dim at ...>
"""
if not self.is_full_dimensional():
return False
Expand All @@ -53,6 +62,15 @@ def is_universe(self):
def dim(self):
r"""
Return the dimension of ``self``.
TESTS::
sage: from sage.geometry.convex_set import ConvexSet_base
sage: C = ConvexSet_base()
sage: C.dim()
Traceback (most recent call last):
...
NotImplementedError: <abstract method dim at ...>
"""

def dimension(self):
Expand Down Expand Up @@ -88,6 +106,15 @@ def ambient(self):
def ambient_dim(self):
r"""
Return the dimension of the ambient convex set or space.
TESTS::
sage: from sage.geometry.convex_set import ConvexSet_base
sage: C = ConvexSet_base()
sage: C.ambient_dim()
Traceback (most recent call last):
...
NotImplementedError: <abstract method ambient_dim at ...>
"""

def ambient_dimension(self):
Expand All @@ -111,11 +138,15 @@ def codimension(self):
r"""
Return the codimension of ``self`` in `self.ambient()``.
An alias is :meth:`codim`.
EXAMPLES::
sage: Polyhedron(vertices=[(1,2,3)], rays=[(1,0,0)]).codimension()
sage: P = Polyhedron(vertices=[(1,2,3)], rays=[(1,0,0)])
sage: P.codimension()
2
An alias is :meth:`codim`::
sage: P.codim()
2
"""
return self.ambient_dim() - self.dim()
Expand Down Expand Up @@ -359,13 +390,28 @@ def _test_convex_set(self, tester=None, **options):
tester.assertTrue(self == cl_self)
if self.is_compact():
tester.assertTrue(self.is_closed())
from sage.misc.sage_unittest import TestSuite
if relint_self is not None and relint_self is not self:
tester.info("\n Running the test suite of self.relative_interior()")
TestSuite(relint_self).run(verbose=tester._verbose,
prefix=tester._prefix + " ")
tester.info(tester._prefix + " ", newline=False)

# Optional methods

@abstract_method(optional=True)
def affine_hull(self):
r"""
Return the affine hull of ``self``.
TESTS::
sage: from sage.geometry.convex_set import ConvexSet_base
sage: C = ConvexSet_base()
sage: C.affine_hull()
Traceback (most recent call last):
...
TypeError: 'NotImplementedType' object is not callable
"""

@abstract_method(optional=True)
Expand All @@ -380,6 +426,15 @@ def cartesian_product(self, other):
OUTPUT:
The Cartesian product of ``self`` and ``other``.
TESTS::
sage: from sage.geometry.convex_set import ConvexSet_base
sage: C = ConvexSet_base()
sage: C.cartesian_product(C)
Traceback (most recent call last):
...
TypeError: 'NotImplementedType' object is not callable
"""

@abstract_method(optional=True)
Expand All @@ -390,6 +445,15 @@ def contains(self, point):
INPUT:
- ``point`` -- a point or its coordinates
TESTS::
sage: from sage.geometry.convex_set import ConvexSet_base
sage: C = ConvexSet_base()
sage: C.contains(vector([0, 0]))
Traceback (most recent call last):
...
TypeError: 'NotImplementedType' object is not callable
"""

def _test_contains(self, tester=None, **options):
Expand Down Expand Up @@ -463,6 +527,15 @@ def intersection(self, other):
OUTPUT:
The intersection.
TESTS::
sage: from sage.geometry.convex_set import ConvexSet_base
sage: C = ConvexSet_base()
sage: C.intersection(C)
Traceback (most recent call last):
...
TypeError: 'NotImplementedType' object is not callable
"""


Expand Down
13 changes: 13 additions & 0 deletions src/sage/geometry/polyhedron/base.py
Expand Up @@ -4797,6 +4797,11 @@ def product(self, other):
sage: P1 * 2.0
A 1-dimensional polyhedron in RDF^1 defined as the convex hull of 2 vertices
An alias is :meth:`cartesian_product`::
sage: P1.cartesian_product(P2) == P1.product(P2)
True
TESTS:
Check that :trac:`15253` is fixed::
Expand Down Expand Up @@ -8455,7 +8460,15 @@ def interior(self):
sage: P_lower.interior()
The empty polyhedron in ZZ^2
TESTS::
sage: Empty = Polyhedron(ambient_dim=2); Empty
The empty polyhedron in ZZ^2
sage: Empty.interior() is Empty
True
"""
if self.is_open():
return self
if not self.is_full_dimensional():
return self.parent().element_class(self.parent(), None, None)
return self.relative_interior()
Expand Down
28 changes: 26 additions & 2 deletions src/sage/geometry/relative_interior.py
Expand Up @@ -79,7 +79,8 @@ def ambient_dim(self):
sage: segment.ambient_dim()
2
sage: ri_segment = segment.relative_interior(); ri_segment
Relative interior of a 1-dimensional polyhedron in ZZ^2 defined as the convex hull of 2 vertices
Relative interior of
a 1-dimensional polyhedron in ZZ^2 defined as the convex hull of 2 vertices
sage: ri_segment.ambient_dim()
2
"""
Expand All @@ -95,7 +96,8 @@ def dim(self):
sage: segment.dim()
1
sage: ri_segment = segment.relative_interior(); ri_segment
Relative interior of a 1-dimensional polyhedron in ZZ^2 defined as the convex hull of 2 vertices
Relative interior of
a 1-dimensional polyhedron in ZZ^2 defined as the convex hull of 2 vertices
sage: ri_segment.dim()
1
"""
Expand Down Expand Up @@ -154,6 +156,28 @@ def closure(self):
"""
return self._polyhedron

def is_universe(self):
r"""
Return whether ``self`` is the whole ambient space
OUTPUT:
Boolean.
EXAMPLES::
sage: segment = Polyhedron([[1, 2], [3, 4]])
sage: ri_segment = segment.relative_interior(); ri_segment
Relative interior of
a 1-dimensional polyhedron in ZZ^2 defined as the convex hull of 2 vertices
sage: ri_segment.is_universe()
False
"""
# Relies on ``self`` not set up for polyhedra that are already
# relatively open themselves.
assert not self._polyhedron.is_universe()
return False

def is_closed(self):
r"""
Return whether ``self`` is closed.
Expand Down

0 comments on commit 2b1d108

Please sign in to comment.