Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove unused vars in matrix/ #36281

Merged
merged 1 commit into from
Sep 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/sage/matrix/matrix0.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ cdef class Matrix(sage.structure.element.Matrix):
This is fast since it is a cdef function and there is no bounds
checking.
"""
raise NotImplementedError("this must be defined in the derived class (type=%s)"%type(self))
raise NotImplementedError("this must be defined in the derived class (type=%s)" % type(self))

cdef get_unsafe(self, Py_ssize_t i, Py_ssize_t j):
"""
Expand Down Expand Up @@ -1396,7 +1396,6 @@ cdef class Matrix(sage.structure.element.Matrix):
"""
cdef list row_list
cdef list col_list
cdef object index
cdef Py_ssize_t row_list_len, col_list_len
cdef list value_list
cdef bint value_list_one_dimensional = 0
Expand Down Expand Up @@ -2241,7 +2240,7 @@ cdef class Matrix(sage.structure.element.Matrix):
tmp = [align*(b-a) for a,b in zip([0] + col_divs, col_divs + [nc])]
format = '|'.join(tmp)

return "\\left" + matrix_delimiters[0] + "\\begin{array}{%s}\n"%format + s + "\n\\end{array}\\right" + matrix_delimiters[1]
return "\\left" + matrix_delimiters[0] + "\\begin{array}{%s}\n" % format + s + "\n\\end{array}\\right" + matrix_delimiters[1]

###################################################
## Basic Properties
Expand Down Expand Up @@ -2345,7 +2344,6 @@ cdef class Matrix(sage.structure.element.Matrix):
if self._nrows != self._ncols:
raise ArithmeticError("self must be a square matrix")

F = f.base_ring()
vars = f.parent().gens()
n = len(self.rows())
ans = []
Expand Down Expand Up @@ -3746,7 +3744,7 @@ cdef class Matrix(sage.structure.element.Matrix):
"""
cdef dict d = {}
cdef list queue = list(range(self._ncols))
cdef int l, sign, i, j
cdef int l, sign, i

if skew:
# testing the diagonal entries to be zero
Expand Down Expand Up @@ -4638,7 +4636,7 @@ cdef class Matrix(sage.structure.element.Matrix):
print(self)
print(self.nrows())
print(self.dict())
raise RuntimeError("BUG: matrix pivots should have been set but weren't, matrix parent = '%s'"%self.parent())
raise RuntimeError("BUG: matrix pivots should have been set but weren't, matrix parent = '%s'" % self.parent())
return tuple(x)

def rank(self):
Expand Down
29 changes: 12 additions & 17 deletions src/sage/matrix/matrix2.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ cdef class Matrix(Matrix1):
...
ValueError: matrix equation has no solutions

A ValueError is raised if the input is invalid::
A :class:`ValueError` is raised if the input is invalid::

sage: A = matrix(QQ,4,2, [0, -1, 1, 0, -2, 2, 1, 0])
sage: B = matrix(QQ,2,2, [1, 0, 1, -1])
Expand Down Expand Up @@ -2184,7 +2184,7 @@ cdef class Matrix(Matrix1):
Compute the determinant of the upper-left level x level submatrix
of self. Does not handle degenerate cases, level MUST be >= 2
"""
cdef Py_ssize_t n, i
cdef Py_ssize_t i
if level == 2:
return self.get_unsafe(0,0) * self.get_unsafe(1,1) - self.get_unsafe(0,1) * self.get_unsafe(1,0)
else:
Expand Down Expand Up @@ -3316,8 +3316,7 @@ cdef class Matrix(Matrix1):
3
"""
if self.nrows() == 0 or self.ncols() == 0:
return ZZ(1)
R = self.base_ring()
return ZZ.one()
x = self.list()
try:
d = x[0].denominator()
Expand Down Expand Up @@ -3905,7 +3904,7 @@ cdef class Matrix(Matrix1):
"""
tm = verbose("computing right kernel matrix over a domain for %sx%s matrix"
% (self.nrows(), self.ncols()), level=1)
d, u, v = self.smith_form()
d, _, v = self.smith_form()
basis = []
cdef Py_ssize_t i, nrows = self._nrows
for i in range(self._ncols):
Expand Down Expand Up @@ -6098,7 +6097,7 @@ cdef class Matrix(Matrix1):
# subrings of fields of which an algebraic closure is implemented.
if format is None:
try:
F = self.base_ring().fraction_field().algebraic_closure()
self.base_ring().fraction_field().algebraic_closure()
return 'all'
except (NotImplementedError, AttributeError):
return 'galois'
Expand Down Expand Up @@ -6922,7 +6921,6 @@ cdef class Matrix(Matrix1):
from warnings import warn
warn("Using generic algorithm for an inexact ring, which may result in garbage from numerical precision issues.")

V = []
from sage.categories.homset import hom
eigenspaces = self.eigenspaces_left(format='galois', algebraic_multiplicity=True)
evec_list=[]
Expand Down Expand Up @@ -8068,7 +8066,7 @@ cdef class Matrix(Matrix1):
if self.fetch('in_echelon_form'):
return self.fetch('pivots')

tm = verbose('generic in-place Gauss elimination on %s x %s matrix using %s algorithm'%(self._nrows, self._ncols, algorithm))
_ = verbose('generic in-place Gauss elimination on %s x %s matrix using %s algorithm' % (self._nrows, self._ncols, algorithm))
self.check_mutability()
cdef Matrix A

Expand Down Expand Up @@ -8367,7 +8365,6 @@ cdef class Matrix(Matrix1):
"""
if subdivide not in [True, False]:
raise TypeError("subdivide must be True or False, not %s" % subdivide)
R = self.base_ring()
ident = self.matrix_space(self.nrows(), self.nrows()).one()
E = self.augment(ident)
extended = E.echelon_form(**kwds)
Expand Down Expand Up @@ -12227,7 +12224,7 @@ cdef class Matrix(Matrix1):
Returns a pair (F, C) such that the rows of C form a symplectic
basis for self and F = C \* self \* C.transpose().

Raises a ValueError if not over a field, or self is not
Raises a :class:`ValueError` if not over a field, or self is not
anti-symmetric, or self is not alternating.

Anti-symmetric means that `M = -M^t`. Alternating means
Expand Down Expand Up @@ -15396,7 +15393,7 @@ cdef class Matrix(Matrix1):
if p == 2:
A = self.change_ring(CDF)
A = A.conjugate().transpose() * A
U, S, V = A.SVD()
S = A.SVD()[1]
return max(S.list()).real().sqrt()

A = self.apply_map(abs, R=RDF)
Expand Down Expand Up @@ -15887,7 +15884,6 @@ cdef class Matrix(Matrix1):
dd, uu, vv = mm.smith_form(transformation=True)
else:
dd = mm.smith_form(transformation=False)
mone = self.new_matrix(1, 1, [1])
d = dd.new_matrix(1,1,[t[0,0]]).block_sum(dd)
if transformation:
u = uu.new_matrix(1,1,[1]).block_sum(uu) * u
Expand Down Expand Up @@ -16081,18 +16077,17 @@ cdef class Matrix(Matrix1):
sage: U * A == H
True
"""
left, H, pivots = self._echelon_form_PID()
left, H, _ = self._echelon_form_PID()
if not include_zero_rows:
i = H.nrows() - 1
while H.row(i) == 0:
i -= 1
H = H[:i+1]
H = H[:i + 1]
if transformation:
left = left[:i+1]
left = left[:i + 1]
if transformation:
return H, left
else:
return H
return H

def _echelon_form_PID(self):
r"""
Expand Down
25 changes: 8 additions & 17 deletions src/sage/matrix/matrix_cyclo_dense.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ AUTHORS:
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
# http://www.gnu.org/licenses/
# https://www.gnu.org/licenses/
#*****************************************************************************

from cysignals.signals cimport sig_on, sig_off
Expand All @@ -51,7 +51,7 @@ from sage.structure.element cimport Element
from sage.misc.randstate cimport randstate, current_randstate
from sage.libs.gmp.randomize cimport *

from sage.libs.flint.types cimport fmpz_t, fmpq
from sage.libs.flint.types cimport fmpz_t
from sage.libs.flint.fmpz cimport fmpz_init, fmpz_clear, fmpz_set_mpz, fmpz_one, fmpz_get_mpz, fmpz_add, fmpz_mul, fmpz_sub, fmpz_mul_si, fmpz_mul_si, fmpz_mul_si, fmpz_divexact, fmpz_lcm
from sage.libs.flint.fmpq cimport fmpq_is_zero, fmpq_set_mpq, fmpq_canonicalise
from sage.libs.flint.fmpq_mat cimport fmpq_mat_entry_num, fmpq_mat_entry_den, fmpq_mat_entry
Expand Down Expand Up @@ -327,7 +327,7 @@ cdef class Matrix_cyclo_dense(Matrix_dense):
cdef Py_ssize_t k, c
cdef NumberFieldElement x
cdef NumberFieldElement_quadratic xq
cdef mpz_t quo, tmp
cdef mpz_t tmp
cdef fmpz_t denom, ftmp
cdef ZZ_c coeff

Expand Down Expand Up @@ -1036,7 +1036,6 @@ cdef class Matrix_cyclo_dense(Matrix_dense):
"""
cdef Py_ssize_t i
cdef Matrix_rational_dense mat = self._matrix
cdef fmpq * entry
cdef mpq_t tmp

sig_on()
Expand Down Expand Up @@ -1198,8 +1197,6 @@ cdef class Matrix_cyclo_dense(Matrix_dense):
if self._nrows <= 3:
return max(1, 3*B, 6*B**2, 4*B**3)

# This is an approximation to 2^(5/6*log_2(5) - 2/3*log_2(6))
alpha = RealNumber('1.15799718800731')
# This is 2*e^(1-(2(7\gamma-4))/(13(3-2\gamma))), where \gamma
# is Euler's constant.
delta = RealNumber('5.418236')
Expand Down Expand Up @@ -1333,20 +1330,20 @@ cdef class Matrix_cyclo_dense(Matrix_dense):
[4 0 0]
[0 0 0]
"""
tm = verbose("Computing characteristic polynomial of cyclotomic matrix modulo %s."%p)
tm = verbose("Computing characteristic polynomial of cyclotomic matrix modulo %s." % p)
# Reduce self modulo all primes over p
R, denom = self._reductions(p)
R, _ = self._reductions(p)
# Compute the characteristic polynomial of each reduced matrix
F = [A.charpoly('x') for A in R]
# Put the characteristic polynomials together as the rows of a mod-p matrix
k = R[0].base_ring()
S = matrix(k, len(F), self.nrows()+1, [f.list() for f in F])
S = matrix(k, len(F), self.nrows() + 1, [f.list() for f in F])
# multiply by inverse of reduction matrix to lift
_, L = self._reduction_matrix(p)
X = L * S
# Now the columns of the matrix X define the entries of the
# charpoly modulo p.
verbose("Finished computing charpoly mod %s."%p, tm)
verbose("Finished computing charpoly mod %s." % p, tm)
return X

def _charpoly_multimodular(self, var='x', proof=None):
Expand Down Expand Up @@ -1676,7 +1673,6 @@ cdef class Matrix_cyclo_dense(Matrix_dense):
[ 1 0 7/19]
[ 0 1 3/19]
"""
cdef int i
cdef Matrix_cyclo_dense res
cdef bint is_square

Expand Down Expand Up @@ -1827,14 +1823,11 @@ cdef class Matrix_cyclo_dense(Matrix_dense):
Traceback (most recent call last):
...
ValueError: echelon form mod 7 not defined

"""
cdef Matrix_cyclo_dense res
cdef int i

# Initialize variables
is_square = self._nrows == self._ncols
ls, denom = self._reductions(p)
ls, _ = self._reductions(p)

# Find our first echelon form, and the associated list
# of pivots
Expand Down Expand Up @@ -1936,13 +1929,11 @@ cdef class Matrix_cyclo_dense(Matrix_dense):
X = R._generator_matrix()
d = self._degree
MS = MatrixSpace(QQ, d, d)
mlst = self.list()
for c in self._matrix.columns():
v = c.list()
for n in range(d-1):
c = c * X
v += c.list()
temp = MS(v)
rmul = MS([v[d*i+j] for j in range(d) for i in range(d)]) # We take the transpose
l.append(rmul * A._rational_matrix())

Expand Down
25 changes: 8 additions & 17 deletions src/sage/matrix/matrix_integer_dense.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,6 @@ cdef class Matrix_integer_dense(Matrix_dense):
# TODO: *maybe* redo this to use mpz_import and mpz_export
# from sec 5.14 of the GMP manual. ??
cdef int i, j, len_so_far, m, n
cdef char *a
cdef char *s
cdef char *t
cdef char *tmp
Expand Down Expand Up @@ -1537,17 +1536,13 @@ cdef class Matrix_integer_dense(Matrix_dense):
"""
cdef Integer h
cdef Matrix_integer_dense left = <Matrix_integer_dense>self
cdef mod_int *moduli
cdef int i, n, k
cdef int i, k

nr = left._nrows
nc = right._ncols
snc = left._ncols


cdef Matrix_integer_dense result


h = left.height() * right.height() * left.ncols()
verbose('multiplying matrices of height %s and %s'%(left.height(),right.height()))
mm = MultiModularBasis(h)
Expand Down Expand Up @@ -1601,7 +1596,6 @@ cdef class Matrix_integer_dense(Matrix_dense):
from .matrix_modn_dense_double import MAX_MODULUS as MAX_MODULUS_DOUBLE

cdef Py_ssize_t i, j
cdef mpz_t* self_row

cdef float* res_row_f
cdef Matrix_modn_dense_float res_f
Expand Down Expand Up @@ -2015,7 +2009,7 @@ cdef class Matrix_integer_dense(Matrix_dense):
if ans is not None:
return ans

cdef Matrix_integer_dense H_m,w,U
cdef Matrix_integer_dense H_m, U
cdef Py_ssize_t nr, nc, n, i, j
nr = self._nrows
nc = self._ncols
Expand Down Expand Up @@ -3757,7 +3751,6 @@ cdef class Matrix_integer_dense(Matrix_dense):
if not self.is_square():
raise ValueError("self must be a square matrix")

cdef Py_ssize_t n = self.nrows()
cdef Integer det = Integer()
cdef fmpz_t e

Expand Down Expand Up @@ -4884,7 +4877,7 @@ cdef class Matrix_integer_dense(Matrix_dense):
[ 0 0 545], [0, 1, 2]
)
"""
cdef Py_ssize_t i, j, piv, n = self._nrows, m = self._ncols
cdef Py_ssize_t i, j, n = self._nrows, m = self._ncols

from .constructor import matrix

Expand Down Expand Up @@ -5380,9 +5373,8 @@ cdef class Matrix_integer_dense(Matrix_dense):
n = ns + na

cdef Matrix_integer_dense Z
Z = self.new_matrix(nrows = m, ncols = n)
cdef Py_ssize_t i, j, p, qs, qa
p, qs, qa = 0, 0, 0
Z = self.new_matrix(nrows=m, ncols=n)
cdef Py_ssize_t i, j
for i from 0 <= i < m:
for j from 0 <= j < ns:
fmpz_set(fmpz_mat_entry(Z._matrix,i,j),
Expand Down Expand Up @@ -5455,7 +5447,7 @@ cdef class Matrix_integer_dense(Matrix_dense):
Return matrix obtained from self by deleting all zero columns along
with the positions of those columns.

OUTPUT: matrix list of integers
OUTPUT: (matrix, list of integers)

EXAMPLES::

Expand All @@ -5468,10 +5460,9 @@ cdef class Matrix_integer_dense(Matrix_dense):
[-1 5], [1]
)
"""
C = self.columns()
zero_cols = [i for i,v in enumerate(self.columns()) if v.is_zero()]
zero_cols = [i for i, v in enumerate(self.columns()) if v.is_zero()]
s = set(zero_cols)
nonzero_cols = [i for i in range(self.ncols()) if not (i in s)]
nonzero_cols = [i for i in range(self.ncols()) if i not in s]
return self.matrix_from_columns(nonzero_cols), zero_cols

def _insert_zero_columns(self, cols):
Expand Down
Loading
Loading