Skip to content

Commit

Permalink
gh-38077: Deprecate is_Element, ...
Browse files Browse the repository at this point in the history
    
<!-- ^ Please provide a concise and informative title. -->
<!-- ^ Don't put issue numbers in the title, do this in the PR
description below. -->
<!-- ^ For example, instead of "Fixes #12345" use "Introduce new method
to calculate 1 + 2". -->
<!-- v Describe your changes below in detail. -->
<!-- v Why is this change required? What problem does it solve? -->
<!-- v If this PR resolves an open issue, please link to it here. For
example, "Fixes #12345". -->



### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [x] The title is concise and informative.
- [ ] The description explains in detail what this PR is about.
- [ ] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation and checked the documentation
preview.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - #12345: short description why this is a dependency -->
<!-- - #34567: ... -->
    
URL: #38077
Reported by: Matthias Köppe
Reviewer(s): Kwankyu Lee
  • Loading branch information
Release Manager committed Jun 7, 2024
2 parents 3f4c50f + 34bf5bd commit 3dd3718
Show file tree
Hide file tree
Showing 91 changed files with 438 additions and 394 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
from sage.rings.integer_ring import ZZ

from sage.categories.magmatic_algebras import MagmaticAlgebras
from sage.matrix.constructor import Matrix, matrix
from sage.structure.element import is_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
from sage.structure.unique_representation import UniqueRepresentation
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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.
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ Elements of Finite Algebras
import re

from sage.matrix.matrix_space import MatrixSpace
from sage.structure.element import is_Matrix
from sage.rings.integer import Integer

from cpython.object cimport PyObject_RichCompare as richcmp
Expand Down Expand Up @@ -119,7 +118,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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@

from .finite_dimensional_algebra_element import FiniteDimensionalAlgebraElement

from sage.matrix.constructor import Matrix
from sage.structure.element import is_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
Expand Down Expand Up @@ -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 is_Matrix(gens):
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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -241,10 +241,10 @@ 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
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)
6 changes: 3 additions & 3 deletions src/sage/algebras/jordan_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -194,15 +194,15 @@ 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)
if arg0.base_ring().characteristic() == 2:
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
Expand Down
4 changes: 2 additions & 2 deletions src/sage/algebras/quatalg/quaternion_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions src/sage/calculus/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/sage/calculus/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, Vector, Expression

lazy_import('sage.matrix.constructor', 'matrix')

Expand Down Expand Up @@ -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])
10 changes: 5 additions & 5 deletions src/sage/coding/binary_code.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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 cimport Matrix
from sage.misc.timing import cputime
from sage.rings.integer cimport Integer
from copy import copy
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = <codeword> 0
Expand Down Expand Up @@ -4187,9 +4187,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)
Expand Down
4 changes: 2 additions & 2 deletions src/sage/coding/delsarte_bounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,9 +694,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()")

Expand Down
14 changes: 7 additions & 7 deletions src/sage/coding/linear_rank_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@
# ****************************************************************************

from sage.categories.fields import Fields
from sage.matrix.constructor import Matrix
from sage.structure.element import is_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

Expand Down Expand Up @@ -166,15 +166,15 @@ 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:
sub_field = base_field.prime_subfield()
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"""
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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))
Expand Down
8 changes: 4 additions & 4 deletions src/sage/combinat/cluster_algebra_quiver/quiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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.')

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/sage/combinat/designs/incidence_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/sage/combinat/integer_matrices.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading

0 comments on commit 3dd3718

Please sign in to comment.