From c861f3c5267f4d6a54fb6ece70b77bca65d3ea4f Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 1 May 2024 23:22:41 -0700 Subject: [PATCH 01/11] src/sage/modules/module.pyx: Deprecate is_Module, is_VectorSpace --- src/sage/modules/module.pyx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/sage/modules/module.pyx b/src/sage/modules/module.pyx index 2d7d21422ac..80a727875b7 100644 --- a/src/sage/modules/module.pyx +++ b/src/sage/modules/module.pyx @@ -174,9 +174,9 @@ cdef class Module(Parent): """ try: - if (is_Module(M) - and self.base_ring().has_coerce_map_from(M.base_ring()) - and M.change_ring(self.base_ring()).is_submodule(self)): + if (isinstance(M, Module) + and self.base_ring().has_coerce_map_from(M.base_ring()) + and M.change_ring(self.base_ring()).is_submodule(self)): return M.hom([self._element_constructor_(x) for x in M.gens()], self) except (TypeError, NotImplementedError, AttributeError, ArithmeticError): pass @@ -288,6 +288,8 @@ def is_Module(x): sage: is_Module(10) False """ + from sage.misc.superseded import deprecation_cython + deprecation_cython(37924, "the function is_Module is deprecated; use 'isinstance(..., Module)' instead") return isinstance(x, Module) @@ -313,6 +315,8 @@ def is_VectorSpace(x): False """ + from sage.misc.superseded import deprecation_cython + deprecation_cython(37924, "the function is_VectorSpace is deprecated; use 'isinstance(..., Module)' and check the base ring instead") try: return is_Module(x) and x.base_ring().is_field() except AttributeError: From 1efa331f2d5e4f107af24ac4a1a8c3a6c840a7dd Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 1 May 2024 23:42:30 -0700 Subject: [PATCH 02/11] src/sage/modules/free_quadratic_module.py: Deprecate is_FreeQuadraticModule --- src/sage/modules/free_module.py | 4 ++-- src/sage/modules/free_quadratic_module.py | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/sage/modules/free_module.py b/src/sage/modules/free_module.py index 1654c8cf6ed..d0924defd91 100644 --- a/src/sage/modules/free_module.py +++ b/src/sage/modules/free_module.py @@ -5804,8 +5804,8 @@ def change_ring(self, R): """ if self.base_ring() is R: return self - from sage.modules.free_quadratic_module import is_FreeQuadraticModule - if is_FreeQuadraticModule(self): + from sage.modules.free_quadratic_module import FreeQuadraticModule_generic + if isinstance(self, FreeQuadraticModule_generic): return FreeModule(R, self.rank(), inner_product_matrix=self.inner_product_matrix(), sparse=self.is_sparse()) diff --git a/src/sage/modules/free_quadratic_module.py b/src/sage/modules/free_quadratic_module.py index 78b3b179b33..03456dfe224 100644 --- a/src/sage/modules/free_quadratic_module.py +++ b/src/sage/modules/free_quadratic_module.py @@ -249,6 +249,8 @@ def is_FreeQuadraticModule(M): sage: is_FreeQuadraticModule(W) True """ + from sage.misc.superseded import deprecation + deprecation(37924, "the function is_FreeQuadraticModule is deprecated; use 'isinstance(..., FreeQuadraticModule_generic)' instead") return isinstance(M, FreeQuadraticModule_generic) From 1219748e38317b02a844d9788db8e7645739e591 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 2 May 2024 00:08:22 -0700 Subject: [PATCH 03/11] src/sage/modules/free_module.py: Deprecate is_FreeModule --- src/sage/geometry/polyhedron/parent.py | 4 ++-- src/sage/manifolds/subsets/pullback.py | 4 ++-- src/sage/matrix/action.pyx | 6 +++--- src/sage/matrix/matrix2.pyx | 2 +- src/sage/matrix/matrix_space.py | 4 ++-- src/sage/modular/abvar/abvar.py | 4 ++-- src/sage/modular/abvar/finite_subgroup.py | 4 ++-- src/sage/modular/hecke/ambient_module.py | 4 ++-- src/sage/modular/hecke/submodule.py | 8 ++++---- src/sage/modular/modsym/ambient.py | 4 ++-- src/sage/modules/fg_pid/fgp_module.py | 10 +++++----- src/sage/modules/fg_pid/fgp_morphism.py | 4 ++-- src/sage/modules/free_module.py | 22 ++++++++++++---------- src/sage/modules/free_module_morphism.py | 2 +- src/sage/modules/free_quadratic_module.py | 2 +- src/sage/numerical/linear_tensor.py | 4 ++-- 16 files changed, 45 insertions(+), 43 deletions(-) diff --git a/src/sage/geometry/polyhedron/parent.py b/src/sage/geometry/polyhedron/parent.py index 5fad17dc55a..79a77e51556 100644 --- a/src/sage/geometry/polyhedron/parent.py +++ b/src/sage/geometry/polyhedron/parent.py @@ -14,7 +14,7 @@ from sage.structure.parent import Parent from sage.structure.element import get_coercion_model from sage.structure.unique_representation import UniqueRepresentation -from sage.modules.free_module import FreeModule, is_FreeModule +from sage.modules.free_module import FreeModule, FreeModule_generic from sage.misc.cachefunc import cached_method, cached_function from sage.misc.lazy_import import lazy_import import sage.rings.abc @@ -1009,7 +1009,7 @@ def _get_action_(self, other, op, self_is_left): from sage.structure.coerce_actions import ActedUponAction from sage.categories.action import PrecomposedAction - if op is operator.add and is_FreeModule(other): + if op is operator.add and isinstance(other, FreeModule_generic): base_ring = self._coerce_base_ring(other) extended_self = self.base_extend(base_ring) extended_other = other.base_extend(base_ring) diff --git a/src/sage/manifolds/subsets/pullback.py b/src/sage/manifolds/subsets/pullback.py index 6ab4a28059f..f096b563844 100644 --- a/src/sage/manifolds/subsets/pullback.py +++ b/src/sage/manifolds/subsets/pullback.py @@ -16,7 +16,7 @@ from sage.categories.sets_cat import Sets, EmptySetError from sage.categories.metric_spaces import MetricSpaces from sage.misc.lazy_import import lazy_import -from sage.modules.free_module import is_FreeModule +from sage.modules.free_module import FreeModule_generic from sage.rings.infinity import infinity, minus_infinity from sage.rings.integer_ring import ZZ from sage.rings.rational_field import QQ @@ -829,7 +829,7 @@ def is_closed(self): # Regardless of their base_ring, we treat polyhedra as closed # convex subsets of R^n return True - elif is_FreeModule(self._codomain_subset) and self._codomain_subset.rank() != infinity: + elif isinstance(self._codomain_subset, FreeModule_generic) and self._codomain_subset.rank() != infinity: if self._codomain_subset.base_ring() in MetricSpaces().Complete(): # Closed topological vector subspace return True diff --git a/src/sage/matrix/action.pyx b/src/sage/matrix/action.pyx index 0db343c9eed..b7e8071305d 100644 --- a/src/sage/matrix/action.pyx +++ b/src/sage/matrix/action.pyx @@ -67,7 +67,7 @@ AUTHOR: import operator from sage.matrix.matrix_space import MatrixSpace, is_MatrixSpace -from sage.modules.free_module import FreeModule, is_FreeModule +from sage.modules.free_module import FreeModule, FreeModule_generic from sage.structure.coerce cimport coercion_model from sage.categories.homset import Hom, End @@ -304,7 +304,7 @@ cdef class MatrixVectorAction(MatrixMulAction): ... TypeError: incompatible dimensions 3, 4 """ - if not is_FreeModule(S): + if not isinstance(S, FreeModule_generic): raise TypeError("Not a free module: %s" % S) MatrixMulAction.__init__(self, G, S, True) @@ -355,7 +355,7 @@ cdef class VectorMatrixAction(MatrixMulAction): ... TypeError: incompatible dimensions 5, 3 """ - if not is_FreeModule(S): + if not isinstance(S, FreeModule_generic): raise TypeError("Not a free module: %s" % S) MatrixMulAction.__init__(self, G, S, False) diff --git a/src/sage/matrix/matrix2.pyx b/src/sage/matrix/matrix2.pyx index e36d913bcd9..cc15ea36efb 100644 --- a/src/sage/matrix/matrix2.pyx +++ b/src/sage/matrix/matrix2.pyx @@ -5786,7 +5786,7 @@ cdef class Matrix(Matrix1): sage: t.decomposition_of_subspace(v, check_restrict=False) == t.decomposition_of_subspace(v) # needs sage.libs.pari True """ - if not sage.modules.free_module.is_FreeModule(M): + if not isinstance(M, sage.modules.free_module.FreeModule_generic): raise TypeError("M must be a free module.") if not self.is_square(): raise ArithmeticError("self must be a square matrix") diff --git a/src/sage/matrix/matrix_space.py b/src/sage/matrix/matrix_space.py index 5d0db5fb742..63d9fdea5a6 100644 --- a/src/sage/matrix/matrix_space.py +++ b/src/sage/matrix/matrix_space.py @@ -1268,7 +1268,7 @@ def _get_action_(self, S, op, self_on_left): if is_MatrixSpace(S): # matrix multiplications return matrix_action.MatrixMatrixAction(self, S) - elif sage.modules.free_module.is_FreeModule(S): + elif isinstance(S, sage.modules.free_module.FreeModule_generic): return matrix_action.MatrixVectorAction(self, S) elif isinstance(S, SchemeHomset_points): return matrix_action.MatrixSchemePointAction(self, S) @@ -1281,7 +1281,7 @@ def _get_action_(self, S, op, self_on_left): if is_MatrixSpace(S): # matrix multiplications return matrix_action.MatrixMatrixAction(S, self) - elif sage.modules.free_module.is_FreeModule(S): + elif isinstance(S, sage.modules.free_module.FreeModule_generic): return matrix_action.VectorMatrixAction(self, S) elif isinstance(S, SchemeHomset_generic): return matrix_action.PolymapMatrixAction(self, S) diff --git a/src/sage/modular/abvar/abvar.py b/src/sage/modular/abvar/abvar.py index 8e0906e45a8..7b5a067af1f 100644 --- a/src/sage/modular/abvar/abvar.py +++ b/src/sage/modular/abvar/abvar.py @@ -51,7 +51,7 @@ from sage.modular.modsym.modsym import ModularSymbols from sage.modular.modsym.space import ModularSymbolsSpace from sage.modular.quatalg.brandt import BrandtModule -from sage.modules.free_module import is_FreeModule +from sage.modules.free_module import FreeModule_generic from sage.modules.free_module_element import vector from sage.rings.fast_arith import prime_range from sage.rings.infinity import infinity @@ -4009,7 +4009,7 @@ def __init__(self, groups, lattice=None, base_field=QQ, is_simple=None, newform_ lattice = ZZ**(2 * self._ambient_dimension()) if check: n = self._ambient_dimension() - if not is_FreeModule(lattice): + if not isinstance(lattice, FreeModule_generic): raise TypeError("lattice must be a free module") if lattice.base_ring() != ZZ: raise TypeError("lattice must be over ZZ") diff --git a/src/sage/modular/abvar/finite_subgroup.py b/src/sage/modular/abvar/finite_subgroup.py index 2725e11a387..00aa5afa414 100644 --- a/src/sage/modular/abvar/finite_subgroup.py +++ b/src/sage/modular/abvar/finite_subgroup.py @@ -103,7 +103,7 @@ from sage.misc.lazy_import import lazy_import from sage.modular.abvar.torsion_point import TorsionPoint from sage.modules.module import Module -from sage.modules.free_module import is_FreeModule +from sage.modules.free_module import FreeModule_generic from sage.structure.gens_py import abelian_iterator from sage.structure.sequence import Sequence from sage.structure.richcmp import richcmp_method, richcmp @@ -871,7 +871,7 @@ def __init__(self, abvar, lattice, field_of_definition=None, check=True): from sage.rings.qqbar import QQbar as field_of_definition if check: from .abvar import is_ModularAbelianVariety - if not is_FreeModule(lattice) or lattice.base_ring() != ZZ: + if not isinstance(lattice, FreeModule_generic) or lattice.base_ring() != ZZ: raise TypeError("lattice must be a free module over ZZ") if not is_ModularAbelianVariety(abvar): raise TypeError("abvar must be a modular abelian variety") diff --git a/src/sage/modular/hecke/ambient_module.py b/src/sage/modular/hecke/ambient_module.py index 7805cd2d364..e402c6fbd7d 100644 --- a/src/sage/modular/hecke/ambient_module.py +++ b/src/sage/modular/hecke/ambient_module.py @@ -22,7 +22,7 @@ from . import module from . import submodule -from sage.modules.free_module import FreeModule, is_FreeModule +from sage.modules.free_module import FreeModule, FreeModule_generic from sage.rings.integer import Integer import sage.arith.all as arith @@ -927,7 +927,7 @@ def submodule(self, M, Mdual=None, check=True): Modular Forms subspace of dimension 2 of Modular Forms space of dimension 3 for Congruence Subgroup Gamma0(37) of weight 2 over Rational Field """ if check: - if not is_FreeModule(M): + if not isinstance(M, FreeModule_generic): V = self.free_module() if isinstance(M, (list, tuple)): M = V.span([V(x.element()) for x in M]) diff --git a/src/sage/modular/hecke/submodule.py b/src/sage/modular/hecke/submodule.py index 5e9bf127496..47a95f928e7 100644 --- a/src/sage/modular/hecke/submodule.py +++ b/src/sage/modular/hecke/submodule.py @@ -22,7 +22,7 @@ import sage.arith.all as arith from sage.misc.verbose import verbose from sage.misc.cachefunc import cached_method -from sage.modules.free_module import is_FreeModule +from sage.modules.free_module import FreeModule_generic from sage.structure.richcmp import richcmp_method, richcmp_not_equal from . import module @@ -81,7 +81,7 @@ def __init__(self, ambient, submodule, dual_free_module=None, check=True): from . import ambient_module if not isinstance(ambient, ambient_module.AmbientHeckeModule): raise TypeError("ambient must be an ambient Hecke module") - if not is_FreeModule(submodule): + if not isinstance(submodule, FreeModule_generic): raise TypeError("submodule must be a free module") if not submodule.is_submodule(ambient.free_module()): raise ValueError("submodule must be a submodule of the ambient free module") @@ -96,7 +96,7 @@ def __init__(self, ambient, submodule, dual_free_module=None, check=True): ambient.level(), ambient.weight()) if dual_free_module is not None: - if not is_FreeModule(dual_free_module): + if not isinstance(dual_free_module, FreeModule_generic): raise TypeError("dual_free_module must be a free module") if dual_free_module.rank() != submodule.rank(): raise ArithmeticError("dual_free_module must have the same rank as submodule") @@ -912,7 +912,7 @@ def submodule(self, M, Mdual=None, check=True): sage: S.submodule(S[0].free_module()) Modular Symbols subspace of dimension 2 of Modular Symbols space of dimension 18 for Gamma_0(18) of weight 4 with sign 0 over Rational Field """ - if not is_FreeModule(M): + if not isinstance(M, FreeModule_generic): V = self.ambient_module().free_module() if isinstance(M, (list, tuple)): M = V.span([V(x.element()) for x in M]) diff --git a/src/sage/modular/modsym/ambient.py b/src/sage/modular/modsym/ambient.py index 00c97e59789..cbd6c8e80b3 100644 --- a/src/sage/modular/modsym/ambient.py +++ b/src/sage/modular/modsym/ambient.py @@ -88,7 +88,7 @@ class ``ModularSymbolsAmbient``, derived from ManinSymbolList_gamma1, ManinSymbolList_gamma_h, ManinSymbolList_character) -from sage.modules.free_module import is_FreeModule +from sage.modules.free_module import FreeModule_generic from sage.modules.free_module_element import FreeModuleElement from sage.rings.integer import Integer from sage.rings.integer_ring import ZZ @@ -2133,7 +2133,7 @@ def submodule(self, M, dual_free_module=None, check=True): Stein, 2007-07-27 """ if check: - if not is_FreeModule(M): + if not isinstance(M, FreeModule_generic): V = self.free_module() if not isinstance(M, (list, tuple)): M = M.gens() diff --git a/src/sage/modules/fg_pid/fgp_module.py b/src/sage/modules/fg_pid/fgp_module.py index 6965b4281b7..2feb18b08d6 100644 --- a/src/sage/modules/fg_pid/fgp_module.py +++ b/src/sage/modules/fg_pid/fgp_module.py @@ -214,7 +214,7 @@ from itertools import product from sage.modules.module import Module -from sage.modules.free_module import is_FreeModule +from sage.modules.free_module import FreeModule_generic from sage.structure.all import parent from sage.structure.sequence import Sequence from .fgp_element import DEBUG, FGP_Element @@ -356,9 +356,9 @@ def __init__(self, V, W, check=True): """ if check: - if not is_FreeModule(V): + if not isinstance(V, FreeModule_generic): raise TypeError("V must be a FreeModule") - if not is_FreeModule(W): + if not isinstance(W, FreeModule_generic): raise TypeError("W must be a FreeModule") if not W.is_submodule(V): raise ValueError("W must be a submodule of V") @@ -501,7 +501,7 @@ def __truediv__(self, other): Finitely generated module V/W over Integer Ring with invariants () """ if not is_FGP_Module(other): - if is_FreeModule(other): + if isinstance(other, FreeModule_generic): other = other / other.zero_submodule() else: raise TypeError("other must be an FGP module") @@ -1598,7 +1598,7 @@ def hom(self, im_gens, codomain=None, check=True): N = codomain im_gens = Sequence(im_gens, universe=N) - if is_FreeModule(N): + if isinstance(N, FreeModule_generic): # If im_smith_gens are not in an R-module, but are in a Free-module, # then we quotient out by the 0 submodule and get an R-module. N = FGP_Module(N, N.zero_submodule(), check=DEBUG) diff --git a/src/sage/modules/fg_pid/fgp_morphism.py b/src/sage/modules/fg_pid/fgp_morphism.py index c3b5374f706..d97ccd2d750 100644 --- a/src/sage/modules/fg_pid/fgp_morphism.py +++ b/src/sage/modules/fg_pid/fgp_morphism.py @@ -506,8 +506,8 @@ def __init__(self, X, Y, category=None): """ if category is None: - from sage.modules.free_module import is_FreeModule - if is_FreeModule(X) and is_FreeModule(Y): + from sage.modules.free_module import FreeModule_generic + if isinstance(X, FreeModule_generic) and isinstance(Y, FreeModule_generic): from sage.categories.modules_with_basis import ModulesWithBasis category = ModulesWithBasis(X.base_ring()) else: diff --git a/src/sage/modules/free_module.py b/src/sage/modules/free_module.py index d0924defd91..952137822fc 100644 --- a/src/sage/modules/free_module.py +++ b/src/sage/modules/free_module.py @@ -858,6 +858,8 @@ def is_FreeModule(M): sage: is_FreeModule(W) True """ + from sage.misc.superseded import deprecation + deprecation(37924, "the function is_FreeModule is deprecated; use 'isinstance(..., FreeModule_generic)' instead") return isinstance(M, FreeModule_generic) @@ -2745,7 +2747,7 @@ def direct_sum(self, other): [ 0 1 -3 0 0 0] [ 0 0 0 1/2 4 2] """ - if not is_FreeModule(other): + if not isinstance(other, FreeModule_generic): raise TypeError("other must be a free module") if other.base_ring() != self.base_ring(): raise TypeError("base rings of self and other must be the same") @@ -2867,7 +2869,7 @@ def coordinate_module(self, V): [ 0 1 1 0 -2 1 -1 1 -1 -2 2 0 0 0 0 0 0 0 0] [ 0 0 3 0 -3 2 -1 2 -1 -4 2 -1 -2 1 2 0 0 -1 1] """ - if not is_FreeModule(V): + if not isinstance(V, FreeModule_generic): raise ValueError("V must be a free module") A = self.basis_matrix() A = A.matrix_from_columns(A.pivots()).transpose() @@ -4144,7 +4146,7 @@ def span_of_basis(self, basis, base_ring=None, check=True, already_echelonized=F ... ValueError: The given basis vectors must be linearly independent. """ - if is_FreeModule(basis): + if isinstance(basis, FreeModule_generic): basis = basis.gens() if base_ring is None or base_ring == self.base_ring(): try: @@ -4306,7 +4308,7 @@ def vector_space_span(self, gens, check=True): Basis matrix: [ 1 3/2 2] """ - if is_FreeModule(gens): + if isinstance(gens, FreeModule_generic): gens = gens.gens() return FreeModule_submodule_field(self.ambient_vector_space(), gens, check=check) @@ -4360,7 +4362,7 @@ def quotient_module(self, sub, check=True, **kwds): """ # Calling is_subspace may be way too slow and repeat work done below. # It will be very desirable to somehow do this step better. - if check and (not is_FreeModule(sub) or not sub.is_submodule(self)): + if check and (not isinstance(sub, FreeModule_generic) or not sub.is_submodule(self)): try: sub = self.submodule(sub) except (TypeError, ArithmeticError): @@ -4695,7 +4697,7 @@ def span_of_basis(self, basis, base_ring=None, check=True, already_echelonized=F ... ValueError: The given basis vectors must be linearly independent. """ - if is_FreeModule(basis): + if isinstance(basis, FreeModule_generic): basis = basis.gens() if base_ring is None: return FreeModule_submodule_with_basis_field( @@ -5189,9 +5191,9 @@ def quotient_module(self, sub, check=True): """ # Calling is_submodule may be way too slow and repeat work done below. # It will be very desirable to somehow do this step better. - if is_FreeModule(sub) and self.base_ring() != sub.base_ring(): + if isinstance(sub, FreeModule_generic) and self.base_ring() != sub.base_ring(): raise ValueError("base rings must be the same") - if check and (not is_FreeModule(sub) or not sub.is_subspace(self)): + if check and (not isinstance(sub, FreeModule_generic) or not sub.is_subspace(self)): try: sub = self.subspace(sub) except (TypeError, ArithmeticError): @@ -5342,7 +5344,7 @@ def quotient_abstract(self, sub, check=True, **kwds): """ # Calling is_subspace may be way too slow and repeat work done below. # It will be very desirable to somehow do this step better. - if check and (not is_FreeModule(sub) or not sub.is_subspace(self)): + if check and (not isinstance(sub, FreeModule_generic) or not sub.is_subspace(self)): try: sub = self.subspace(sub) except (TypeError, ArithmeticError): @@ -8015,7 +8017,7 @@ def __init__(self, ambient, gens, check=True, already_echelonized=False, categor [ 1 0 -1] [ 0 1 2] """ - if is_FreeModule(gens): + if isinstance(gens, FreeModule_generic): gens = gens.gens() FreeModule_submodule_with_basis_field.__init__(self, ambient, basis=gens, check=check, diff --git a/src/sage/modules/free_module_morphism.py b/src/sage/modules/free_module_morphism.py index 6974b31f18c..ae8416125d2 100644 --- a/src/sage/modules/free_module_morphism.py +++ b/src/sage/modules/free_module_morphism.py @@ -128,7 +128,7 @@ def pushforward(self, x): sage: phi(2*W.1) (6, 0, 8/3) """ - if free_module.is_FreeModule(x): + if isinstance(x, free_module.FreeModule_generic): V = self.domain().submodule(x) return self.restrict_domain(V).image() raise TypeError("`pushforward` is only defined for submodules") diff --git a/src/sage/modules/free_quadratic_module.py b/src/sage/modules/free_quadratic_module.py index 03456dfe224..7967b42dada 100644 --- a/src/sage/modules/free_quadratic_module.py +++ b/src/sage/modules/free_quadratic_module.py @@ -753,7 +753,7 @@ def span(self, gens, check=True, already_echelonized=False): Basis matrix: [1 1 1] """ - if free_module.is_FreeModule(gens): + if isinstance(gens, free_module.FreeModule_generic): gens = gens.gens() if not isinstance(gens, (list, tuple)): raise TypeError("gens (=%s) must be a list or tuple" % gens) diff --git a/src/sage/numerical/linear_tensor.py b/src/sage/numerical/linear_tensor.py index 2402845b896..dae27a69dc3 100644 --- a/src/sage/numerical/linear_tensor.py +++ b/src/sage/numerical/linear_tensor.py @@ -269,8 +269,8 @@ def is_vector_space(self): sage: LF.tensor(RDF^(2,2)).is_vector_space() False """ - from sage.modules.free_module import is_FreeModule - return is_FreeModule(self.free_module()) + from sage.modules.free_module import FreeModule_generic + return isinstance(self.free_module(), FreeModule_generic) def is_matrix_space(self): """ From a15c49fdecafac619080ecde14f3b499dafe08ff Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 2 May 2024 11:05:34 -0700 Subject: [PATCH 04/11] src/sage/modules/fg_pid/fgp_module.py: Deprecate is_FGP_Module --- src/sage/groups/matrix_gps/isometries.py | 4 ++-- src/sage/modules/fg_pid/fgp_module.py | 16 +++++++++------- src/sage/modules/fg_pid/fgp_morphism.py | 8 ++++---- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/sage/groups/matrix_gps/isometries.py b/src/sage/groups/matrix_gps/isometries.py index 4763b13721a..c39c0e3bd80 100644 --- a/src/sage/groups/matrix_gps/isometries.py +++ b/src/sage/groups/matrix_gps/isometries.py @@ -227,9 +227,9 @@ def _get_action_(self, S, op, self_on_left): return GroupActionOnSubmodule(self, S) if S is self._invariant_quotient_module: return GroupActionOnQuotientModule(self, S) - from sage.modules.fg_pid.fgp_module import is_FGP_Module + from sage.modules.fg_pid.fgp_module import FGP_Module_class T = self._invariant_quotient_module - if is_FGP_Module(S): + if isinstance(S, FGP_Module_class): if S.is_submodule(T): V = S.V() if all(V == V * f.matrix() for f in self.gens()): diff --git a/src/sage/modules/fg_pid/fgp_module.py b/src/sage/modules/fg_pid/fgp_module.py index 2feb18b08d6..241ea66c870 100644 --- a/src/sage/modules/fg_pid/fgp_module.py +++ b/src/sage/modules/fg_pid/fgp_module.py @@ -284,6 +284,8 @@ def is_FGP_Module(x): sage: sage.modules.fg_pid.fgp_module.is_FGP_Module(Q) True """ + from sage.misc.superseded import deprecation + deprecation(37924, "the function is_FGP_Module is deprecated; use 'isinstance(..., FGP_Module_class)' instead") return isinstance(x, FGP_Module_class) @@ -441,7 +443,7 @@ def _coerce_map_from_(self, S): sage: Q._coerce_map_from_(V.scale(2)) True """ - if is_FGP_Module(S): + if isinstance(S, FGP_Module_class): return S.has_canonical_map_to(self) return self._V.has_coerce_map_from(S) @@ -500,7 +502,7 @@ def __truediv__(self, other): sage: Q/Q Finitely generated module V/W over Integer Ring with invariants () """ - if not is_FGP_Module(other): + if not isinstance(other, FGP_Module_class): if isinstance(other, FreeModule_generic): other = other / other.zero_submodule() else: @@ -525,7 +527,7 @@ def __eq__(self, other): sage: Q == V/V.zero_submodule() False """ - if not is_FGP_Module(other): + if not isinstance(other, FGP_Module_class): return False return self._V == other._V and self._W == other._W @@ -745,7 +747,7 @@ def submodule(self, x): ... ValueError: x.V() must be contained in self's V. """ - if is_FGP_Module(x): + if isinstance(x, FGP_Module_class): if not x._W.is_submodule(self._W): raise ValueError("x.W() must be contained in self's W.") @@ -759,7 +761,7 @@ def submodule(self, x): raise TypeError("x must be a list, tuple, or FGP module") x = Sequence(x) - if is_FGP_Module(x.universe()): + if isinstance(x.universe(), FGP_Module_class): # TODO: possibly inefficient in some cases x = [self(v).lift() for v in x] V = self._V.submodule(x) + self._W @@ -791,7 +793,7 @@ def has_canonical_map_to(self, A): False """ - if not is_FGP_Module(A): + if not isinstance(A, FGP_Module_class): return False if self.cardinality() == 0 and self.base_ring() == A.base_ring(): return True @@ -2047,7 +2049,7 @@ def random_fgp_morphism_0(*args, **kwds): sage: mor = fgp.random_fgp_morphism_0(4) sage: mor.domain() == mor.codomain() True - sage: fgp.is_FGP_Module(mor.domain()) + sage: isinstance(mor.domain(), fgp.FGP_Module_class) True Each generator is sent to a random multiple of itself:: diff --git a/src/sage/modules/fg_pid/fgp_morphism.py b/src/sage/modules/fg_pid/fgp_morphism.py index d97ccd2d750..ae8309d6d87 100644 --- a/src/sage/modules/fg_pid/fgp_morphism.py +++ b/src/sage/modules/fg_pid/fgp_morphism.py @@ -277,8 +277,8 @@ def __call__(self, x): sage: phi(8*Q.1) == phi(x) True """ - from .fgp_module import is_FGP_Module - if is_FGP_Module(x): + from .fgp_module import FGP_Module_class + if isinstance(x, FGP_Module_class): if not x.is_submodule(self.domain()): raise ValueError("x must be a submodule or element of the domain") # perhaps can be optimized with a matrix multiply; but note @@ -355,8 +355,8 @@ def inverse_image(self, A): ... ValueError: A must be a submodule of the codomain """ - from .fgp_module import is_FGP_Module - if not is_FGP_Module(A): + from .fgp_module import FGP_Module_class + if not isinstance(A, FGP_Module_class): raise TypeError("A must be a finitely generated quotient module") if not A.is_submodule(self.codomain()): raise ValueError("A must be a submodule of the codomain") From a91e7b8cf11a249ca349db0ccd649c6f213656d7 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 2 May 2024 11:27:44 -0700 Subject: [PATCH 05/11] src/sage/modules/free_module_homspace.py: Deprecate is_FreeModuleHomspace --- src/sage/modules/free_module_homspace.py | 2 ++ src/sage/modules/free_module_morphism.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/sage/modules/free_module_homspace.py b/src/sage/modules/free_module_homspace.py index 9222bd8105e..355a8d549aa 100644 --- a/src/sage/modules/free_module_homspace.py +++ b/src/sage/modules/free_module_homspace.py @@ -120,6 +120,8 @@ def is_FreeModuleHomspace(x): sage: sage.modules.free_module_homspace.is_FreeModuleHomspace('junk') False """ + from sage.misc.superseded import deprecation + deprecation(37924, "the function is_FreeModuleHomspace is deprecated; use 'isinstance(..., FreeModuleHomspace)' instead") return isinstance(x, FreeModuleHomspace) diff --git a/src/sage/modules/free_module_morphism.py b/src/sage/modules/free_module_morphism.py index ae8416125d2..173075ee5c0 100644 --- a/src/sage/modules/free_module_morphism.py +++ b/src/sage/modules/free_module_morphism.py @@ -90,7 +90,7 @@ def __init__(self, parent, A, side="left"): sage: type(phi) """ - if not free_module_homspace.is_FreeModuleHomspace(parent): + if not isinstance(parent, free_module_homspace.FreeModuleHomspace): raise TypeError("parent (=%s) must be a free module hom space" % parent) if isinstance(A, matrix_morphism.MatrixMorphism): A = A.matrix() From 791c58a3b4094a69f15b476a8ef494e6cd318399 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 2 May 2024 11:31:35 -0700 Subject: [PATCH 06/11] src/sage/modules/vector_space_homspace.py: Deprecate is_VectorSpaceHomspace --- src/sage/modules/vector_space_homspace.py | 2 ++ src/sage/modules/vector_space_morphism.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/sage/modules/vector_space_homspace.py b/src/sage/modules/vector_space_homspace.py index 475e70ed00f..e973fe455ec 100644 --- a/src/sage/modules/vector_space_homspace.py +++ b/src/sage/modules/vector_space_homspace.py @@ -238,6 +238,8 @@ def is_VectorSpaceHomspace(x): sage: sage.modules.vector_space_homspace.is_VectorSpaceHomspace('junk') False """ + from sage.misc.superseded import deprecation + deprecation(37924, "the function is_VectorSpaceHomspace is deprecated; use 'isinstance(..., VectorSpaceHomspace)' instead") return isinstance(x, VectorSpaceHomspace) diff --git a/src/sage/modules/vector_space_morphism.py b/src/sage/modules/vector_space_morphism.py index dba263de586..f9df6ea412c 100644 --- a/src/sage/modules/vector_space_morphism.py +++ b/src/sage/modules/vector_space_morphism.py @@ -869,7 +869,7 @@ def __init__(self, homspace, A, side="left"): sage: type(rho) """ - if not vector_space_homspace.is_VectorSpaceHomspace(homspace): + if not isinstance(homspace, vector_space_homspace.VectorSpaceHomspace): raise TypeError('homspace must be a vector space hom space, not {}'.format(homspace)) if isinstance(A, matrix_morphism.MatrixMorphism): A = A.matrix() From 8682043df7df79cf7dccb998e9e4fa9fd4081ca3 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 2 May 2024 11:46:49 -0700 Subject: [PATCH 07/11] src/sage/matrix/matrix_space.py: Deprecate is_MatrixSpace --- src/sage/groups/matrix_gps/finitely_generated.py | 4 ++-- src/sage/matrix/action.pyx | 6 +++--- src/sage/matrix/matrix_space.py | 6 ++++-- src/sage/numerical/linear_tensor.py | 4 ++-- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/sage/groups/matrix_gps/finitely_generated.py b/src/sage/groups/matrix_gps/finitely_generated.py index 1df22e6c3a6..4d5562fc661 100644 --- a/src/sage/groups/matrix_gps/finitely_generated.py +++ b/src/sage/groups/matrix_gps/finitely_generated.py @@ -72,7 +72,7 @@ from sage.groups.matrix_gps.group_element import is_MatrixGroupElement from sage.groups.matrix_gps.matrix_group import MatrixGroup_generic from sage.matrix.constructor import matrix -from sage.matrix.matrix_space import is_MatrixSpace +from sage.matrix.matrix_space import MatrixSpace from sage.misc.cachefunc import cached_method from sage.rings.integer_ring import ZZ from sage.structure.element import is_Matrix @@ -130,7 +130,7 @@ def normalize_square_matrices(matrices): raise ValueError('not all matrices have the same size') gens = Sequence(gens, immutable=True) MS = gens.universe() - if not is_MatrixSpace(MS): + if not isinstance(MS, MatrixSpace): raise TypeError('all generators must be matrices') if MS.nrows() != MS.ncols(): raise ValueError('matrices must be square') diff --git a/src/sage/matrix/action.pyx b/src/sage/matrix/action.pyx index b7e8071305d..96587b99cbc 100644 --- a/src/sage/matrix/action.pyx +++ b/src/sage/matrix/action.pyx @@ -66,7 +66,7 @@ AUTHOR: import operator -from sage.matrix.matrix_space import MatrixSpace, is_MatrixSpace +from sage.matrix.matrix_space import MatrixSpace from sage.modules.free_module import FreeModule, FreeModule_generic from sage.structure.coerce cimport coercion_model from sage.categories.homset import Hom, End @@ -100,7 +100,7 @@ cdef class MatrixMulAction(Action): over Univariate Polynomial Ring in x over Rational Field """ def __init__(self, G, S, is_left): - if not is_MatrixSpace(G): + if not isinstance(G, MatrixSpace): raise TypeError("Not a matrix space: %s" % G) if isinstance(S, SchemeHomset_generic): if G.base_ring() is not S.domain().base_ring(): @@ -160,7 +160,7 @@ cdef class MatrixMatrixAction(MatrixMulAction): example is good practice. """ def __init__(self, G, S): - if not is_MatrixSpace(S): + if not isinstance(S, MatrixSpace): raise TypeError("Not a matrix space: %s" % S) MatrixMulAction.__init__(self, G, S, True) diff --git a/src/sage/matrix/matrix_space.py b/src/sage/matrix/matrix_space.py index 63d9fdea5a6..66d1a9274b9 100644 --- a/src/sage/matrix/matrix_space.py +++ b/src/sage/matrix/matrix_space.py @@ -80,6 +80,8 @@ def is_MatrixSpace(x): sage: is_MatrixSpace(5) False """ + from sage.misc.superseded import deprecation + deprecation(37924, "the function is_MatrixSpace is deprecated; use 'isinstance(..., MatrixSpace)' instead") return isinstance(x, MatrixSpace) @@ -1265,7 +1267,7 @@ def _get_action_(self, S, op, self_on_left): if op is operator.mul: from . import action as matrix_action if self_on_left: - if is_MatrixSpace(S): + if isinstance(S, MatrixSpace): # matrix multiplications return matrix_action.MatrixMatrixAction(self, S) elif isinstance(S, sage.modules.free_module.FreeModule_generic): @@ -1278,7 +1280,7 @@ def _get_action_(self, S, op, self_on_left): # action of base ring return sage.structure.coerce_actions.RightModuleAction(S, self) else: - if is_MatrixSpace(S): + if isinstance(S, MatrixSpace): # matrix multiplications return matrix_action.MatrixMatrixAction(S, self) elif isinstance(S, sage.modules.free_module.FreeModule_generic): diff --git a/src/sage/numerical/linear_tensor.py b/src/sage/numerical/linear_tensor.py index dae27a69dc3..217bd98f3bb 100644 --- a/src/sage/numerical/linear_tensor.py +++ b/src/sage/numerical/linear_tensor.py @@ -290,8 +290,8 @@ def is_matrix_space(self): sage: LF.tensor(RDF^(2,2)).is_matrix_space() True """ - from sage.matrix.matrix_space import is_MatrixSpace - return is_MatrixSpace(self.free_module()) + from sage.matrix.matrix_space import MatrixSpace + return isinstance(self.free_module(), MatrixSpace) def linear_functions(self): """ From 4796d796d0201ab40f8315d599a8d5a676d51ff9 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 2 May 2024 11:50:19 -0700 Subject: [PATCH 08/11] src/sage/modules/filtered_vector_space.py: Deprecate is_FilteredVectorSpace --- src/sage/modules/filtered_vector_space.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/sage/modules/filtered_vector_space.py b/src/sage/modules/filtered_vector_space.py index 68bbff12c8d..0d4594e214b 100644 --- a/src/sage/modules/filtered_vector_space.py +++ b/src/sage/modules/filtered_vector_space.py @@ -148,6 +148,8 @@ def is_FilteredVectorSpace(X): sage: is_FilteredVectorSpace('ceci n\'est pas une pipe') False """ + from sage.misc.superseded import deprecation + deprecation(37924, "the function is_FilteredVectorSpace is deprecated; use 'isinstance(..., FilteredVectorSpace_class)' instead") return isinstance(X, FilteredVectorSpace_class) From d6f29ba9371473b12fc5b4573f34f6e00a298bca Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 7 May 2024 19:19:40 -0700 Subject: [PATCH 09/11] Update doctests for deprecation warnings --- src/sage/matrix/matrix_space.py | 4 ++++ src/sage/modules/fg_pid/fgp_module.py | 4 ++++ src/sage/modules/filtered_vector_space.py | 4 ++++ src/sage/modules/free_module.py | 4 ++++ src/sage/modules/free_module_homspace.py | 4 ++++ src/sage/modules/free_quadratic_module.py | 4 ++++ src/sage/modules/module.pyx | 10 +++++++++- src/sage/modules/vector_space_homspace.py | 4 ++++ 8 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/sage/matrix/matrix_space.py b/src/sage/matrix/matrix_space.py index 66d1a9274b9..54703de84c6 100644 --- a/src/sage/matrix/matrix_space.py +++ b/src/sage/matrix/matrix_space.py @@ -74,6 +74,10 @@ def is_MatrixSpace(x): sage: MS = MatrixSpace(QQ,2) sage: A = MS.random_element() sage: is_MatrixSpace(MS) + doctest:warning... + DeprecationWarning: the function is_MatrixSpace is deprecated; + use 'isinstance(..., MatrixSpace)' instead + See https://github.com/sagemath/sage/issues/37924 for details. True sage: is_MatrixSpace(A) False diff --git a/src/sage/modules/fg_pid/fgp_module.py b/src/sage/modules/fg_pid/fgp_module.py index 241ea66c870..026f55533f7 100644 --- a/src/sage/modules/fg_pid/fgp_module.py +++ b/src/sage/modules/fg_pid/fgp_module.py @@ -280,6 +280,10 @@ def is_FGP_Module(x): sage: V = span([[1/2,1,1],[3/2,2,1],[0,0,1]],ZZ) sage: W = V.span([2*V.0 + 4*V.1, 9*V.0 + 12*V.1, 4*V.2]); Q = V/W sage: sage.modules.fg_pid.fgp_module.is_FGP_Module(V) + doctest:warning... + DeprecationWarning: the function is_FGP_Module is deprecated; + use 'isinstance(..., FGP_Module_class)' instead + See https://github.com/sagemath/sage/issues/37924 for details. False sage: sage.modules.fg_pid.fgp_module.is_FGP_Module(Q) True diff --git a/src/sage/modules/filtered_vector_space.py b/src/sage/modules/filtered_vector_space.py index 0d4594e214b..6bf2ae7fc17 100644 --- a/src/sage/modules/filtered_vector_space.py +++ b/src/sage/modules/filtered_vector_space.py @@ -144,6 +144,10 @@ def is_FilteredVectorSpace(X): sage: from sage.modules.filtered_vector_space import is_FilteredVectorSpace sage: V = FilteredVectorSpace(2, 1) sage: is_FilteredVectorSpace(V) + doctest:warning...: + DeprecationWarning: the function is_FilteredVectorSpace is deprecated; + use 'isinstance(..., FilteredVectorSpace_class)' instead + See https://github.com/sagemath/sage/issues/37924 for details. True sage: is_FilteredVectorSpace('ceci n\'est pas une pipe') False diff --git a/src/sage/modules/free_module.py b/src/sage/modules/free_module.py index 952137822fc..102d13aacd2 100644 --- a/src/sage/modules/free_module.py +++ b/src/sage/modules/free_module.py @@ -853,6 +853,10 @@ def is_FreeModule(M): sage: from sage.modules.free_module import is_FreeModule sage: V = ZZ^3 sage: is_FreeModule(V) + doctest:warning... + DeprecationWarning: the function is_FreeModule is deprecated; + use 'isinstance(..., FreeModule_generic)' instead + See https://github.com/sagemath/sage/issues/37924 for details. True sage: W = V.span([ V.random_element() for i in range(2) ]) sage: is_FreeModule(W) diff --git a/src/sage/modules/free_module_homspace.py b/src/sage/modules/free_module_homspace.py index 355a8d549aa..ae4503ea9d3 100644 --- a/src/sage/modules/free_module_homspace.py +++ b/src/sage/modules/free_module_homspace.py @@ -97,6 +97,10 @@ def is_FreeModuleHomspace(x): sage: type(H) sage: sage.modules.free_module_homspace.is_FreeModuleHomspace(H) + doctest:warning... + DeprecationWarning: the function is_FreeModuleHomspace is deprecated; + use 'isinstance(..., FreeModuleHomspace)' instead + See https://github.com/sagemath/sage/issues/37924 for details. True sage: K = Hom(QQ^3, ZZ^2) diff --git a/src/sage/modules/free_quadratic_module.py b/src/sage/modules/free_quadratic_module.py index 7967b42dada..da54426e9c9 100644 --- a/src/sage/modules/free_quadratic_module.py +++ b/src/sage/modules/free_quadratic_module.py @@ -241,6 +241,10 @@ def is_FreeQuadraticModule(M): sage: from sage.modules.free_quadratic_module import is_FreeQuadraticModule sage: U = FreeModule(QQ,3) sage: is_FreeQuadraticModule(U) + doctest:warning... + DeprecationWarning: the function is_FreeQuadraticModule is deprecated; + use 'isinstance(..., FreeQuadraticModule_generic)' instead + See https://github.com/sagemath/sage/issues/37924 for details. False sage: V = FreeModule(QQ,3,inner_product_matrix=diagonal_matrix([1,1,1])) sage: is_FreeQuadraticModule(V) diff --git a/src/sage/modules/module.pyx b/src/sage/modules/module.pyx index 80a727875b7..f602478187a 100644 --- a/src/sage/modules/module.pyx +++ b/src/sage/modules/module.pyx @@ -284,6 +284,10 @@ def is_Module(x): sage: from sage.modules.module import is_Module sage: M = FreeModule(RationalField(),30) # needs sage.modules sage: is_Module(M) # needs sage.modules + doctest:warning... + DeprecationWarning: the function is_Module is deprecated; + use 'isinstance(..., Module)' instead + See https://github.com/sagemath/sage/issues/37924 for details. True sage: is_Module(10) False @@ -307,6 +311,10 @@ def is_VectorSpace(x): sage: from sage.modules.module import is_Module, is_VectorSpace sage: M = FreeModule(RationalField(),30) sage: is_VectorSpace(M) + doctest:warning... + DeprecationWarning: the function is_VectorSpace is deprecated; + use 'isinstance(..., Module)' and check the base ring instead + See https://github.com/sagemath/sage/issues/37924 for details. True sage: M = FreeModule(IntegerRing(),30) sage: is_Module(M) @@ -318,6 +326,6 @@ def is_VectorSpace(x): from sage.misc.superseded import deprecation_cython deprecation_cython(37924, "the function is_VectorSpace is deprecated; use 'isinstance(..., Module)' and check the base ring instead") try: - return is_Module(x) and x.base_ring().is_field() + return isinstance(x, Module) and x.base_ring().is_field() except AttributeError: return False diff --git a/src/sage/modules/vector_space_homspace.py b/src/sage/modules/vector_space_homspace.py index e973fe455ec..bfbcae9ade0 100644 --- a/src/sage/modules/vector_space_homspace.py +++ b/src/sage/modules/vector_space_homspace.py @@ -221,6 +221,10 @@ def is_VectorSpaceHomspace(x): sage: type(H) sage: sage.modules.vector_space_homspace.is_VectorSpaceHomspace(H) + doctest:warning... + DeprecationWarning: the function is_VectorSpaceHomspace is deprecated; + use 'isinstance(..., VectorSpaceHomspace)' instead + See https://github.com/sagemath/sage/issues/37924 for details. True sage: K = Hom(QQ^3, ZZ^2) From 729878b3181e06c24db6144899eeacf17c67a65e Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 11 May 2024 17:35:27 -0700 Subject: [PATCH 10/11] src/sage/modules/module.pyx: Update doctest with deprecation --- src/sage/modules/module.pyx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/sage/modules/module.pyx b/src/sage/modules/module.pyx index f602478187a..000c8a88bcd 100644 --- a/src/sage/modules/module.pyx +++ b/src/sage/modules/module.pyx @@ -318,6 +318,10 @@ def is_VectorSpace(x): True sage: M = FreeModule(IntegerRing(),30) sage: is_Module(M) + doctest:warning... + DeprecationWarning: the function is_Module is deprecated; + use 'isinstance(..., Module)' instead + See https://github.com/sagemath/sage/issues/37924 for details. True sage: is_VectorSpace(M) False From 72e46f7cf7df96d653ba07a5e0b7d8842df38b65 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 11 May 2024 17:36:17 -0700 Subject: [PATCH 11/11] src/sage/modules/vector_space_morphism.py: Remove use of is_VectorSpace --- src/sage/modules/vector_space_morphism.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/sage/modules/vector_space_morphism.py b/src/sage/modules/vector_space_morphism.py index f9df6ea412c..c981acc8d67 100644 --- a/src/sage/modules/vector_space_morphism.py +++ b/src/sage/modules/vector_space_morphism.py @@ -696,7 +696,7 @@ def linear_transformation(arg0, arg1=None, arg2=None, side='left'): from sage.categories.homset import Hom from sage.matrix.constructor import matrix from sage.modules.free_module import VectorSpace - from sage.modules.module import is_VectorSpace + from sage.modules.module import Module try: from sage.modules.vector_callable_symbolic_dense import ( Vector_callable_symbolic_dense, @@ -706,8 +706,6 @@ def linear_transformation(arg0, arg1=None, arg2=None, side='left'): if side not in ['left', 'right']: raise ValueError("side must be 'left' or 'right', not {}".format(side)) - if not (is_Matrix(arg0) or is_VectorSpace(arg0)): - raise TypeError('first argument must be a matrix or a vector space, not {}'.format(arg0)) if is_Matrix(arg0): R = arg0.base_ring() if not R.is_field(): @@ -722,14 +720,15 @@ def linear_transformation(arg0, arg1=None, arg2=None, side='left'): arg2 = arg0 arg0 = VectorSpace(R, arg2.nrows()) arg1 = VectorSpace(R, arg2.ncols()) - elif is_VectorSpace(arg0): - if not is_VectorSpace(arg1): + elif isinstance(arg0, Module) and arg0.base_ring().is_field(): + if not (isinstance(arg1, Module) and arg1.base_ring().is_field()): msg = 'if first argument is a vector space, then second argument must be a vector space, not {0}' raise TypeError(msg.format(arg1)) if arg0.base_ring() != arg1.base_ring(): msg = 'vector spaces must have the same field of scalars, not {0} and {1}' raise TypeError(msg.format(arg0.base_ring(), arg1.base_ring())) - + else: + raise TypeError('first argument must be a matrix or a vector space, not {}'.format(arg0)) # Now arg0 = domain D, arg1 = codomain C, and # both are vector spaces with common field of scalars # use these to make a VectorSpaceHomSpace