Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deprecated functions is_Cone, is_Polyhedron, is_LatticePolytope #37057

Merged
merged 6 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/sage/geometry/cone.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@
from sage.combinat.posets.posets import FinitePoset
from sage.geometry.point_collection import PointCollection
from sage.geometry.polyhedron.constructor import Polyhedron
from sage.geometry.polyhedron.base import is_Polyhedron
from sage.geometry.hasse_diagram import lattice_from_incidences
from sage.geometry.toric_lattice import (ToricLattice, is_ToricLattice,
is_ToricLatticeQuotient)
Expand Down Expand Up @@ -259,13 +258,18 @@ def is_Cone(x):

sage: from sage.geometry.cone import is_Cone
sage: is_Cone(1)
doctest:warning...
DeprecationWarning: is_Cone is deprecated, use isinstance instead
See https://github.com/sagemath/sage/issues/34307 for details.
False
sage: quadrant = Cone([(1,0), (0,1)])
sage: quadrant
2-d cone in 2-d lattice N
sage: is_Cone(quadrant)
True
"""
from sage.misc.superseded import deprecation
deprecation(34307, "is_Cone is deprecated, use isinstance instead")
return isinstance(x, ConvexRationalPolyhedralCone)


Expand Down Expand Up @@ -439,7 +443,7 @@ def Cone(rays, lattice=None, check=True, normalize=True):
0-d cone in 2-d lattice N
"""
# Cone from Polyhedron
if is_Polyhedron(rays):
if isinstance(rays, sage.geometry.abc.Polyhedron):
polyhedron = rays
if lattice is None:
lattice = ToricLattice(polyhedron.ambient_dim())
Expand Down Expand Up @@ -1894,7 +1898,7 @@ def cartesian_product(self, other, lattice=None):
N+N(0, 1)
in 2-d lattice N+N
"""
assert is_Cone(other)
assert isinstance(other, sage.geometry.abc.ConvexRationalPolyhedralCone)
rc = super().cartesian_product(other, lattice)
return ConvexRationalPolyhedralCone(rc.rays(), rc.lattice())

Expand Down Expand Up @@ -1952,7 +1956,7 @@ def __richcmp__(self, right, op):
sage: c2 is c3
False
"""
if is_Cone(right):
if isinstance(right, sage.geometry.abc.ConvexRationalPolyhedralCone):
# We don't care about particular type of right in this case
return richcmp((self.lattice(), self.rays()),
(right.lattice(), right.rays()), op)
Expand Down Expand Up @@ -2413,7 +2417,7 @@ def embed(self, cone):
ValueError: 2-d cone in 3-d lattice N is not a face
of 3-d cone in 3-d lattice N!
"""
assert is_Cone(cone)
assert isinstance(cone, sage.geometry.abc.ConvexRationalPolyhedralCone)
if cone.ambient() is self:
return cone
if self.is_strictly_convex():
Expand Down Expand Up @@ -2935,7 +2939,7 @@ def facet_of(self):
L = self._ambient._face_lattice_function()
H = L.hasse_diagram()
return self._sort_faces(
f for f in H.neighbors_out(L(self)) if is_Cone(f))
f for f in H.neighbors_out(L(self)) if isinstance(f, sage.geometry.abc.ConvexRationalPolyhedralCone))

def facets(self):
r"""
Expand Down Expand Up @@ -6387,9 +6391,8 @@ def random_cone(lattice=None, min_ambient_dim=0, max_ambient_dim=None,
It's hard to test the output of a random process, but we can at
least make sure that we get a cone back::

sage: from sage.geometry.cone import is_Cone
sage: K = random_cone(max_ambient_dim=6, max_rays=10)
sage: is_Cone(K)
sage: isinstance(K, sage.geometry.abc.ConvexRationalPolyhedralCone)
True

The upper/lower bounds are respected::
Expand Down
13 changes: 6 additions & 7 deletions src/sage/geometry/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,15 @@
from copy import copy
from warnings import warn

import sage.geometry.abc

from sage.structure.richcmp import richcmp_method, richcmp
from sage.combinat.combination import Combinations
from sage.combinat.posets.posets import FinitePoset
from sage.geometry.cone import (_ambient_space_point,
Cone,
ConvexRationalPolyhedralCone,
IntegralRayCollection,
is_Cone,
normalize_rays)
from sage.geometry.hasse_diagram import lattice_from_incidences
from sage.geometry.point_collection import PointCollection
Expand Down Expand Up @@ -571,7 +572,7 @@ def result():
cones = ((), )
rays = ()
return result()
if is_Cone(cones[0]):
if isinstance(cones[0], sage.geometry.abc.ConvexRationalPolyhedralCone):
# Construct the fan from Cone objects
if lattice is None:
lattice = cones[0].lattice()
Expand Down Expand Up @@ -749,11 +750,10 @@ def FaceFan(polytope, lattice=None):
ValueError: face fans are defined only for
polytopes containing the origin as an interior point!
"""
from sage.geometry.lattice_polytope import is_LatticePolytope
interior_point_error = ValueError(
"face fans are defined only for polytopes containing "
"the origin as an interior point!")
if is_LatticePolytope(polytope):
if isinstance(polytope, sage.geometry.abc.LatticePolytope):
if any(d <= 0 for d in polytope.distances([0] * polytope.dim())):
raise interior_point_error
cones = (f.ambient_vertex_indices() for f in polytope.facets())
Expand Down Expand Up @@ -843,8 +843,7 @@ def NormalFan(polytope, lattice=None):
"""
dimension_error = ValueError(
'the normal fan is only defined for full-dimensional polytopes')
from sage.geometry.lattice_polytope import is_LatticePolytope
if is_LatticePolytope(polytope):
if isinstance(polytope, sage.geometry.abc.LatticePolytope):
if polytope.dim() != polytope.lattice_dim():
raise dimension_error
rays = polytope.facet_normals()
Expand Down Expand Up @@ -2425,7 +2424,7 @@ def embed(self, cone):
ValueError: 2-d cone in 3-d lattice N does not belong
to Rational polyhedral fan in 3-d lattice N!
"""
if not is_Cone(cone):
if not isinstance(cone, sage.geometry.abc.ConvexRationalPolyhedralCone):
raise TypeError("%s is not a cone!" % cone)
if cone.ambient() is self:
return cone
Expand Down
6 changes: 3 additions & 3 deletions src/sage/geometry/hyperplane_arrangement/hyperplane.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,10 @@
# http://www.gnu.org/licenses/
# *****************************************************************************

import sage.geometry.abc

from sage.misc.cachefunc import cached_method
from sage.geometry.linear_expression import LinearExpression, LinearExpressionModule
from sage.misc.cachefunc import cached_method


class Hyperplane(LinearExpression):
Expand Down Expand Up @@ -460,9 +461,8 @@ def intersection(self, other):
sage: h.intersection(polytopes.cube())
A 2-dimensional polyhedron in QQ^3 defined as the convex hull of 3 vertices
"""
from sage.geometry.polyhedron.base import is_Polyhedron
from sage.geometry.polyhedron.constructor import Polyhedron
if not is_Polyhedron(other):
if not isinstance(other, sage.geometry.abc.Polyhedron):
try:
other = other.polyhedron()
except AttributeError:
Expand Down
13 changes: 9 additions & 4 deletions src/sage/geometry/lattice_polytope.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,13 +482,18 @@ def is_LatticePolytope(x):

sage: from sage.geometry.lattice_polytope import is_LatticePolytope
sage: is_LatticePolytope(1)
doctest:warning...
DeprecationWarning: is_LatticePolytope is deprecated, use isinstance instead
See https://github.com/sagemath/sage/issues/34307 for details.
False
sage: p = LatticePolytope([(1,0), (0,1), (-1,-1)])
sage: p # needs palp
2-d reflexive polytope #0 in 2-d lattice M
sage: is_LatticePolytope(p)
True
"""
from sage.misc.superseded import deprecation
deprecation(34307, "is_LatticePolytope is deprecated, use isinstance instead")
return isinstance(x, LatticePolytopeClass)

@richcmp_method
Expand Down Expand Up @@ -989,7 +994,7 @@ def _palp(self, command, reduce_dimension=False):
sage: o = lattice_polytope.cross_polytope(3)
sage: o._palp("poly.x -f") # needs palp
'M:7 6 N:27 8 Pic:17 Cor:0\n'
sage: print(o._palp("nef.x -f -N -p")) # random time information # needs palp
sage: print(o._palp("nef.x -f -N -p")) # random time information # needs palp
M:27 8 N:7 6 codim=2 #part=5
H:[0] P:0 V:2 4 5 0sec 0cpu
H:[0] P:2 V:3 4 5 0sec 0cpu
Expand Down Expand Up @@ -1234,7 +1239,7 @@ def _read_nef_partitions(self, data):

sage: o = lattice_polytope.cross_polytope(3)
sage: s = o.nef_x("-p -N -Lv") # needs palp
sage: print(s) # random time values # needs palp
sage: print(s) # random time values # needs palp
M:27 8 N:7 6 codim=2 #part=5
3 6 Vertices in N-lattice:
1 0 0 -1 0 0
Expand Down Expand Up @@ -3139,7 +3144,7 @@ def normal_form(self, algorithm="palp_native", permutation=False):
M( 12, -1, -9, -6, 6),
M( 12, -1, -6, -3, 3)
in 5-d lattice M
sage: P.normal_form(algorithm="palp_modified") # not tested (22s; MemoryError on 32 bit), needs sage.groups
sage: P.normal_form(algorithm="palp_modified") # not tested (22s; MemoryError on 32 bit), needs sage.groups
M( 6, 0, 0, 0, 0),
M( -6, 0, 0, 0, 0),
M( 0, 1, 0, 0, 0),
Expand Down Expand Up @@ -5264,7 +5269,7 @@ def _read_nef_x_partitions(data):

sage: o = lattice_polytope.cross_polytope(3)
sage: s = o.nef_x("-N -p") # needs palp
sage: print(s) # random # needs palp
sage: print(s) # random # needs palp
M:27 8 N:7 6 codim=2 #part=5
P:0 V:2 4 5 0sec 0cpu
P:2 V:3 4 5 0sec 0cpu
Expand Down
5 changes: 3 additions & 2 deletions src/sage/geometry/newton_polygon.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# https://www.gnu.org/licenses/
#############################################################################

import sage.geometry.abc

from sage.structure.unique_representation import UniqueRepresentation
from sage.structure.parent import Parent
from sage.structure.element import Element
Expand All @@ -22,7 +24,6 @@

from sage.rings.infinity import Infinity
from sage.geometry.polyhedron.constructor import Polyhedron
from sage.geometry.polyhedron.base import is_Polyhedron


class NewtonPolygon_element(Element):
Expand Down Expand Up @@ -716,7 +717,7 @@ def _element_constructor_(self, arg, sort_slopes=True, last_slope=Infinity):
sage: NewtonPolygon(1)
Finite Newton polygon with 1 vertex: (0, 0)
"""
if is_Polyhedron(arg):
if isinstance(arg, sage.geometry.abc.Polyhedron):
return self.element_class(arg, parent=self)
if arg == 0:
polyhedron = Polyhedron(base_ring=self.base_ring(), ambient_dim=2)
Expand Down
12 changes: 7 additions & 5 deletions src/sage/geometry/polyhedral_complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,11 @@
# ****************************************************************************

from copy import copy

import sage.geometry.abc

from sage.topology.cell_complex import GenericCellComplex
from sage.geometry.polyhedron.constructor import Polyhedron
from sage.geometry.polyhedron.base import is_Polyhedron
from sage.modules.free_module_element import vector
from sage.rings.integer_ring import ZZ
from sage.graphs.graph import Graph
Expand Down Expand Up @@ -308,7 +310,7 @@ def __init__(self, maximal_cells=None, backend=None, maximality_check=True,
ambient_dim = next(iter(cells_dict[self._dim])).ambient_dim()
self._ambient_dim = ambient_dim
self._maximal_cells = cells_dict
if not all((is_Polyhedron(cell) and
if not all((isinstance(cell, sage.geometry.abc.Polyhedron) and
cell.ambient_dim() == self._ambient_dim)
for cell in self.maximal_cell_iterator()):
raise ValueError("the given cells are not polyhedra " +
Expand Down Expand Up @@ -959,7 +961,7 @@ def __contains__(self, x):
sage: (0, 0) in pc # not a polyhedron
False
"""
if not is_Polyhedron(x):
if not isinstance(x, sage.geometry.abc.Polyhedron):
return False
dim = x.dimension()
return dim in self.cells() and x in self.cells()[dim]
Expand Down Expand Up @@ -2028,7 +2030,7 @@ def add_cell(self, cell):
"""
if self._is_immutable:
raise ValueError("this polyhedral complex is not mutable")
if not is_Polyhedron(cell) or cell.ambient_dim() != self._ambient_dim:
if not isinstance(cell, sage.geometry.abc.Polyhedron) or cell.ambient_dim() != self._ambient_dim:
raise ValueError("the given cell is not a polyhedron " +
"in the same ambient space")
# if cell is already in self, do nothing.
Expand Down Expand Up @@ -2191,7 +2193,7 @@ def remove_cell(self, cell, check=False):
"""
if self._is_immutable:
raise ValueError("this polyhedral complex is not mutable")
if not is_Polyhedron(cell) or cell.ambient_dim() != self._ambient_dim:
if not isinstance(cell, sage.geometry.abc.Polyhedron) or cell.ambient_dim() != self._ambient_dim:
raise ValueError("the given cell is not a polyhedron " +
"in the same ambient space")
# if cell is not in self, delete nothing.
Expand Down
5 changes: 5 additions & 0 deletions src/sage/geometry/polyhedron/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,15 @@ def is_Polyhedron(X):
sage: p = polytopes.hypercube(2)
sage: from sage.geometry.polyhedron.base import is_Polyhedron
sage: is_Polyhedron(p)
doctest:warning...
DeprecationWarning: is_Polyhedron is deprecated, use isinstance instead
See https://github.com/sagemath/sage/issues/34307 for details.
True
sage: is_Polyhedron(123456)
False
"""
from sage.misc.superseded import deprecation
deprecation(34307, "is_Polyhedron is deprecated, use isinstance instead")
return isinstance(X, Polyhedron_base)


Expand Down
6 changes: 3 additions & 3 deletions src/sage/geometry/polyhedron/parent.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
# https://www.gnu.org/licenses/
# *****************************************************************************

import sage.geometry.abc

from sage.structure.parent import Parent
from sage.structure.element import get_coercion_model
from sage.structure.unique_representation import UniqueRepresentation
Expand All @@ -22,8 +24,6 @@
from sage.categories.fields import Fields
from sage.categories.rings import Rings
from sage.categories.modules import Modules

from sage.geometry.polyhedron.base import is_Polyhedron
from .representation import Inequality, Equation, Vertex, Ray, Line


Expand Down Expand Up @@ -691,7 +691,7 @@ def convert_base_ring_Hrep(lstlst):
if convert and Vrep:
Vrep = [convert_base_ring(_) for _ in Vrep]
return self.element_class(self, Vrep, Hrep, **kwds)
if nargs == 1 and is_Polyhedron(args[0]):
if nargs == 1 and isinstance(args[0], sage.geometry.abc.Polyhedron):
copy = kwds.pop('copy', args[0].parent() is not self)
mutable = kwds.pop('mutable', False)

Expand Down
2 changes: 1 addition & 1 deletion src/sage/schemes/toric/variety.py
Original file line number Diff line number Diff line change
Expand Up @@ -2660,7 +2660,7 @@ def _orbit_closure_projection(self, cone, x):
# TODO: make the following work nicely.
# if x in cone.lattice():
# return quot(x)
# assert is_Cone(x)
# assert x is ConvexRationalPolyhedralCone object
# return Cone(x.rays(), lattice=quot)

def orbit_closure(self, cone):
Expand Down
Loading