Skip to content

Commit

Permalink
fix E502 in pyx files inside matrix/ and some other folders
Browse files Browse the repository at this point in the history
  • Loading branch information
fchapoton committed Dec 11, 2022
1 parent bb7ee85 commit 04ac04c
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 101 deletions.
6 changes: 3 additions & 3 deletions src/sage/coding/binary_code.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4104,7 +4104,7 @@ cdef class BinaryCodeClassifier:

m_aut_gp_gens, m_labeling, m_size, m_base = self._aut_gp_and_can_label(m)
from sage.arith.all import factorial
if True:#size*factorial(n-B.ncols) == m_size:
if True: # size*factorial(n-B.ncols) == m_size:

if len(m_aut_gp_gens) == 0:
aut_m = PermutationGroup([()])
Expand All @@ -4116,8 +4116,8 @@ cdef class BinaryCodeClassifier:
else:
aut_B_aug = PermutationGroup([PermutationGroupElement([a+1 for a in g]) for g in aug_aut_gp_gens])
H = aut_m._gap_(gap).Intersection2(aut_B_aug._gap_(gap))
rt_transversal = list(gap('List(RightTransversal( %s,%s ));'\
%(str(aut_B_aug.__interface[gap]),str(H))))
rt_transversal = list(gap('List(RightTransversal( %s,%s ));'
% (str(aut_B_aug.__interface[gap]), str(H))))
rt_transversal = [PermutationGroupElement(g) for g in rt_transversal if str(g) != '()']
rt_transversal = [[a-1 for a in g.domain()] for g in rt_transversal]
rt_transversal = [g + list(xrange(len(g), n))
Expand Down
4 changes: 2 additions & 2 deletions src/sage/groups/libgap_wrapper.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ cdef class ElementLibGAP(MultiplicativeGroupElement):
True
"""
P = (<ElementLibGAP> left)._parent
return P.element_class(P, (<ElementLibGAP> left)._libgap * \
return P.element_class(P, (<ElementLibGAP> left)._libgap *
(<ElementLibGAP> right)._libgap)

cpdef _richcmp_(left, right, int op):
Expand Down Expand Up @@ -669,7 +669,7 @@ cdef class ElementLibGAP(MultiplicativeGroupElement):
False
"""
P = (<ElementLibGAP> left)._parent
return P.element_class(P, (<ElementLibGAP> left)._libgap / \
return P.element_class(P, (<ElementLibGAP> left)._libgap /
(<ElementLibGAP> right)._libgap)

def __pow__(self, n, dummy):
Expand Down
2 changes: 1 addition & 1 deletion src/sage/libs/gap/element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1847,7 +1847,7 @@ cdef class GapElement_FiniteField(GapElement):
if ring is None:
from sage.rings.finite_rings.finite_field_constructor import GF
ring = GF(char**deg, name=var)
elif not (ring.is_field() and ring.is_finite() and \
elif not (ring.is_field() and ring.is_finite() and
ring.characteristic() == char and ring.degree() % deg == 0):
raise ValueError(('the given ring is incompatible (must be a '
'finite field of characteristic {} and degree '
Expand Down
13 changes: 6 additions & 7 deletions src/sage/libs/singular/function.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -459,10 +459,11 @@ cdef ring* access_singular_ring(r) except <ring*> -1:
cdef poly* copy_sage_polynomial_into_singular_poly(p):
return p_Copy(access_singular_poly(p), access_singular_ring(p.parent()))


def all_vectors(s):
"""
Checks if a sequence ``s`` consists of free module
elements over a singular ring.
Check if a sequence ``s`` consists of free module elements
over a singular ring.
EXAMPLES::
Expand All @@ -478,11 +479,9 @@ def all_vectors(s):
sage: all_vectors([M(0), M((x,y)),(0,0)])
False
"""
for p in s:
if not (isinstance(p, FreeModuleElement_generic_dense)\
and is_sage_wrapper_for_singular_ring(p.parent().base_ring())):
return False
return True
return all(isinstance(p, FreeModuleElement_generic_dense)
and is_sage_wrapper_for_singular_ring(p.parent().base_ring())
for p in s)


cdef class Converter(SageObject):
Expand Down
25 changes: 13 additions & 12 deletions src/sage/matrix/matrix2.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -8695,8 +8695,8 @@ cdef class Matrix(Matrix1):
nrows = self._nrows - row
if ncols == -1:
ncols = self._ncols - col
if check and (row < 0 or col < 0 or row + nrows > self._nrows or \
col + ncols > self._ncols):
if check and (row < 0 or col < 0 or row + nrows > self._nrows or
col + ncols > self._ncols):
raise IndexError("matrix window index out of range")
return matrix_window.MatrixWindow(self, row, col, nrows, ncols)

Expand Down Expand Up @@ -9270,7 +9270,7 @@ cdef class Matrix(Matrix1):
if density >= 1:
for i from 0 <= i < self._nrows:
for j from 0 <= j < self._ncols:
self.set_unsafe(i, j, R._random_nonzero_element(*args,\
self.set_unsafe(i, j, R._random_nonzero_element(*args,
**kwds))
else:
num = int(self._nrows * self._ncols * density)
Expand Down Expand Up @@ -11262,16 +11262,17 @@ cdef class Matrix(Matrix1):
while ranks[i] > ranks[i+1] and ranks[i+1] > n-mult:
C = B*C
ranks.append(C.rank())
i = i+1
i += 1
diagram = [ranks[i]-ranks[i+1] for i in xrange(len(ranks)-1)]
blocks.extend([(eval, i) \
for i in Partition(diagram).conjugate()])
blocks.extend([(eval, i)
for i in Partition(diagram).conjugate()])

# ``J`` is the matrix in Jordan canonical form. Note that the blocks
# are ordered firstly by the eigenvalues, in the same order as obeyed
# by ``.roots()``, and secondly by size from greatest to smallest.
J = block_diagonal_matrix([jordan_block(eval, size, sparse=sparse) \
for (eval, size) in blocks], subdivide=subdivide)
J = block_diagonal_matrix([jordan_block(eval, size, sparse=sparse)
for (eval, size) in blocks],
subdivide=subdivide)

if transformation:
from itertools import groupby
Expand All @@ -11287,15 +11288,15 @@ cdef class Matrix(Matrix1):
# Let B be the matrix `A - eval Id`.
B = A - eval

block_sizes = [size for e,size in blocks if e == eval]
block_size_pairs = [(val,len(list(c))) \
for val,c in groupby(block_sizes)]
block_sizes = [size for e, size in blocks if e == eval]
block_size_pairs = [(val, len(list(c)))
for val, c in groupby(block_sizes)]

# Y is a list of vectors, spanning everything that we have
# covered by the Jordan chains we developed so far.
Y = []

for l,count in block_size_pairs:
for l, count in block_size_pairs:

# There are ``count`` Jordan blocks of size ``l``
# associated to this eigenvalue.
Expand Down
16 changes: 9 additions & 7 deletions src/sage/matrix/matrix_cyclo_dense.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ cdef class Matrix_cyclo_dense(Matrix_dense):
mpq_clear(tmp)
sig_off()

def randomize(self, density=1, num_bound=2, den_bound=2, \
def randomize(self, density=1, num_bound=2, den_bound=2,
distribution=None, nonzero=False, *args, **kwds):
r"""
Randomize the entries of ``self``.
Expand Down Expand Up @@ -1118,7 +1118,7 @@ cdef class Matrix_cyclo_dense(Matrix_dense):
for col in range(self._matrix._ncols):
col_is_zero = True
while col_is_zero:
self._randomize_rational_column_unsafe(col, B.value, \
self._randomize_rational_column_unsafe(col, B.value,
C.value, distribution)
# Check whether the new column is non-zero
for i in range(self._degree):
Expand All @@ -1131,7 +1131,7 @@ cdef class Matrix_cyclo_dense(Matrix_dense):
col = rstate.c_random() % self._matrix._ncols
col_is_zero = True
while col_is_zero:
self._randomize_rational_column_unsafe(col, B.value, \
self._randomize_rational_column_unsafe(col, B.value,
C.value, distribution)
# Check whether the new column is non-zero
for i in range(self._degree):
Expand All @@ -1141,25 +1141,27 @@ cdef class Matrix_cyclo_dense(Matrix_dense):
else:
if density >= 1:
for col in range(self._matrix._ncols):
self._randomize_rational_column_unsafe(col, B.value, \
self._randomize_rational_column_unsafe(col, B.value,
C.value, distribution)
else:
num = int(self._nrows * self._ncols * density)
for k in range(num):
col = rstate.c_random() % self._matrix._ncols
self._randomize_rational_column_unsafe(col, B.value, \
self._randomize_rational_column_unsafe(col, B.value,
C.value, distribution)

def _charpoly_bound(self):
"""
Determine a bound for the coefficients of the characteristic
polynomial of self. We use the bound in Lemma 2.2 of:
polynomial of ``self``.
We use the bound in Lemma 2.2 of:
Dumas, J-G. "Bounds on the coefficients of characteristic
and minimal polynomials." J. Inequal. Pure Appl. Math. 8
(2007), no. 2.
This bound only applies for `self._nrows >= 4`, so in all
This bound only applies for ``self._nrows >= 4``, so in all
smaller cases, we just use a naive bound.
EXAMPLES::
Expand Down
12 changes: 6 additions & 6 deletions src/sage/matrix/matrix_integer_dense.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3416,7 +3416,7 @@ cdef class Matrix_integer_dense(Matrix_dense):
from .misc import matrix_integer_dense_rational_reconstruction
return matrix_integer_dense_rational_reconstruction(self, N)

def randomize(self, density=1, x=None, y=None, distribution=None, \
def randomize(self, density=1, x=None, y=None, distribution=None,
nonzero=False):
"""
Randomize ``density`` proportion of the entries of this matrix,
Expand Down Expand Up @@ -3487,16 +3487,16 @@ cdef class Matrix_integer_dense(Matrix_dense):
if density == 1:
for i from 0 <= i < self._nrows:
for j from 0 <= j < self._ncols:
the_integer_ring._randomize_mpz(tmp, x, y, \
distribution)
the_integer_ring._randomize_mpz(tmp, x, y,
distribution)
self.set_unsafe_mpz(i,j,tmp)
else:
nc = self._ncols
num_per_row = int(density * nc)
for i from 0 <= i < self._nrows:
for j from 0 <= j < num_per_row:
k = rstate.c_random()%nc
the_integer_ring._randomize_mpz(tmp, \
the_integer_ring._randomize_mpz(tmp,
x, y, distribution)
self.set_unsafe_mpz(i,k,tmp)
sig_off()
Expand All @@ -3509,7 +3509,7 @@ cdef class Matrix_integer_dense(Matrix_dense):
for i from 0 <= i < self._nrows:
for j from 0 <= j < self._ncols:
while fmpz_sgn(fmpz_mat_entry(self._matrix,i,j)) == 0:
the_integer_ring._randomize_mpz(tmp, \
the_integer_ring._randomize_mpz(tmp,
x, y, distribution)
self.set_unsafe_mpz(i,j,tmp)
else:
Expand All @@ -3519,7 +3519,7 @@ cdef class Matrix_integer_dense(Matrix_dense):
for j from 0 <= j < num_per_row:
k = rstate.c_random() % nc
while fmpz_sgn(fmpz_mat_entry(self._matrix,i,k)) == 0:
the_integer_ring._randomize_mpz(tmp,\
the_integer_ring._randomize_mpz(tmp,
x, y, distribution)
self.set_unsafe_mpz(i,k,tmp)

Expand Down
Loading

0 comments on commit 04ac04c

Please sign in to comment.