Skip to content

Commit 92e94d9

Browse files
committed
some care for unused variables in matrix/
1 parent 4103129 commit 92e94d9

9 files changed

+33
-47
lines changed

src/sage/matrix/args.pyx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,6 @@ cdef class MatrixArgs:
739739
"""
740740
self.finalize()
741741

742-
cdef long i
743742
cdef list L
744743
if self.typ == MA_ENTRIES_SEQ_FLAT and not convert:
745744
# Try to re-use existing list
@@ -788,7 +787,6 @@ cdef class MatrixArgs:
788787
"""
789788
self.finalize()
790789

791-
R = self.base
792790
cdef dict D = {}
793791
for t in self.iter(convert, True):
794792
se = <SparseEntry>t

src/sage/matrix/matrix_double_dense.pyx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,7 +1375,7 @@ cdef class Matrix_double_dense(Matrix_numpy_dense):
13751375
location = None
13761376
best_fit = tol
13771377
for i in range(len(ev_group)):
1378-
s, m, avg = ev_group[i]
1378+
_, m, avg = ev_group[i]
13791379
d = numpy.abs(avg - e)
13801380
if d < best_fit:
13811381
best_fit = d
@@ -1739,14 +1739,13 @@ cdef class Matrix_double_dense(Matrix_numpy_dense):
17391739
import scipy
17401740
import scipy.linalg
17411741
X = self._new(self._ncols, B.ncols())
1742-
arr, resid, rank, s = scipy.linalg.lstsq(self._matrix_numpy, B.numpy())
1742+
arr, _, _, _ = scipy.linalg.lstsq(self._matrix_numpy, B.numpy())
17431743
X._matrix_numpy = arr
17441744
return X
17451745

1746-
17471746
def determinant(self):
17481747
"""
1749-
Return the determinant of self.
1748+
Return the determinant of ``self``.
17501749
17511750
ALGORITHM:
17521751
@@ -1808,7 +1807,6 @@ cdef class Matrix_double_dense(Matrix_numpy_dense):
18081807
[]
18091808
sage: m.log_determinant()
18101809
0.0
1811-
18121810
"""
18131811
global numpy
18141812
cdef Matrix_double_dense U
@@ -1819,7 +1817,7 @@ cdef class Matrix_double_dense(Matrix_numpy_dense):
18191817
if not self.is_square():
18201818
raise ArithmeticError("self must be a square matrix")
18211819

1822-
P, L, U = self.LU()
1820+
_, _, U = self.LU()
18231821
if numpy is None:
18241822
import numpy
18251823

@@ -2490,7 +2488,7 @@ cdef class Matrix_double_dense(Matrix_numpy_dense):
24902488
return True
24912489
if numpy is None:
24922490
import numpy
2493-
cdef Py_ssize_t i, j
2491+
cdef Py_ssize_t i
24942492
cdef Matrix_double_dense T
24952493
# A matrix M is skew-hermitian iff I*M is hermitian
24962494
T = self.__mul__(1j) if skew else self.__copy__()
@@ -2500,13 +2498,13 @@ cdef class Matrix_double_dense(Matrix_numpy_dense):
25002498
hermitian = T._is_lower_triangular(tol)
25012499
if hermitian:
25022500
for i in range(T._nrows):
2503-
if abs(T.get_unsafe(i,i).imag()) > tol:
2501+
if abs(T.get_unsafe(i, i).imag()) > tol:
25042502
hermitian = False
25052503
break
25062504
self.cache(key, hermitian)
25072505
return hermitian
25082506

2509-
def is_hermitian(self, tol = 1e-12, algorithm = "naive"):
2507+
def is_hermitian(self, tol=1e-12, algorithm = "naive"):
25102508
r"""
25112509
Return ``True`` if the matrix is equal to its conjugate-transpose.
25122510

src/sage/matrix/matrix_gf2e_dense.pyx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,6 @@ cdef class Matrix_gf2e_dense(matrix_dense.Matrix_dense):
804804
cdef m4ri_word mask = (1<<(self._parent.base_ring().degree())) - 1
805805

806806
cdef randstate rstate = current_randstate()
807-
K = self._parent.base_ring()
808807

809808
if self._ncols == 0 or self._nrows == 0:
810809
return
@@ -898,7 +897,7 @@ cdef class Matrix_gf2e_dense(matrix_dense.Matrix_dense):
898897
self.cache('pivots', [])
899898
return self
900899

901-
cdef int k, n, full
900+
cdef int full
902901

903902
full = int(reduced)
904903

src/sage/matrix/matrix_gfpn_dense.pyx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ cdef class Matrix_gfpn_dense(Matrix_dense):
730730
x = self.Data.Data
731731
cdef int nr = self.Data.Nor
732732
cdef int nc = self.Data.Noc
733-
cdef int i, j, k
733+
cdef int i, j
734734

735735
FfSetField(fl)
736736
FfSetNoc(nc)
@@ -1392,15 +1392,13 @@ cdef class Matrix_gfpn_dense(Matrix_dense):
13921392
True
13931393
sage: M*int(-1)+M == 0
13941394
True
1395-
13961395
"""
13971396
if self.Data == NULL:
13981397
raise ValueError("The matrix must not be empty")
1399-
cdef Matrix_gfpn_dense left
14001398
FfSetField(self.Data.Field)
14011399
cdef FEL r
14021400
with cython.cdivision(False):
1403-
r = FfFromInt(n%FfChar)
1401+
r = FfFromInt(n % FfChar)
14041402
sig_on()
14051403
try:
14061404
mat = MatDup(self.Data)

src/sage/matrix/matrix_integer_sparse.pyx

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -182,24 +182,21 @@ cdef class Matrix_integer_sparse(Matrix_sparse):
182182
return M
183183

184184
cpdef _add_(self, right):
185-
cdef Py_ssize_t i, j
186-
cdef mpz_vector *self_row
187-
cdef mpz_vector *M_row
185+
cdef Py_ssize_t i
188186
cdef Matrix_integer_sparse M
189187

190188
M = Matrix_integer_sparse.__new__(Matrix_integer_sparse, self._parent, None, None, None)
191189
cdef mpz_t mul
192190
mpz_init_set_si(mul,1)
193-
for i from 0 <= i < self._nrows:
191+
for i in range(self._nrows):
194192
mpz_vector_clear(&M._matrix[i])
195-
add_mpz_vector_init(&M._matrix[i], &self._matrix[i], &(<Matrix_integer_sparse>right)._matrix[i], mul)
193+
add_mpz_vector_init(&M._matrix[i], &self._matrix[i],
194+
&(<Matrix_integer_sparse>right)._matrix[i], mul)
196195
mpz_clear(mul)
197196
return M
198197

199198
cpdef _sub_(self, right):
200-
cdef Py_ssize_t i, j
201-
cdef mpz_vector *self_row
202-
cdef mpz_vector *M_row
199+
cdef Py_ssize_t i
203200
cdef Matrix_integer_sparse M
204201

205202
M = Matrix_integer_sparse.__new__(Matrix_integer_sparse, self._parent, None, None, None)
@@ -214,6 +211,7 @@ cdef class Matrix_integer_sparse(Matrix_sparse):
214211
def _dict(self):
215212
"""
216213
Unsafe version of the dict method, mainly for internal use.
214+
217215
This may return the dict of elements, but as an *unsafe*
218216
reference to the underlying dict of the object. It might
219217
be dangerous if you change entries of the returned dict.
@@ -222,13 +220,13 @@ cdef class Matrix_integer_sparse(Matrix_sparse):
222220
if d is not None:
223221
return d
224222

225-
cdef Py_ssize_t i, j, k
223+
cdef Py_ssize_t i, j
226224
d = {}
227-
for i from 0 <= i < self._nrows:
228-
for j from 0 <= j < self._matrix[i].num_nonzero:
225+
for i in range(self._nrows):
226+
for j in range(self._matrix[i].num_nonzero):
229227
x = Integer()
230228
mpz_set((<Integer>x).value, self._matrix[i].entries[j])
231-
d[(int(i),int(self._matrix[i].positions[j]))] = x
229+
d[(int(i), int(self._matrix[i].positions[j]))] = x
232230
self.cache('dict', d)
233231
return d
234232

src/sage/matrix/matrix_rational_sparse.pyx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -303,13 +303,13 @@ cdef class Matrix_rational_sparse(Matrix_sparse):
303303
if d is not None:
304304
return d
305305

306-
cdef Py_ssize_t i, j, k
306+
cdef Py_ssize_t i, j
307307
d = {}
308-
for i from 0 <= i < self._nrows:
309-
for j from 0 <= j < self._matrix[i].num_nonzero:
308+
for i in range(self._nrows):
309+
for j in range(self._matrix[i].num_nonzero):
310310
x = Rational()
311311
mpq_set((<Rational>x).value, self._matrix[i].entries[j])
312-
d[(int(i),int(self._matrix[i].positions[j]))] = x
312+
d[(int(i), int(self._matrix[i].positions[j]))] = x
313313
self.cache('dict', d)
314314
return d
315315

@@ -396,25 +396,23 @@ cdef class Matrix_rational_sparse(Matrix_sparse):
396396
return 0
397397

398398
cdef int mpz_denom(self, mpz_t d) except -1:
399-
mpz_set_si(d,1)
399+
mpz_set_si(d, 1)
400400
cdef Py_ssize_t i, j
401-
cdef mpq_vector *v
402401

403402
sig_on()
404-
for i from 0 <= i < self._nrows:
405-
for j from 0 <= j < self._matrix[i].num_nonzero:
403+
for i in range(self._nrows):
404+
for j in range(self._matrix[i].num_nonzero):
406405
mpz_lcm(d, d, mpq_denref(self._matrix[i].entries[j]))
407406
sig_off()
408407
return 0
409408

410-
411409
def denominator(self):
412410
"""
413411
Return the denominator of this matrix.
414412
415413
OUTPUT:
416414
417-
-- Sage Integer
415+
- Sage Integer
418416
419417
EXAMPLES::
420418

src/sage/matrix/matrix_sparse.pyx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,10 @@ cdef class Matrix_sparse(matrix.Matrix):
363363
return data, version
364364

365365
def _unpickle_generic(self, data, int version):
366-
cdef Py_ssize_t i, j, k
366+
cdef Py_ssize_t i, j
367367
if version == -1:
368-
for ij, x in data.iteritems():
369-
self.set_unsafe(ij[0], ij[1], x)
368+
for (i, j), x in data.iteritems():
369+
self.set_unsafe(i, j, x)
370370
else:
371371
raise RuntimeError("unknown matrix version (=%s)" % version)
372372

@@ -929,7 +929,6 @@ cdef class Matrix_sparse(matrix.Matrix):
929929

930930
cdef Py_ssize_t nrows, ncols,k,r,i,j
931931

932-
r = 0
933932
ncols = PyList_GET_SIZE(columns)
934933
nrows = PyList_GET_SIZE(rows)
935934
cdef Matrix_sparse A = self.new_matrix(nrows = nrows, ncols = ncols)
@@ -963,7 +962,7 @@ cdef class Matrix_sparse(matrix.Matrix):
963962
i = get_ij(nz, k, 0)
964963
j = get_ij(nz, k, 1)
965964
if i in row_map and j in col_map:
966-
entry = self.get_unsafe(i,j)
965+
entry = self.get_unsafe(i, j)
967966
for new_row in row_map[i]:
968967
for new_col in col_map[j]:
969968
A.set_unsafe(new_row, new_col, entry)

src/sage/matrix/matrix_window.pyx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,14 @@ cdef class MatrixWindow:
104104

105105
def __getitem__(self, ij):
106106
cdef Py_ssize_t i, j
107-
cdef object x
108107

109108
if isinstance(ij, tuple):
110109
# ij is a tuple, so we get i and j efficiently, construct corresponding integer entry.
111110
if PyTuple_Size(ij) != 2:
112111
raise IndexError("index must be an integer or pair of integers")
113112
i = <object> PyTuple_GET_ITEM(ij, 0)
114113
j = <object> PyTuple_GET_ITEM(ij, 1)
115-
if i<0 or i >= self._nrows or j<0 or j >= self._ncols:
114+
if i < 0 or i >= self._nrows or j < 0 or j >= self._ncols:
116115
raise IndexError("matrix index out of range")
117116
return self.get_unsafe(i, j)
118117
else:

src/sage/matrix/strassen.pyx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ cdef strassen_window_multiply_c(MatrixWindow C, MatrixWindow A,
9898

9999
cdef MatrixWindow S0, S1, S2, S3, T0, T1 ,T2, T3, P0, P1, P2, P3, P4, P5, P6, U0, U1, U2, U3, U4, U5, U6
100100
cdef MatrixWindow X, Y
101-
cdef Py_ssize_t tmp_cols, start_row
102101
X = A.new_empty_window(A_sub_nrows, max(A_sub_ncols,B_sub_ncols))
103102
Y = B.new_empty_window(A_sub_ncols, B_sub_ncols)
104103

0 commit comments

Comments
 (0)