Skip to content

Commit d4ffc89

Browse files
committed
minor pep8 details in various cython files
1 parent 8a8453f commit d4ffc89

File tree

10 files changed

+52
-53
lines changed

10 files changed

+52
-53
lines changed

src/sage/algebras/quatalg/quaternion_algebra_element.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ cdef class QuaternionAlgebraElement_abstract(AlgebraElement):
704704
"""
705705
if base_map is None:
706706
base_map = lambda v: v
707-
return sum(base_map(c)*g for c,g in zip(self, [1] + list(im_gens)))
707+
return sum(base_map(c) * g for c, g in zip(self, [1] + list(im_gens)))
708708

709709

710710
cdef class QuaternionAlgebraElement_generic(QuaternionAlgebraElement_abstract):

src/sage/coding/ag_code_decoders.pyx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1800,7 +1800,7 @@ cdef class Decoder_K():
18001800
h = [W.zero() for k in range(gamma)]
18011801
for j in range(code_length):
18021802
t = delta[j]
1803-
h[<Py_ssize_t> t[1]] += matinv[i,j] * x**(<int> t[0])
1803+
h[<Py_ssize_t> t[1]] += matinv[i, j] * x**(<int> t[0])
18041804
vecs[i] = vector(h)
18051805

18061806

@@ -2032,7 +2032,7 @@ cdef class EvaluationAGCodeDecoder_K(Decoder_K):
20322032
f = yR[i] * yRbar[j]
20332033
v = vec_form(f)
20342034
self._exponents((<int> dR[i]) + (<int> dRbar[j]), &sk, &si)
2035-
coeff_mat[i,j] = v[si][sk]
2035+
coeff_mat[i, j] = v[si][sk]
20362036
(<list> mul_mat[i])[j] = v
20372037

20382038
if verbose:
@@ -2287,7 +2287,7 @@ cdef class DifferentialAGCodeDecoder_K(Decoder_K):
22872287
f = yR[i] * wWbar[j]
22882288
v = vec_form(f)
22892289
self._exponents((<int> dR[i]) + (<int> dWbar[j]), &sk, &si)
2290-
coeff_mat[i,j] = v[si][sk]
2290+
coeff_mat[i, j] = v[si][sk]
22912291
(<list> mul_mat[i])[j] = v
22922292

22932293
if verbose:

src/sage/coding/codecan/codecan.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ cdef class PartitionRefinementLinearCode(PartitionRefinement_generic):
756756
This graph will be later used in the refinement procedures.
757757
"""
758758
cdef FFSS_projPoint iter = FFSS_projPoint(self._matrix)
759-
cdef mp_bitcnt_t i,j
759+
cdef mp_bitcnt_t i, j
760760
761761
ambient_space = (self._matrix.base_ring()) ** (self._n)
762762
weights2size = [0] * (self.len() + 1)

src/sage/crypto/boolean_function.pyx

+20-21
Original file line numberDiff line numberDiff line change
@@ -288,11 +288,11 @@ cdef class BooleanFunction(SageObject):
288288
if isinstance(x, str):
289289
L = ZZ(len(x))
290290
if L.is_power_of(2):
291-
x = ZZ("0x"+x).digits(base=2,padto=4*L)
291+
x = ZZ("0x" + x).digits(base=2, padto=4*L)
292292
else:
293293
raise ValueError("the length of the truth table must be a power of 2")
294294
from types import GeneratorType
295-
if isinstance(x, (list,tuple,GeneratorType)):
295+
if isinstance(x, (list, tuple, GeneratorType)):
296296
# initialisation from a truth table
297297

298298
# first, check the length
@@ -336,14 +336,15 @@ cdef class BooleanFunction(SageObject):
336336
FiniteField_givaro = ()
337337
if isinstance(K, FiniteField_givaro): # the ordering is not the same in this case
338338
for u in K:
339-
bitset_set_to(self._truth_table, ZZ(u._vector_().list(),2), (x(u)).trace())
339+
bitset_set_to(self._truth_table,
340+
ZZ(u._vector_().list(), 2), (x(u)).trace())
340341
else:
341-
for i,u in enumerate(K):
342+
for i, u in enumerate(K):
342343
bitset_set_to(self._truth_table, i, (x(u)).trace())
343344
elif isinstance(x, BooleanFunction):
344345
self._nvariables = x.nvariables()
345346
bitset_init(self._truth_table, <mp_bitcnt_t> (1<<self._nvariables))
346-
bitset_copy(self._truth_table,(<BooleanFunction>x)._truth_table)
347+
bitset_copy(self._truth_table, (<BooleanFunction>x)._truth_table)
347348
else:
348349
raise TypeError("unable to init the Boolean function")
349350

@@ -507,7 +508,7 @@ cdef class BooleanFunction(SageObject):
507508
bitset_copy(anf, self._truth_table)
508509
reed_muller(anf.bits, ZZ(anf.limbs).exact_log(2))
509510
from sage.rings.polynomial.pbori.pbori import BooleanPolynomialRing
510-
R = BooleanPolynomialRing(self._nvariables,"x")
511+
R = BooleanPolynomialRing(self._nvariables, "x")
511512
G = R.gens()
512513
P = R(0)
513514

@@ -517,7 +518,7 @@ cdef class BooleanFunction(SageObject):
517518
inf = i*sizeof(long)*8
518519
sup = min((i+1)*sizeof(long)*8, (1<<self._nvariables))
519520
for j in range(inf, sup):
520-
if bitset_in(anf,j):
521+
if bitset_in(anf, j):
521522
m = R(1)
522523
for k in range(self._nvariables):
523524
if (j>>k)&1:
@@ -592,9 +593,9 @@ cdef class BooleanFunction(SageObject):
592593
if format == 'bin':
593594
return tuple(self)
594595
if format == 'int':
595-
return tuple(map(int,self))
596+
return tuple(map(int, self))
596597
if format == 'hex':
597-
S = ZZ(self.truth_table(),2).str(16)
598+
S = ZZ(self.truth_table(), 2).str(16)
598599
S = "0"*((1<<(self._nvariables-2)) - len(S)) + S
599600
return S
600601
raise ValueError("unknown output format")
@@ -713,7 +714,7 @@ cdef class BooleanFunction(SageObject):
713714
(0, -4, 0, 4, 0, 4, 0, 4)
714715
"""
715716
cdef long *temp
716-
cdef mp_bitcnt_t i,n
717+
cdef mp_bitcnt_t i, n
717718

718719
if self._walsh_hadamard_transform is None:
719720
n = self._truth_table.size
@@ -1010,7 +1011,7 @@ cdef class BooleanFunction(SageObject):
10101011
"""
10111012
# NOTE: this is a toy implementation
10121013
from sage.rings.polynomial.polynomial_ring_constructor import BooleanPolynomialRing_constructor
1013-
R = BooleanPolynomialRing_constructor(self._nvariables,'x')
1014+
R = BooleanPolynomialRing_constructor(self._nvariables, 'x')
10141015
G = R.gens()
10151016
r = [R(1)]
10161017

@@ -1022,7 +1023,8 @@ cdef class BooleanFunction(SageObject):
10221023

10231024
from sage.matrix.constructor import Matrix
10241025
from sage.arith.misc import binomial
1025-
M = Matrix(GF(2), sum(binomial(self._nvariables,i) for i in range(d+1)), len(s))
1026+
M = Matrix(GF(2), sum(binomial(self._nvariables, i)
1027+
for i in range(d+1)), len(s))
10261028

10271029
cdef long i
10281030
for i in range(1, d+1):
@@ -1036,23 +1038,20 @@ cdef class BooleanFunction(SageObject):
10361038
cdef long j
10371039
cdef mp_bitcnt_t v
10381040

1039-
for i,m in enumerate(r):
1041+
for i, m in enumerate(r):
10401042
t = BooleanFunction(m)
1041-
for j,v in enumerate(s):
1043+
for j, v in enumerate(s):
10421044
sig_check()
1043-
M[i,j] = bitset_in(t._truth_table,v)
1045+
M[i, j] = bitset_in(t._truth_table, v)
10441046

10451047
kg = M.kernel().gens()
10461048

10471049
if kg:
1048-
res = sum([kg[0][i]*ri for i,ri in enumerate(r)])
1050+
res = sum([kg[0][i]*ri for i, ri in enumerate(r)])
10491051
else:
10501052
res = None
10511053

1052-
if dim:
1053-
return res, len(kg)
1054-
else:
1055-
return res
1054+
return res, len(kg) if dim else res
10561055

10571056
def algebraic_immunity(self, annihilator=False):
10581057
"""
@@ -1483,5 +1482,5 @@ def random_boolean_function(n):
14831482
T[0] = B._truth_table[0]
14841483
for i in range(T.limbs):
14851484
sig_check()
1486-
T.bits[i] = r.randrange(0,Integer(1)<<(sizeof(unsigned long)*8))
1485+
T.bits[i] = r.randrange(0, Integer(1)<<(sizeof(unsigned long)*8))
14871486
return B

src/sage/geometry/polyhedron/combinatorial_polyhedron/base.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1469,12 +1469,12 @@ cdef class CombinatorialPolyhedron(SageObject):
14691469
return tuple(
14701470
((f(self._ridges.get(i).first),) + self.equations(),
14711471
(f(self._ridges.get(i).second),) + self.equations())
1472-
for i in range (n_ridges))
1472+
for i in range(n_ridges))
14731473
else:
14741474
return tuple(
14751475
(f(self._ridges.get(i).first),
14761476
f(self._ridges.get(i).second))
1477-
for i in range (n_ridges))
1477+
for i in range(n_ridges))
14781478

14791479
@cached_method
14801480
def facet_adjacency_matrix(self, algorithm=None):

src/sage/modules/vector_integer_sparse.pyx

+4-4
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ cdef Py_ssize_t mpz_binary_search0(mpz_t* v, Py_ssize_t n, mpz_t x) noexcept:
6666
j = n-1
6767
while i<=j:
6868
if i == j:
69-
if mpz_cmp(v[i],x) == 0:
69+
if mpz_cmp(v[i], x) == 0:
7070
return i
7171
return -1
7272
k = (i+j)/2
73-
c = mpz_cmp(v[k],x)
73+
c = mpz_cmp(v[k], x)
7474
if c > 0: # v[k] > x
7575
j = k-1
7676
elif c < 0: # v[k] < x
@@ -103,9 +103,9 @@ cdef Py_ssize_t mpz_binary_search(mpz_t* v, Py_ssize_t n, mpz_t x, Py_ssize_t* i
103103
return -1
104104
i = 0
105105
j = n-1
106-
while i<=j:
106+
while i <= j:
107107
if i == j:
108-
c = mpz_cmp(v[i],x)
108+
c = mpz_cmp(v[i], x)
109109
if c == 0: # v[i] == x
110110
ins[0] = i
111111
return i

src/sage/modules/vector_mod2_dense.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ cdef class Vector_mod2_dense(free_module_element.FreeModuleElement):
515515
K = self.base_ring()
516516
z = K.zero()
517517
o = K.one()
518-
cdef list switch = [z,o]
518+
cdef list switch = [z, o]
519519
for i in range(d):
520520
v[i] = switch[mzd_read_bit(self._entries, 0, i)]
521521
return v

src/sage/modules/vector_rational_sparse.pyx

+5-5
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ cdef Py_ssize_t mpq_binary_search0(mpq_t* v, Py_ssize_t n, mpq_t x) noexcept:
7373
j = n-1
7474
while i<=j:
7575
if i == j:
76-
if mpq_equal(v[i],x):
76+
if mpq_equal(v[i], x):
7777
return i
7878
return -1
7979
k = (i+j)/2
80-
c = mpq_cmp(v[k],x)
80+
c = mpq_cmp(v[k], x)
8181
if c > 0: # v[k] > x
8282
j = k-1
8383
elif c < 0: # v[k] < x
@@ -112,7 +112,7 @@ cdef Py_ssize_t mpq_binary_search(mpq_t* v, Py_ssize_t n, mpq_t x, Py_ssize_t* i
112112
j = n-1
113113
while i<=j:
114114
if i == j:
115-
c = mpq_cmp(v[i],x)
115+
c = mpq_cmp(v[i], x)
116116
if c == 0: # v[i] == x
117117
ins[0] = i
118118
return i
@@ -147,7 +147,7 @@ cdef int mpq_vector_get_entry(mpq_t ans, mpq_vector* v, Py_ssize_t n) except -1:
147147
cdef Py_ssize_t m
148148
m = binary_search0(v.positions, v.num_nonzero, n)
149149
if m == -1:
150-
mpq_set_si(ans, 0,1)
150+
mpq_set_si(ans, 0, 1)
151151
return 0
152152
mpq_set(ans, v.entries[m])
153153
return 0
@@ -279,7 +279,7 @@ cdef int add_mpq_vector_init(mpq_vector* sum,
279279

280280
mpq_init(tmp)
281281
# Do not do the multiply if the multiple is 1.
282-
do_multiply = mpq_cmp_si(multiple, 1,1)
282+
do_multiply = mpq_cmp_si(multiple, 1, 1)
283283

284284
z = sum
285285
# ALGORITHM:

src/sage/modules/with_basis/indexed_element.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ cdef class IndexedFreeModuleElement(ModuleElement):
858858
zero = free_module.base_ring().zero()
859859
if sparse:
860860
if order is None:
861-
order = {k: i for i,k in enumerate(self._parent.get_order())}
861+
order = {k: i for i, k in enumerate(self._parent.get_order())}
862862
return free_module.element_class(free_module,
863863
{order[k]: c for k, c in d.items()},
864864
coerce=True, copy=False)

src/sage/rings/complex_mpc.pyx

+14-14
Original file line numberDiff line numberDiff line change
@@ -1546,7 +1546,7 @@ cdef class MPComplexNumber(sage.structure.element.FieldElement):
15461546
"""
15471547
cdef RealNumber x
15481548
x = RealNumber(self._parent._real_field())
1549-
mpc_abs (x.value, self.value, (<RealField_class>x._parent).rnd)
1549+
mpc_abs(x.value, self.value, (<RealField_class>x._parent).rnd)
15501550
return x
15511551

15521552
def norm(self):
@@ -1649,7 +1649,7 @@ cdef class MPComplexNumber(sage.structure.element.FieldElement):
16491649
"""
16501650
cdef MPComplexNumber z
16511651
z = self._new()
1652-
mpc_cos (z.value, self.value, (<MPComplexField_class>self._parent).__rnd)
1652+
mpc_cos(z.value, self.value, (<MPComplexField_class>self._parent).__rnd)
16531653
return z
16541654

16551655
def sin(self):
@@ -1669,7 +1669,7 @@ cdef class MPComplexNumber(sage.structure.element.FieldElement):
16691669
"""
16701670
cdef MPComplexNumber z
16711671
z = self._new()
1672-
mpc_sin (z.value, self.value, (<MPComplexField_class>self._parent).__rnd)
1672+
mpc_sin(z.value, self.value, (<MPComplexField_class>self._parent).__rnd)
16731673
return z
16741674

16751675
def tan(self):
@@ -1689,7 +1689,7 @@ cdef class MPComplexNumber(sage.structure.element.FieldElement):
16891689
"""
16901690
cdef MPComplexNumber z
16911691
z = self._new()
1692-
mpc_tan (z.value, self.value, (<MPComplexField_class>self._parent).__rnd)
1692+
mpc_tan(z.value, self.value, (<MPComplexField_class>self._parent).__rnd)
16931693
return z
16941694

16951695
def cosh(self):
@@ -1709,7 +1709,7 @@ cdef class MPComplexNumber(sage.structure.element.FieldElement):
17091709
"""
17101710
cdef MPComplexNumber z
17111711
z = self._new()
1712-
mpc_cosh (z.value, self.value, (<MPComplexField_class>self._parent).__rnd)
1712+
mpc_cosh(z.value, self.value, (<MPComplexField_class>self._parent).__rnd)
17131713
return z
17141714

17151715
def sinh(self):
@@ -1729,7 +1729,7 @@ cdef class MPComplexNumber(sage.structure.element.FieldElement):
17291729
"""
17301730
cdef MPComplexNumber z
17311731
z = self._new()
1732-
mpc_sinh (z.value, self.value, (<MPComplexField_class>self._parent).__rnd)
1732+
mpc_sinh(z.value, self.value, (<MPComplexField_class>self._parent).__rnd)
17331733
return z
17341734

17351735
def tanh(self):
@@ -1749,7 +1749,7 @@ cdef class MPComplexNumber(sage.structure.element.FieldElement):
17491749
"""
17501750
cdef MPComplexNumber z
17511751
z = self._new()
1752-
mpc_tanh (z.value, self.value, (<MPComplexField_class>self._parent).__rnd)
1752+
mpc_tanh(z.value, self.value, (<MPComplexField_class>self._parent).__rnd)
17531753
return z
17541754

17551755
def arccos(self):
@@ -1765,7 +1765,7 @@ cdef class MPComplexNumber(sage.structure.element.FieldElement):
17651765
"""
17661766
cdef MPComplexNumber z
17671767
z = self._new()
1768-
mpc_acos (z.value, self.value, (<MPComplexField_class>self._parent).__rnd)
1768+
mpc_acos(z.value, self.value, (<MPComplexField_class>self._parent).__rnd)
17691769
return z
17701770

17711771
def arcsin(self):
@@ -1781,7 +1781,7 @@ cdef class MPComplexNumber(sage.structure.element.FieldElement):
17811781
"""
17821782
cdef MPComplexNumber z
17831783
z = self._new()
1784-
mpc_asin (z.value, self.value, (<MPComplexField_class>self._parent).__rnd)
1784+
mpc_asin(z.value, self.value, (<MPComplexField_class>self._parent).__rnd)
17851785
return z
17861786

17871787
def arctan(self):
@@ -1797,7 +1797,7 @@ cdef class MPComplexNumber(sage.structure.element.FieldElement):
17971797
"""
17981798
cdef MPComplexNumber z
17991799
z = self._new()
1800-
mpc_atan (z.value, self.value, (<MPComplexField_class>self._parent).__rnd)
1800+
mpc_atan(z.value, self.value, (<MPComplexField_class>self._parent).__rnd)
18011801
return z
18021802

18031803
def arccosh(self):
@@ -1813,7 +1813,7 @@ cdef class MPComplexNumber(sage.structure.element.FieldElement):
18131813
"""
18141814
cdef MPComplexNumber z
18151815
z = self._new()
1816-
mpc_acosh (z.value, self.value, (<MPComplexField_class>self._parent).__rnd)
1816+
mpc_acosh(z.value, self.value, (<MPComplexField_class>self._parent).__rnd)
18171817
return z
18181818

18191819
def arcsinh(self):
@@ -1829,7 +1829,7 @@ cdef class MPComplexNumber(sage.structure.element.FieldElement):
18291829
"""
18301830
cdef MPComplexNumber z
18311831
z = self._new()
1832-
mpc_asinh (z.value, self.value, (<MPComplexField_class>self._parent).__rnd)
1832+
mpc_asinh(z.value, self.value, (<MPComplexField_class>self._parent).__rnd)
18331833
return z
18341834

18351835
def arctanh(self):
@@ -1845,7 +1845,7 @@ cdef class MPComplexNumber(sage.structure.element.FieldElement):
18451845
"""
18461846
cdef MPComplexNumber z
18471847
z = self._new()
1848-
mpc_atanh (z.value, self.value, (<MPComplexField_class>self._parent).__rnd)
1848+
mpc_atanh(z.value, self.value, (<MPComplexField_class>self._parent).__rnd)
18491849
return z
18501850

18511851
def coth(self):
@@ -2028,7 +2028,7 @@ cdef class MPComplexNumber(sage.structure.element.FieldElement):
20282028
"""
20292029
cdef MPComplexNumber z
20302030
z = self._new()
2031-
mpc_sqr (z.value, self.value, (<MPComplexField_class>self._parent).__rnd)
2031+
mpc_sqr(z.value, self.value, (<MPComplexField_class>self._parent).__rnd)
20322032
return z
20332033

20342034
def sqrt(self):

0 commit comments

Comments
 (0)