Skip to content

Commit 35c302f

Browse files
author
Release Manager
committed
gh-36281: remove unused vars in matrix/ remove unused variables in matrix folder, as suggested by cython-lint ### 📝 Checklist - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. URL: #36281 Reported by: Frédéric Chapoton Reviewer(s): David Coudert, Matthias Köppe
2 parents 979b368 + 8b11d8f commit 35c302f

File tree

7 files changed

+38
-71
lines changed

7 files changed

+38
-71
lines changed

src/sage/matrix/matrix0.pyx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ cdef class Matrix(sage.structure.element.Matrix):
524524
This is fast since it is a cdef function and there is no bounds
525525
checking.
526526
"""
527-
raise NotImplementedError("this must be defined in the derived class (type=%s)"%type(self))
527+
raise NotImplementedError("this must be defined in the derived class (type=%s)" % type(self))
528528

529529
cdef get_unsafe(self, Py_ssize_t i, Py_ssize_t j):
530530
"""
@@ -1396,7 +1396,6 @@ cdef class Matrix(sage.structure.element.Matrix):
13961396
"""
13971397
cdef list row_list
13981398
cdef list col_list
1399-
cdef object index
14001399
cdef Py_ssize_t row_list_len, col_list_len
14011400
cdef list value_list
14021401
cdef bint value_list_one_dimensional = 0
@@ -2241,7 +2240,7 @@ cdef class Matrix(sage.structure.element.Matrix):
22412240
tmp = [align*(b-a) for a,b in zip([0] + col_divs, col_divs + [nc])]
22422241
format = '|'.join(tmp)
22432242

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

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

2348-
F = f.base_ring()
23492347
vars = f.parent().gens()
23502348
n = len(self.rows())
23512349
ans = []
@@ -3746,7 +3744,7 @@ cdef class Matrix(sage.structure.element.Matrix):
37463744
"""
37473745
cdef dict d = {}
37483746
cdef list queue = list(range(self._ncols))
3749-
cdef int l, sign, i, j
3747+
cdef int l, sign, i
37503748

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

46444642
def rank(self):

src/sage/matrix/matrix2.pyx

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ cdef class Matrix(Matrix1):
541541
...
542542
ValueError: matrix equation has no solutions
543543

544-
A ValueError is raised if the input is invalid::
544+
A :class:`ValueError` is raised if the input is invalid::
545545

546546
sage: A = matrix(QQ,4,2, [0, -1, 1, 0, -2, 2, 1, 0])
547547
sage: B = matrix(QQ,2,2, [1, 0, 1, -1])
@@ -2184,7 +2184,7 @@ cdef class Matrix(Matrix1):
21842184
Compute the determinant of the upper-left level x level submatrix
21852185
of self. Does not handle degenerate cases, level MUST be >= 2
21862186
"""
2187-
cdef Py_ssize_t n, i
2187+
cdef Py_ssize_t i
21882188
if level == 2:
21892189
return self.get_unsafe(0,0) * self.get_unsafe(1,1) - self.get_unsafe(0,1) * self.get_unsafe(1,0)
21902190
else:
@@ -3316,8 +3316,7 @@ cdef class Matrix(Matrix1):
33163316
3
33173317
"""
33183318
if self.nrows() == 0 or self.ncols() == 0:
3319-
return ZZ(1)
3320-
R = self.base_ring()
3319+
return ZZ.one()
33213320
x = self.list()
33223321
try:
33233322
d = x[0].denominator()
@@ -3905,7 +3904,7 @@ cdef class Matrix(Matrix1):
39053904
"""
39063905
tm = verbose("computing right kernel matrix over a domain for %sx%s matrix"
39073906
% (self.nrows(), self.ncols()), level=1)
3908-
d, u, v = self.smith_form()
3907+
d, _, v = self.smith_form()
39093908
basis = []
39103909
cdef Py_ssize_t i, nrows = self._nrows
39113910
for i in range(self._ncols):
@@ -6098,7 +6097,7 @@ cdef class Matrix(Matrix1):
60986097
# subrings of fields of which an algebraic closure is implemented.
60996098
if format is None:
61006099
try:
6101-
F = self.base_ring().fraction_field().algebraic_closure()
6100+
self.base_ring().fraction_field().algebraic_closure()
61026101
return 'all'
61036102
except (NotImplementedError, AttributeError):
61046103
return 'galois'
@@ -6922,7 +6921,6 @@ cdef class Matrix(Matrix1):
69226921
from warnings import warn
69236922
warn("Using generic algorithm for an inexact ring, which may result in garbage from numerical precision issues.")
69246923

6925-
V = []
69266924
from sage.categories.homset import hom
69276925
eigenspaces = self.eigenspaces_left(format='galois', algebraic_multiplicity=True)
69286926
evec_list=[]
@@ -8068,7 +8066,7 @@ cdef class Matrix(Matrix1):
80688066
if self.fetch('in_echelon_form'):
80698067
return self.fetch('pivots')
80708068

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

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

12230-
Raises a ValueError if not over a field, or self is not
12227+
Raises a :class:`ValueError` if not over a field, or self is not
1223112228
anti-symmetric, or self is not alternating.
1223212229

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

1540215399
A = self.apply_map(abs, R=RDF)
@@ -15887,7 +15884,6 @@ cdef class Matrix(Matrix1):
1588715884
dd, uu, vv = mm.smith_form(transformation=True)
1588815885
else:
1588915886
dd = mm.smith_form(transformation=False)
15890-
mone = self.new_matrix(1, 1, [1])
1589115887
d = dd.new_matrix(1,1,[t[0,0]]).block_sum(dd)
1589215888
if transformation:
1589315889
u = uu.new_matrix(1,1,[1]).block_sum(uu) * u
@@ -16081,18 +16077,17 @@ cdef class Matrix(Matrix1):
1608116077
sage: U * A == H
1608216078
True
1608316079
"""
16084-
left, H, pivots = self._echelon_form_PID()
16080+
left, H, _ = self._echelon_form_PID()
1608516081
if not include_zero_rows:
1608616082
i = H.nrows() - 1
1608716083
while H.row(i) == 0:
1608816084
i -= 1
16089-
H = H[:i+1]
16085+
H = H[:i + 1]
1609016086
if transformation:
16091-
left = left[:i+1]
16087+
left = left[:i + 1]
1609216088
if transformation:
1609316089
return H, left
16094-
else:
16095-
return H
16090+
return H
1609616091

1609716092
def _echelon_form_PID(self):
1609816093
r"""

src/sage/matrix/matrix_cyclo_dense.pyx

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ AUTHORS:
4040
# it under the terms of the GNU General Public License as published by
4141
# the Free Software Foundation, either version 2 of the License, or
4242
# (at your option) any later version.
43-
# http://www.gnu.org/licenses/
43+
# https://www.gnu.org/licenses/
4444
#*****************************************************************************
4545

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

54-
from sage.libs.flint.types cimport fmpz_t, fmpq
54+
from sage.libs.flint.types cimport fmpz_t
5555
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
5656
from sage.libs.flint.fmpq cimport fmpq_is_zero, fmpq_set_mpq, fmpq_canonicalise
5757
from sage.libs.flint.fmpq_mat cimport fmpq_mat_entry_num, fmpq_mat_entry_den, fmpq_mat_entry
@@ -327,7 +327,7 @@ cdef class Matrix_cyclo_dense(Matrix_dense):
327327
cdef Py_ssize_t k, c
328328
cdef NumberFieldElement x
329329
cdef NumberFieldElement_quadratic xq
330-
cdef mpz_t quo, tmp
330+
cdef mpz_t tmp
331331
cdef fmpz_t denom, ftmp
332332
cdef ZZ_c coeff
333333

@@ -1036,7 +1036,6 @@ cdef class Matrix_cyclo_dense(Matrix_dense):
10361036
"""
10371037
cdef Py_ssize_t i
10381038
cdef Matrix_rational_dense mat = self._matrix
1039-
cdef fmpq * entry
10401039
cdef mpq_t tmp
10411040

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

1201-
# This is an approximation to 2^(5/6*log_2(5) - 2/3*log_2(6))
1202-
alpha = RealNumber('1.15799718800731')
12031200
# This is 2*e^(1-(2(7\gamma-4))/(13(3-2\gamma))), where \gamma
12041201
# is Euler's constant.
12051202
delta = RealNumber('5.418236')
@@ -1333,20 +1330,20 @@ cdef class Matrix_cyclo_dense(Matrix_dense):
13331330
[4 0 0]
13341331
[0 0 0]
13351332
"""
1336-
tm = verbose("Computing characteristic polynomial of cyclotomic matrix modulo %s."%p)
1333+
tm = verbose("Computing characteristic polynomial of cyclotomic matrix modulo %s." % p)
13371334
# Reduce self modulo all primes over p
1338-
R, denom = self._reductions(p)
1335+
R, _ = self._reductions(p)
13391336
# Compute the characteristic polynomial of each reduced matrix
13401337
F = [A.charpoly('x') for A in R]
13411338
# Put the characteristic polynomials together as the rows of a mod-p matrix
13421339
k = R[0].base_ring()
1343-
S = matrix(k, len(F), self.nrows()+1, [f.list() for f in F])
1340+
S = matrix(k, len(F), self.nrows() + 1, [f.list() for f in F])
13441341
# multiply by inverse of reduction matrix to lift
13451342
_, L = self._reduction_matrix(p)
13461343
X = L * S
13471344
# Now the columns of the matrix X define the entries of the
13481345
# charpoly modulo p.
1349-
verbose("Finished computing charpoly mod %s."%p, tm)
1346+
verbose("Finished computing charpoly mod %s." % p, tm)
13501347
return X
13511348

13521349
def _charpoly_multimodular(self, var='x', proof=None):
@@ -1676,7 +1673,6 @@ cdef class Matrix_cyclo_dense(Matrix_dense):
16761673
[ 1 0 7/19]
16771674
[ 0 1 3/19]
16781675
"""
1679-
cdef int i
16801676
cdef Matrix_cyclo_dense res
16811677
cdef bint is_square
16821678

@@ -1827,14 +1823,11 @@ cdef class Matrix_cyclo_dense(Matrix_dense):
18271823
Traceback (most recent call last):
18281824
...
18291825
ValueError: echelon form mod 7 not defined
1830-
18311826
"""
1832-
cdef Matrix_cyclo_dense res
18331827
cdef int i
18341828

18351829
# Initialize variables
1836-
is_square = self._nrows == self._ncols
1837-
ls, denom = self._reductions(p)
1830+
ls, _ = self._reductions(p)
18381831

18391832
# Find our first echelon form, and the associated list
18401833
# of pivots
@@ -1936,13 +1929,11 @@ cdef class Matrix_cyclo_dense(Matrix_dense):
19361929
X = R._generator_matrix()
19371930
d = self._degree
19381931
MS = MatrixSpace(QQ, d, d)
1939-
mlst = self.list()
19401932
for c in self._matrix.columns():
19411933
v = c.list()
19421934
for n in range(d-1):
19431935
c = c * X
19441936
v += c.list()
1945-
temp = MS(v)
19461937
rmul = MS([v[d*i+j] for j in range(d) for i in range(d)]) # We take the transpose
19471938
l.append(rmul * A._rational_matrix())
19481939

src/sage/matrix/matrix_integer_dense.pyx

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,6 @@ cdef class Matrix_integer_dense(Matrix_dense):
520520
# TODO: *maybe* redo this to use mpz_import and mpz_export
521521
# from sec 5.14 of the GMP manual. ??
522522
cdef int i, j, len_so_far, m, n
523-
cdef char *a
524523
cdef char *s
525524
cdef char *t
526525
cdef char *tmp
@@ -1537,17 +1536,13 @@ cdef class Matrix_integer_dense(Matrix_dense):
15371536
"""
15381537
cdef Integer h
15391538
cdef Matrix_integer_dense left = <Matrix_integer_dense>self
1540-
cdef mod_int *moduli
1541-
cdef int i, n, k
1539+
cdef int i, k
15421540

15431541
nr = left._nrows
15441542
nc = right._ncols
1545-
snc = left._ncols
1546-
15471543

15481544
cdef Matrix_integer_dense result
15491545

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

16031598
cdef Py_ssize_t i, j
1604-
cdef mpz_t* self_row
16051599

16061600
cdef float* res_row_f
16071601
cdef Matrix_modn_dense_float res_f
@@ -2015,7 +2009,7 @@ cdef class Matrix_integer_dense(Matrix_dense):
20152009
if ans is not None:
20162010
return ans
20172011

2018-
cdef Matrix_integer_dense H_m,w,U
2012+
cdef Matrix_integer_dense H_m, U
20192013
cdef Py_ssize_t nr, nc, n, i, j
20202014
nr = self._nrows
20212015
nc = self._ncols
@@ -3757,7 +3751,6 @@ cdef class Matrix_integer_dense(Matrix_dense):
37573751
if not self.is_square():
37583752
raise ValueError("self must be a square matrix")
37593753

3760-
cdef Py_ssize_t n = self.nrows()
37613754
cdef Integer det = Integer()
37623755
cdef fmpz_t e
37633756

@@ -4884,7 +4877,7 @@ cdef class Matrix_integer_dense(Matrix_dense):
48844877
[ 0 0 545], [0, 1, 2]
48854878
)
48864879
"""
4887-
cdef Py_ssize_t i, j, piv, n = self._nrows, m = self._ncols
4880+
cdef Py_ssize_t i, j, n = self._nrows, m = self._ncols
48884881

48894882
from .constructor import matrix
48904883

@@ -5380,9 +5373,8 @@ cdef class Matrix_integer_dense(Matrix_dense):
53805373
n = ns + na
53815374

53825375
cdef Matrix_integer_dense Z
5383-
Z = self.new_matrix(nrows = m, ncols = n)
5384-
cdef Py_ssize_t i, j, p, qs, qa
5385-
p, qs, qa = 0, 0, 0
5376+
Z = self.new_matrix(nrows=m, ncols=n)
5377+
cdef Py_ssize_t i, j
53865378
for i from 0 <= i < m:
53875379
for j from 0 <= j < ns:
53885380
fmpz_set(fmpz_mat_entry(Z._matrix,i,j),
@@ -5455,7 +5447,7 @@ cdef class Matrix_integer_dense(Matrix_dense):
54555447
Return matrix obtained from self by deleting all zero columns along
54565448
with the positions of those columns.
54575449
5458-
OUTPUT: matrix list of integers
5450+
OUTPUT: (matrix, list of integers)
54595451
54605452
EXAMPLES::
54615453
@@ -5468,10 +5460,9 @@ cdef class Matrix_integer_dense(Matrix_dense):
54685460
[-1 5], [1]
54695461
)
54705462
"""
5471-
C = self.columns()
5472-
zero_cols = [i for i,v in enumerate(self.columns()) if v.is_zero()]
5463+
zero_cols = [i for i, v in enumerate(self.columns()) if v.is_zero()]
54735464
s = set(zero_cols)
5474-
nonzero_cols = [i for i in range(self.ncols()) if not (i in s)]
5465+
nonzero_cols = [i for i in range(self.ncols()) if i not in s]
54755466
return self.matrix_from_columns(nonzero_cols), zero_cols
54765467

54775468
def _insert_zero_columns(self, cols):

0 commit comments

Comments
 (0)