Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
14 changes: 7 additions & 7 deletions src/sage/geometry/cone.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@
from sage.geometry.point_collection import PointCollection
from sage.geometry.polyhedron.constructor import Polyhedron
from sage.geometry.hasse_diagram import lattice_from_incidences
from sage.geometry.toric_lattice import (ToricLattice, is_ToricLattice,
is_ToricLatticeQuotient)
from sage.geometry.toric_lattice import (ToricLattice, ToricLattice_generic,
ToricLattice_quotient)
from sage.geometry.toric_plotter import ToricPlotter, label_list
from sage.geometry.relative_interior import RelativeInterior
from sage.graphs.digraph import DiGraph
Expand Down Expand Up @@ -471,7 +471,7 @@ def Cone(rays, lattice=None, check=True, normalize=True):
if not check or not rays:
return ConvexRationalPolyhedralCone(rays, lattice)
# Any set of rays forms a cone, but we want to keep only generators
if is_ToricLatticeQuotient(lattice):
if isinstance(lattice, ToricLattice_quotient):
gs = Generator_System(
PPL_point(Linear_Expression(lattice(0).vector(), 0)))
for r in rays:
Expand Down Expand Up @@ -620,7 +620,7 @@ def try_base_extend(ring):
p = try_base_extend(ZZ)
if p is not None:
return p
if is_ToricLattice(parent(data)):
if isinstance(parent(data), ToricLattice_generic):
raise TypeError("the point %s and %s have incompatible "
"lattices" % (data, body))

Expand Down Expand Up @@ -720,7 +720,7 @@ def normalize_rays(rays, lattice):
if rays:
if lattice is None:
ray_parent = parent(rays[0])
lattice = (ray_parent if is_ToricLattice(ray_parent)
lattice = (ray_parent if isinstance(ray_parent, ToricLattice_generic)
else ToricLattice(len(rays[0])))
if lattice.base_ring() is not ZZ:
raise TypeError("lattice must be a free module over ZZ")
Expand Down Expand Up @@ -2006,7 +2006,7 @@ def _repr_(self):
result = "%d-d" % self.dim()
if self.ambient() is self:
result += " cone in"
if is_ToricLattice(self.lattice()):
if isinstance(self.lattice(), ToricLattice_generic):
result += " %s" % self.lattice()
else:
result += " %d-d lattice" % self.lattice_dim()
Expand Down Expand Up @@ -3661,7 +3661,7 @@ def strict_quotient(self):
# for sublattices. But it seems to be the most natural choice
# for names. If many subcones land in the same lattice -
# that's just how it goes.
if is_ToricLattice(L):
if isinstance(L, ToricLattice_generic):
S = ToricLattice(Q.dimension(), L._name, L._dual_name,
L._latex_name, L._latex_dual_name)
else:
Expand Down
17 changes: 12 additions & 5 deletions src/sage/geometry/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@
normalize_rays)
from sage.geometry.hasse_diagram import lattice_from_incidences
from sage.geometry.point_collection import PointCollection
from sage.geometry.toric_lattice import ToricLattice, is_ToricLattice
from sage.geometry.toric_lattice import ToricLattice, ToricLattice_generic
from sage.geometry.toric_plotter import ToricPlotter
from sage.graphs.digraph import DiGraph
from sage.matrix.constructor import matrix
Expand Down Expand Up @@ -279,12 +279,19 @@ def is_Fan(x) -> bool:

sage: from sage.geometry.fan import is_Fan
sage: is_Fan(1)
doctest:warning...
DeprecationWarning: The function is_Fan is deprecated; use 'isinstance(..., RationalPolyhedralFan)' instead.
See https://github.com/sagemath/sage/issues/38126 for details.
False
sage: fan = toric_varieties.P2().fan(); fan # needs palp
Rational polyhedral fan in 2-d lattice N
sage: is_Fan(fan) # needs palp
True
"""
from sage.misc.superseded import deprecation
deprecation(38126,
"The function is_Fan is deprecated; "
"use 'isinstance(..., RationalPolyhedralFan)' instead.")
return isinstance(x, RationalPolyhedralFan)


Expand Down Expand Up @@ -1330,7 +1337,7 @@ def __richcmp__(self, right, op):
sage: f2 is f3
False
"""
if is_Fan(right):
if isinstance(right, RationalPolyhedralFan):
return richcmp([self.rays(), self.virtual_rays(),
self.generating_cones()],
[right.rays(), right.virtual_rays(),
Expand Down Expand Up @@ -1397,7 +1404,7 @@ def _compute_cone_lattice(self):
not even need to check if it is complete::

sage: fan = toric_varieties.P1xP1().fan() # needs palp
sage: fan.cone_lattice() # indirect doctest # needs palp
sage: fan.cone_lattice() # indirect doctest # needs palp
Finite lattice containing 10 elements with distinguished linear extension

These 10 elements are: 1 origin, 4 rays, 4 generating cones, 1 fan.
Expand Down Expand Up @@ -1679,7 +1686,7 @@ def cartesian_product(self, other, lattice=None):
sage: _.ngenerating_cones()
6
"""
assert is_Fan(other)
assert isinstance(other, RationalPolyhedralFan)
rc = super().cartesian_product(other, lattice)
self_cones = [cone.ambient_ray_indices() for cone in self]
n = self.nrays()
Expand Down Expand Up @@ -1859,7 +1866,7 @@ def _repr_(self) -> str:
'Rational polyhedral fan in 2-d lattice'
"""
result = "Rational polyhedral fan in"
if is_ToricLattice(self.lattice()):
if isinstance(self.lattice(), ToricLattice_generic):
result += " %s" % self.lattice()
else:
result += " %d-d lattice" % self.lattice_dim()
Expand Down
6 changes: 3 additions & 3 deletions src/sage/geometry/fan_morphism.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@

from sage.categories.homset import Hom
from sage.geometry.cone import Cone
from sage.geometry.fan import Fan, is_Fan
from sage.geometry.fan import Fan, RationalPolyhedralFan
from sage.matrix.constructor import matrix
from sage.matrix.special import identity_matrix
from sage.structure.element import is_Matrix
Expand Down Expand Up @@ -270,8 +270,8 @@ def __init__(self, morphism, domain_fan,
Codomain fan: Rational polyhedral fan in 2-d lattice N
sage: TestSuite(fm).run(skip="_test_category")
"""
assert is_Fan(domain_fan)
if is_Fan(codomain):
assert isinstance(domain_fan, RationalPolyhedralFan)
if isinstance(codomain, RationalPolyhedralFan):
codomain, codomain_fan = codomain.lattice(), codomain
else:
codomain_fan = None
Expand Down
29 changes: 16 additions & 13 deletions src/sage/geometry/lattice_polytope.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,8 @@
from sage.geometry.cone import _ambient_space_point, integral_length
from sage.geometry.hasse_diagram import lattice_from_incidences
from sage.geometry.point_collection import (PointCollection,
is_PointCollection,
read_palp_point_collection)
from sage.geometry.toric_lattice import ToricLattice, is_ToricLattice
from sage.geometry.toric_lattice import ToricLattice, ToricLattice_generic
from sage.groups.perm_gps.permgroup_named import SymmetricGroup

from sage.misc.lazy_import import lazy_import
Expand Down Expand Up @@ -318,7 +317,7 @@ def LatticePolytope(data, compute_vertices=True, n=0, lattice=None):
if isinstance(data, LatticePolytopeClass):
data = data._vertices
compute_vertices = False
if (is_PointCollection(data) and
if (isinstance(data, PointCollection) and
(lattice is None or lattice is data.module())):
return LatticePolytopeClass(data, compute_vertices)
if isinstance(data, str):
Expand All @@ -328,7 +327,7 @@ def LatticePolytope(data, compute_vertices=True, n=0, lattice=None):
f.close()
if isinstance(data, (IOBase, StringIO)):
data = read_palp_point_collection(data)
if not is_PointCollection(data) and not isinstance(data, (list, tuple)):
if not isinstance(data, PointCollection) and not isinstance(data, (list, tuple)):
try:
data = list(data)
except TypeError:
Expand All @@ -338,7 +337,7 @@ def LatticePolytope(data, compute_vertices=True, n=0, lattice=None):
raise ValueError("lattice must be given explicitly for "
"empty polytopes!")
try:
if is_ToricLattice(data[0].parent()):
if isinstance(data[0].parent(), ToricLattice_generic):
lattice = data[0].parent()
except AttributeError:
pass
Expand Down Expand Up @@ -934,7 +933,7 @@ def _embed(self, data):
return data
self._compute_embedding()
M = self.lattice()
if is_PointCollection(data):
if isinstance(data, PointCollection):
r = [M(self._embedding_matrix * point + self._shift_vector)
for point in data]
for point in r:
Expand Down Expand Up @@ -1103,7 +1102,7 @@ def _pullback(self, data):
self._compute_embedding()
if data is self._vertices:
return self._sublattice_polytope._vertices
if is_PointCollection(data):
if isinstance(data, PointCollection):
r = [self._pullback(point) for point in data]
for point in r:
point.set_immutable()
Expand Down Expand Up @@ -1334,7 +1333,7 @@ def _repr_(self):
parts.insert(-1, "#%d" % self.index())
except ValueError:
pass
if is_ToricLattice(self.lattice()):
if isinstance(self.lattice(), ToricLattice_generic):
parts.append(str(self.lattice()))
else:
parts.append("%d-d lattice" % self.lattice_dim())
Expand Down Expand Up @@ -4199,15 +4198,19 @@ def is_NefPartition(x):

EXAMPLES::

sage: from sage.geometry.lattice_polytope import is_NefPartition
sage: is_NefPartition(1)
sage: from sage.geometry.lattice_polytope import NefPartition
sage: isinstance(1, NefPartition)
False
sage: o = lattice_polytope.cross_polytope(3)
sage: np = o.nef_partitions()[0]; np # needs palp
Nef-partition {0, 1, 3} ⊔ {2, 4, 5}
sage: is_NefPartition(np) # needs palp
sage: isinstance(np, NefPartition) # needs palp
True
"""
from sage.misc.superseded import deprecation
deprecation(38126,
"The function is_NefPartition is deprecated; "
"use 'isinstance(..., NefPartition)' instead.")
return isinstance(x, NefPartition)


Expand Down Expand Up @@ -4408,7 +4411,7 @@ def __eq__(self, other):
sage: np == 0
False
"""
return (is_NefPartition(other)
return (isinstance(other, NefPartition)
and self._Delta_polar == other._Delta_polar
and self._vertex_to_part == other._vertex_to_part)

Expand Down Expand Up @@ -5989,7 +5992,7 @@ def write_palp_matrix(m, ofile=None, comment="", format=None):
0 1 0 0 -1 0
0 0 1 0 0 -1
"""
if is_PointCollection(m):
if isinstance(m, PointCollection):
m = m.column_matrix()
if format is None:
n = max(len(str(m[i,j]))
Expand Down
12 changes: 8 additions & 4 deletions src/sage/geometry/point_collection.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,17 @@ def is_PointCollection(x):

EXAMPLES::

sage: from sage.geometry.point_collection import is_PointCollection
sage: is_PointCollection(1)
sage: from sage.geometry.point_collection import PointCollection
sage: isinstance(1, PointCollection)
False
sage: c = Cone([(0,0,1), (1,0,1), (0,1,1), (1,1,1)])
sage: is_PointCollection(c.rays())
sage: isinstance(c.rays(), PointCollection)
True
"""
from sage.misc.superseded import deprecation_cython
deprecation_cython(38126,
"The function is_PointCollection is deprecated; "
"use 'isinstance(..., PointCollection)' instead.")
return isinstance(x, PointCollection)


Expand Down Expand Up @@ -665,7 +669,7 @@ cdef class PointCollection(SageObject):
N+N(1, 1, 1, 1, 1, 1)
in 6-d lattice N+N
"""
assert is_PointCollection(other)
assert isinstance(other, PointCollection)
if module is None:
module = self._module.direct_sum(other.module())
P = [list(p) for p in self]
Expand Down
33 changes: 24 additions & 9 deletions src/sage/geometry/toric_lattice.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@
# https://www.gnu.org/licenses/
# ****************************************************************************

from sage.geometry.toric_lattice_element import (ToricLatticeElement,
is_ToricLatticeElement)
from sage.geometry.toric_lattice_element import ToricLatticeElement
from sage.geometry.toric_plotter import ToricPlotter
from sage.misc.latex import latex
from sage.structure.all import parent
Expand Down Expand Up @@ -180,13 +179,21 @@ def is_ToricLattice(x):
sage: from sage.geometry.toric_lattice import (
....: is_ToricLattice)
sage: is_ToricLattice(1)
doctest:warning...
DeprecationWarning: The function is_ToricLattice is deprecated;
use 'isinstance(..., ToricLattice_generic)' instead.
See https://github.com/sagemath/sage/issues/38126 for details.
False
sage: N = ToricLattice(3)
sage: N
3-d lattice N
sage: is_ToricLattice(N)
True
"""
from sage.misc.superseded import deprecation
deprecation(38126,
"The function is_ToricLattice is deprecated; "
"use 'isinstance(..., ToricLattice_generic)' instead.")
return isinstance(x, ToricLattice_generic)


Expand All @@ -207,6 +214,10 @@ def is_ToricLatticeQuotient(x):
sage: from sage.geometry.toric_lattice import (
....: is_ToricLatticeQuotient)
sage: is_ToricLatticeQuotient(1)
doctest:warning...
DeprecationWarning: The function is_ToricLatticeQuotient is deprecated;
use 'isinstance(..., ToricLattice_quotient)' instead.
See https://github.com/sagemath/sage/issues/38126 for details.
False
sage: N = ToricLattice(3)
sage: N
Expand All @@ -220,6 +231,10 @@ def is_ToricLatticeQuotient(x):
sage: is_ToricLatticeQuotient(Q)
True
"""
from sage.misc.superseded import deprecation
deprecation(38126,
"The function is_ToricLatticeQuotient is deprecated; "
"use 'isinstance(..., ToricLattice_quotient)' instead.")
return isinstance(x, ToricLattice_quotient)


Expand Down Expand Up @@ -445,7 +460,7 @@ def __call__(self, *args, **kwds):
coordinates = [ZZ(_) for _ in args]
except TypeError:
# Prohibit conversion of elements of other lattices
if (is_ToricLatticeElement(args[0])
if (isinstance(args[0], ToricLatticeElement)
and args[0].parent().ambient_module()
is not self.ambient_module()):
raise TypeError("%s cannot be converted to %s!"
Expand All @@ -471,7 +486,7 @@ def _coerce_map_from_(self, other):
TypeError: N(1, 2, 3) cannot be converted to 3-d lattice M!

"""
if (is_ToricLattice(other) and
if (isinstance(other, ToricLattice_generic) and
other.ambient_module() is not self.ambient_module()):
return None
return super()._convert_map_from_(other)
Expand Down Expand Up @@ -624,14 +639,14 @@ def intersection(self, other):
True
"""
# Lattice-specific input check
if not is_ToricLattice(other):
if not isinstance(other, ToricLattice_generic):
raise TypeError("%s is not a toric lattice!" % other)
if self.ambient_module() != other.ambient_module():
raise ValueError("%s and %s have different ambient lattices!" %
(self, other))
# Construct a generic intersection, but make sure to return a lattice.
I = super().intersection(other)
if not is_ToricLattice(I):
if not isinstance(I, ToricLattice_generic):
I = self.ambient_module().submodule(I.basis())
return I

Expand Down Expand Up @@ -756,7 +771,7 @@ def saturation(self):
True
"""
S = super().saturation()
return S if is_ToricLattice(S) else self.ambient_module().submodule(S)
return S if isinstance(S, ToricLattice_generic) else self.ambient_module().submodule(S)

def span(self, gens, base_ring=ZZ, *args, **kwds):
r"""
Expand Down Expand Up @@ -799,7 +814,7 @@ def span(self, gens, base_ring=ZZ, *args, **kwds):
if base_ring is ZZ and all(g in A for g in gens):
return ToricLattice_sublattice(A, gens)
for g in gens:
if is_ToricLatticeElement(g) and g not in A:
if isinstance(g, ToricLatticeElement) and g not in A:
raise ValueError("%s cannot generate a sublattice of %s"
% (g, A))
return super().span(gens, base_ring, *args, **kwds)
Expand Down Expand Up @@ -853,7 +868,7 @@ def span_of_basis(self, basis, base_ring=ZZ, *args, **kwds):
if base_ring is ZZ and all(g in A for g in basis):
return ToricLattice_sublattice_with_basis(A, basis)
for g in basis:
if is_ToricLatticeElement(g) and g not in A:
if isinstance(g, ToricLatticeElement) and g not in A:
raise ValueError("%s cannot generate a sublattice of %s"
% (g, A))
return super().span_of_basis(basis, base_ring, *args, **kwds)
Expand Down
Loading