Skip to content

Commit

Permalink
Import matrix, not Matrix, from sage.matrix.constructor to avoid clashes
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koeppe committed May 25, 2024
1 parent 2d35995 commit 3a4ed06
Show file tree
Hide file tree
Showing 18 changed files with 51 additions and 52 deletions.
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 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 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 @@ -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)
4 changes: 2 additions & 2 deletions src/sage/coding/binary_code.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 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 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 @@ -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"""
Expand Down
4 changes: 2 additions & 2 deletions src/sage/combinat/cluster_algebra_quiver/quiver.py
Original file line number Diff line number Diff line change
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
10 changes: 5 additions & 5 deletions src/sage/combinat/root_system/reflection_group_complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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])

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/similarity_class_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/sage/geometry/polyhedron/base5.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/sage/libs/ntl/ntl_mat_GF2.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/sage/libs/ntl/ntl_mat_GF2E.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
8 changes: 4 additions & 4 deletions src/sage/matroids/constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions src/sage/numerical/backends/matrix_sdp_backend.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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])


Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/sage/numerical/sdp.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/sage/quadratic_forms/ternary_qf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
12 changes: 6 additions & 6 deletions src/sage/rings/polynomial/multi_polynomial_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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

Expand All @@ -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()
Expand Down
10 changes: 5 additions & 5 deletions src/sage/schemes/plane_conics/con_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]])

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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]])

Expand Down
4 changes: 2 additions & 2 deletions src/sage/schemes/plane_conics/constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 3a4ed06

Please sign in to comment.