From 2d3599596f3259bb1a33b6a381a1f1381c187246 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 25 May 2024 13:04:19 -0700 Subject: [PATCH 01/16] for a in "CLASS='Element|InfinityElement|CommutativeAlgebraElement|AlgebraElement|FieldElement|EuclideanDomainElement|PrincipalIdealDomainElement|DedekindDomainElement|IntegralDomainElement|Matrix|Vector|ModuleElement|MonoidElement|AdditiveGroupElement|MultiplicativeGroupElement|RingElement|CommutativeRingElement';SUFFIX=" ; do eval "$a"; git --no-pager grep -l -E 'is_('$CLASS')' | xargs sed -E -i.bak 's/import is_('$CLASS')/import \1'$SUFFIX'/;/^ +/s/is_('$CLASS')[(]([^()]*([(][^()]*[)])?[^()]*)[)]/isinstance(\2, \1'$SUFFIX')/g'; done --- .../finite_dimensional_algebra.py | 4 +- .../finite_dimensional_algebra_element.pyx | 4 +- .../finite_dimensional_algebra_ideal.py | 4 +- .../finite_dimensional_algebra_morphism.py | 4 +- src/sage/algebras/jordan_algebra.py | 6 +-- .../algebras/quatalg/quaternion_algebra.py | 4 +- src/sage/calculus/expr.py | 4 +- src/sage/calculus/functions.py | 8 ++-- src/sage/coding/binary_code.pyx | 6 +-- src/sage/coding/delsarte_bounds.py | 4 +- src/sage/coding/linear_rank_metric.py | 10 ++--- .../combinat/cluster_algebra_quiver/quiver.py | 4 +- src/sage/combinat/integer_matrices.py | 4 +- .../combinat/root_system/cartan_matrix.py | 4 +- .../combinat/root_system/dynkin_diagram.py | 4 +- .../root_system/reflection_group_complex.py | 4 +- src/sage/combinat/rsk.py | 4 +- src/sage/combinat/similarity_class_type.py | 2 +- src/sage/crypto/boolean_function.pyx | 8 ++-- src/sage/crypto/mq/sr.py | 42 +++++++++---------- src/sage/crypto/sbox.pyx | 4 +- .../endPN_automorphism_group.py | 8 ++-- src/sage/games/sudoku.py | 8 ++-- src/sage/geometry/fan_morphism.py | 4 +- .../hyperbolic_space/hyperbolic_point.py | 4 +- src/sage/geometry/lattice_polytope.py | 6 +-- src/sage/geometry/polyhedron/base5.py | 4 +- .../geometry/polyhedron/representation.py | 4 +- src/sage/graphs/bipartite_graph.py | 4 +- src/sage/graphs/digraph.py | 4 +- src/sage/graphs/graph.py | 4 +- src/sage/graphs/graph_input.py | 16 +++---- src/sage/graphs/strongly_regular_db.pyx | 4 +- src/sage/groups/affine_gps/group_element.py | 6 +-- .../groups/matrix_gps/finitely_generated.py | 4 +- src/sage/groups/matrix_gps/group_element.pyx | 4 +- .../groups/matrix_gps/group_element_gap.pyx | 4 +- .../perm_gps/partn_ref/refinement_binary.pyx | 6 +-- .../groups/perm_gps/permgroup_element.pyx | 6 +-- src/sage/homology/chain_complex.py | 2 +- src/sage/interfaces/four_ti_2.py | 4 +- src/sage/libs/ntl/ntl_mat_GF2.pyx | 4 +- src/sage/libs/ntl/ntl_mat_GF2E.pyx | 4 +- src/sage/matrix/matrix2.pyx | 12 +++--- src/sage/matrix/matrix_integer_dense.pyx | 6 +-- src/sage/matrix/matrix_polynomial_dense.pyx | 16 +++---- src/sage/matrix/special.py | 20 ++++----- src/sage/matroids/constructor.py | 8 ++-- src/sage/misc/sage_input.py | 4 +- src/sage/modular/abvar/homspace.py | 4 +- src/sage/modular/cusps.py | 12 +++--- src/sage/modular/cusps_nf.py | 8 ++-- src/sage/modular/hecke/hecke_operator.py | 4 +- src/sage/modular/modsym/manin_symbol.pyx | 4 +- src/sage/modular/modsym/relation_matrix.py | 4 +- src/sage/modules/free_module.py | 4 +- src/sage/modules/free_module_homspace.py | 4 +- ...free_quadratic_module_integer_symmetric.py | 4 +- src/sage/modules/vector_space_homspace.py | 4 +- src/sage/modules/vector_space_morphism.py | 8 ++-- src/sage/modules/with_basis/morphism.py | 4 +- .../numerical/backends/matrix_sdp_backend.pyx | 4 +- src/sage/numerical/mip.pyx | 6 +-- src/sage/numerical/sdp.pyx | 6 +-- src/sage/plot/matrix_plot.py | 4 +- src/sage/plot/plot.py | 4 +- src/sage/plot/plot3d/list_plot3d.py | 4 +- src/sage/plot/plot3d/parametric_plot3d.py | 4 +- src/sage/quadratic_forms/extras.py | 4 +- src/sage/quadratic_forms/quadratic_form.py | 14 +++---- src/sage/quadratic_forms/ternary_qf.py | 6 +-- src/sage/rings/number_field/number_field.py | 4 +- src/sage/rings/number_field/order.py | 4 +- src/sage/rings/padics/factory.py | 4 +- .../polynomial/multi_polynomial_sequence.py | 4 +- src/sage/rings/polynomial/polynomial_ring.py | 4 +- src/sage/rings/valuation/value_group.py | 8 ++-- src/sage/schemes/plane_conics/con_field.py | 8 ++-- src/sage/schemes/plane_conics/constructor.py | 4 +- src/sage/schemes/toric/divisor.py | 4 +- src/sage/schemes/toric/divisor_class.pyx | 4 +- src/sage/schemes/toric/homset.py | 4 +- src/sage/stats/hmm/chmm.pyx | 4 +- src/sage/stats/hmm/hmm.pyx | 4 +- src/sage/stats/hmm/util.pyx | 4 +- src/sage/structure/element.pyx | 4 +- 86 files changed, 253 insertions(+), 253 deletions(-) diff --git a/src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra.py b/src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra.py index a3b8742b4e0..3d0142bbac7 100644 --- a/src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra.py +++ b/src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra.py @@ -19,7 +19,7 @@ from sage.categories.magmatic_algebras import MagmaticAlgebras from sage.matrix.constructor import Matrix, matrix -from sage.structure.element import is_Matrix +from sage.structure.element import Matrix from sage.rings.ring import Algebra from sage.structure.category_object import normalize_names from sage.structure.unique_representation import UniqueRepresentation @@ -136,7 +136,7 @@ def __classcall_private__(cls, k, table, names='e', assume_associative=False, table = [b.base_extend(k) for b in table] for b in table: b.set_immutable() - if not (is_Matrix(b) and b.dimensions() == (n, n)): + if not (isinstance(b, Matrix) and b.dimensions() == (n, n)): raise ValueError("input is not a multiplication table") table = tuple(table) diff --git a/src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra_element.pyx b/src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra_element.pyx index 08feb228e5e..f4a85ea7667 100644 --- a/src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra_element.pyx +++ b/src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra_element.pyx @@ -15,7 +15,7 @@ Elements of Finite Algebras import re from sage.matrix.matrix_space import MatrixSpace -from sage.structure.element import is_Matrix +from sage.structure.element import Matrix from sage.rings.integer import Integer from cpython.object cimport PyObject_RichCompare as richcmp @@ -119,7 +119,7 @@ cdef class FiniteDimensionalAlgebraElement(AlgebraElement): raise TypeError("algebra is not unitary") elif isinstance(elt, Vector): self._vector = MatrixSpace(k, 1, n)(list(elt)) - elif is_Matrix(elt): + elif isinstance(elt, Matrix): if elt.ncols() != n: raise ValueError("matrix does not define an element of the algebra") if elt.nrows() == 1: diff --git a/src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra_ideal.py b/src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra_ideal.py index 15f0881bb8b..d19c60e0681 100644 --- a/src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra_ideal.py +++ b/src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra_ideal.py @@ -16,7 +16,7 @@ from .finite_dimensional_algebra_element import FiniteDimensionalAlgebraElement from sage.matrix.constructor import Matrix -from sage.structure.element import is_Matrix +from sage.structure.element import Matrix from sage.rings.ideal import Ideal_generic from sage.structure.element import parent @@ -63,7 +63,7 @@ def __init__(self, A, gens=None, given_by_matrix=False): B = [FiniteDimensionalAlgebraIdeal(A, x).basis_matrix() for x in gens] B = reduce(lambda x, y: x.stack(y), B, Matrix(k, 0, n)) self._basis_matrix = B.echelon_form().image().basis_matrix() - elif is_Matrix(gens): + elif isinstance(gens, Matrix): gens = FiniteDimensionalAlgebraElement(A, gens) elif isinstance(gens, FiniteDimensionalAlgebraElement): gens = gens.vector() diff --git a/src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra_morphism.py b/src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra_morphism.py index d2114511ae6..7e6e265990b 100644 --- a/src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra_morphism.py +++ b/src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra_morphism.py @@ -15,7 +15,7 @@ from sage.misc.cachefunc import cached_method from sage.rings.morphism import RingHomomorphism_im_gens from sage.rings.homset import RingHomset_generic -from sage.structure.element import is_Matrix +from sage.structure.element import Matrix class FiniteDimensionalAlgebraMorphism(RingHomomorphism_im_gens): @@ -240,7 +240,7 @@ def __call__(self, f, check=True, unitary=True): return f if f.parent() == self: return FiniteDimensionalAlgebraMorphism(self, f._matrix, check, unitary) - elif is_Matrix(f): + elif isinstance(f, Matrix): return FiniteDimensionalAlgebraMorphism(self, f, check, unitary) try: from sage.matrix.constructor import Matrix diff --git a/src/sage/algebras/jordan_algebra.py b/src/sage/algebras/jordan_algebra.py index f783dc890c8..adbcdd53eee 100644 --- a/src/sage/algebras/jordan_algebra.py +++ b/src/sage/algebras/jordan_algebra.py @@ -22,7 +22,7 @@ from sage.structure.richcmp import richcmp from sage.categories.magmatic_algebras import MagmaticAlgebras from sage.misc.cachefunc import cached_method -from sage.structure.element import is_Matrix +from sage.structure.element import Matrix from sage.modules.free_module import FreeModule from sage.matrix.constructor import matrix from sage.sets.family import Family @@ -194,7 +194,7 @@ def __classcall_private__(self, arg0, arg1=None, names=None): names = tuple(names) if arg1 is None: - if not is_Matrix(arg0): + if not isinstance(arg0, Matrix): from sage.algebras.octonion_algebra import OctonionAlgebra if isinstance(arg0, OctonionAlgebra): return ExceptionalJordanAlgebra(arg0) @@ -202,7 +202,7 @@ def __classcall_private__(self, arg0, arg1=None, names=None): raise ValueError("the base ring cannot have characteristic 2") return SpecialJordanAlgebra(arg0, names) arg0, arg1 = arg0.base_ring(), arg0 - elif is_Matrix(arg0): + elif isinstance(arg0, Matrix): arg0, arg1 = arg1, arg0 # arg0 is the base ring and arg1 is a matrix diff --git a/src/sage/algebras/quatalg/quaternion_algebra.py b/src/sage/algebras/quatalg/quaternion_algebra.py index 5d9ca10e9f0..212425b5500 100644 --- a/src/sage/algebras/quatalg/quaternion_algebra.py +++ b/src/sage/algebras/quatalg/quaternion_algebra.py @@ -61,7 +61,7 @@ from sage.matrix.matrix_space import MatrixSpace from sage.matrix.constructor import diagonal_matrix, matrix from sage.structure.sequence import Sequence -from sage.structure.element import is_RingElement +from sage.structure.element import RingElement from sage.structure.factory import UniqueFactory from sage.modules.free_module import FreeModule from sage.modules.free_module_element import vector @@ -248,7 +248,7 @@ def create_key(self, arg0, arg1=None, arg2=None, names='i,j,k'): # to the relevant Sage types. This is a bit inelegant. L = [] for a in [arg0, arg1]: - if is_RingElement(a): + if isinstance(a, RingElement): L.append(a) elif isinstance(a, int): L.append(Integer(a)) diff --git a/src/sage/calculus/expr.py b/src/sage/calculus/expr.py index 0aa62851d24..7e56c888cac 100644 --- a/src/sage/calculus/expr.py +++ b/src/sage/calculus/expr.py @@ -3,7 +3,7 @@ """ from sage.misc.lazy_import import lazy_import -from sage.structure.element import is_Matrix +from sage.structure.element import Matrix from sage.symbolic.expression import Expression from sage.symbolic.ring import SR @@ -178,7 +178,7 @@ def symbolic_expression(x): if isinstance(expressions[0], FreeModuleElement): return matrix(expressions) return vector(expressions) - elif is_Matrix(x): + elif isinstance(x, Matrix): if not x.nrows() or not x.ncols(): # Make sure it is symbolic and of correct dimensions # also when a matrix dimension is 0 diff --git a/src/sage/calculus/functions.py b/src/sage/calculus/functions.py index 11a23aac323..e02ff8f7235 100644 --- a/src/sage/calculus/functions.py +++ b/src/sage/calculus/functions.py @@ -3,7 +3,7 @@ Calculus functions """ from sage.misc.lazy_import import lazy_import -from sage.structure.element import is_Matrix, is_Vector, Expression +from sage.structure.element import Matrix, is_Vector, Expression lazy_import('sage.matrix.constructor', 'matrix') @@ -138,13 +138,13 @@ def jacobian(functions, variables): [ cos(x)*cos(y) -sin(x)*sin(y)] [ 0 e^x] """ - if is_Matrix(functions) and (functions.nrows() == 1 + if isinstance(functions, Matrix) and (functions.nrows() == 1 or functions.ncols() == 1): functions = functions.list() - elif not (isinstance(functions, (tuple, list)) or is_Vector(functions)): + elif not (isinstance(functions, (tuple, list)) or isinstance(functions, Vector)): functions = [functions] - if not isinstance(variables, (tuple, list)) and not is_Vector(variables): + if not isinstance(variables, (tuple, list)) and not isinstance(variables, Vector): variables = [variables] return matrix([[diff(f, v) for v in variables] for f in functions]) diff --git a/src/sage/coding/binary_code.pyx b/src/sage/coding/binary_code.pyx index 81065a7dbd3..2f8fb08d808 100644 --- a/src/sage/coding/binary_code.pyx +++ b/src/sage/coding/binary_code.pyx @@ -46,7 +46,7 @@ from cpython.mem cimport * from cpython.object cimport PyObject_RichCompare from cysignals.memory cimport sig_malloc, sig_realloc, sig_free -from sage.structure.element import is_Matrix +from sage.structure.element import Matrix from sage.misc.timing import cputime from sage.rings.integer cimport Integer from copy import copy @@ -759,7 +759,7 @@ cdef class BinaryCode: self.radix = sizeof(int) << 3 - if is_Matrix(arg1): + if isinstance(arg1, Matrix): self.ncols = arg1.ncols() self.nrows = arg1.nrows() nrows = self.nrows @@ -795,7 +795,7 @@ cdef class BinaryCode: self_words = self.words self_basis = self.basis - if is_Matrix(arg1): + if isinstance(arg1, Matrix): rows = arg1.rows() for i from 0 <= i < nrows: word = 0 diff --git a/src/sage/coding/delsarte_bounds.py b/src/sage/coding/delsarte_bounds.py index 0f8fa305a08..ab16b1792df 100644 --- a/src/sage/coding/delsarte_bounds.py +++ b/src/sage/coding/delsarte_bounds.py @@ -693,9 +693,9 @@ def delsarte_bound_Q_matrix(q, d, return_data=False, [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1] """ from sage.numerical.mip import MIPSolverException - from sage.structure.element import is_Matrix + from sage.structure.element import Matrix - if not is_Matrix(q): + if not isinstance(q, Matrix): raise ValueError("Input to delsarte_bound_Q_matrix " "should be a sage Matrix()") diff --git a/src/sage/coding/linear_rank_metric.py b/src/sage/coding/linear_rank_metric.py index 6a7cd14cb62..517081a6bb4 100644 --- a/src/sage/coding/linear_rank_metric.py +++ b/src/sage/coding/linear_rank_metric.py @@ -113,7 +113,7 @@ from sage.categories.fields import Fields from sage.matrix.constructor import Matrix -from sage.structure.element import is_Matrix, is_Vector +from sage.structure.element import Matrix, is_Vector from sage.modules.free_module_element import vector from sage.rings.infinity import Infinity @@ -166,7 +166,7 @@ def to_matrix_representation(v, sub_field=None, basis=None): ... TypeError: Input must be a vector """ - if not is_Vector(v): + if not isinstance(v, Vector): raise TypeError("Input must be a vector") base_field = v.base_ring() if not sub_field: @@ -214,7 +214,7 @@ def from_matrix_representation(w, base_field=None, basis=None): ... TypeError: Input must be a matrix """ - if not is_Matrix(w): + if not isinstance(w, Matrix): raise TypeError("Input must be a matrix") sub_field = w.base_ring() if not base_field: @@ -252,7 +252,7 @@ def rank_weight(c, sub_field=None, basis=None): sage: rank_weight(a, GF(4)) 2 """ - if is_Vector(c): + if isinstance(c, Vector): c = to_matrix_representation(c, sub_field, basis) return c.rank() @@ -310,7 +310,7 @@ def rank_distance(a, b, sub_field=None, basis=None): """ if not (a.base_ring() == b.base_ring()): raise ValueError("The base field of {} and {} has to be the same".format(a, b)) - if not (is_Vector(a) and is_Vector(b)): + if not (isinstance(a, Vector) and isinstance(b, Vector)): raise TypeError("Both inputs have to be vectors") if not len(a) == len(b): raise ValueError("The length of {} and {} has to be the same".format(a, b)) diff --git a/src/sage/combinat/cluster_algebra_quiver/quiver.py b/src/sage/combinat/cluster_algebra_quiver/quiver.py index 37103b623f4..849a07ae8a4 100644 --- a/src/sage/combinat/cluster_algebra_quiver/quiver.py +++ b/src/sage/combinat/cluster_algebra_quiver/quiver.py @@ -222,7 +222,7 @@ def __init__(self, data, frozen=None, user_labels=None): sage: TestSuite(Q).run() """ from sage.combinat.cluster_algebra_quiver.cluster_seed import ClusterSeed - from sage.structure.element import is_Matrix + from sage.structure.element import Matrix if isinstance(user_labels, list): user_labels = [tuple(x) if isinstance(x, list) else x for x in user_labels] @@ -334,7 +334,7 @@ def __init__(self, data, frozen=None, user_labels=None): self._description = data._description # constructs a quiver from a matrix - elif is_Matrix(data): + elif isinstance(data, Matrix): if not _principal_part(data).is_skew_symmetrizable( positive=True ): raise ValueError('The principal part of the matrix data must be skew-symmetrizable.') diff --git a/src/sage/combinat/integer_matrices.py b/src/sage/combinat/integer_matrices.py index 238d0ef4091..db8105dd6ba 100644 --- a/src/sage/combinat/integer_matrices.py +++ b/src/sage/combinat/integer_matrices.py @@ -167,8 +167,8 @@ def __contains__(self, x): sage: matrix([[-1, 3, 1]]) in IM False """ - from sage.structure.element import is_Matrix - if not is_Matrix(x): + from sage.structure.element import Matrix + if not isinstance(x, Matrix): return False row_sums = [ZZ.zero()] * x.nrows() col_sums = [ZZ.zero()] * x.ncols() diff --git a/src/sage/combinat/root_system/cartan_matrix.py b/src/sage/combinat/root_system/cartan_matrix.py index 23da5ab2e4b..03ae889382a 100644 --- a/src/sage/combinat/root_system/cartan_matrix.py +++ b/src/sage/combinat/root_system/cartan_matrix.py @@ -29,7 +29,7 @@ from sage.misc.cachefunc import cached_method from sage.matrix.constructor import matrix from sage.misc.lazy_import import lazy_import -from sage.structure.element import is_Matrix +from sage.structure.element import Matrix from sage.matrix.matrix_space import MatrixSpace from sage.misc.inherit_comparison import InheritComparisonClasscallMetaclass from sage.misc.classcall_metaclass import typecall @@ -1064,7 +1064,7 @@ def is_borcherds_cartan_matrix(M): sage: is_borcherds_cartan_matrix(O) False """ - if not is_Matrix(M): + if not isinstance(M, Matrix): return False if not M.is_square(): return False diff --git a/src/sage/combinat/root_system/dynkin_diagram.py b/src/sage/combinat/root_system/dynkin_diagram.py index f5aa29ba129..0b815043999 100644 --- a/src/sage/combinat/root_system/dynkin_diagram.py +++ b/src/sage/combinat/root_system/dynkin_diagram.py @@ -30,7 +30,7 @@ # **************************************************************************** from sage.misc.cachefunc import cached_method from sage.misc.lazy_import import lazy_import -from sage.structure.element import is_Matrix +from sage.structure.element import Matrix from sage.graphs.digraph import DiGraph from sage.combinat.root_system.cartan_type import CartanType, CartanType_abstract @@ -181,7 +181,7 @@ def DynkinDiagram(*args, **kwds): if len(args) == 0: return DynkinDiagram_class() mat = args[0] - if is_Matrix(mat): + if isinstance(mat, Matrix): mat = CartanMatrix(*args) if isinstance(mat, CartanMatrix): if mat.cartan_type() is not mat: diff --git a/src/sage/combinat/root_system/reflection_group_complex.py b/src/sage/combinat/root_system/reflection_group_complex.py index 3287b516d08..279f25820a0 100644 --- a/src/sage/combinat/root_system/reflection_group_complex.py +++ b/src/sage/combinat/root_system/reflection_group_complex.py @@ -211,7 +211,7 @@ from sage.rings.rational_field import QQ from sage.matrix.constructor import Matrix from sage.matrix.special import identity_matrix -from sage.structure.element import is_Matrix +from sage.structure.element import Matrix from sage.interfaces.gap3 import gap3 from sage.modules.free_module_element import vector from sage.combinat.root_system.cartan_matrix import CartanMatrix @@ -244,7 +244,7 @@ def __init__(self, W_types, index_set=None, hyperplane_index_set=None, reflectio call_str = 'ComplexReflectionGroup(%s)' % W_type elif isinstance(W_type, CartanMatrix): call_str = 'PermRootGroup(IdentityMat(%s),%s)' % (W_type._rank, str(W_type._M._gap_())) - elif is_Matrix(W_type): + elif isinstance(W_type, Matrix): call_str = 'PermRootGroup(IdentityMat(%s),%s)' % (W_type._rank, str(W_type._gap_())) elif W_type in ZZ or (isinstance(W_type, tuple) and len(W_type) == 3): call_str = 'ComplexReflectionGroup%s' % str(W_type) diff --git a/src/sage/combinat/rsk.py b/src/sage/combinat/rsk.py index 21557d306de..be565ccd75d 100644 --- a/src/sage/combinat/rsk.py +++ b/src/sage/combinat/rsk.py @@ -170,7 +170,7 @@ from sage.structure.unique_representation import UniqueRepresentation from bisect import bisect_left, bisect_right -from sage.structure.element import is_Matrix +from sage.structure.element import Matrix from sage.matrix.constructor import matrix from sage.rings.integer_ring import ZZ @@ -3181,7 +3181,7 @@ def RSK(obj1=None, obj2=None, insertion=InsertionRules.RSK, check_standard=False else: raise ValueError("invalid input") - if is_Matrix(obj1): + if isinstance(obj1, Matrix): obj1 = obj1.rows() output = rule.forward_rule(obj1, obj2, check_standard) diff --git a/src/sage/combinat/similarity_class_type.py b/src/sage/combinat/similarity_class_type.py index 64acd5696dc..efea98f6812 100644 --- a/src/sage/combinat/similarity_class_type.py +++ b/src/sage/combinat/similarity_class_type.py @@ -807,7 +807,7 @@ def __classcall_private__(cls, tau): sage: tau.parent().size() 24 """ - if is_Matrix(tau): + if isinstance(tau, Matrix): n = tau.nrows() F = tau.base_ring() R = PolynomialRing(F, 't') diff --git a/src/sage/crypto/boolean_function.pyx b/src/sage/crypto/boolean_function.pyx index e12ae15dbc8..1fd0b39d2ef 100644 --- a/src/sage/crypto/boolean_function.pyx +++ b/src/sage/crypto/boolean_function.pyx @@ -1183,12 +1183,12 @@ cdef class BooleanFunction(SageObject): ... TypeError: cannot compute is_linear_structure() using parameter X """ - from sage.structure.element import is_Vector + from sage.structure.element import Vector nvars = self._nvariables if isinstance(val, (tuple, list)): i = ZZ(val, base=2) - elif is_Vector(val): + elif isinstance(val, Vector): if val.base_ring() != GF(2): raise TypeError("base ring of input vector must be GF(2)") elif val.parent().dimension() != nvars: @@ -1302,12 +1302,12 @@ cdef class BooleanFunction(SageObject): ... IndexError: index out of bound """ - from sage.structure.element import is_Vector + from sage.structure.element import Vector nvars = self._nvariables if isinstance(u, (tuple, list)): v = ZZ(u, base=2) - elif is_Vector(u): + elif isinstance(u, Vector): if u.base_ring() != GF(2): raise TypeError("base ring of input vector must be GF(2)") elif u.parent().dimension() != nvars: diff --git a/src/sage/crypto/mq/sr.py b/src/sage/crypto/mq/sr.py index 5fcffef726d..6829b6548e0 100644 --- a/src/sage/crypto/mq/sr.py +++ b/src/sage/crypto/mq/sr.py @@ -320,7 +320,7 @@ BooleanPolynomialRing_constructor as BooleanPolynomialRing from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing from sage.rings.polynomial.term_order import TermOrder -from sage.structure.element import is_Matrix +from sage.structure.element import Matrix from .mpolynomialsystemgenerator import MPolynomialSystemGenerator @@ -1028,7 +1028,7 @@ def state_array(self, d=None): if d is None: return Matrix(k, r, c) - if is_Matrix(d): + if isinstance(d, Matrix): if d.nrows() == r*c*e: return Matrix(k, c, r, self.antiphi(d).list()).transpose() elif d.ncols() == c and d.nrows() == r and d.base_ring() == k: @@ -1056,7 +1056,7 @@ def is_state_array(self, d): sage: sr.is_state_array( matrix(k, 4, 4) ) False """ - return is_Matrix(d) and \ + return isinstance(d, Matrix) and \ d.nrows() == self.r and \ d.ncols() == self.c and \ d.base_ring() == self.base_ring() @@ -2185,7 +2185,7 @@ def is_vector(self, d): sage: sr.is_vector(B) True """ - return is_Matrix(d) and \ + return isinstance(d, Matrix) and \ d.nrows() == self.r*self.c*self.e and \ d.ncols() == 1 and \ d.base_ring() == self.base_ring() @@ -2212,7 +2212,7 @@ def phi(self, l): [a^2 + 1 0] """ ret = [] - if is_Matrix(l): + if isinstance(l, Matrix): for e in l.transpose().list(): ret += [e**(2**i) for i in range(self.e)] else: @@ -2222,7 +2222,7 @@ def phi(self, l): return ret elif isinstance(l, tuple): return tuple(ret) - elif is_Matrix(l): + elif isinstance(l, Matrix): return Matrix(l.base_ring(), l.ncols(), l.nrows()*self.e, ret).transpose() else: raise TypeError @@ -2242,7 +2242,7 @@ def antiphi(self, l): sage: sr.antiphi(sr.phi(A)) == A True """ - if is_Matrix(l): + if isinstance(l, Matrix): ret = [e for e in l.transpose().list()[0:-1:self.e]] else: ret = [e for e in l[0:-1:self.e]] @@ -2251,7 +2251,7 @@ def antiphi(self, l): return ret elif isinstance(l, tuple): return tuple(ret) - elif is_Matrix(l): + elif isinstance(l, Matrix): return Matrix(self.base_ring(), l.ncols(), l.nrows() // self.e, ret).transpose() else: @@ -2526,7 +2526,7 @@ def vector(self, d=None): if d is None: return Matrix(k, r*c*e, 1) - elif is_Matrix(d) and d.ncols() == c and d.nrows() == r and d.base_ring() == self.k: + elif isinstance(d, Matrix) and d.ncols() == c and d.nrows() == r and d.base_ring() == self.k: l = flatten([self.phi(x) for x in d.transpose().list()], (Vector_modn_dense,list,tuple)) return Matrix(k, r*c*e, 1, l) elif isinstance(d, (list, tuple)): @@ -2565,7 +2565,7 @@ def is_vector(self, d): sage: sr.is_vector(B) True """ - return is_Matrix(d) and \ + return isinstance(d, Matrix) and \ d.nrows() == self.r*self.c*self.e and \ d.ncols() == 1 and \ d.base_ring() == GF(2) @@ -2599,7 +2599,7 @@ def phi(self, l, diffusion_matrix=False): r, c, e = self.r, self.c, self.e # handle diffusion layer matrices first - if is_Matrix(l) and diffusion_matrix and \ + if isinstance(l, Matrix) and diffusion_matrix and \ l.nrows() == r*c and l.ncols() == r*c and \ l.base_ring() == self.k: B = Matrix(GF(2), r*c*e, r*c*e) @@ -2614,7 +2614,7 @@ def phi(self, l, diffusion_matrix=False): return list(reversed(l._vector_())) # remaining matrices - if is_Matrix(l): + if isinstance(l, Matrix): for x in l.transpose().list(): ret += list(reversed(x._vector_())) # or lists @@ -2626,7 +2626,7 @@ def phi(self, l, diffusion_matrix=False): return ret elif isinstance(l, tuple): return tuple(ret) - elif is_Matrix(l): + elif isinstance(l, Matrix): return Matrix(GF(2), l.ncols(), l.nrows()*self.e, ret).transpose() else: raise TypeError @@ -2649,7 +2649,7 @@ def antiphi(self, l): e = self.e V = self.k.vector_space(map=False) - if is_Matrix(l): + if isinstance(l, Matrix): l2 = l.transpose().list() else: l2 = l @@ -2662,7 +2662,7 @@ def antiphi(self, l): return ret elif isinstance(l, tuple): return tuple(ret) - elif is_Matrix(l): + elif isinstance(l, Matrix): return Matrix(self.base_ring(), self.r * self.c, 1, ret) else: raise TypeError @@ -2916,14 +2916,14 @@ def inversion_polynomials_single_sbox(self, x=None, w=None, biaffine_only=None, else: if isinstance(x, (tuple, list)): P = x[0].parent() - elif is_Matrix(x): + elif isinstance(x, Matrix): P = x.base_ring() else: raise TypeError("x not understood") - if is_Matrix(x): + if isinstance(x, Matrix): x = x.column(0).list() - if is_Matrix(w): + if isinstance(w, Matrix): w = w.column(0).list() if e == 4: @@ -3091,7 +3091,7 @@ def _inversion_polynomials_single_sbox(self, x=None, w=None, biaffine_only=None, else: if isinstance(x, (tuple, list)): P = x[0].parent() - elif is_Matrix(x): + elif isinstance(x, Matrix): P = x.base_ring() else: raise TypeError("x not understood") @@ -3153,9 +3153,9 @@ def inversion_polynomials(self, xi, wi, length): x100*w101 + x100*w103 + x100*w104 + x101*w100 + x101*w102 + x101*w103 + x101*w107 + x102*w101 + x102*w102 + x102*w106 + x103*w100 + x103*w101 + x103*w105 + x104*w100 + x104*w104 + x105*w103 + x106*w102 + x107*w101, x100*w102 + x100*w104 + x100*w105 + x101*w101 + x101*w103 + x101*w104 + x102*w100 + x102*w102 + x102*w103 + x102*w107 + x103*w101 + x103*w102 + x103*w106 + x104*w100 + x104*w101 + x104*w105 + x105*w100 + x105*w104 + x106*w103 + x107*w102] """ - if is_Matrix(xi): + if isinstance(xi, Matrix): xi = xi.list() - if is_Matrix(wi): + if isinstance(wi, Matrix): wi = wi.list() e = self.e diff --git a/src/sage/crypto/sbox.pyx b/src/sage/crypto/sbox.pyx index 322f7ca5f45..46049d0cdd4 100644 --- a/src/sage/crypto/sbox.pyx +++ b/src/sage/crypto/sbox.pyx @@ -594,12 +594,12 @@ cdef class SBox(SageObject): sage: PRESENT.derivative(1).max_degree() < PRESENT.max_degree() # needs sage.rings.polynomial.pbori True """ - from sage.structure.element import is_Vector + from sage.structure.element import Vector nvars = self.m if isinstance(u, (tuple, list)): v = ZZ(u, base=2) - elif is_Vector(u): + elif isinstance(u, Vector): if u.base_ring() != GF(2): raise TypeError("base ring of input vector must be GF(2)") elif u.parent().dimension() != nvars: diff --git a/src/sage/dynamics/arithmetic_dynamics/endPN_automorphism_group.py b/src/sage/dynamics/arithmetic_dynamics/endPN_automorphism_group.py index c82f10aed0d..c11bd2bf8b2 100644 --- a/src/sage/dynamics/arithmetic_dynamics/endPN_automorphism_group.py +++ b/src/sage/dynamics/arithmetic_dynamics/endPN_automorphism_group.py @@ -38,7 +38,7 @@ from sage.rings.rational_field import QQ from sage.sets.primes import Primes from sage.sets.set import Set -from sage.structure.element import is_Matrix +from sage.structure.element import Matrix lazy_import('sage.rings.number_field.number_field', 'NumberField') @@ -352,7 +352,7 @@ def PGL_repn(rational_function): [-2 1] [ 1 -3] """ - if is_Matrix(rational_function): + if isinstance(rational_function, Matrix): return rational_function K = rational_function.parent() F = K.base_ring() @@ -592,7 +592,7 @@ def remove_redundant_automorphisms(automorphisms, order_elts, moduli, integral_a for psi in integral_autos: #The return_functions boolean determines if the automorphisms #are matrices or linear fractional transformations - if is_Matrix(psi): + if isinstance(psi, Matrix): ppsi = psi.change_ring(GF(p)) B = [ppsi[0,0], ppsi[0,1], ppsi[1,0], psi[1,1]] else: @@ -1714,7 +1714,7 @@ def which_group(list_of_elements): sage: which_group(G) 'Dihedral of order 6' """ - if is_Matrix(list_of_elements[-1]): + if isinstance(list_of_elements[-1], Matrix): R = PolynomialRing(list_of_elements[-1].base_ring(),'z') z = R.gen(0) G = [(t[0,0]*z+t[0,1])/(t[1,0]*z+t[1,1]) for t in list_of_elements] diff --git a/src/sage/games/sudoku.py b/src/sage/games/sudoku.py index abcadd08ca3..acd7f4fc54b 100644 --- a/src/sage/games/sudoku.py +++ b/src/sage/games/sudoku.py @@ -76,9 +76,9 @@ def sudoku(m): ... ValueError: sudoku function expects puzzle to be a matrix, perhaps use the Sudoku class """ - from sage.structure.element import is_Matrix + from sage.structure.element import Matrix - if not is_Matrix(m): + if not isinstance(m, Matrix): raise ValueError('sudoku function expects puzzle to be a matrix, perhaps use the Sudoku class') solution = next(Sudoku(m).solve(algorithm='dlx')) return (solution.to_matrix() if solution else None) @@ -170,12 +170,12 @@ def __init__(self, puzzle, verify_input=True): ValueError: Sudoku puzzle has an invalid entry """ from math import sqrt - from sage.structure.element import is_Matrix + from sage.structure.element import Matrix if isinstance(puzzle, list): puzzle_size = int(round(sqrt(len(puzzle)))) self.puzzle = tuple(puzzle) - elif is_Matrix(puzzle): + elif isinstance(puzzle, Matrix): puzzle_size = puzzle.ncols() if verify_input and not puzzle.is_square(): raise ValueError('Sudoku puzzle must be a square matrix') diff --git a/src/sage/geometry/fan_morphism.py b/src/sage/geometry/fan_morphism.py index c12f8135027..251efc8d2d3 100644 --- a/src/sage/geometry/fan_morphism.py +++ b/src/sage/geometry/fan_morphism.py @@ -83,7 +83,7 @@ from sage.geometry.fan import Fan, is_Fan from sage.matrix.constructor import matrix from sage.matrix.special import identity_matrix -from sage.structure.element import is_Matrix +from sage.structure.element import Matrix from sage.misc.cachefunc import cached_method from sage.misc.latex import latex from sage.misc.misc import walltime @@ -278,7 +278,7 @@ def __init__(self, morphism, domain_fan, if isinstance(morphism, FreeModuleMorphism): parent = morphism.parent() A = morphism.matrix() - elif is_Matrix(morphism): + elif isinstance(morphism, Matrix): A = morphism if codomain is None: raise ValueError("codomain (fan) must be given explicitly if " diff --git a/src/sage/geometry/hyperbolic_space/hyperbolic_point.py b/src/sage/geometry/hyperbolic_space/hyperbolic_point.py index 650c90a4403..62127ffe425 100644 --- a/src/sage/geometry/hyperbolic_space/hyperbolic_point.py +++ b/src/sage/geometry/hyperbolic_space/hyperbolic_point.py @@ -64,7 +64,7 @@ from sage.structure.richcmp import richcmp, op_NE from sage.symbolic.constants import I from sage.misc.latex import latex -from sage.structure.element import is_Matrix +from sage.structure.element import Matrix from sage.matrix.constructor import matrix from sage.modules.free_module_element import vector from sage.rings.infinity import infinity @@ -324,7 +324,7 @@ def __rmul__(self, other): """ if isinstance(other, HyperbolicIsometry): return other(self) - elif is_Matrix(other): + elif isinstance(other, Matrix): # TODO: Currently the __mul__ from the matrices gets called first # and returns an error instead of calling this method A = self.parent().get_isometry(other) diff --git a/src/sage/geometry/lattice_polytope.py b/src/sage/geometry/lattice_polytope.py index 666548b9f39..cc8dfc67579 100644 --- a/src/sage/geometry/lattice_polytope.py +++ b/src/sage/geometry/lattice_polytope.py @@ -141,7 +141,7 @@ feature=PythonModule("ppl", spkg="pplpy", type="standard")) from sage.matrix.constructor import matrix -from sage.structure.element import is_Matrix +from sage.structure.element import Matrix from sage.misc.cachefunc import cached_method from sage.misc.flatten import flatten from sage.misc.temporary_file import tmp_filename @@ -940,7 +940,7 @@ def _embed(self, data): for point in r: point.set_immutable() return PointCollection(r, M) - elif is_Matrix(data): + elif isinstance(data, Matrix): r = self._embedding_matrix * data for i, col in enumerate(r.columns(copy=False)): r.set_column(i, col + self._shift_vector) @@ -1108,7 +1108,7 @@ def _pullback(self, data): for point in r: point.set_immutable() return PointCollection(r, self._sublattice) - if is_Matrix(data): + if isinstance(data, Matrix): r = matrix([self._pullback(col) for col in data.columns(copy=False)]).transpose() return r diff --git a/src/sage/geometry/polyhedron/base5.py b/src/sage/geometry/polyhedron/base5.py index a1e57a63b99..c193c5ca529 100644 --- a/src/sage/geometry/polyhedron/base5.py +++ b/src/sage/geometry/polyhedron/base5.py @@ -1441,9 +1441,9 @@ def _acted_upon_(self, actor, self_on_left): """ if isinstance(actor, Polyhedron_base5): return self.product(actor) - elif is_Vector(actor): + elif isinstance(actor, Vector): return self.translation(actor) - elif is_Matrix(actor): + elif isinstance(actor, Matrix): if self_on_left: raise ValueError("matrices should act on the left") else: diff --git a/src/sage/geometry/polyhedron/representation.py b/src/sage/geometry/polyhedron/representation.py index ea803b2e558..49993d6ada1 100644 --- a/src/sage/geometry/polyhedron/representation.py +++ b/src/sage/geometry/polyhedron/representation.py @@ -15,7 +15,7 @@ from sage.structure.sage_object import SageObject -from sage.structure.element import is_Vector +from sage.structure.element import Vector from sage.structure.richcmp import richcmp_method, richcmp from sage.rings.integer_ring import ZZ from sage.modules.free_module_element import vector @@ -645,7 +645,7 @@ def eval(self, Vobj): sage: ineq.eval( vector(ZZ, [3,2]) ) 5 """ - if is_Vector(Vobj): + if isinstance(Vobj, Vector): return self.A() * Vobj + self.b() return Vobj.evaluated_on(self) diff --git a/src/sage/graphs/bipartite_graph.py b/src/sage/graphs/bipartite_graph.py index 6d8e909fa57..54c4d501aa4 100644 --- a/src/sage/graphs/bipartite_graph.py +++ b/src/sage/graphs/bipartite_graph.py @@ -420,7 +420,7 @@ def __init__(self, data=None, partition=None, check=True, hash_labels=None, *arg self.add_edges = MethodType(Graph.add_edges, self) alist_file = True - from sage.structure.element import is_Matrix + from sage.structure.element import Matrix if isinstance(data, BipartiteGraph): Graph.__init__(self, data, *args, **kwds) self.left = set(data.left) @@ -463,7 +463,7 @@ def __init__(self, data=None, partition=None, check=True, hash_labels=None, *arg else: # Automatically get partitions if not provided self._upgrade_from_graph() - elif is_Matrix(data): + elif isinstance(data, Matrix): # sanity check for mutually exclusive keywords if kwds.get("multiedges", False) and kwds.get("weighted", False): raise TypeError("weighted multi-edge bipartite graphs from " diff --git a/src/sage/graphs/digraph.py b/src/sage/graphs/digraph.py index e59b62bff9e..ddb0f36c627 100644 --- a/src/sage/graphs/digraph.py +++ b/src/sage/graphs/digraph.py @@ -638,7 +638,7 @@ def __init__(self, data=None, pos=None, loops=None, format=None, """ msg = '' GenericGraph.__init__(self) - from sage.structure.element import is_Matrix + from sage.structure.element import Matrix if sparse is False: if data_structure != "sparse": @@ -671,7 +671,7 @@ def __init__(self, data=None, pos=None, loops=None, format=None, format = 'dig6' if data[:8] == ">>dig6<<": data = data[8:] - if format is None and is_Matrix(data): + if format is None and isinstance(data, Matrix): if data.is_square(): format = 'adjacency_matrix' else: diff --git a/src/sage/graphs/graph.py b/src/sage/graphs/graph.py index d8e88b023f0..0764b27533e 100644 --- a/src/sage/graphs/graph.py +++ b/src/sage/graphs/graph.py @@ -1034,7 +1034,7 @@ def __init__(self, data=None, pos=None, loops=None, format=None, """ GenericGraph.__init__(self) - from sage.structure.element import is_Matrix + from sage.structure.element import Matrix if sparse is False: if data_structure != "sparse": @@ -1073,7 +1073,7 @@ def __init__(self, data=None, pos=None, loops=None, format=None, format = 'sparse6' else: format = 'graph6' - if format is None and is_Matrix(data): + if format is None and isinstance(data, Matrix): if data.is_symmetric(): format = 'adjacency_matrix' else: diff --git a/src/sage/graphs/graph_input.py b/src/sage/graphs/graph_input.py index ce1f8916423..5282fc10c40 100644 --- a/src/sage/graphs/graph_input.py +++ b/src/sage/graphs/graph_input.py @@ -190,9 +190,9 @@ def from_seidel_adjacency_matrix(G, M): sage: g.is_isomorphic(graphs.PetersenGraph()) # needs sage.modules True """ - from sage.structure.element import is_Matrix + from sage.structure.element import Matrix from sage.rings.integer_ring import ZZ - assert is_Matrix(M) + assert isinstance(M, Matrix) if M.base_ring() != ZZ: try: @@ -240,9 +240,9 @@ def from_adjacency_matrix(G, M, loops=False, multiedges=False, weighted=False): sage: g.is_isomorphic(graphs.PetersenGraph()) # needs sage.modules True """ - from sage.structure.element import is_Matrix + from sage.structure.element import Matrix from sage.rings.integer_ring import ZZ - assert is_Matrix(M) + assert isinstance(M, Matrix) # note: the adjacency matrix might be weighted and hence not # necessarily consists of integers if not weighted and M.base_ring() != ZZ: @@ -316,8 +316,8 @@ def from_incidence_matrix(G, M, loops=False, multiedges=False, weighted=False): sage: g.is_isomorphic(graphs.PetersenGraph()) # needs sage.modules True """ - from sage.structure.element import is_Matrix - assert is_Matrix(M) + from sage.structure.element import Matrix + assert isinstance(M, Matrix) oriented = any(M[pos] < 0 for pos in M.nonzero_positions(copy=False)) @@ -411,8 +411,8 @@ def from_oriented_incidence_matrix(G, M, loops=False, multiedges=False, weighted sage: list(G.edges(sort=True, labels=False)) # needs sage.modules [(1, 0)] """ - from sage.structure.element import is_Matrix - assert is_Matrix(M) + from sage.structure.element import Matrix + assert isinstance(M, Matrix) positions = [] for c in M.columns(): diff --git a/src/sage/graphs/strongly_regular_db.pyx b/src/sage/graphs/strongly_regular_db.pyx index b24441b3f18..8ec246bc454 100644 --- a/src/sage/graphs/strongly_regular_db.pyx +++ b/src/sage/graphs/strongly_regular_db.pyx @@ -2384,8 +2384,8 @@ def strongly_regular_from_two_weight_code(L): sage: G.is_strongly_regular(parameters=True) # needs sage.modules sage.rings.finite_rings (81, 50, 31, 30) """ - from sage.structure.element import is_Matrix - if is_Matrix(L): + from sage.structure.element import Matrix + if isinstance(L, Matrix): L = LinearCode(L) V = [tuple(l) for l in L] w1, _ = sorted(set(sum(map(bool, x)) for x in V).difference([0])) diff --git a/src/sage/groups/affine_gps/group_element.py b/src/sage/groups/affine_gps/group_element.py index c4ffa997e94..a5e1fd64fa3 100644 --- a/src/sage/groups/affine_gps/group_element.py +++ b/src/sage/groups/affine_gps/group_element.py @@ -40,7 +40,7 @@ # http://www.gnu.org/licenses/ #***************************************************************************** -from sage.structure.element import is_Matrix +from sage.structure.element import Matrix from sage.misc.cachefunc import cached_method from sage.structure.element import MultiplicativeGroupElement from sage.structure.richcmp import richcmp, richcmp_not_equal @@ -119,7 +119,7 @@ def __init__(self, parent, A, b=0, convert=True, check=True): A = A.matrix() except AttributeError: pass - if is_Matrix(A) and A.nrows() == A.ncols() == parent.degree()+1: + if isinstance(A, Matrix) and A.nrows() == A.ncols() == parent.degree()+1: g = A d = parent.degree() A = g.submatrix(0, 0, d, d) @@ -130,7 +130,7 @@ def __init__(self, parent, A, b=0, convert=True, check=True): b = parent.vector_space()(b) if check: # Note: the coercion framework expects that we raise TypeError for invalid input - if not is_Matrix(A): + if not isinstance(A, Matrix): raise TypeError('A must be a matrix') if not (A.parent() is parent.matrix_space()): raise TypeError('A must be an element of ' + str(parent.matrix_space())) diff --git a/src/sage/groups/matrix_gps/finitely_generated.py b/src/sage/groups/matrix_gps/finitely_generated.py index 4d5562fc661..909e92b80cc 100644 --- a/src/sage/groups/matrix_gps/finitely_generated.py +++ b/src/sage/groups/matrix_gps/finitely_generated.py @@ -75,7 +75,7 @@ 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 +from sage.structure.element import Matrix from sage.structure.sequence import Sequence @@ -105,7 +105,7 @@ def normalize_square_matrices(matrices): deg.append(m.parent().degree()) gens.append(m.matrix()) continue - if is_Matrix(m): + if isinstance(m, Matrix): if not m.is_square(): raise TypeError('matrix must be square') deg.append(m.ncols()) diff --git a/src/sage/groups/matrix_gps/group_element.pyx b/src/sage/groups/matrix_gps/group_element.pyx index 99c21b2589a..cfabb0c1be0 100644 --- a/src/sage/groups/matrix_gps/group_element.pyx +++ b/src/sage/groups/matrix_gps/group_element.pyx @@ -78,7 +78,7 @@ AUTHORS: from sage.rings.integer_ring import ZZ from sage.structure.element cimport MultiplicativeGroupElement, Matrix -from sage.structure.element import is_Matrix +from sage.structure.element import Matrix from sage.structure.parent cimport Parent from sage.structure.richcmp cimport richcmp @@ -156,7 +156,7 @@ cdef class MatrixGroupElement_generic(MultiplicativeGroupElement): if convert: M = parent.matrix_space()(M) if check: - if not is_Matrix(M): + if not isinstance(M, Matrix): raise TypeError('M must be a matrix') if M.parent() is not parent.matrix_space(): raise TypeError('M must be a in the matrix space of the group') diff --git a/src/sage/groups/matrix_gps/group_element_gap.pyx b/src/sage/groups/matrix_gps/group_element_gap.pyx index 2b363f7c303..b24e845b8f1 100644 --- a/src/sage/groups/matrix_gps/group_element_gap.pyx +++ b/src/sage/groups/matrix_gps/group_element_gap.pyx @@ -20,7 +20,7 @@ Matrix group elements implemented in GAP from sage.groups.matrix_gps.group_element cimport is_MatrixGroupElement from sage.libs.gap.element cimport GapElement from sage.misc.cachefunc import cached_method -from sage.structure.element import is_Matrix +from sage.structure.element import Matrix from sage.structure.factorization import Factorization from sage.structure.richcmp cimport richcmp @@ -65,7 +65,7 @@ cdef class MatrixGroupElement_gap(ElementLibGAP): from sage.libs.gap.libgap import libgap M_gap = libgap(M) if check: - if not is_Matrix(M): + if not isinstance(M, Matrix): raise TypeError('M must be a matrix') if M.parent() is not parent.matrix_space(): raise TypeError('M must be a in the matrix space of the group') diff --git a/src/sage/groups/perm_gps/partn_ref/refinement_binary.pyx b/src/sage/groups/perm_gps/partn_ref/refinement_binary.pyx index 1abbf635d9c..b52bab1c1ca 100644 --- a/src/sage/groups/perm_gps/partn_ref/refinement_binary.pyx +++ b/src/sage/groups/perm_gps/partn_ref/refinement_binary.pyx @@ -30,7 +30,7 @@ REFERENCE: from sage.data_structures.bitset_base cimport * from sage.groups.perm_gps.partn_ref.data_structures cimport * from sage.rings.integer cimport Integer -from sage.structure.element import is_Matrix +from sage.structure.element import Matrix from sage.groups.perm_gps.partn_ref.double_coset cimport double_coset @@ -373,7 +373,7 @@ cdef class NonlinearBinaryCodeStruct(BinaryCodeStruct): def __cinit__(self, arg): cdef int i,j - if is_Matrix(arg): + if isinstance(arg, Matrix): self.degree = arg.ncols() self.nwords = arg.nrows() elif isinstance(arg, tuple): @@ -450,7 +450,7 @@ cdef class NonlinearBinaryCodeStruct(BinaryCodeStruct): for j from 0 <= j < self.nwords: bitset_zero(&self.words[j]) - if is_Matrix(arg): + if isinstance(arg, Matrix): for i, j in arg.nonzero_positions(): bitset_set(&self.words[i], j) diff --git a/src/sage/groups/perm_gps/permgroup_element.pyx b/src/sage/groups/perm_gps/permgroup_element.pyx index c2a462d9727..543ac3e7135 100644 --- a/src/sage/groups/perm_gps/permgroup_element.pyx +++ b/src/sage/groups/perm_gps/permgroup_element.pyx @@ -128,7 +128,7 @@ from sage.rings.polynomial.multi_polynomial import MPolynomial from sage.rings.polynomial.polynomial_element import Polynomial from sage.sets.finite_enumerated_set import FiniteEnumeratedSet from sage.structure.coerce cimport coercion_model -from sage.structure.element import is_Matrix +from sage.structure.element import Matrix from sage.structure.richcmp cimport richcmp_not_equal, rich_to_bool import sage.interfaces.abc @@ -1246,10 +1246,10 @@ cdef class PermutationGroupElement(MultiplicativeGroupElement): raise TypeError("%s does not act on %s" % (self, left.parent())) return left(tuple(sigma_x)) - elif is_Matrix(left): + elif isinstance(left, Matrix): return left.with_permuted_columns(~self) else: - if is_Matrix(x): + if isinstance(x, Matrix): return x.with_permuted_rows(self) diff --git a/src/sage/homology/chain_complex.py b/src/sage/homology/chain_complex.py index 680a5a911d7..54f9b93049d 100644 --- a/src/sage/homology/chain_complex.py +++ b/src/sage/homology/chain_complex.py @@ -731,7 +731,7 @@ def _element_constructor_(self, vectors, check=True): vectors = vectors._vec data = dict() for degree, vec in vectors.items(): - if not is_Vector(vec): + if not isinstance(vec, Vector): vec = vector(self.base_ring(), vec) vec.set_immutable() if check and vec.degree() != self.free_module_rank(degree): diff --git a/src/sage/interfaces/four_ti_2.py b/src/sage/interfaces/four_ti_2.py index 42fa64d0155..7815c9eda62 100644 --- a/src/sage/interfaces/four_ti_2.py +++ b/src/sage/interfaces/four_ti_2.py @@ -129,8 +129,8 @@ def write_matrix(self, mat, filename): sage: four_ti_2.write_matrix([[1,2],[3,4]], "test_file") """ from sage.matrix.constructor import matrix - from sage.structure.element import is_Matrix - if not is_Matrix(mat): + from sage.structure.element import Matrix + if not isinstance(mat, Matrix): mat = matrix(ZZ, mat) if mat.base_ring() != ZZ: mat = mat.change_ring(ZZ) diff --git a/src/sage/libs/ntl/ntl_mat_GF2.pyx b/src/sage/libs/ntl/ntl_mat_GF2.pyx index 318747e9ade..cec8066e46b 100644 --- a/src/sage/libs/ntl/ntl_mat_GF2.pyx +++ b/src/sage/libs/ntl/ntl_mat_GF2.pyx @@ -89,9 +89,9 @@ cdef class ntl_mat_GF2(): cdef Py_ssize_t i, j cdef GF2_c _elem - from sage.structure.element import is_Matrix + from sage.structure.element import Matrix - if is_Matrix(nrows): + if isinstance(nrows, Matrix): _nrows = nrows.nrows() _ncols = nrows.ncols() v = nrows diff --git a/src/sage/libs/ntl/ntl_mat_GF2E.pyx b/src/sage/libs/ntl/ntl_mat_GF2E.pyx index 7ab9b92c020..d5cf9b90130 100644 --- a/src/sage/libs/ntl/ntl_mat_GF2E.pyx +++ b/src/sage/libs/ntl/ntl_mat_GF2E.pyx @@ -93,8 +93,8 @@ cdef class ntl_mat_GF2E(): cdef unsigned long _nrows, _ncols cdef unsigned long i, j - from sage.structure.element import is_Matrix - if is_Matrix(nrows): + from sage.structure.element import Matrix + if isinstance(nrows, Matrix): _nrows = nrows.nrows() _ncols = nrows.ncols() v = nrows.list() diff --git a/src/sage/matrix/matrix2.pyx b/src/sage/matrix/matrix2.pyx index cc15ea36efb..b2b9fc993fe 100644 --- a/src/sage/matrix/matrix2.pyx +++ b/src/sage/matrix/matrix2.pyx @@ -89,7 +89,7 @@ from sage.misc.randstate cimport current_randstate from sage.structure.coerce cimport py_scalar_parent from sage.structure.sequence import Sequence from sage.structure.coerce cimport coercion_model -from sage.structure.element import is_Vector +from sage.structure.element import Vector from sage.structure.element cimport have_same_parent from sage.misc.verbose import verbose from sage.rings.number_field.number_field_base import NumberField @@ -444,7 +444,7 @@ cdef class Matrix(Matrix1): (2) """ - if is_Vector(B): + if isinstance(B, Vector): try: return self.transpose().solve_right(B, check=check) except ValueError as e: @@ -883,7 +883,7 @@ cdef class Matrix(Matrix1): L = B.base_ring() except AttributeError: raise TypeError("the second argument must be a vector or a matrix") - b_is_vec = is_Vector(B) + b_is_vec = isinstance(B, Vector) if b_is_vec: if self.nrows() != B.degree(): raise ValueError("number of rows of self must equal " @@ -12392,9 +12392,9 @@ cdef class Matrix(Matrix1): ... ValueError: similarity only makes sense for square matrices """ - from sage.structure.element import is_Matrix + from sage.structure.element import Matrix - if not is_Matrix(other): + if not isinstance(other, Matrix): raise TypeError('similarity requires a matrix as an argument, not {0}'.format(other)) if transformation not in [True, False]: raise ValueError('transformation keyword must be True or False') @@ -12816,7 +12816,7 @@ cdef class Matrix(Matrix1): import sage.rings.polynomial.polynomial_ring n = self.ncols() R = self.base_ring() - if not is_Vector(v): + if not isinstance(v, Vector): raise TypeError('first input should be a vector, not {0}'.format(v)) if not (var is None or isinstance(var, str)): generator = False diff --git a/src/sage/matrix/matrix_integer_dense.pyx b/src/sage/matrix/matrix_integer_dense.pyx index 84a61f15a5e..05aebe83a27 100644 --- a/src/sage/matrix/matrix_integer_dense.pyx +++ b/src/sage/matrix/matrix_integer_dense.pyx @@ -113,7 +113,7 @@ from sage.rings.finite_rings.integer_mod_ring import IntegerModRing from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing from sage.rings.polynomial.polynomial_integer_dense_flint cimport Polynomial_integer_dense_flint from sage.structure.element cimport Element, Vector -from sage.structure.element import is_Vector +from sage.structure.element import Vector from sage.matrix.matrix_modn_dense_float cimport Matrix_modn_dense_template from sage.matrix.matrix_modn_dense_float cimport Matrix_modn_dense_float @@ -4295,7 +4295,7 @@ cdef class Matrix_integer_dense(Matrix_dense): if not self.is_square(): raise NotImplementedError("the input matrix must be square.") - if is_Vector(B): + if isinstance(B, Vector): if self.nrows() != B.degree(): raise ValueError("number of rows of self must equal degree of B.") elif self.nrows() != B.nrows(): @@ -4307,7 +4307,7 @@ cdef class Matrix_integer_dense(Matrix_dense): matrix = True C = B if not isinstance(B, Matrix_integer_dense): - if is_Vector(B): + if isinstance(B, Vector): matrix = False C = self.matrix_space(self.nrows(), 1)(B.list()) else: diff --git a/src/sage/matrix/matrix_polynomial_dense.pyx b/src/sage/matrix/matrix_polynomial_dense.pyx index 7c0c1cd71eb..5b15f522328 100644 --- a/src/sage/matrix/matrix_polynomial_dense.pyx +++ b/src/sage/matrix/matrix_polynomial_dense.pyx @@ -905,8 +905,8 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): :meth:`solve_right_series_trunc` . """ - from sage.structure.element import is_Vector - if is_Vector(B): + from sage.structure.element import Vector + if isinstance(B, Vector): if self.ncols() != B.degree(): raise ValueError("number of columns of self must equal " "degree of right-hand side") @@ -920,7 +920,7 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): try: # case where self is square, with invertible constant term precA = 1+self.degree() - if is_Vector(B): + if isinstance(B, Vector): BB = B.row() X = B.row().parent().zero().__copy__() else: @@ -934,12 +934,12 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): BB = (BB - XX*self).shift(-precA) # update X = X + x^(k*precA) * XX X = X + XX.shift(k*precA) - return X.truncate(d)[0] if is_Vector(B) else X.truncate(d) + return X.truncate(d)[0] if isinstance(B, Vector) else X.truncate(d) except (ZeroDivisionError,ArithmeticError): # general case (possibly no solution) m = self.nrows() from sage.matrix.constructor import matrix - if is_Vector(B): + if isinstance(B, Vector): F = matrix.block([[self],[-B.row()]]) s = [0]*m + [d] else: @@ -953,7 +953,7 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): if P[m:,m:] != 1: raise ValueError("matrix equation has no solutions") else: - return P[m][:m] if is_Vector(B) else P[m:,:m] + return P[m][:m] if isinstance(B, Vector) else P[m:,:m] def solve_right_series_trunc(self, B, d): r""" @@ -1056,8 +1056,8 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): :meth:`solve_left_series_trunc` . """ - from sage.structure.element import is_Vector - if is_Vector(B): + from sage.structure.element import Vector + if isinstance(B, Vector): try: return self.transpose().solve_left_series_trunc(B, d) except ValueError as e: diff --git a/src/sage/matrix/special.py b/src/sage/matrix/special.py index c2afffd7a4d..b7734e5e73e 100644 --- a/src/sage/matrix/special.py +++ b/src/sage/matrix/special.py @@ -66,7 +66,7 @@ import sage.matrix.matrix_space as matrix_space from sage.categories.rings import Rings from sage.modules.free_module_element import vector -from sage.structure.element import is_Matrix, parent +from sage.structure.element import Matrix, parent from sage.structure.sequence import Sequence from sage.rings.integer_ring import ZZ from sage.rings.rational_field import QQ @@ -1420,7 +1420,7 @@ def elementary_matrix(arg0, arg1=None, **kwds): R = arg0 arg0 = arg1 elif scale is not None: - if not sage.structure.element.is_RingElement(scale): + if not sage.structure.element.isinstance(scale, RingElement): raise TypeError('scale must be an element of some ring, not {0}'.format(scale)) R = scale.parent() else: @@ -1598,7 +1598,7 @@ def _determine_block_matrix_grid(sub_matrices): M = sub_matrices[i][j] sub_width = None sub_height = None - if is_Matrix(M): + if isinstance(M, Matrix): sub_width = M.ncols() sub_height = M.nrows() elif M: # non-zero scalar is interpreted as a square matrix @@ -1669,7 +1669,7 @@ def _determine_block_matrix_rows(sub_matrices): # of this row found_zeroes = False for M in R: - if is_Matrix(M): + if isinstance(M, Matrix): if height is None: height = M.nrows() elif height != M.nrows(): @@ -1684,7 +1684,7 @@ def _determine_block_matrix_rows(sub_matrices): if height is not None and not found_zeroes: width = 0 for M in R: - if is_Matrix(M): + if isinstance(M, Matrix): width += M.ncols() else: # non-zero scalar @@ -1719,7 +1719,7 @@ def _determine_block_matrix_rows(sub_matrices): height = None for j in range(len(R)): M = R[j] - if is_Matrix(M): + if isinstance(M, Matrix): height = M.nrows() width += M.ncols() if zero_state == 1: @@ -1983,7 +1983,7 @@ def block_matrix(*args, **kwds): sub_matrices = args[0] - if is_Matrix(sub_matrices): + if isinstance(sub_matrices, Matrix): M = sub_matrices # a single matrix (check nrows/ncols/ring) if (nrows is not None and nrows != 1) or \ @@ -2043,7 +2043,7 @@ def block_matrix(*args, **kwds): ring = ZZ for row in sub_matrices: for M in row: - R = M.base_ring() if is_Matrix(M) else parent(M) + R = M.base_ring() if isinstance(M, Matrix) else parent(M) if R is not ZZ: ring = sage.categories.pushout.pushout(ring, R) @@ -2051,7 +2051,7 @@ def block_matrix(*args, **kwds): sparse = True for row in sub_matrices: for M in row: - if sparse and is_Matrix(M) and not M.is_sparse(): + if sparse and isinstance(M, Matrix) and not M.is_sparse(): sparse = False row_heights = None @@ -2081,7 +2081,7 @@ def block_matrix(*args, **kwds): for j in range(len(R)): M = R[j] - if is_Matrix(M): + if isinstance(M, Matrix): if M.base_ring() is not ring: M = M.change_ring(ring) if M.is_sparse() != sparse: diff --git a/src/sage/matroids/constructor.py b/src/sage/matroids/constructor.py index 9a44462fed3..80d943b8f84 100644 --- a/src/sage/matroids/constructor.py +++ b/src/sage/matroids/constructor.py @@ -104,7 +104,7 @@ from itertools import combinations from sage.combinat.posets.lattices import FiniteLatticePoset from sage.matrix.constructor import Matrix -from sage.structure.element import is_Matrix +from sage.structure.element import Matrix from sage.rings.integer_ring import ZZ from sage.rings.rational_field import QQ from sage.categories.fields import Fields @@ -805,8 +805,8 @@ def Matroid(groundset=None, data=None, **kwds): Graph = () if isinstance(data, Graph): key = 'graph' - elif is_Matrix(data) or ( - isinstance(data, tuple) and is_Matrix(data[0])): + elif isinstance(data, Matrix) or ( + isinstance(data, tuple) and isinstance(data[0], Matrix)): key = 'matrix' elif isinstance(data, sage.modules.with_basis.morphism.ModuleMorphism) or ( isinstance(data, tuple) and @@ -958,7 +958,7 @@ def Matroid(groundset=None, data=None, **kwds): A = A.matrix() # Fix the representation - if not is_Matrix(A): + if not isinstance(A, Matrix): if base_ring is not None: A = Matrix(base_ring, A) else: diff --git a/src/sage/misc/sage_input.py b/src/sage/misc/sage_input.py index fcb271a7f75..c8909d14a50 100644 --- a/src/sage/misc/sage_input.py +++ b/src/sage/misc/sage_input.py @@ -3473,8 +3473,8 @@ def verify_same(a, b): assert(a.parent() == b.parent()) AssertionError """ - from sage.structure.element import is_Element - if is_Element(a): + from sage.structure.element import Element + if isinstance(a, Element): assert a.parent() == b.parent() else: assert type(a) is type(b) diff --git a/src/sage/modular/abvar/homspace.py b/src/sage/modular/abvar/homspace.py index e914e11cc8e..f514605d3aa 100644 --- a/src/sage/modular/abvar/homspace.py +++ b/src/sage/modular/abvar/homspace.py @@ -193,7 +193,7 @@ from sage.matrix.matrix_space import MatrixSpace from sage.matrix.constructor import Matrix, identity_matrix -from sage.structure.element import is_Matrix +from sage.structure.element import Matrix from sage.rings.integer_ring import ZZ @@ -356,7 +356,7 @@ def __call__(self, M, **kwds): M = M.matrix() else: raise ValueError("cannot convert %s into %s" % (M, self)) - elif is_Matrix(M): + elif isinstance(M, Matrix): if M.base_ring() != ZZ: M = M.change_ring(ZZ) if side == "left": diff --git a/src/sage/modular/cusps.py b/src/sage/modular/cusps.py index 263eb61308a..180e8943a94 100644 --- a/src/sage/modular/cusps.py +++ b/src/sage/modular/cusps.py @@ -35,7 +35,7 @@ from sage.rings.rational import Rational from sage.rings.rational_field import QQ from sage.structure.element import Element, is_InfinityElement -from sage.structure.element import is_Matrix +from sage.structure.element import Matrix from sage.structure.parent import Parent from sage.structure.richcmp import richcmp @@ -173,7 +173,7 @@ def __init__(self, a, b=None, parent=None, check=True): elif isinstance(a, Rational): self.__a = a.numer() self.__b = a.denom() - elif (is_InfinityElement(a) or + elif (isinstance(a, InfinityElement) or (isinstance(a, pari_gen) and a.type() == 't_INFINITY')): self.__a = ZZ.one() self.__b = ZZ.zero() @@ -205,8 +205,8 @@ def __init__(self, a, b=None, parent=None, check=True): raise TypeError("unable to convert %r to a cusp" % a) return - if is_InfinityElement(b): - if is_InfinityElement(a) or (isinstance(a, Cusp) and a.is_infinity()): + if isinstance(b, InfinityElement): + if isinstance(a, InfinityElement) or (isinstance(a, Cusp) and a.is_infinity()): raise TypeError("unable to convert (%r, %r) to a cusp" % (a, b)) self.__a = ZZ.zero() self.__b = ZZ.one() @@ -220,7 +220,7 @@ def __init__(self, a, b=None, parent=None, check=True): if isinstance(a, (Integer, Rational)): r = a / ZZ(b) - elif is_InfinityElement(a): + elif isinstance(a, InfinityElement): self.__a = ZZ.one() self.__b = ZZ.zero() return @@ -836,7 +836,7 @@ def _acted_upon_(self, g, self_on_left): Set P^1(QQ) of all cusps """ if not self_on_left: - if (is_Matrix(g) and g.base_ring() is ZZ + if (isinstance(g, Matrix) and g.base_ring() is ZZ and g.ncols() == 2 == g.nrows()): a, b, c, d = g.list() return Cusp(a * self.__a + b * self.__b, diff --git a/src/sage/modular/cusps_nf.py b/src/sage/modular/cusps_nf.py index d2a7eb8942e..bdaf304d7d6 100644 --- a/src/sage/modular/cusps_nf.py +++ b/src/sage/modular/cusps_nf.py @@ -461,7 +461,7 @@ def __init__(self, number_field, a, b=None, parent=None, lreps=None): elif a in number_field: self.__b = R(a.denominator()) self.__a = R(a * self.__b) - elif is_InfinityElement(a): + elif isinstance(a, InfinityElement): self.__a = R.one() self.__b = R.zero() elif isinstance(a, int): @@ -502,8 +502,8 @@ def __init__(self, number_field, a, b=None, parent=None, lreps=None): raise TypeError("unable to convert %r to a cusp " "of the number field" % a) else: # 'b' is given - if is_InfinityElement(b): - if is_InfinityElement(a) or (isinstance(a, NFCusp) and a.is_infinity()): + if isinstance(b, InfinityElement): + if isinstance(a, InfinityElement) or (isinstance(a, NFCusp) and a.is_infinity()): raise TypeError("unable to convert (%r, %r) " "to a cusp of the number field" % (a, b)) self.__a = R.zero() @@ -526,7 +526,7 @@ def __init__(self, number_field, a, b=None, parent=None, lreps=None): else: if a in R or a in number_field: r = a / b - elif is_InfinityElement(a): + elif isinstance(a, InfinityElement): self.__a = R.one() self.__b = R.zero() return diff --git a/src/sage/modular/hecke/hecke_operator.py b/src/sage/modular/hecke/hecke_operator.py index 22d4ac929e9..eb2b5313b01 100644 --- a/src/sage/modular/hecke/hecke_operator.py +++ b/src/sage/modular/hecke/hecke_operator.py @@ -451,8 +451,8 @@ def __init__(self, parent, A): TypeError: A must be a square matrix of rank 3 """ HeckeAlgebraElement.__init__(self, parent) - from sage.structure.element import is_Matrix - if not is_Matrix(A): + from sage.structure.element import Matrix + if not isinstance(A, Matrix): raise TypeError("A must be a matrix") if not A.base_ring() == self.parent().base_ring(): raise TypeError("base ring of matrix (%s) does not match base ring of space (%s)" % (A.base_ring(), self.parent().base_ring())) diff --git a/src/sage/modular/modsym/manin_symbol.pyx b/src/sage/modular/modsym/manin_symbol.pyx index 6da79e21b2d..9bf955b562b 100644 --- a/src/sage/modular/modsym/manin_symbol.pyx +++ b/src/sage/modular/modsym/manin_symbol.pyx @@ -273,8 +273,8 @@ cdef class ManinSymbol(Element): if self.weight() > 2: raise NotImplementedError("ModSym * Matrix only implemented " "in weight 2") - from sage.structure.element import is_Matrix - if is_Matrix(matrix): + from sage.structure.element import Matrix + if isinstance(matrix, Matrix): if (not matrix.nrows() == 2) or (not matrix.ncols() == 2): raise ValueError("matrix(=%s) must be 2x2" % matrix) matrix = matrix.list() diff --git a/src/sage/modular/modsym/relation_matrix.py b/src/sage/modular/modsym/relation_matrix.py index 609d70c2446..f58e76562c3 100644 --- a/src/sage/modular/modsym/relation_matrix.py +++ b/src/sage/modular/modsym/relation_matrix.py @@ -294,8 +294,8 @@ def gens_to_basis_matrix(syms, relation_matrix, mod, field, sparse): sage: gens_to_basis_matrix(L, T_relation_matrix_wtk_g0(L, modS, GF(3), 24), modS, GF(3), True) (24 x 2 sparse matrix over Finite Field of size 3, [13, 23]) """ - from sage.structure.element import is_Matrix - if not is_Matrix(relation_matrix): + from sage.structure.element import Matrix + if not isinstance(relation_matrix, Matrix): raise TypeError("relation_matrix must be a matrix") if not isinstance(mod, list): raise TypeError("mod must be a list") diff --git a/src/sage/modules/free_module.py b/src/sage/modules/free_module.py index 102d13aacd2..cf9bf361460 100644 --- a/src/sage/modules/free_module.py +++ b/src/sage/modules/free_module.py @@ -3110,8 +3110,8 @@ def hom(self, im_gens, codomain=None, **kwds): Domain: Vector space of dimension 2 over Rational Field Codomain: Vector space of dimension 2 over Rational Field """ - from sage.structure.element import is_Matrix - if codomain is None and is_Matrix(im_gens): + from sage.structure.element import Matrix + if codomain is None and isinstance(im_gens, Matrix): side = kwds.get("side", "left") n = im_gens.nrows() if side == "right" else im_gens.ncols() from sage.categories.pushout import pushout diff --git a/src/sage/modules/free_module_homspace.py b/src/sage/modules/free_module_homspace.py index ae4503ea9d3..8fb97a48e5a 100644 --- a/src/sage/modules/free_module_homspace.py +++ b/src/sage/modules/free_module_homspace.py @@ -76,7 +76,7 @@ # https://www.gnu.org/licenses/ # **************************************************************************** import sage.categories.homset -from sage.structure.element import is_Matrix +from sage.structure.element import Matrix from sage.matrix.constructor import matrix, identity_matrix from sage.matrix.matrix_space import MatrixSpace from sage.misc.cachefunc import cached_method @@ -202,7 +202,7 @@ def __call__(self, A, **kwds): """ from . import free_module_morphism side = kwds.get("side", "left") - if not is_Matrix(A): + if not isinstance(A, Matrix): # Compute the matrix of the morphism that sends the # generators of the domain to the elements of A. C = self.codomain() diff --git a/src/sage/modules/free_quadratic_module_integer_symmetric.py b/src/sage/modules/free_quadratic_module_integer_symmetric.py index c899c5203fb..f7343dfc484 100644 --- a/src/sage/modules/free_quadratic_module_integer_symmetric.py +++ b/src/sage/modules/free_quadratic_module_integer_symmetric.py @@ -57,7 +57,7 @@ from sage.rings.rational_field import QQ from sage.modules.free_quadratic_module import FreeQuadraticModule_submodule_with_basis_pid, FreeQuadraticModule from sage.matrix.constructor import matrix -from sage.structure.element import is_Matrix +from sage.structure.element import Matrix from sage.arith.misc import gcd from sage.misc.cachefunc import cached_method @@ -233,7 +233,7 @@ def IntegralLattice(data, basis=None): ... ValueError: lattices must be nondegenerate; use FreeQuadraticModule instead """ - if is_Matrix(data): + if isinstance(data, Matrix): inner_product_matrix = data elif isinstance(data, Integer): inner_product_matrix = matrix.identity(ZZ, data) diff --git a/src/sage/modules/vector_space_homspace.py b/src/sage/modules/vector_space_homspace.py index bfbcae9ade0..83cc51790f7 100644 --- a/src/sage/modules/vector_space_homspace.py +++ b/src/sage/modules/vector_space_homspace.py @@ -378,8 +378,8 @@ def __call__(self, A, check=True, **kwds): D = self.domain() C = self.codomain() side = kwds.get("side", "left") - from sage.structure.element import is_Matrix - if is_Matrix(A): + from sage.structure.element import Matrix + if isinstance(A, Matrix): pass elif isinstance(A, VectorSpaceMorphism): A = A.matrix() diff --git a/src/sage/modules/vector_space_morphism.py b/src/sage/modules/vector_space_morphism.py index c981acc8d67..28860655883 100644 --- a/src/sage/modules/vector_space_morphism.py +++ b/src/sage/modules/vector_space_morphism.py @@ -332,7 +332,7 @@ import sage.modules.free_module_morphism as free_module_morphism import sage.modules.matrix_morphism as matrix_morphism from sage.modules import vector_space_homspace -from sage.structure.element import is_Matrix +from sage.structure.element import Matrix def linear_transformation(arg0, arg1=None, arg2=None, side='left'): @@ -706,7 +706,7 @@ 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 is_Matrix(arg0): + if isinstance(arg0, Matrix): R = arg0.base_ring() if not R.is_field(): try: @@ -740,7 +740,7 @@ def linear_transformation(arg0, arg1=None, arg2=None, side='left'): # Examine arg2 as the "rule" for the linear transformation # Pass on matrices, Python functions and lists to homspace call # Convert symbolic function here, to a matrix - if is_Matrix(arg2): + if isinstance(arg2, Matrix): if side == 'right': arg2 = arg2.transpose() elif isinstance(arg2, (list, tuple)): @@ -872,7 +872,7 @@ def __init__(self, homspace, A, side="left"): raise TypeError('homspace must be a vector space hom space, not {}'.format(homspace)) if isinstance(A, matrix_morphism.MatrixMorphism): A = A.matrix() - if not is_Matrix(A): + if not isinstance(A, Matrix): msg = 'input must be a matrix representation or another matrix morphism, not {0}' raise TypeError(msg.format(A)) # now have a vector space homspace, and a matrix, check compatibility diff --git a/src/sage/modules/with_basis/morphism.py b/src/sage/modules/with_basis/morphism.py index ea1dcf93f65..ed5f26f0a30 100644 --- a/src/sage/modules/with_basis/morphism.py +++ b/src/sage/modules/with_basis/morphism.py @@ -122,7 +122,7 @@ from sage.categories.sets_cat import Sets from sage.categories.sets_with_partial_maps import SetsWithPartialMaps from sage.structure.richcmp import op_EQ, op_NE -from sage.structure.element import is_Matrix +from sage.structure.element import Matrix from sage.structure.sage_object import SageObject @@ -1345,7 +1345,7 @@ def __init__(self, domain, matrix, codomain=None, category=None, side="left"): raise ValueError("The codomain %s should be specified") if codomain not in C: raise ValueError("The codomain %s should be finite dimensional" % codomain) - if not is_Matrix(matrix): + if not isinstance(matrix, Matrix): raise ValueError("matrix (=%s) should be a matrix" % matrix) import sage.combinat.ranker indices = tuple(domain.basis().keys()) diff --git a/src/sage/numerical/backends/matrix_sdp_backend.pyx b/src/sage/numerical/backends/matrix_sdp_backend.pyx index f4e7ecb13f0..8b1e05dfecf 100644 --- a/src/sage/numerical/backends/matrix_sdp_backend.pyx +++ b/src/sage/numerical/backends/matrix_sdp_backend.pyx @@ -279,10 +279,10 @@ cdef class MatrixSDPBackend(GenericSDPBackend): 'fun' """ coefficients = list(coefficients) - from sage.structure.element import is_Matrix + from sage.structure.element import Matrix for t in coefficients: m = t[1] - if not is_Matrix(m): + if not isinstance(m, Matrix): raise ValueError("The coefficients must be matrices") if not m.is_square(): raise ValueError("The matrix has to be a square") diff --git a/src/sage/numerical/mip.pyx b/src/sage/numerical/mip.pyx index c8aecbf6482..dc3a2c7c9b8 100644 --- a/src/sage/numerical/mip.pyx +++ b/src/sage/numerical/mip.pyx @@ -234,7 +234,7 @@ AUTHORS: # **************************************************************************** from copy import copy -from sage.structure.element import is_Matrix +from sage.structure.element import Matrix from sage.rings.integer_ring import ZZ @@ -3656,11 +3656,11 @@ cdef class MIPVariable(FiniteFamily): (1, 2/3)*x_0 + (1/2, 3/4)*x_1 """ if isinstance(left, MIPVariable): - if not is_Matrix(right): + if not isinstance(right, Matrix): return NotImplemented return ( left)._matrix_rmul_impl(right) else: - if not is_Matrix(left): + if not isinstance(left, Matrix): return NotImplemented return ( right)._matrix_lmul_impl(left) diff --git a/src/sage/numerical/sdp.pyx b/src/sage/numerical/sdp.pyx index 8701ed22150..99f31255769 100644 --- a/src/sage/numerical/sdp.pyx +++ b/src/sage/numerical/sdp.pyx @@ -236,7 +236,7 @@ from sage.structure.parent cimport Parent from sage.structure.element cimport Element from sage.numerical.linear_functions import is_LinearFunction, is_LinearConstraint from sage.matrix.constructor import Matrix -from sage.structure.element import is_Matrix +from sage.structure.element import Matrix cdef class SemidefiniteProgram(SageObject): @@ -1374,8 +1374,8 @@ cdef class SDPVariable(Element): sage: m * v (1.0, 3.0)*x_0 + (2.0, 4.0)*x_1 """ - from sage.structure.element import is_Matrix - if is_Matrix(mat): + from sage.structure.element import Matrix + if isinstance(mat, Matrix): return self._matrix_rmul_impl(mat) if self_on_left else self._matrix_lmul_impl(mat) diff --git a/src/sage/plot/matrix_plot.py b/src/sage/plot/matrix_plot.py index 3e3e5c7dd24..d0103a7e11b 100644 --- a/src/sage/plot/matrix_plot.py +++ b/src/sage/plot/matrix_plot.py @@ -568,10 +568,10 @@ def matrix_plot(mat, xrange=None, yrange=None, **options): import numpy as np import scipy.sparse as scipysparse from sage.plot.all import Graphics - from sage.structure.element import is_Matrix + from sage.structure.element import Matrix from sage.rings.real_double import RDF orig_mat = mat - if is_Matrix(mat): + if isinstance(mat, Matrix): sparse = mat.is_sparse() if sparse: entries = list(mat._dict().items()) diff --git a/src/sage/plot/plot.py b/src/sage/plot/plot.py index 4f650fa4613..69e85c6c5e9 100644 --- a/src/sage/plot/plot.py +++ b/src/sage/plot/plot.py @@ -2026,8 +2026,8 @@ def f(x): return (floor(x)+0.5) / (1-(x-0.5)**2) original_opts = kwds.pop('__original_opts', {}) do_show = kwds.pop('show',False) - from sage.structure.element import is_Vector - if kwds.get('parametric',False) and is_Vector(funcs): + from sage.structure.element import Vector + if kwds.get('parametric',False) and isinstance(funcs, Vector): funcs = tuple(funcs) if hasattr(funcs, 'plot'): diff --git a/src/sage/plot/plot3d/list_plot3d.py b/src/sage/plot/plot3d/list_plot3d.py index a2b0781796c..313ab80f16e 100644 --- a/src/sage/plot/plot3d/list_plot3d.py +++ b/src/sage/plot/plot3d/list_plot3d.py @@ -2,7 +2,7 @@ List plots """ -from sage.structure.element import is_Matrix +from sage.structure.element import Matrix from sage.matrix.constructor import matrix from sage.rings.real_double import RDF from sage.misc.superseded import deprecation @@ -262,7 +262,7 @@ def list_plot3d(v, interpolation_type='default', point_list=None, **kwds): if txtr == "automatic": txtr = "lightblue" kwds['color'] = txtr - if is_Matrix(v): + if isinstance(v, Matrix): if (interpolation_type == 'default' or interpolation_type == 'linear' and 'num_points' not in kwds): return list_plot3d_matrix(v, **kwds) diff --git a/src/sage/plot/plot3d/parametric_plot3d.py b/src/sage/plot/plot3d/parametric_plot3d.py index 680cb187787..bd57f133467 100644 --- a/src/sage/plot/plot3d/parametric_plot3d.py +++ b/src/sage/plot/plot3d/parametric_plot3d.py @@ -6,7 +6,7 @@ from .parametric_surface import ParametricSurface from .shapes2 import line3d from sage.arith.srange import xsrange, srange -from sage.structure.element import is_Vector +from sage.structure.element import Vector from sage.misc.decorators import rename_keyword @@ -988,7 +988,7 @@ def g(x,y): return x, y+sin(y), x**2 + y**2 # mesh_shading -- (default: None) how to shade regions between mesh divisions # plot_range -- (default: "automatic") range of values to include - if is_Vector(f): + if isinstance(f, Vector): f = tuple(f) if isinstance(f, (list, tuple)) and len(f) > 0 and isinstance(f[0], (list, tuple)): diff --git a/src/sage/quadratic_forms/extras.py b/src/sage/quadratic_forms/extras.py index 7bdba23c32e..fe300e79acb 100644 --- a/src/sage/quadratic_forms/extras.py +++ b/src/sage/quadratic_forms/extras.py @@ -3,7 +3,7 @@ """ from sage.matrix.constructor import matrix -from sage.structure.element import is_Matrix +from sage.structure.element import Matrix from sage.arith.misc import legendre_symbol from sage.rings.integer_ring import ZZ @@ -103,7 +103,7 @@ def extend_to_primitive(A_input): [(1, 2, 3), (0, 1, 1), (-1, 0, 0)] """ # Deal with a list of vectors - if not is_Matrix(A_input): + if not isinstance(A_input, Matrix): A = matrix(A_input) # Make a matrix A with the given rows. vec_output_flag = True else: diff --git a/src/sage/quadratic_forms/quadratic_form.py b/src/sage/quadratic_forms/quadratic_form.py index b9a9767a54a..b28bca0fb39 100644 --- a/src/sage/quadratic_forms/quadratic_form.py +++ b/src/sage/quadratic_forms/quadratic_form.py @@ -24,7 +24,7 @@ from sage.matrix.constructor import matrix from sage.matrix.matrix_space import MatrixSpace from sage.misc.lazy_import import lazy_import -from sage.structure.element import is_Matrix +from sage.structure.element import Matrix from sage.categories.rings import Rings from sage.categories.fields import Fields from sage.categories.principal_ideal_domains import PrincipalIdealDomains @@ -34,7 +34,7 @@ from sage.arith.functions import lcm as LCM from sage.rings.ideal import Ideal from sage.rings.rational_field import QQ -from sage.structure.element import is_Vector +from sage.structure.element import Vector from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing from sage.rings.polynomial.polynomial_element import Polynomial from sage.rings.polynomial.multi_polynomial import MPolynomial @@ -554,7 +554,7 @@ def __init__(self, R, n=None, entries=None, unsafe_initialization=False, number_ # Deal with: QuadraticForm(ring, matrix) matrix_init_flag = False if R in Rings(): - if is_Matrix(n): + if isinstance(n, Matrix): # Test if n is symmetric and has even diagonal if not self._is_even_symmetric_matrix_(n, R): raise TypeError("the matrix is not a symmetric with even diagonal defined over R") @@ -564,7 +564,7 @@ def __init__(self, R, n=None, entries=None, unsafe_initialization=False, number_ M_ring = R matrix_init_flag = True - elif is_Matrix(R): + elif isinstance(R, Matrix): M = R # Test if R is symmetric and has even diagonal @@ -1049,7 +1049,7 @@ def __call__(self, v): # (In matrix notation: A^t * Q * A) n = self.dim() - if is_Matrix(v): + if isinstance(v, Matrix): # Check that v has the correct number of rows if v.nrows() != n: raise TypeError(f"the matrix must have {n} rows") @@ -1059,7 +1059,7 @@ def __call__(self, v): Q2 = QuadraticForm(self.base_ring(), m) return QFEvaluateMatrix(self, v, Q2) - elif (is_Vector(v) or isinstance(v, (list, tuple))): + elif (isinstance(v, Vector) or isinstance(v, (list, tuple))): # Check the vector/tuple/list has the correct length if not (len(v) == n): raise TypeError(f"your vector needs to have length {n}") @@ -1103,7 +1103,7 @@ def _is_even_symmetric_matrix_(self, A, R=None): False """ - if not is_Matrix(A): + if not isinstance(A, Matrix): raise TypeError("A is not a matrix.") ring_coerce_test = True diff --git a/src/sage/quadratic_forms/ternary_qf.py b/src/sage/quadratic_forms/ternary_qf.py index cb7eeb179c8..0e9e55b95d2 100644 --- a/src/sage/quadratic_forms/ternary_qf.py +++ b/src/sage/quadratic_forms/ternary_qf.py @@ -43,7 +43,7 @@ from sage.rings.finite_rings.integer_mod import mod from sage.rings.integer_ring import ZZ from sage.rings.polynomial.polynomial_ring import polygens -from sage.structure.element import is_Vector, is_Matrix +from sage.structure.element import Vector, is_Matrix from sage.structure.sage_object import SageObject @@ -226,7 +226,7 @@ def __call__(self, v): [5 0 7] [12 -13 -16] """ - if is_Matrix(v): + if isinstance(v, Matrix): # Check that v has 3 rows if v.nrows() != 3: raise TypeError("the matrix must have 3 rows") @@ -237,7 +237,7 @@ def __call__(self, v): M[1, 2], M[0, 2], M[0, 1]]) else: return QuadraticForm(ZZ, v.transpose() * self.matrix() * v) - elif (is_Vector(v) or isinstance(v, (list, tuple))): + elif (isinstance(v, Vector) or isinstance(v, (list, tuple))): # Check that v has length 3 if len(v) != 3: raise TypeError("your vector needs to have length 3") diff --git a/src/sage/rings/number_field/number_field.py b/src/sage/rings/number_field/number_field.py index 1413b1ea057..d8fe5852e60 100644 --- a/src/sage/rings/number_field/number_field.py +++ b/src/sage/rings/number_field/number_field.py @@ -107,7 +107,7 @@ from .class_group import ClassGroup from .class_group import SClassGroup -from sage.structure.element import is_Element +from sage.structure.element import Element from sage.structure.parent import Parent from sage.structure.sequence import Sequence from sage.structure.factorization import Factorization @@ -1939,7 +1939,7 @@ def _convert_from_str(self, x): -1/3*theta25 - 1 """ w = sage_eval(x, locals=self.gens_dict()) - if not (is_Element(w) and w.parent() is self): + if not (isinstance(w, Element) and w.parent() is self): return self(w) else: return w diff --git a/src/sage/rings/number_field/order.py b/src/sage/rings/number_field/order.py index 94d0732704d..c29d7ed9672 100644 --- a/src/sage/rings/number_field/order.py +++ b/src/sage/rings/number_field/order.py @@ -83,7 +83,7 @@ from sage.structure.sequence import Sequence from sage.rings.integer_ring import ZZ import sage.rings.abc -from sage.structure.element import is_Element +from sage.structure.element import Element from sage.structure.factory import UniqueFactory from .number_field_element import OrderElement_absolute, OrderElement_relative @@ -1609,7 +1609,7 @@ def _element_constructor_(self, x): """ if isinstance(x, (tuple, list)): x = sum(xi*gi for xi, gi in zip(x, self.gens())) - if not is_Element(x) or x.parent() is not self._K: + if not isinstance(x, Element) or x.parent() is not self._K: x = self._K(x) V, _, embedding = self._K.vector_space() if not embedding(x) in self._module_rep: diff --git a/src/sage/rings/padics/factory.py b/src/sage/rings/padics/factory.py index 60c37322bd2..b3d7a232b7e 100644 --- a/src/sage/rings/padics/factory.py +++ b/src/sage/rings/padics/factory.py @@ -36,7 +36,7 @@ from sage.structure.factorization import Factorization from sage.rings.integer_ring import ZZ from sage.rings.polynomial.polynomial_element import Polynomial -from sage.structure.element import is_Element +from sage.structure.element import Element from .padic_base_leaves import (pAdicRingCappedRelative, pAdicRingCappedAbsolute, pAdicRingFixedMod, @@ -1322,7 +1322,7 @@ def Qq(q, prec=None, type='capped-rel', modulus=None, names=None, sage: K0 is K1 # needs sage.libs.ntl True """ - if is_Element(q): + if isinstance(q, Element): F = Integer(q).factor() if len(F) != 1: raise ValueError("q must be a prime power") diff --git a/src/sage/rings/polynomial/multi_polynomial_sequence.py b/src/sage/rings/polynomial/multi_polynomial_sequence.py index 8797a84efd8..50f91cd16a0 100644 --- a/src/sage/rings/polynomial/multi_polynomial_sequence.py +++ b/src/sage/rings/polynomial/multi_polynomial_sequence.py @@ -291,7 +291,7 @@ def PolynomialSequence(arg1, arg2=None, immutable=False, cr=False, cr_str=None): sage: PolynomialSequence(iter([(x,y), (z,)]), R) [x, y, z] """ - from sage.structure.element import is_Matrix + from sage.structure.element import Matrix try: from sage.rings.polynomial.pbori.pbori import BooleanMonomialMonoid except ImportError: @@ -305,7 +305,7 @@ def PolynomialSequence(arg1, arg2=None, immutable=False, cr=False, cr_str=None): elif is_ring(arg2): ring, gens = arg2, arg1 - elif is_Matrix(arg1): + elif isinstance(arg1, Matrix): ring, gens = arg1.base_ring(), arg1.list() elif isinstance(arg1, MPolynomialIdeal): diff --git a/src/sage/rings/polynomial/polynomial_ring.py b/src/sage/rings/polynomial/polynomial_ring.py index f7201447019..28810eba535 100644 --- a/src/sage/rings/polynomial/polynomial_ring.py +++ b/src/sage/rings/polynomial/polynomial_ring.py @@ -151,7 +151,7 @@ from sage.categories.rings import Rings from sage.rings.ring import (Ring, IntegralDomain, PrincipalIdealDomain) -from sage.structure.element import is_RingElement +from sage.structure.element import RingElement import sage.rings.rational_field as rational_field from sage.rings.rational_field import QQ from sage.rings.integer_ring import ZZ @@ -3700,7 +3700,7 @@ def polygen(ring_or_element, name="x"): get a tuple of indeterminates, exactly as if you called :func:`polygens`. """ - if is_RingElement(ring_or_element): + if isinstance(ring_or_element, RingElement): base_ring = ring_or_element.parent() elif ring_or_element in Rings(): base_ring = ring_or_element diff --git a/src/sage/rings/valuation/value_group.py b/src/sage/rings/valuation/value_group.py index 1b9073255da..c7414a92761 100644 --- a/src/sage/rings/valuation/value_group.py +++ b/src/sage/rings/valuation/value_group.py @@ -245,8 +245,8 @@ def __add__(self, other): return DiscreteValueGroup(self._generator.gcd(other._generator)) if isinstance(other, DiscreteValueSemigroup): return other + self - from sage.structure.element import is_Element - if is_Element(other) and QQ.has_coerce_map_from(other.parent()): + from sage.structure.element import Element + if isinstance(other, Element) and QQ.has_coerce_map_from(other.parent()): return self + DiscreteValueGroup(other) raise ValueError("`other` must be a DiscreteValueGroup or a rational number") @@ -620,8 +620,8 @@ def __add__(self, other): return DiscreteValueSemigroup(self._generators + other._generators) if isinstance(other, DiscreteValueGroup): return DiscreteValueSemigroup(self._generators + (other._generator, -other._generator)) - from sage.structure.element import is_Element - if is_Element(other) and QQ.has_coerce_map_from(other.parent()): + from sage.structure.element import Element + if isinstance(other, Element) and QQ.has_coerce_map_from(other.parent()): return self + DiscreteValueSemigroup(other) raise ValueError("`other` must be a DiscreteValueGroup, a DiscreteValueSemigroup or a rational number") diff --git a/src/sage/schemes/plane_conics/con_field.py b/src/sage/schemes/plane_conics/con_field.py index edb6cc82eb4..356a9a3fe06 100644 --- a/src/sage/schemes/plane_conics/con_field.py +++ b/src/sage/schemes/plane_conics/con_field.py @@ -30,10 +30,10 @@ from sage.modules.free_module_element import vector from sage.structure.sequence import Sequence -from sage.structure.element import is_Vector +from sage.structure.element import Vector from sage.schemes.projective.projective_space import ProjectiveSpace from sage.matrix.constructor import Matrix -from sage.structure.element import is_Matrix +from sage.structure.element import Matrix from sage.schemes.curves.projective_curve import ProjectivePlaneCurve_field @@ -715,7 +715,7 @@ def hom(self, x, Y=None): Defn: Defined on coordinates by sending (x : y : z) to (t*x + z : y : z) """ - if is_Matrix(x): + if isinstance(x, Matrix): from .constructor import Conic y = x.inverse() A = y.transpose()*self.matrix()*y @@ -992,7 +992,7 @@ def point(self, v, check=True): sage: d.rational_point() # needs sage.libs.pari (-1 : 1 : 0) """ - if is_Vector(v): + if isinstance(v, Vector): v = Sequence(v) p = super().point(v, check=check) if self._rational_point is None: diff --git a/src/sage/schemes/plane_conics/constructor.py b/src/sage/schemes/plane_conics/constructor.py index a078bc07d22..4d6ae3755d3 100644 --- a/src/sage/schemes/plane_conics/constructor.py +++ b/src/sage/schemes/plane_conics/constructor.py @@ -40,7 +40,7 @@ from sage.schemes.projective.projective_point import SchemeMorphism_point_projective_field from sage.schemes.projective.projective_space import ProjectiveSpace from sage.structure.all import Sequence -from sage.structure.element import is_Matrix +from sage.structure.element import Matrix from .con_field import ProjectiveConic_field from .con_finite_field import ProjectiveConic_finite_field @@ -202,7 +202,7 @@ def Conic(base_field, F=None, names=None, unique=True): if isinstance(F, QuadraticForm): F = F.matrix() - if is_Matrix(F) and F.is_square() and F.ncols() == 3: + if isinstance(F, Matrix) and F.is_square() and F.ncols() == 3: if names is None: names = 'x,y,z' temp_ring = PolynomialRing(F.base_ring(), 3, names) diff --git a/src/sage/schemes/toric/divisor.py b/src/sage/schemes/toric/divisor.py index 3ec4b2adb62..b6a387c9d27 100644 --- a/src/sage/schemes/toric/divisor.py +++ b/src/sage/schemes/toric/divisor.py @@ -187,7 +187,7 @@ from sage.schemes.toric.divisor_class import ToricRationalDivisorClass from sage.schemes.toric.variety import CohomologyRing, ToricVariety_field from sage.structure.unique_representation import UniqueRepresentation -from sage.structure.element import is_Vector +from sage.structure.element import Vector def is_ToricDivisor(x): @@ -2014,7 +2014,7 @@ def _element_constructor_(self, x): """ if is_ToricDivisor(x): x = self._projection_matrix * vector(x) - if is_Vector(x): + if isinstance(x, Vector): x = list(x) return self.element_class(self, x) diff --git a/src/sage/schemes/toric/divisor_class.pyx b/src/sage/schemes/toric/divisor_class.pyx index a0334faee88..a463cfc358a 100644 --- a/src/sage/schemes/toric/divisor_class.pyx +++ b/src/sage/schemes/toric/divisor_class.pyx @@ -64,7 +64,7 @@ from sage.modules.vector_rational_dense cimport Vector_rational_dense from sage.rings.rational_field import QQ from sage.rings.rational cimport Rational from sage.structure.element cimport Vector -from sage.structure.element import is_Vector +from sage.structure.element import Vector def is_ToricRationalDivisorClass(x): @@ -192,7 +192,7 @@ cdef class ToricRationalDivisorClass(Vector_rational_dense): if isinstance(other, Vector_rational_dense): return Vector_rational_dense._dot_product_(self, other) cdef Vector v - if is_Vector(other) and not is_ToricRationalDivisorClass(other): + if isinstance(other, Vector) and not is_ToricRationalDivisorClass(other): try: v = vector(QQ, other) if v._degree == self._degree: diff --git a/src/sage/schemes/toric/homset.py b/src/sage/schemes/toric/homset.py index 80a879a6aed..830eb09de44 100644 --- a/src/sage/schemes/toric/homset.py +++ b/src/sage/schemes/toric/homset.py @@ -104,7 +104,7 @@ from sage.categories.finite_fields import FiniteFields from sage.rings.integer_ring import ZZ -from sage.structure.element import is_Matrix +from sage.structure.element import Matrix from sage.matrix.matrix_space import MatrixSpace from sage.geometry.fan_morphism import FanMorphism @@ -255,7 +255,7 @@ def _element_constructor_(self, x, check=True): assert x.codomain() is self.domain().coordinate_ring() return SchemeMorphism_polynomial_toric_variety(self, x.im_gens(), check=check) - if is_Matrix(x): + if isinstance(x, Matrix): x = FanMorphism(x, self.domain().fan(), self.codomain().fan()) if isinstance(x, FanMorphism): if x.is_dominant(): diff --git a/src/sage/stats/hmm/chmm.pyx b/src/sage/stats/hmm/chmm.pyx index f0940c5849d..dc8bd1144b3 100644 --- a/src/sage/stats/hmm/chmm.pyx +++ b/src/sage/stats/hmm/chmm.pyx @@ -23,7 +23,7 @@ cdef double sqrt2pi = sqrt(2*M_PI) from cysignals.signals cimport sig_on, sig_off from sage.misc.flatten import flatten -from sage.structure.element import is_Matrix +from sage.structure.element import Matrix from sage.stats.time_series cimport TimeSeries from sage.stats.intlist cimport IntList @@ -220,7 +220,7 @@ cdef class GaussianHiddenMarkovModel(HiddenMarkovModel): # B should be a matrix of N rows, with column 0 the mean and 1 # the standard deviation. - if is_Matrix(B): + if isinstance(B, Matrix): B = B.list() else: B = flatten(B) diff --git a/src/sage/stats/hmm/hmm.pyx b/src/sage/stats/hmm/hmm.pyx index 0935c9398ee..73efd28e5e5 100644 --- a/src/sage/stats/hmm/hmm.pyx +++ b/src/sage/stats/hmm/hmm.pyx @@ -36,7 +36,7 @@ from libc.math cimport log from cysignals.signals cimport sig_on, sig_off from sage.stats.time_series cimport TimeSeries -from sage.structure.element import is_Matrix +from sage.structure.element import Matrix from sage.matrix.constructor import matrix from sage.misc.randstate cimport current_randstate, randstate from cpython.object cimport PyObject_RichCompare @@ -357,7 +357,7 @@ cdef class DiscreteHiddenMarkovModel(HiddenMarkovModel): if self._emission_symbols is not None: self._emission_symbols_dict = dict([(y,x) for x,y in enumerate(emission_symbols)]) - if not is_Matrix(B): + if not isinstance(B, Matrix): B = matrix(B) if B.nrows() != self.N: raise ValueError("number of rows of B must equal number of states") diff --git a/src/sage/stats/hmm/util.pyx b/src/sage/stats/hmm/util.pyx index 553eb997364..6d4f95cd44f 100644 --- a/src/sage/stats/hmm/util.pyx +++ b/src/sage/stats/hmm/util.pyx @@ -15,7 +15,7 @@ AUTHOR: ############################################################################# -from sage.structure.element import is_Matrix +from sage.structure.element import Matrix from sage.misc.flatten import flatten cdef class HMM_Util: @@ -156,7 +156,7 @@ cdef class HMM_Util: cdef TimeSeries T if isinstance(A, TimeSeries): T = A - elif is_Matrix(A): + elif isinstance(A, Matrix): T = TimeSeries(A.list()) elif isinstance(A, list): T = TimeSeries(flatten(A)) diff --git a/src/sage/structure/element.pyx b/src/sage/structure/element.pyx index bb50fbb2b9b..11158d9a6ec 100644 --- a/src/sage/structure/element.pyx +++ b/src/sage/structure/element.pyx @@ -3718,7 +3718,7 @@ cdef class Vector(ModuleElementWithMutability): raise ZeroDivisionError("division by zero vector") else: raise ArithmeticError("vector is not in free module") - if is_Matrix(right): + if isinstance(right, Matrix): return right.solve_left(self) raise bin_op_exception('/', self, right) @@ -4146,7 +4146,7 @@ cdef class Matrix(ModuleElement): sage: (b / a) * a == b True """ - if is_Matrix(right): + if isinstance(right, Matrix): return right.solve_left(left) return coercion_model.bin_op(left, right, truediv) From 3a4ed06470c047532d79582a11164194cf57c42b Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 25 May 2024 13:05:32 -0700 Subject: [PATCH 02/16] Import matrix, not Matrix, from sage.matrix.constructor to avoid clashes --- .../finite_dimensional_algebra_ideal.py | 11 +++++------ .../finite_dimensional_algebra_morphism.py | 4 ++-- src/sage/coding/binary_code.pyx | 4 ++-- src/sage/coding/linear_rank_metric.py | 6 +++--- src/sage/combinat/cluster_algebra_quiver/quiver.py | 4 ++-- src/sage/combinat/designs/incidence_structures.py | 4 ++-- .../combinat/root_system/reflection_group_complex.py | 10 +++++----- src/sage/combinat/similarity_class_type.py | 2 +- src/sage/geometry/polyhedron/base5.py | 2 +- src/sage/libs/ntl/ntl_mat_GF2.pyx | 4 ++-- src/sage/libs/ntl/ntl_mat_GF2E.pyx | 4 ++-- src/sage/matroids/constructor.py | 8 ++++---- src/sage/numerical/backends/matrix_sdp_backend.pyx | 8 ++++---- src/sage/numerical/sdp.pyx | 4 ++-- src/sage/quadratic_forms/ternary_qf.py | 2 +- .../rings/polynomial/multi_polynomial_sequence.py | 12 ++++++------ src/sage/schemes/plane_conics/con_field.py | 10 +++++----- src/sage/schemes/plane_conics/constructor.py | 4 ++-- 18 files changed, 51 insertions(+), 52 deletions(-) diff --git a/src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra_ideal.py b/src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra_ideal.py index d19c60e0681..100a3d335f3 100644 --- a/src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra_ideal.py +++ b/src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra_ideal.py @@ -15,10 +15,9 @@ from .finite_dimensional_algebra_element import FiniteDimensionalAlgebraElement -from sage.matrix.constructor import Matrix -from sage.structure.element import Matrix +from sage.matrix.constructor import matrix from sage.rings.ideal import Ideal_generic -from sage.structure.element import parent +from sage.structure.element import Matrix, parent from sage.misc.cachefunc import cached_method from functools import reduce @@ -58,16 +57,16 @@ def __init__(self, A, gens=None, given_by_matrix=False): self._basis_matrix = gens gens = gens.rows() elif gens is None: - self._basis_matrix = Matrix(k, 0, n) + self._basis_matrix = matrix(k, 0, n) elif isinstance(gens, (list, tuple)): B = [FiniteDimensionalAlgebraIdeal(A, x).basis_matrix() for x in gens] - B = reduce(lambda x, y: x.stack(y), B, Matrix(k, 0, n)) + B = reduce(lambda x, y: x.stack(y), B, matrix(k, 0, n)) self._basis_matrix = B.echelon_form().image().basis_matrix() elif isinstance(gens, Matrix): gens = FiniteDimensionalAlgebraElement(A, gens) elif isinstance(gens, FiniteDimensionalAlgebraElement): gens = gens.vector() - B = Matrix([(gens * b).list() for b in A.table()]) + B = matrix([(gens * b).list() for b in A.table()]) self._basis_matrix = B.echelon_form().image().basis_matrix() Ideal_generic.__init__(self, A, gens) diff --git a/src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra_morphism.py b/src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra_morphism.py index 7e6e265990b..2a049ce30f4 100644 --- a/src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra_morphism.py +++ b/src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra_morphism.py @@ -243,7 +243,7 @@ def __call__(self, f, check=True, unitary=True): elif isinstance(f, Matrix): return FiniteDimensionalAlgebraMorphism(self, f, check, unitary) try: - from sage.matrix.constructor import Matrix - return FiniteDimensionalAlgebraMorphism(self, Matrix(f), check, unitary) + from sage.matrix.constructor import matrix + return FiniteDimensionalAlgebraMorphism(self, matrix(f), check, unitary) except Exception: return RingHomset_generic.__call__(self, f, check) diff --git a/src/sage/coding/binary_code.pyx b/src/sage/coding/binary_code.pyx index 2f8fb08d808..bc75df85d88 100644 --- a/src/sage/coding/binary_code.pyx +++ b/src/sage/coding/binary_code.pyx @@ -4185,9 +4185,9 @@ cdef class BinaryCodeClassifier: dealloc_word_perm(hwp) break if bingo2: - from sage.matrix.constructor import Matrix + from sage.matrix.constructor import matrix from sage.rings.finite_rings.finite_field_constructor import GF - M = Matrix(GF(2), B_aug.nrows, B_aug.ncols) + M = matrix(GF(2), B_aug.nrows, B_aug.ncols) for i from 0 <= i < B_aug.ncols: for j from 0 <= j < B_aug.nrows: M[j,i] = B_aug.is_one(1 << j, i) diff --git a/src/sage/coding/linear_rank_metric.py b/src/sage/coding/linear_rank_metric.py index 517081a6bb4..490c6acf1af 100644 --- a/src/sage/coding/linear_rank_metric.py +++ b/src/sage/coding/linear_rank_metric.py @@ -112,8 +112,8 @@ # **************************************************************************** from sage.categories.fields import Fields -from sage.matrix.constructor import Matrix -from sage.structure.element import Matrix, is_Vector +from sage.matrix.constructor import matrix +from sage.structure.element import Matrix, Vector from sage.modules.free_module_element import vector from sage.rings.infinity import Infinity @@ -174,7 +174,7 @@ def to_matrix_representation(v, sub_field=None, basis=None): n = v.length() m = base_field.degree()//sub_field.degree() extension, to_big_field, from_big_field = base_field.vector_space(sub_field, basis, map=True) - return Matrix(sub_field, m, n, lambda i, j: from_big_field(v[j])[i]) + return matrix(sub_field, m, n, lambda i, j: from_big_field(v[j])[i]) def from_matrix_representation(w, base_field=None, basis=None): r""" diff --git a/src/sage/combinat/cluster_algebra_quiver/quiver.py b/src/sage/combinat/cluster_algebra_quiver/quiver.py index 849a07ae8a4..dae81b4b48f 100644 --- a/src/sage/combinat/cluster_algebra_quiver/quiver.py +++ b/src/sage/combinat/cluster_algebra_quiver/quiver.py @@ -758,11 +758,11 @@ def qmu_save(self, filename=None): """ M = self.b_matrix() if self.m(): - from sage.matrix.constructor import Matrix + from sage.matrix.constructor import matrix from sage.matrix.constructor import block_matrix M1 = M.matrix_from_rows(list(range(self.n()))) M2 = M.matrix_from_rows(list(range(self.n(), self.n() + self.m()))) - M3 = Matrix(self.m(), self.m()) + M3 = matrix(self.m(), self.m()) M = block_matrix([[M1, -M2.transpose()], [M2, M3]]) dg = self.digraph() dg.plot(save_pos=True) diff --git a/src/sage/combinat/designs/incidence_structures.py b/src/sage/combinat/designs/incidence_structures.py index 79c95d2c4fb..c6d9446797c 100644 --- a/src/sage/combinat/designs/incidence_structures.py +++ b/src/sage/combinat/designs/incidence_structures.py @@ -1147,9 +1147,9 @@ def incidence_matrix(self): [1 1 0 0] [0 1 1 1] """ - from sage.matrix.constructor import Matrix + from sage.matrix.constructor import matrix from sage.rings.integer_ring import ZZ - A = Matrix(ZZ, self.num_points(), self.num_blocks(), sparse=True) + A = matrix(ZZ, self.num_points(), self.num_blocks(), sparse=True) for j, b in enumerate(self._blocks): for i in b: A[i, j] = 1 diff --git a/src/sage/combinat/root_system/reflection_group_complex.py b/src/sage/combinat/root_system/reflection_group_complex.py index 279f25820a0..d4c6c5b677b 100644 --- a/src/sage/combinat/root_system/reflection_group_complex.py +++ b/src/sage/combinat/root_system/reflection_group_complex.py @@ -209,7 +209,7 @@ from sage.combinat.permutation import Permutation from sage.rings.integer_ring import ZZ from sage.rings.rational_field import QQ -from sage.matrix.constructor import Matrix +from sage.matrix.constructor import matrix from sage.matrix.special import identity_matrix from sage.structure.element import Matrix from sage.interfaces.gap3 import gap3 @@ -841,7 +841,7 @@ def discriminant_in_invariant_ring(self, invariants=None): D = D.change_ring(P) f = D - sum(X[i] * F for i,F in enumerate(FsPowers)) coeffs = f.coefficients() - lhs = Matrix(R, [[coeff.coefficient(X[i]) for i in range(m)] + lhs = matrix(R, [[coeff.coefficient(X[i]) for i in range(m)] for coeff in coeffs]) rhs = vector([coeff.constant_coefficient() for coeff in coeffs]) @@ -1320,7 +1320,7 @@ def independent_roots(self): basis = {} for ind in self._index_set: vec = Delta[ind] - if Matrix(list(basis.values()) + [vec]).rank() == len(basis) + 1: + if matrix(list(basis.values()) + [vec]).rank() == len(basis) + 1: basis[ind] = vec return Family(basis) @@ -1459,7 +1459,7 @@ def jacobian_of_fundamental_invariants(self, invs=None): invs = self.fundamental_invariants() P = invs[0].parent() X = P.gens() - return Matrix(P, [[ P(g).derivative(x) for x in X ] for g in invs ]) + return matrix(P, [[ P(g).derivative(x) for x in X ] for g in invs ]) @cached_method def primitive_vector_field(self, invs=None): @@ -1743,7 +1743,7 @@ def invariant_value(i,j): coeff = QQ(coeff) coeffs.append(coeff) - return Matrix([[invariant_value(i,j) / self.cardinality() for j in range(n)] + return matrix([[invariant_value(i,j) / self.cardinality() for j in range(n)] for i in range(n)]) def invariant_form_standardization(self): diff --git a/src/sage/combinat/similarity_class_type.py b/src/sage/combinat/similarity_class_type.py index efea98f6812..f6a67af12c0 100644 --- a/src/sage/combinat/similarity_class_type.py +++ b/src/sage/combinat/similarity_class_type.py @@ -203,7 +203,7 @@ class type, it is also possible to compute the number of classes of that type from sage.rings.integer_ring import ZZ from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing from sage.rings.rational_field import QQ -from sage.structure.element import Element, is_Matrix +from sage.structure.element import Element, Matrix from sage.structure.parent import Parent from sage.structure.unique_representation import UniqueRepresentation diff --git a/src/sage/geometry/polyhedron/base5.py b/src/sage/geometry/polyhedron/base5.py index c193c5ca529..2ac8b75cdd8 100644 --- a/src/sage/geometry/polyhedron/base5.py +++ b/src/sage/geometry/polyhedron/base5.py @@ -32,7 +32,7 @@ # https://www.gnu.org/licenses/ # **************************************************************************** -from sage.structure.element import coerce_binop, is_Vector, is_Matrix +from sage.structure.element import coerce_binop, Vector, Matrix from sage.rings.integer_ring import ZZ from sage.rings.rational_field import QQ diff --git a/src/sage/libs/ntl/ntl_mat_GF2.pyx b/src/sage/libs/ntl/ntl_mat_GF2.pyx index cec8066e46b..5ffef1c6b31 100644 --- a/src/sage/libs/ntl/ntl_mat_GF2.pyx +++ b/src/sage/libs/ntl/ntl_mat_GF2.pyx @@ -470,8 +470,8 @@ cdef class ntl_mat_GF2(): True """ from sage.rings.finite_rings.finite_field_constructor import FiniteField - from sage.matrix.constructor import Matrix - m = Matrix(FiniteField(2),self.x.NumRows(),self.x.NumCols()) + from sage.matrix.constructor import matrix + m = matrix(FiniteField(2),self.x.NumRows(),self.x.NumCols()) cdef Py_ssize_t i, j diff --git a/src/sage/libs/ntl/ntl_mat_GF2E.pyx b/src/sage/libs/ntl/ntl_mat_GF2E.pyx index d5cf9b90130..bad26279d05 100644 --- a/src/sage/libs/ntl/ntl_mat_GF2E.pyx +++ b/src/sage/libs/ntl/ntl_mat_GF2E.pyx @@ -544,8 +544,8 @@ cdef class ntl_mat_GF2E(): l = [e._sage_(k) for e in self.list()] # we actually can do faster than this - from sage.matrix.constructor import Matrix - return Matrix(k,self.x.NumRows(),self.x.NumCols(),l) + from sage.matrix.constructor import matrix + return matrix(k, self.x.NumRows(), self.x.NumCols(), l) def transpose(ntl_mat_GF2E self): """ diff --git a/src/sage/matroids/constructor.py b/src/sage/matroids/constructor.py index 80d943b8f84..6581a721f58 100644 --- a/src/sage/matroids/constructor.py +++ b/src/sage/matroids/constructor.py @@ -103,7 +103,7 @@ from itertools import combinations from sage.combinat.posets.lattices import FiniteLatticePoset -from sage.matrix.constructor import Matrix +from sage.matrix.constructor import matrix from sage.structure.element import Matrix from sage.rings.integer_ring import ZZ from sage.rings.rational_field import QQ @@ -928,7 +928,7 @@ def Matroid(groundset=None, data=None, **kwds): # 2) Sage will sort the columns, making it impossible to keep labels! V = G.vertices(sort=True) n = G.num_verts() - A = Matrix(ZZ, n, m, 0) + A = matrix(ZZ, n, m, 0) mm = 0 for i, j, k in G.edge_iterator(): A[V.index(i), mm] = -1 @@ -960,9 +960,9 @@ def Matroid(groundset=None, data=None, **kwds): # Fix the representation if not isinstance(A, Matrix): if base_ring is not None: - A = Matrix(base_ring, A) + A = matrix(base_ring, A) else: - A = Matrix(A) + A = matrix(A) # Fix the ring if base_ring is not None: diff --git a/src/sage/numerical/backends/matrix_sdp_backend.pyx b/src/sage/numerical/backends/matrix_sdp_backend.pyx index 8b1e05dfecf..03d4c430bd2 100644 --- a/src/sage/numerical/backends/matrix_sdp_backend.pyx +++ b/src/sage/numerical/backends/matrix_sdp_backend.pyx @@ -20,7 +20,7 @@ other classes implementing solvers. # http://www.gnu.org/licenses/ #***************************************************************************** -from sage.matrix.constructor import Matrix +from sage.matrix.constructor import matrix from sage.numerical.backends.generic_sdp_backend cimport GenericSDPBackend cdef class MatrixSDPBackend(GenericSDPBackend): @@ -125,7 +125,7 @@ cdef class MatrixSDPBackend(GenericSDPBackend): i = 0 for row in self.coeffs_matrix: if self.matrices_dim.get(i) is not None: - row.append( Matrix.zero(self.matrices_dim[i], self.matrices_dim[i]) ) + row.append( matrix.zero(self.matrices_dim[i], self.matrices_dim[i]) ) else: row.append(0) i+=1 @@ -313,7 +313,7 @@ cdef class MatrixSDPBackend(GenericSDPBackend): ([], []) """ for i in range(number): - self.add_linear_constraint(zip(range(self.ncols()+1),[Matrix.zero(1,1) for i in range(self.ncols()+1)]), + self.add_linear_constraint(zip(range(self.ncols()+1),[matrix.zero(1,1) for i in range(self.ncols()+1)]), name=None if names is None else names[i]) @@ -431,7 +431,7 @@ cdef class MatrixSDPBackend(GenericSDPBackend): indices = [] matrices = [] for index,m in self.coeffs_matrix[i]: - if m != Matrix.zero(self.matrices_dim[i],self.matrices_dim[i]): + if m != matrix.zero(self.matrices_dim[i],self.matrices_dim[i]): indices.append(index) matrices.append(m) return (indices, matrices) diff --git a/src/sage/numerical/sdp.pyx b/src/sage/numerical/sdp.pyx index 99f31255769..e562b8287ec 100644 --- a/src/sage/numerical/sdp.pyx +++ b/src/sage/numerical/sdp.pyx @@ -235,7 +235,7 @@ AUTHORS: from sage.structure.parent cimport Parent from sage.structure.element cimport Element from sage.numerical.linear_functions import is_LinearFunction, is_LinearConstraint -from sage.matrix.constructor import Matrix +from sage.matrix.constructor import matrix from sage.structure.element import Matrix @@ -675,7 +675,7 @@ cdef class SemidefiniteProgram(SageObject): if l[-1][0] == -1: last_i,last_value = l.pop() else: - last_value = Matrix.zero( l[0][1].dimensions()[0],l[0][1].dimensions()[1] ) + last_value = matrix.zero( l[0][1].dimensions()[0],l[0][1].dimensions()[1] ) l.reverse() for j, c in l: if c == 0: diff --git a/src/sage/quadratic_forms/ternary_qf.py b/src/sage/quadratic_forms/ternary_qf.py index 0e9e55b95d2..447bd37a794 100644 --- a/src/sage/quadratic_forms/ternary_qf.py +++ b/src/sage/quadratic_forms/ternary_qf.py @@ -43,7 +43,7 @@ from sage.rings.finite_rings.integer_mod import mod from sage.rings.integer_ring import ZZ from sage.rings.polynomial.polynomial_ring import polygens -from sage.structure.element import Vector, is_Matrix +from sage.structure.element import Vector, Matrix from sage.structure.sage_object import SageObject diff --git a/src/sage/rings/polynomial/multi_polynomial_sequence.py b/src/sage/rings/polynomial/multi_polynomial_sequence.py index 50f91cd16a0..80ae390385b 100644 --- a/src/sage/rings/polynomial/multi_polynomial_sequence.py +++ b/src/sage/rings/polynomial/multi_polynomial_sequence.py @@ -748,7 +748,7 @@ def coefficients_monomials(self, order=None, sparse=True): 2*a*b + 2*b*c + 2*c*d - b, b^2 + 2*a*c + 2*b*d - c) """ from sage.modules.free_module_element import vector - from sage.matrix.constructor import Matrix + from sage.matrix.constructor import matrix if order is None: v = sorted(self.monomials(), reverse=True) @@ -759,7 +759,7 @@ def coefficients_monomials(self, order=None, sparse=True): raise ValueError("order argument can only accept list or tuple") y = dict(zip(v, range(len(v)))) # construct dictionary for fast lookups - A = Matrix(self.ring().base_ring(), len(self), len(v), sparse=sparse) + A = matrix(self.ring().base_ring(), len(self), len(v), sparse=sparse) for x, poly in enumerate(self): for c, m in poly: try: @@ -825,13 +825,13 @@ def coefficient_matrix(self, sparse=True): [ 2*a*b + 2*b*c + 2*c*d - b] [ b^2 + 2*a*c + 2*b*d - c] """ - from sage.matrix.constructor import Matrix + from sage.matrix.constructor import matrix from sage.misc.superseded import deprecation deprecation(37035, "the function coefficient_matrix is deprecated; use coefficients_monomials instead") R = self.ring() A, v = self.coefficients_monomials(sparse=sparse) - return A, Matrix(R,len(v),1,v) + return A, matrix(R,len(v),1,v) def subs(self, *args, **kwargs): """ @@ -1739,7 +1739,7 @@ def coefficients_monomials(self, order=None, sparse=True): (a + b + c) """ from sage.modules.free_module_element import vector - from sage.matrix.constructor import Matrix + from sage.matrix.constructor import matrix from sage.rings.polynomial.multi_polynomial_ring_base import \ BooleanPolynomialRing_base @@ -1754,7 +1754,7 @@ def coefficients_monomials(self, order=None, sparse=True): R = self.ring() K = R.base_ring() y = dict(zip(v, range(len(v)))) # construct dictionary for fast lookups - A = Matrix(K, len(self), len(v), sparse=sparse) + A = matrix(K, len(self), len(v), sparse=sparse) if isinstance(R, BooleanPolynomialRing_base): one = K.one() diff --git a/src/sage/schemes/plane_conics/con_field.py b/src/sage/schemes/plane_conics/con_field.py index 356a9a3fe06..420360fe6f3 100644 --- a/src/sage/schemes/plane_conics/con_field.py +++ b/src/sage/schemes/plane_conics/con_field.py @@ -32,7 +32,7 @@ from sage.structure.sequence import Sequence from sage.structure.element import Vector from sage.schemes.projective.projective_space import ProjectiveSpace -from sage.matrix.constructor import Matrix +from sage.matrix.constructor import matrix from sage.structure.element import Matrix from sage.schemes.curves.projective_curve import ProjectivePlaneCurve_field @@ -209,7 +209,7 @@ def derivative_matrix(self): [t^2 1 0] """ a, b, c, d, e, f = self.coefficients() - return Matrix([[2 * a, b, c], + return matrix([[2 * a, b, c], [b, 2 * d, e], [c, e, 2 * f]]) @@ -305,7 +305,7 @@ def diagonal_matrix(self): for j in range(i+1,3): basis[j] = basis[j] - \ (basis[i]*A*basis[j].column())/l * basis[i] - T = Matrix(basis).transpose() + T = matrix(basis).transpose() return T.transpose()*A*T, T def diagonalization(self, names=None): @@ -1241,11 +1241,11 @@ def symmetric_matrix(self): a, b, c, d, e, f = self.coefficients() if self.base_ring().characteristic() == 2: if b == 0 and c == 0 and e == 0: - return Matrix([[a, 0, 0], [0, d, 0], [0, 0, f]]) + return matrix([[a, 0, 0], [0, d, 0], [0, 0, f]]) raise ValueError("The conic self (= %s) has no symmetric matrix " "because the base field has characteristic 2" % self) - return Matrix([[a, b / 2, c / 2], + return matrix([[a, b / 2, c / 2], [b / 2, d, e / 2], [c / 2, e / 2, f]]) diff --git a/src/sage/schemes/plane_conics/constructor.py b/src/sage/schemes/plane_conics/constructor.py index 4d6ae3755d3..9400888327a 100644 --- a/src/sage/schemes/plane_conics/constructor.py +++ b/src/sage/schemes/plane_conics/constructor.py @@ -24,7 +24,7 @@ # https://www.gnu.org/licenses/ # **************************************************************************** -from sage.matrix.constructor import Matrix +from sage.matrix.constructor import matrix from sage.modules.free_module_element import vector from sage.categories.integral_domains import IntegralDomains from sage.rings.rational_field import is_RationalField @@ -179,7 +179,7 @@ def Conic(base_field, F=None, names=None, unique=True): L.append(Sequence([C[0]**2, C[0] * C[1], C[0] * C[2], C[1]**2, C[1] * C[2], C[2]**2], P.fraction_field())) - M = Matrix(L) + M = matrix(L) if unique and M.rank() != 5: raise ValueError("points in F (=%s) do not define a unique " "conic" % F) From 615a98ac2c6bc093dad9c27ea1711fa132a06e88 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 25 May 2024 17:44:06 -0700 Subject: [PATCH 03/16] src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra_element.pyx: Remove import duplicated from .pxd --- .../finite_dimensional_algebra_element.pyx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra_element.pyx b/src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra_element.pyx index f4a85ea7667..f1ad68cbe6a 100644 --- a/src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra_element.pyx +++ b/src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra_element.pyx @@ -15,7 +15,6 @@ Elements of Finite Algebras import re from sage.matrix.matrix_space import MatrixSpace -from sage.structure.element import Matrix from sage.rings.integer import Integer from cpython.object cimport PyObject_RichCompare as richcmp From 331ae5f3fb144b3bbe315fc6de6716720cced03f Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 25 May 2024 17:52:06 -0700 Subject: [PATCH 04/16] src/sage/calculus/functions.py: Fix up import --- src/sage/calculus/functions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/calculus/functions.py b/src/sage/calculus/functions.py index e02ff8f7235..efb8926b317 100644 --- a/src/sage/calculus/functions.py +++ b/src/sage/calculus/functions.py @@ -3,7 +3,7 @@ Calculus functions """ from sage.misc.lazy_import import lazy_import -from sage.structure.element import Matrix, is_Vector, Expression +from sage.structure.element import Matrix, Vector, Expression lazy_import('sage.matrix.constructor', 'matrix') From ea059fe7c743293f506041b7c7fb532490504863 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 25 May 2024 18:10:11 -0700 Subject: [PATCH 05/16] sage.structure.element: Deprecate is_Element, ... --- src/sage/structure/element.pyx | 49 ++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/sage/structure/element.pyx b/src/sage/structure/element.pyx index 11158d9a6ec..2b2cb2c149b 100644 --- a/src/sage/structure/element.pyx +++ b/src/sage/structure/element.pyx @@ -353,10 +353,15 @@ def is_Element(x): sage: from sage.structure.element import is_Element sage: is_Element(2/3) + doctest:warning... + DeprecationWarning: The function is_Element is deprecated; use 'isinstance(..., Element)' instead. + See https://github.com/sagemath/sage/issues/38077 for details. True sage: is_Element(QQ^3) # needs sage.modules False """ + from sage.misc.superseded import deprecation_cython + deprecation_cython(38077, "The function is_Element is deprecated; use 'isinstance(..., Element)' instead.") return isinstance(x, Element) @@ -2139,12 +2144,17 @@ def is_ModuleElement(x): sage: from sage.structure.element import is_ModuleElement sage: is_ModuleElement(2/3) + doctest:warning... + DeprecationWarning: The function is_ModuleElement is deprecated; use 'isinstance(..., ModuleElement)' instead. + See https://github.com/sagemath/sage/issues/38077 for details. True sage: is_ModuleElement((QQ^3).0) # needs sage.modules True sage: is_ModuleElement('a') False """ + from sage.misc.superseded import deprecation_cython + deprecation_cython(38077, "The function is_ModuleElement is deprecated; use 'isinstance(..., ModuleElement)' instead.") return isinstance(x, ModuleElement) @@ -2521,6 +2531,8 @@ def is_MonoidElement(x): """ Return ``True`` if x is of type MonoidElement. """ + from sage.misc.superseded import deprecation_cython + deprecation_cython(38077, "The function is_MonoidElement is deprecated; use 'isinstance(..., MonoidElement)' instead.") return isinstance(x, MonoidElement) @@ -2581,6 +2593,8 @@ def is_AdditiveGroupElement(x): """ Return ``True`` if x is of type AdditiveGroupElement. """ + from sage.misc.superseded import deprecation_cython + deprecation_cython(38077, "The function is_AdditiveGroupElement is deprecated; use 'isinstance(..., AdditiveGroupElement)' instead.") return isinstance(x, AdditiveGroupElement) @@ -2602,6 +2616,8 @@ def is_MultiplicativeGroupElement(x): """ Return ``True`` if x is of type MultiplicativeGroupElement. """ + from sage.misc.superseded import deprecation_cython + deprecation_cython(38077, "The function is_MultiplicativeGroupElement is deprecated; use 'isinstance(..., MultiplicativeGroupElement)' instead.") return isinstance(x, MultiplicativeGroupElement) @@ -2636,6 +2652,8 @@ def is_RingElement(x): """ Return ``True`` if x is of type RingElement. """ + from sage.misc.superseded import deprecation_cython + deprecation_cython(38077, "The function is_RingElement is deprecated; use 'isinstance(..., RingElement)' instead.") return isinstance(x, RingElement) @@ -2971,11 +2989,16 @@ def is_CommutativeRingElement(x): sage: from sage.structure.element import is_CommutativeRingElement sage: is_CommutativeRingElement(oo) + doctest:warning... + DeprecationWarning: The function is_CommutativeRingElement is deprecated; use 'isinstance(..., CommutativeRingElement)' instead. + See https://github.com/sagemath/sage/issues/38077 for details. False sage: is_CommutativeRingElement(1) True """ + from sage.misc.superseded import deprecation_cython + deprecation_cython(38077, "The function is_CommutativeRingElement is deprecated; use 'isinstance(..., CommutativeRingElement)' instead.") return isinstance(x, CommutativeRingElement) @@ -3766,6 +3789,8 @@ cdef class Vector(ModuleElementWithMutability): def is_Vector(x): + from sage.misc.superseded import deprecation_cython + deprecation_cython(38077, "The function is_Vector is deprecated; use 'isinstance(..., Vector)' instead.") return isinstance(x, Vector) @@ -4161,6 +4186,8 @@ cdef class Matrix(ModuleElement): def is_Matrix(x): + from sage.misc.superseded import deprecation_cython + deprecation_cython(38077, "The function is_Matrix is deprecated; use 'isinstance(..., Matrix)' instead.") return isinstance(x, Matrix) @@ -4168,6 +4195,8 @@ def is_IntegralDomainElement(x): """ Return ``True`` if x is of type IntegralDomainElement. """ + from sage.misc.superseded import deprecation_cython + deprecation_cython(38077, "The function is_IntegralDomainElement is deprecated; use 'isinstance(..., IntegralDomainElement)' instead.") return isinstance(x, IntegralDomainElement) @@ -4180,6 +4209,8 @@ def is_DedekindDomainElement(x): """ Return ``True`` if x is of type DedekindDomainElement. """ + from sage.misc.superseded import deprecation_cython + deprecation_cython(38077, "The function is_DedekindDomainElement is deprecated; use 'isinstance(..., DedekindDomainElement)' instead.") return isinstance(x, DedekindDomainElement) @@ -4191,6 +4222,8 @@ def is_PrincipalIdealDomainElement(x): """ Return ``True`` if x is of type PrincipalIdealDomainElement. """ + from sage.misc.superseded import deprecation_cython + deprecation_cython(38077, "The function is_PrincipalIdealDomainElement is deprecated; use 'isinstance(..., PrincipalIdealDomainElement)' instead.") return isinstance(x, PrincipalIdealDomainElement) @@ -4278,6 +4311,8 @@ def is_EuclideanDomainElement(x): """ Return ``True`` if x is of type EuclideanDomainElement. """ + from sage.misc.superseded import deprecation_cython + deprecation_cython(38077, "The function is_EuclideanDomainElement is deprecated; use 'isinstance(..., EuclideanDomainElement)' instead.") return isinstance(x, EuclideanDomainElement) @@ -4351,6 +4386,8 @@ def is_FieldElement(x): """ Return ``True`` if x is of type FieldElement. """ + from sage.misc.superseded import deprecation_cython + deprecation_cython(38077, "The function is_FieldElement is deprecated; use 'isinstance(..., FieldElement)' instead.") return isinstance(x, FieldElement) @@ -4464,11 +4501,16 @@ def is_AlgebraElement(x): sage: from sage.structure.element import is_AlgebraElement sage: R. = FreeAlgebra(QQ, 2) # needs sage.combinat sage.modules sage: is_AlgebraElement(x * y) # needs sage.combinat sage.modules + doctest:warning... + DeprecationWarning: The function is_AlgebraElement is deprecated; use 'isinstance(..., AlgebraElement)' instead. + See https://github.com/sagemath/sage/issues/38077 for details. True sage: is_AlgebraElement(1) False """ + from sage.misc.superseded import deprecation_cython + deprecation_cython(38077, "The function is_AlgebraElement is deprecated; use 'isinstance(..., AlgebraElement)' instead.") return isinstance(x, AlgebraElement) @@ -4480,6 +4522,8 @@ def is_CommutativeAlgebraElement(x): """ Return ``True`` if x is of type CommutativeAlgebraElement. """ + from sage.misc.superseded import deprecation_cython + deprecation_cython(38077, "The function is_CommutativeAlgebraElement is deprecated; use 'isinstance(..., CommutativeAlgebraElement)' instead.") return isinstance(x, CommutativeAlgebraElement) @@ -4497,11 +4541,16 @@ def is_InfinityElement(x): sage: from sage.structure.element import is_InfinityElement sage: is_InfinityElement(1) + doctest:warning... + DeprecationWarning: The function is_InfinityElement is deprecated; use 'isinstance(..., InfinityElement)' instead. + See https://github.com/sagemath/sage/issues/38077 for details. False sage: is_InfinityElement(oo) True """ + from sage.misc.superseded import deprecation_cython + deprecation_cython(38077, "The function is_InfinityElement is deprecated; use 'isinstance(..., InfinityElement)' instead.") return isinstance(x, InfinityElement) From 6f7f49c2ceca46b29e0fff6adbb6fe5fde4bda00 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 25 May 2024 21:21:09 -0700 Subject: [PATCH 06/16] fixups --- src/sage/geometry/polyhedron/library.py | 10 +++++----- src/sage/interfaces/singular.py | 6 +++--- src/sage/matroids/lean_matrix.pyx | 10 +++++----- src/sage/modular/cusps.py | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/sage/geometry/polyhedron/library.py b/src/sage/geometry/polyhedron/library.py index 81cf67b2d8b..f00daedbbd1 100644 --- a/src/sage/geometry/polyhedron/library.py +++ b/src/sage/geometry/polyhedron/library.py @@ -434,7 +434,7 @@ def gale_transform_to_primal(vectors, base_ring=None, backend=None): ValueError: input vectors not totally cyclic """ from sage.modules.free_module_element import vector - from sage.matrix.constructor import Matrix + from sage.matrix.constructor import matrix if base_ring: vectors = tuple(vector(base_ring, x) for x in vectors) else: @@ -454,9 +454,9 @@ def gale_transform_to_primal(vectors, base_ring=None, backend=None): # (And this is faster.) if base_ring: - ker = Matrix(base_ring, vectors).left_kernel() + ker = matrix(base_ring, vectors).left_kernel() else: - ker = Matrix(vectors).left_kernel() + ker = matrix(vectors).left_kernel() solutions = Polyhedron(lines=tuple(ker.basis_matrix()), base_ring=base_ring, backend=backend) from sage.matrix.special import identity_matrix @@ -476,9 +476,9 @@ def gale_transform_to_primal(vectors, base_ring=None, backend=None): # where ``V`` is the dehomogenized dual point configuration. # If we append a row of ones to ``vectors``, ``V`` is just the right kernel. if base_ring: - m = Matrix(base_ring, vectors).transpose().stack(Matrix(base_ring, [[1]*len(vectors)])) + m = matrix(base_ring, vectors).transpose().stack(Matrix(base_ring, [[1]*len(vectors)])) else: - m = Matrix(vectors).transpose().stack(Matrix([[1]*len(vectors)])) + m = matrix(vectors).transpose().stack(Matrix([[1]*len(vectors)])) if m.rank() != len(vectors[0]) + 1: # The given vectors do not span the ambient space, diff --git a/src/sage/interfaces/singular.py b/src/sage/interfaces/singular.py index 4697b9763d3..7533fdb8c15 100644 --- a/src/sage/interfaces/singular.py +++ b/src/sage/interfaces/singular.py @@ -1940,19 +1940,19 @@ def sage_matrix(self, R, sparse=True): [0.0 0.0] [0.0 0.0] """ - from sage.matrix.constructor import Matrix + from sage.matrix.constructor import matrix nrows, ncols = int(self.nrows()), int(self.ncols()) if R is None: R = self.sage_global_ring() - A = Matrix(R, nrows, ncols, sparse=sparse) + A = matrix(R, nrows, ncols, sparse=sparse) # this is slow for x in range(nrows): for y in range(ncols): A[x, y] = self[x + 1, y + 1].sage_poly(R) return A - A = Matrix(R, nrows, ncols, sparse=sparse) + A = matrix(R, nrows, ncols, sparse=sparse) # this is slow for x in range(nrows): for y in range(ncols): diff --git a/src/sage/matroids/lean_matrix.pyx b/src/sage/matroids/lean_matrix.pyx index ff511148392..5863a58d4eb 100644 --- a/src/sage/matroids/lean_matrix.pyx +++ b/src/sage/matroids/lean_matrix.pyx @@ -35,6 +35,7 @@ from cysignals.memory cimport sig_malloc, sig_realloc, sig_free from cysignals.signals cimport sig_on, sig_off from sage.data_structures.bitset_base cimport * +from sage.matrix.constructor import matrix from sage.matrix.matrix2 cimport Matrix from sage.rings.integer_ring import ZZ from sage.rings.finite_rings.finite_field_constructor import FiniteField as GF @@ -42,7 +43,6 @@ from sage.rings.rational_field import QQ from sage.rings.integer cimport Integer from sage.rings.rational cimport Rational from sage.libs.gmp.mpq cimport * -import sage.matrix.constructor cdef class LeanMatrix: @@ -105,7 +105,7 @@ cdef class LeanMatrix: True """ cdef long r, c - M = sage.matrix.constructor.Matrix(self.base_ring(), self._nrows, self._ncols) + M = matrix(self.base_ring(), self._nrows, self._ncols) for r in range(self._nrows): for c in range(self._ncols): M[r, c] = self.get_unsafe(r, c) @@ -1049,7 +1049,7 @@ cdef class BinaryMatrix(LeanMatrix): True """ cdef long i, j - M = sage.matrix.constructor.Matrix(GF(2), self._nrows, self._ncols) + M = matrix(GF(2), self._nrows, self._ncols) for i in range(self._nrows): for j in range(self._ncols): if bitset_in(self._M[i], j): @@ -1686,7 +1686,7 @@ cdef class TernaryMatrix(LeanMatrix): True """ cdef int i, j - M = sage.matrix.constructor.Matrix(GF(3), self._nrows, self._ncols) + M = matrix(GF(3), self._nrows, self._ncols) for i in range(self._nrows): for j in range(self._ncols): M[i, j] = self.get(i, j) @@ -2264,7 +2264,7 @@ cdef class QuaternaryMatrix(LeanMatrix): [0 0 0] [0 0 0] """ - M = sage.matrix.constructor.Matrix(self._gf4, self._nrows, self._ncols) + M = matrix(self._gf4, self._nrows, self._ncols) for i in range(self._nrows): for j in range(self._ncols): M[i, j] = self.get(i, j) diff --git a/src/sage/modular/cusps.py b/src/sage/modular/cusps.py index 180e8943a94..edf91be35ac 100644 --- a/src/sage/modular/cusps.py +++ b/src/sage/modular/cusps.py @@ -34,7 +34,7 @@ from sage.rings.integer_ring import ZZ from sage.rings.rational import Rational from sage.rings.rational_field import QQ -from sage.structure.element import Element, is_InfinityElement +from sage.structure.element import Element, InfinityElement from sage.structure.element import Matrix from sage.structure.parent import Parent from sage.structure.richcmp import richcmp From 4b38dd802204af5eb655520b693429f76a6adfb8 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 25 May 2024 22:07:43 -0700 Subject: [PATCH 07/16] src/sage/matrix/special.py: Fixup --- src/sage/matrix/special.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/sage/matrix/special.py b/src/sage/matrix/special.py index b7734e5e73e..7cc73d4c9a1 100644 --- a/src/sage/matrix/special.py +++ b/src/sage/matrix/special.py @@ -66,7 +66,7 @@ import sage.matrix.matrix_space as matrix_space from sage.categories.rings import Rings from sage.modules.free_module_element import vector -from sage.structure.element import Matrix, parent +from sage.structure.element import Matrix, parent, RingElement from sage.structure.sequence import Sequence from sage.rings.integer_ring import ZZ from sage.rings.rational_field import QQ @@ -1411,7 +1411,6 @@ def elementary_matrix(arg0, arg1=None, **kwds): - Rob Beezer (2011-03-04) """ - import sage.structure.element # determine ring and matrix size if arg1 is not None and arg0 not in Rings(): raise TypeError('optional first parameter must be a ring, not {0}'.format(arg0)) @@ -1420,7 +1419,7 @@ def elementary_matrix(arg0, arg1=None, **kwds): R = arg0 arg0 = arg1 elif scale is not None: - if not sage.structure.element.isinstance(scale, RingElement): + if not isinstance(scale, RingElement): raise TypeError('scale must be an element of some ring, not {0}'.format(scale)) R = scale.parent() else: From 43370f6724965418f249d9ffc47d520740f31b44 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 26 May 2024 18:23:21 -0700 Subject: [PATCH 08/16] src/sage/matrix/constructor.pyx: Define Matrix after importing from .special --- src/sage/matrix/constructor.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sage/matrix/constructor.pyx b/src/sage/matrix/constructor.pyx index f343fd82578..bf19830a0ae 100644 --- a/src/sage/matrix/constructor.pyx +++ b/src/sage/matrix/constructor.pyx @@ -676,10 +676,10 @@ def matrix(*args, **kwds): return MatrixArgs(*args, **kwds).element(immutable=immutable) -Matrix = matrix +from sage.matrix.special import * -from sage.matrix.special import * +Matrix = matrix @matrix_method From 95e6c8bb066d08bdea7886dbd8c97074ef10576b Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 26 May 2024 19:30:50 -0700 Subject: [PATCH 09/16] src/sage/homology/chain_complex.py: Fix import --- src/sage/homology/chain_complex.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/homology/chain_complex.py b/src/sage/homology/chain_complex.py index 54f9b93049d..6a06a469cb5 100644 --- a/src/sage/homology/chain_complex.py +++ b/src/sage/homology/chain_complex.py @@ -50,7 +50,7 @@ from functools import reduce from sage.structure.parent import Parent -from sage.structure.element import ModuleElement, is_Vector, coercion_model +from sage.structure.element import ModuleElement, Vector, coercion_model from sage.misc.cachefunc import cached_method from sage.rings.integer_ring import ZZ From ffe8071009e4de2ecc3a73bcd6a4ec5969631823 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 26 May 2024 19:33:26 -0700 Subject: [PATCH 10/16] src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra.py: Fix import, use matrix() instead of Matrix() --- .../finite_dimensional_algebra.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra.py b/src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra.py index 3d0142bbac7..506c8977463 100644 --- a/src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra.py +++ b/src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra.py @@ -18,7 +18,7 @@ from sage.rings.integer_ring import ZZ from sage.categories.magmatic_algebras import MagmaticAlgebras -from sage.matrix.constructor import Matrix, matrix +from sage.matrix.constructor import matrix from sage.structure.element import Matrix from sage.rings.ring import Algebra from sage.structure.category_object import normalize_names @@ -389,7 +389,7 @@ def left_table(self): """ B = self.table() n = self.degree() - table = [Matrix([B[j][i] for j in range(n)]) for i in range(n)] + table = [matrix([B[j][i] for j in range(n)]) for i in range(n)] for b in table: b.set_immutable() return tuple(table) @@ -596,9 +596,9 @@ def is_unitary(self): self._one = matrix(k, 1, n) return True B1 = reduce(lambda x, y: x.augment(y), - self._table, Matrix(k, n, 0)) + self._table, matrix(k, n, 0)) B2 = reduce(lambda x, y: x.augment(y), - self.left_table(), Matrix(k, n, 0)) + self.left_table(), matrix(k, n, 0)) # This is the vector obtained by concatenating the rows of the # n times n identity matrix: kone = k.one() @@ -882,7 +882,7 @@ def primary_decomposition(self): and (self._assume_associative or self.is_associative())): raise TypeError("algebra must be unitary, commutative and associative") # Start with the trivial decomposition of self. - components = [Matrix.identity(k, n)] + components = [matrix.identity(k, n)] for b in self.table(): # Use the action of the basis element b to refine our # decomposition of self. @@ -903,7 +903,7 @@ def primary_decomposition(self): components = components_new quotients = [] for i in range(len(components)): - I = Matrix(k, 0, n) + I = matrix(k, 0, n) for j,c in enumerate(components): if j != i: I = I.stack(c) From 5d5977f33a6640c4ab4201764c876df1d12bfcf9 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 27 May 2024 00:26:48 -0700 Subject: [PATCH 11/16] src/sage/crypto/mq/sr.py: Use matrix instead of Matrix --- src/sage/crypto/mq/sr.py | 128 +++++++++++++++++++-------------------- 1 file changed, 64 insertions(+), 64 deletions(-) diff --git a/src/sage/crypto/mq/sr.py b/src/sage/crypto/mq/sr.py index 6829b6548e0..4b946a68db4 100644 --- a/src/sage/crypto/mq/sr.py +++ b/src/sage/crypto/mq/sr.py @@ -308,7 +308,7 @@ - [MR2002]_ """ -from sage.matrix.constructor import Matrix, random_matrix +from sage.matrix.constructor import matrix, random_matrix from sage.matrix.matrix_space import MatrixSpace from sage.misc.flatten import flatten from sage.misc.verbose import get_verbose @@ -683,7 +683,7 @@ def sub_bytes(self, d): [ a^6 + a^5 + a^4 + a^3 + a^2 a^6 + a^5 + a^4 + a^2 + a + 1] """ d = self.state_array(d) - return Matrix(self.base_ring(), d.nrows(), d.ncols(), [self.sub_byte(b) for b in d.list()]) + return matrix(self.base_ring(), d.nrows(), d.ncols(), [self.sub_byte(b) for b in d.list()]) def sub_byte(self, b): r""" @@ -741,14 +741,14 @@ def sub_byte(self, b): # GF(2) linear map if e == 4: if not hasattr(self, "_L"): - self._L = Matrix(GF(2), 4, 4, [[1, 1, 1, 0], + self._L = matrix(GF(2), 4, 4, [[1, 1, 1, 0], [0, 1, 1, 1], [1, 0, 1, 1], [1, 1, 0, 1]]) elif e == 8: if not hasattr(self, "_L"): - self._L = Matrix(GF(2), 8, 8, [[1, 0, 0, 0, 1, 1, 1, 1], + self._L = matrix(GF(2), 8, 8, [[1, 0, 0, 0, 1, 1, 1, 1], [1, 1, 0, 0, 0, 1, 1, 1], [1, 1, 1, 0, 0, 0, 1, 1], [1, 1, 1, 1, 0, 0, 0, 1], @@ -910,7 +910,7 @@ def shift_rows(self, d): ret = [] for i in range(d.nrows()): ret += list(d.row(i)[i % d.ncols():]) + list(d.row(i)[:i % d.ncols()]) - return Matrix(self.base_ring(), self._r, self._c, ret) + return matrix(self.base_ring(), self._r, self._c, ret) def mix_columns(self, d): r""" @@ -946,13 +946,13 @@ def mix_columns(self, d): a = k.gen() r = self._r if r == 1: - M = Matrix(self.base_ring(), 1, 1, [[1]]) + M = matrix(self.base_ring(), 1, 1, [[1]]) elif r == 2: - M = Matrix(self.base_ring(), 2, 2, [[a + 1, a], + M = matrix(self.base_ring(), 2, 2, [[a + 1, a], [a, a + 1]]) elif r == 4: - M = Matrix(self.base_ring(), 4, 4, [[a, a+1, 1, 1], + M = matrix(self.base_ring(), 4, 4, [[a, a+1, 1, 1], [1, a, a+1, 1], [1, 1, a, a+1], [a+1, 1, 1, a]]) @@ -960,7 +960,7 @@ def mix_columns(self, d): for column in d.columns(): ret.append(M * column) # AES uses the column major ordering - return Matrix(k, d.ncols(), d.nrows(), ret).transpose() + return matrix(k, d.ncols(), d.nrows(), ret).transpose() def add_round_key(self, d, key): r""" @@ -1026,16 +1026,16 @@ def state_array(self, d=None): k = self.base_ring() if d is None: - return Matrix(k, r, c) + return matrix(k, r, c) if isinstance(d, Matrix): if d.nrows() == r*c*e: - return Matrix(k, c, r, self.antiphi(d).list()).transpose() + return matrix(k, c, r, self.antiphi(d).list()).transpose() elif d.ncols() == c and d.nrows() == r and d.base_ring() == k: return d if isinstance(d, tuple([list, tuple])): - return Matrix(k, c, r, d).transpose() + return matrix(k, c, r, d).transpose() def is_state_array(self, d): """ @@ -1154,8 +1154,8 @@ def key_schedule(self, kj, i): a = F.gen() SubByte = self.sub_byte - rc = Matrix(F, r, c, ([a**(i-1)] * c) + [F(0)]*((r-1)*c) ) - ki = Matrix(F, r, c) + rc = matrix(F, r, c, ([a**(i-1)] * c) + [F(0)]*((r-1)*c) ) + ki = matrix(F, r, c) if r == 1: s0 = SubByte(kj[0, c-1]) @@ -1852,10 +1852,10 @@ def round_polynomials(self, i, plaintext=None, ciphertext=None): _vars = self.vars if i == 0: - w1 = Matrix(R, r*c*e, 1, _vars("w", 1, r*c, e)) - k0 = Matrix(R, r*c*e, 1, _vars("k", 0, r*c, e)) + w1 = matrix(R, r*c*e, 1, _vars("w", 1, r*c, e)) + k0 = matrix(R, r*c*e, 1, _vars("k", 0, r*c, e)) if isinstance(plaintext, (tuple, list)) and len(plaintext) == r*c: - plaintext = Matrix(R, r*c*e, 1, self.phi(plaintext)) + plaintext = matrix(R, r*c*e, 1, self.phi(plaintext)) return tuple((w1 + k0 + plaintext).list()) elif i > 0 and i <= n: @@ -1863,21 +1863,21 @@ def round_polynomials(self, i, plaintext=None, ciphertext=None): if self._star and i == n: M = self.Mstar - xj = Matrix(R, r*c*e, 1, _vars("x", i, r*c, e)) - ki = Matrix(R, r*c*e, 1, _vars("k", i, r*c, e)) - rcon = Matrix(R, r*c*e, 1, self.phi([self.sbox_constant()]*r*c)) + xj = matrix(R, r*c*e, 1, _vars("x", i, r*c, e)) + ki = matrix(R, r*c*e, 1, _vars("k", i, r*c, e)) + rcon = matrix(R, r*c*e, 1, self.phi([self.sbox_constant()]*r*c)) if i < n: - wj = Matrix(R, r*c*e, 1, _vars("w", i+1, r*c, e)) + wj = matrix(R, r*c*e, 1, _vars("w", i+1, r*c, e)) if i == n: if isinstance(ciphertext, (tuple, list)) and len(ciphertext) == r*c: - ciphertext = Matrix(R, r*c*e, 1, self.phi(ciphertext)) + ciphertext = matrix(R, r*c*e, 1, self.phi(ciphertext)) wj = ciphertext lin = (wj + ki + M * xj + rcon).list() - wi = Matrix(R, r*c*e, 1, _vars("w", i, r*c, e)) - xi = Matrix(R, r*c*e, 1, _vars("x", i, r*c, e)) + wi = matrix(R, r*c*e, 1, _vars("w", i, r*c, e)) + xi = matrix(R, r*c*e, 1, _vars("x", i, r*c, e)) sbox = [] sbox += self.inversion_polynomials(xi, wi, r*c*e) sbox += self.field_polynomials("x", i) @@ -1940,12 +1940,12 @@ def key_schedule_polynomials(self, i): return tuple(self.field_polynomials("k", i, r*c)) else: L = self.lin_matrix(r) - ki = Matrix(R, r*c*e, 1, self.vars("k", i , r*c, e)) - kj = Matrix(R, r*c*e, 1, self.vars("k", i-1, r*c, e)) - si = Matrix(R, r*e, 1, self.vars("s", i-1, r, e)) + ki = matrix(R, r*c*e, 1, self.vars("k", i , r*c, e)) + kj = matrix(R, r*c*e, 1, self.vars("k", i-1, r*c, e)) + si = matrix(R, r*e, 1, self.vars("s", i-1, r, e)) - rc = Matrix(R, r*e, 1, self.phi([a**(i-1)] + [k(0)]*(r-1)) ) - d = Matrix(R, r*e, 1, self.phi([self.sbox_constant()]*r) ) + rc = matrix(R, r*e, 1, self.phi([a**(i-1)] + [k(0)]*(r-1)) ) + d = matrix(R, r*e, 1, self.phi([self.sbox_constant()]*r) ) sbox = [] @@ -1970,7 +1970,7 @@ def key_schedule_polynomials(self, i): sbox += self.inversion_polynomials( kj[(4*c-4)*e : (4*c-4)*e + e] , si[3*e : 4*e] , e ) si = L * si + d + rc - Sum = Matrix(R, r*e, 1) + Sum = matrix(R, r*e, 1) lin = [] if c > 1: for q in range(c): @@ -2090,7 +2090,7 @@ def polynomial_system(self, P=None, K=None, C=None): if isinstance(d[0], int): d = [GF(2)(_) for _ in d] if len(d) == r*c*e and (d[0].parent() is R or d[0].parent() == R): - data.append( Matrix(R,r*c*e,1,d) ) + data.append( matrix(R,r*c*e,1,d) ) continue try: data.append( self.phi(self.state_array(d)) ) @@ -2164,9 +2164,9 @@ def vector(self, d=None): k = self.base_ring() if d is None: - return Matrix(k, r*c*e, 1) + return matrix(k, r*c*e, 1) elif d.ncols() == c and d.nrows() == r and d.base_ring() == k: - return Matrix(k, r*c*e, 1, self.phi(d).transpose().list()) + return matrix(k, r*c*e, 1, self.phi(d).transpose().list()) def is_vector(self, d): """ @@ -2223,7 +2223,7 @@ def phi(self, l): elif isinstance(l, tuple): return tuple(ret) elif isinstance(l, Matrix): - return Matrix(l.base_ring(), l.ncols(), l.nrows()*self.e, ret).transpose() + return matrix(l.base_ring(), l.ncols(), l.nrows()*self.e, ret).transpose() else: raise TypeError @@ -2252,7 +2252,7 @@ def antiphi(self, l): elif isinstance(l, tuple): return tuple(ret) elif isinstance(l, Matrix): - return Matrix(self.base_ring(), l.ncols(), l.nrows() // self.e, + return matrix(self.base_ring(), l.ncols(), l.nrows() // self.e, ret).transpose() else: raise TypeError @@ -2275,7 +2275,7 @@ def shift_rows_matrix(self): c = self.c k = self.base_ring() bs = r*c*e - shift_rows = Matrix(k, bs, bs) + shift_rows = matrix(k, bs, bs) I = MatrixSpace(k, e, e)(1) for x in range(0, c): for y in range(0, r): @@ -2316,7 +2316,7 @@ def lin_matrix(self, length=None): if length is None: length = r*c - lin = Matrix(self.base_ring(), length*e, length*e) + lin = matrix(self.base_ring(), length*e, length*e) if e == 4: l = [k.from_integer(x) for x in (5, 1, 12, 5)] for k in range( 0, length ): @@ -2364,7 +2364,7 @@ def D(b): [ 0 0 a + 1 0 0 0 a 0] [ 0 0 0 a^2 + 1 0 0 0 a^2] """ - D = Matrix(self.base_ring(), self._e, self._e) + D = matrix(self.base_ring(), self._e, self._e) for i in range(self._e): D[i, i] = b**(2**i) return D @@ -2375,7 +2375,7 @@ def D(b): k = self.k a = k.gen() - M = Matrix(k, r*e, r*e) + M = matrix(k, r*e, r*e) if r == 1: self._insert_matrix_into_matrix(M, D(1), 0, 0) @@ -2407,7 +2407,7 @@ def D(b): self._insert_matrix_into_matrix(M, D(1), 2*e, 1*e) self._insert_matrix_into_matrix(M, D(1), 3*e, 2*e) - mix_columns = Matrix(k, r*c*e, r*c*e) + mix_columns = matrix(k, r*c*e, r*c*e) for i in range(c): self._insert_matrix_into_matrix(mix_columns, M, r*e*i, r*e*i) @@ -2525,16 +2525,16 @@ def vector(self, d=None): k = GF(2) if d is None: - return Matrix(k, r*c*e, 1) + return matrix(k, r*c*e, 1) elif isinstance(d, Matrix) and d.ncols() == c and d.nrows() == r and d.base_ring() == self.k: l = flatten([self.phi(x) for x in d.transpose().list()], (Vector_modn_dense,list,tuple)) - return Matrix(k, r*c*e, 1, l) + return matrix(k, r*c*e, 1, l) elif isinstance(d, (list, tuple)): if len(d) == self.r*self.c: l = flatten([self.phi(x) for x in d], (Vector_modn_dense,list,tuple)) - return Matrix(k, r*c*e, 1, l) + return matrix(k, r*c*e, 1, l) elif len(d) == self.r*self.c*self.e: - return Matrix(k, r*c*e, 1, d) + return matrix(k, r*c*e, 1, d) else: raise TypeError else: @@ -2602,7 +2602,7 @@ def phi(self, l, diffusion_matrix=False): if isinstance(l, Matrix) and diffusion_matrix and \ l.nrows() == r*c and l.ncols() == r*c and \ l.base_ring() == self.k: - B = Matrix(GF(2), r*c*e, r*c*e) + B = matrix(GF(2), r*c*e, r*c*e) for x in range(r*c): for y in range(r*c): T = self._mul_matrix(l[x, y]) @@ -2627,7 +2627,7 @@ def phi(self, l, diffusion_matrix=False): elif isinstance(l, tuple): return tuple(ret) elif isinstance(l, Matrix): - return Matrix(GF(2), l.ncols(), l.nrows()*self.e, ret).transpose() + return matrix(GF(2), l.ncols(), l.nrows()*self.e, ret).transpose() else: raise TypeError @@ -2663,7 +2663,7 @@ def antiphi(self, l): elif isinstance(l, tuple): return tuple(ret) elif isinstance(l, Matrix): - return Matrix(self.base_ring(), self.r * self.c, 1, ret) + return matrix(self.base_ring(), self.r * self.c, 1, ret) else: raise TypeError @@ -2684,7 +2684,7 @@ def shift_rows_matrix(self): c = self.c k = self.k bs = r*c - shift_rows = Matrix(k, r*c, r*c) + shift_rows = matrix(k, r*c, r*c) for x in range(0, c): for y in range(0, r): _r = ((x*r)+y) @@ -2711,18 +2711,18 @@ def mix_columns_matrix(self): a = k.gen() if r == 1: - M = Matrix(k, r, r, 1) + M = matrix(k, r, r, 1) elif r == 2: - M = Matrix(k, r, r, [a+1, a, a, a+1]) + M = matrix(k, r, r, [a+1, a, a, a+1]) elif r == 4: - M = Matrix(k, r, [a, a+1, 1, 1, + M = matrix(k, r, [a, a+1, 1, 1, 1, a, a+1, 1, 1, 1, a, a+1, a+1, 1, 1, a]) - mix_columns = Matrix(k, r*c, r*c) + mix_columns = matrix(k, r*c, r*c) for i in range(c): self._insert_matrix_into_matrix(mix_columns, M, r*i, r*i) @@ -2758,7 +2758,7 @@ def lin_matrix(self, length=None): length = r*c if e == 8: - Z = Matrix(GF(2), 8, 8, [1, 0, 0, 0, 1, 1, 1, 1, + Z = matrix(GF(2), 8, 8, [1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, @@ -2767,14 +2767,14 @@ def lin_matrix(self, length=None): 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1]) else: - Z = Matrix(GF(2), 4, 4, [1, 1, 1, 0, + Z = matrix(GF(2), 4, 4, [1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1]) Z = Z.transpose() # account for endianess mismatch - lin = Matrix(GF(2), length*e, length*e) + lin = matrix(GF(2), length*e, length*e) for i in range(length): self._insert_matrix_into_matrix(lin, Z, i*e, i*e) @@ -2811,7 +2811,7 @@ def _mul_matrix(self, x): columns = [list(reversed((x * a**i)._vector_())) for i in reversed(range(e))] - return Matrix(GF(2), e, e, columns).transpose() + return matrix(GF(2), e, e, columns).transpose() def _square_matrix(self): """ @@ -2837,7 +2837,7 @@ def _square_matrix(self): columns = [] for i in reversed(range(e)): columns.append( list(reversed(((a**i)**2)._vector_())) ) - return Matrix(GF(2), e , e, columns).transpose() + return matrix(GF(2), e , e, columns).transpose() def inversion_polynomials_single_sbox(self, x=None, w=None, biaffine_only=None, correct_only=None): """ @@ -3086,8 +3086,8 @@ def _inversion_polynomials_single_sbox(self, x=None, w=None, biaffine_only=None, # make sure it prints like in the book. names = ["w%d" % i for i in reversed(range(e))] + ["x%d" % i for i in reversed(range(e))] P = PolynomialRing(GF(2), e*2, names, order='lex') - x = Matrix(P, e, 1, P.gens()[e:]) - w = Matrix(P, e, 1, P.gens()[:e]) + x = matrix(P, e, 1, P.gens()[e:]) + w = matrix(P, e, 1, P.gens()[:e]) else: if isinstance(x, (tuple, list)): P = x[0].parent() @@ -3097,22 +3097,22 @@ def _inversion_polynomials_single_sbox(self, x=None, w=None, biaffine_only=None, raise TypeError("x not understood") if isinstance(x, (tuple, list)): - x = Matrix(P, e, 1, x) + x = matrix(P, e, 1, x) if isinstance(w, (tuple, list)): - w = Matrix(P, e, 1, w) + w = matrix(P, e, 1, w) T = self._mul_matrix(self.k.gen()) - o = Matrix(P, e, 1, [0]*(e-1) + [1]) + o = matrix(P, e, 1, [0]*(e-1) + [1]) columns = [] for i in reversed(range(e)): columns.append((T**i * w).list()) - Cw = Matrix(P, e, e, columns).transpose() + Cw = matrix(P, e, e, columns).transpose() columns = [] for i in reversed(range(e)): columns.append((T**i * x).list()) - Cx = Matrix(P, e, e, columns).transpose() + Cx = matrix(P, e, e, columns).transpose() S = self._square_matrix() From 9b9f3e8859090eaaaf699f163dfc569070fa17f4 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 27 May 2024 10:59:03 -0700 Subject: [PATCH 12/16] src/sage/geometry/polyhedron/library.py: Use matrix instead of Matrix (fixup) --- src/sage/geometry/polyhedron/library.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sage/geometry/polyhedron/library.py b/src/sage/geometry/polyhedron/library.py index f00daedbbd1..c26fad3c014 100644 --- a/src/sage/geometry/polyhedron/library.py +++ b/src/sage/geometry/polyhedron/library.py @@ -476,9 +476,9 @@ def gale_transform_to_primal(vectors, base_ring=None, backend=None): # where ``V`` is the dehomogenized dual point configuration. # If we append a row of ones to ``vectors``, ``V`` is just the right kernel. if base_ring: - m = matrix(base_ring, vectors).transpose().stack(Matrix(base_ring, [[1]*len(vectors)])) + m = matrix(base_ring, vectors).transpose().stack(matrix(base_ring, [[1]*len(vectors)])) else: - m = matrix(vectors).transpose().stack(Matrix([[1]*len(vectors)])) + m = matrix(vectors).transpose().stack(matrix([[1]*len(vectors)])) if m.rank() != len(vectors[0]) + 1: # The given vectors do not span the ambient space, From 5bedf2acb6374b9848917fb90f5178851ca09a44 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 27 May 2024 11:13:33 -0700 Subject: [PATCH 13/16] src/sage/groups/matrix_gps/group_element.pyx: Remove duplicate imports --- src/sage/groups/matrix_gps/group_element.pyx | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/sage/groups/matrix_gps/group_element.pyx b/src/sage/groups/matrix_gps/group_element.pyx index cfabb0c1be0..952cdc0c6c2 100644 --- a/src/sage/groups/matrix_gps/group_element.pyx +++ b/src/sage/groups/matrix_gps/group_element.pyx @@ -77,8 +77,6 @@ AUTHORS: #***************************************************************************** from sage.rings.integer_ring import ZZ -from sage.structure.element cimport MultiplicativeGroupElement, Matrix -from sage.structure.element import Matrix from sage.structure.parent cimport Parent from sage.structure.richcmp cimport richcmp From 83b7d061da75c9eb75d6987fd50787f84e186fe1 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 27 May 2024 15:17:25 -0700 Subject: [PATCH 14/16] src/sage/modular/abvar/homspace.py: Fix import --- src/sage/modular/abvar/homspace.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sage/modular/abvar/homspace.py b/src/sage/modular/abvar/homspace.py index f514605d3aa..95e22baaabc 100644 --- a/src/sage/modular/abvar/homspace.py +++ b/src/sage/modular/abvar/homspace.py @@ -192,7 +192,7 @@ from sage.rings.infinity import Infinity from sage.matrix.matrix_space import MatrixSpace -from sage.matrix.constructor import Matrix, identity_matrix +from sage.matrix.constructor import matrix, identity_matrix from sage.structure.element import Matrix from sage.rings.integer_ring import ZZ @@ -929,7 +929,7 @@ def discriminant(self): 2 """ g = self.gens() - M = Matrix(ZZ, len(g), [(g[i]*g[j]).trace() + M = matrix(ZZ, len(g), [(g[i]*g[j]).trace() for i in range(len(g)) for j in range(len(g))]) return M.determinant() From 08b12208881421f27ede0204ab3e0fbf943bb072 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 27 May 2024 15:18:05 -0700 Subject: [PATCH 15/16] src/sage/modular/cusps_nf.py: Fix import --- src/sage/modular/cusps_nf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/modular/cusps_nf.py b/src/sage/modular/cusps_nf.py index bdaf304d7d6..052c5a108fd 100644 --- a/src/sage/modular/cusps_nf.py +++ b/src/sage/modular/cusps_nf.py @@ -74,7 +74,7 @@ # **************************************************************************** from sage.structure.parent import Parent -from sage.structure.element import Element, is_InfinityElement +from sage.structure.element import Element, InfinityElement from sage.structure.richcmp import richcmp, rich_to_bool from sage.structure.unique_representation import UniqueRepresentation From beb6c1d2cc74fe88cbdbcafbe8e91592a9fda229 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 27 May 2024 15:20:04 -0700 Subject: [PATCH 16/16] src/sage/coding/binary_code.pyx: Only cimport sage.structure.element.Matrix to hide it from 'import *' --- src/sage/coding/binary_code.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/coding/binary_code.pyx b/src/sage/coding/binary_code.pyx index bc75df85d88..a5081c1a18a 100644 --- a/src/sage/coding/binary_code.pyx +++ b/src/sage/coding/binary_code.pyx @@ -46,7 +46,7 @@ from cpython.mem cimport * from cpython.object cimport PyObject_RichCompare from cysignals.memory cimport sig_malloc, sig_realloc, sig_free -from sage.structure.element import Matrix +from sage.structure.element cimport Matrix from sage.misc.timing import cputime from sage.rings.integer cimport Integer from copy import copy