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

Commit

Permalink
Updated to Python3. Works with Sage 9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sorger-c committed May 4, 2020
1 parent a58edec commit b5769ac
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 32 deletions.
4 changes: 2 additions & 2 deletions src/sage/schemes/chow/finite_ring_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@
# ****************************************************************************

from sage.all import QQ
from sage.matrix.constructor import matrix
from sage.matrix.all import matrix
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
from sage.rings.quotient_ring import QuotientRing_generic
from sage.rings.polynomial.term_order import TermOrder
from sage.libs.singular.function import singular_function, lib as singular_lib
from sage.libs.singular.function_factory import singular_function, lib as singular_lib
from sage.rings.polynomial.multi_polynomial_ring_generic import \
is_MPolynomialRing

Expand Down
6 changes: 3 additions & 3 deletions src/sage/schemes/chow/library/all.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

from grass import Grass, GrassBundle
from proj import Proj, ProjBundle
from twisted_cubics import variety_of_nets_of_quadrics, incidence_variety, map_incidence_to_nets_of_quadrics
from .grass import Grass, GrassBundle
from .proj import Proj, ProjBundle
from .twisted_cubics import variety_of_nets_of_quadrics, incidence_variety, map_incidence_to_nets_of_quadrics
4 changes: 2 additions & 2 deletions src/sage/schemes/chow/morphism.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ def upperstar(self, v):
sage: i.upperstar(Y.tangent_bundle())
Bundle(X, 3, [1, 12*w])
"""
from sheaf import Sheaf, is_sheaf
from .sheaf import Sheaf, is_sheaf
if is_sheaf(v):
# Return a sheaf if the argument is a sheaf
if not v.chowscheme() is self.codomain():
Expand Down Expand Up @@ -566,7 +566,7 @@ def lowerstar(self, v, normal_bundle=None, verbose=False):
3
"""
X, Y = self.domain(), self.codomain()
from sheaf import Sheaf, is_sheaf
from .sheaf import Sheaf, is_sheaf
if is_sheaf(v):
# Return a sheaf if the argument is a sheaf
if not v.chowscheme() is self.domain():
Expand Down
26 changes: 15 additions & 11 deletions src/sage/schemes/chow/ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,12 @@

from sage.all import QQ
from sage.modules.all import vector
from sage.matrix.constructor import matrix
from sage.matrix.all import matrix
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
from sage.rings.polynomial.term_order import TermOrder
from sage.rings.quotient_ring import QuotientRing_generic
from sage.rings.polynomial.multi_polynomial_ring_generic import \
is_MPolynomialRing
from sage.libs.singular.function import singular_function, lib as singular_lib
from sage.rings.polynomial.multi_polynomial_ring import is_MPolynomialRing
from sage.libs.singular.function_factory import singular_function, lib as singular_lib
from sage.misc.cachefunc import cached_method
from sage.rings.integer import is_Integer

Expand Down Expand Up @@ -343,10 +342,10 @@ def ChowRing(generators=None, degrees=None, relations=None,
"""
# Construct a quotient ring by generators and relations.
if generators: # Not None neither []
if isinstance(generators, basestring):
if isinstance(generators, str):
generators = [generators]
for gen in generators:
if not isinstance(gen, basestring):
if not isinstance(gen, str):
raise TypeError("Expect list of strings for generators.")
if is_Integer(degrees) or isinstance(degrees, int):
degrees = [int(degrees)]
Expand All @@ -362,7 +361,7 @@ def ChowRing(generators=None, degrees=None, relations=None,
order=TermOrder('wdegrevlex', tuple(degrees)))
I = R.ideal(0)
if relations:
if isinstance(relations, basestring):
if isinstance(relations, str):
relations = [relations]
if not all(isinstance(r, str) for r in relations):
raise TypeError("Expect list of strings as relations")
Expand Down Expand Up @@ -426,6 +425,12 @@ def __init__(self, R, I, names=None, name=None, latex_name=None):
self._dimension = None
self._point_class = None

def _cache_key(self):
return(self.parent(),str(self))

def __hash__(self):
return hash(type(self))

def __eq__(self, other):
"""
Two ChowRings are considered to be "equal" their dimensions are equal,
Expand Down Expand Up @@ -965,7 +970,7 @@ def max_degree(self):
if self.krull_dimension() != 0:
return 0
# Compute max degree:
return max([x.lift().degree() for x in self.basis()])
return max([self(x).lift().degree() for x in self.basis()])

@cached_method
def basis_by_degree(self):
Expand Down Expand Up @@ -997,7 +1002,7 @@ def basis_by_degree(self):
return [[1]]
bbd = [[] for _ in range(self.max_degree() + 1)]
for e in self.basis():
d = e.lift().degree()
d = self(e).lift().degree()
bbd[d].append(e)
return bbd

Expand Down Expand Up @@ -1043,7 +1048,6 @@ def intersection_matrix(self):
for i in range(n) for j in range(n)]
return matrix(QQ, n, n, m)

@cached_method
def dual_basis_slow(self):
"""
Returns the basis dual to self.basis() with respect to the intersection
Expand Down Expand Up @@ -1121,7 +1125,7 @@ def dual_basis(self, verbose=False):
division = singular_function('division')
# We will compute the dictionary degree by degree.
rbbd, maxdeg = self.basis_by_degree(), len(self.basis_by_degree())
for d in range(1 + maxdeg / 2):
for d in range(1 + maxdeg // 2):
# Ring basis in degree d and complementary degree maxdeg - d - 1
rbd, rbdc, n = rbbd[d], rbbd[maxdeg - d - 1], len(rbbd[d])
if verbose:
Expand Down
2 changes: 1 addition & 1 deletion src/sage/schemes/chow/ring_homset.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def __call__(self, im_gens, check=True):
if not im_gens:
phi = pi.domain().hom([], self.codomain())
else:
if isinstance(im_gens, basestring):
if isinstance(im_gens, str):
im_gens = [im_gens]
im_gens = [self.codomain()(x) for x in im_gens]
phi = pi.domain().hom(im_gens, check=check)
Expand Down
12 changes: 9 additions & 3 deletions src/sage/schemes/chow/scheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def _latex_(self):
TESTS::
sage: P1 = ChowScheme(1, 'h', 1, 'h^2', latex_name='\mathbb{P}^1')
sage: P1 = ChowScheme(1, 'h', 1, 'h^2', latex_name='\\mathbb{P}^1')
sage: P1._latex_()
'\\mathbb{P}^1'
Expand All @@ -293,6 +293,12 @@ def _latex_(self):
return self._latex_name
return self._repr_()

def _cache_key(self):
return(self.parent(),str(self))

def __hash__(self):
return hash(type(self))

def __eq__(self, other):
"""
Return True if the two ChowScheme are "equal", e.g. if their underlying
Expand Down Expand Up @@ -396,7 +402,7 @@ def __mul__(self, other):
sage: B.betti_numbers()
[1, 2, 4, 7, 8, 7, 4, 2, 1]
"""
from bundle import Bundle
from .bundle import Bundle
dimension = self.dimension() + other.dimension()
generators = self.variable_names() + other.variable_names()
degrees = self.degs() + other.degs()
Expand Down Expand Up @@ -1168,7 +1174,7 @@ def o(self, n=0):
if not isinstance(n, int):
raise ValueError('Only integers allowed here.')
if n == 0:
from bundle import Bundle
from .bundle import Bundle
return Bundle(self, 1, [1])

if 'o1' not in self.sheaves:
Expand Down
2 changes: 1 addition & 1 deletion src/sage/schemes/chow/scheme_homset.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def create_key_and_extra_args(self, X, Y, category=None,
if not is_chowScheme(base):
raise ValueError("Expect a ChowScheme as base")
if not category:
from schemes import ChowSchemes
from .schemes import ChowSchemes
category = ChowSchemes(base)
key = tuple([id(X), id(Y), category])
extra = {'X': X, 'Y': Y, 'base_chowscheme': base, 'check': check}
Expand Down
12 changes: 3 additions & 9 deletions src/sage/schemes/chow/schemes.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@

from sage.categories.category import Category
from sage.categories.category_types import Category_over_base
from sage.categories.homsets import HomsetsCategory
from sage.categories.sets_cat import Sets


# noinspection PyAbstractClass
class ChowSchemes(Category):
r"""
Construct a category of ChowSchemes.
Expand All @@ -33,7 +31,7 @@ class ChowSchemes(Category):
@staticmethod
def __classcall_private__(cls, X=None):
if X is not None:
from scheme import is_chowScheme
from .scheme import is_chowScheme
if not is_chowScheme(X):
X = ChowSchemes()(X)
return ChowSchemes_over_base(X)
Expand All @@ -44,20 +42,16 @@ def super_categories(self):
return [Sets()]

def _call_(self, x):
from scheme import is_chowScheme
from .scheme import is_chowScheme
if is_chowScheme(x):
return x
from morphism import is_chowSchemeMorphism
from .morphism import is_chowSchemeMorphism
if is_chowSchemeMorphism(x):
return x
else:
m = "Can't create an object or morphism in %s from %s" % (self, x)
raise TypeError(m)

# noinspection PyAbstractClass
class HomCategory(HomsetsCategory):
def extra_super_categories(self):
return []


#############################################################
Expand Down

0 comments on commit b5769ac

Please sign in to comment.