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

minor pep8 details in various cython files #39823

Merged
merged 2 commits into from
Apr 2, 2025
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
2 changes: 1 addition & 1 deletion src/sage/algebras/quatalg/quaternion_algebra_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ cdef class QuaternionAlgebraElement_abstract(AlgebraElement):
"""
if base_map is None:
base_map = lambda v: v
return sum(base_map(c)*g for c,g in zip(self, [1] + list(im_gens)))
return sum(base_map(c) * g for c, g in zip(self, [1] + list(im_gens)))


cdef class QuaternionAlgebraElement_generic(QuaternionAlgebraElement_abstract):
Expand Down
6 changes: 3 additions & 3 deletions src/sage/coding/ag_code_decoders.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1800,7 +1800,7 @@ cdef class Decoder_K():
h = [W.zero() for k in range(gamma)]
for j in range(code_length):
t = delta[j]
h[<Py_ssize_t> t[1]] += matinv[i,j] * x**(<int> t[0])
h[<Py_ssize_t> t[1]] += matinv[i, j] * x**(<int> t[0])
vecs[i] = vector(h)


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

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

if verbose:
Expand Down
2 changes: 1 addition & 1 deletion src/sage/coding/codecan/codecan.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ cdef class PartitionRefinementLinearCode(PartitionRefinement_generic):
This graph will be later used in the refinement procedures.
"""
cdef FFSS_projPoint iter = FFSS_projPoint(self._matrix)
cdef mp_bitcnt_t i,j
cdef mp_bitcnt_t i, j

ambient_space = (self._matrix.base_ring()) ** (self._n)
weights2size = [0] * (self.len() + 1)
Expand Down
41 changes: 20 additions & 21 deletions src/sage/crypto/boolean_function.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,11 @@ cdef class BooleanFunction(SageObject):
if isinstance(x, str):
L = ZZ(len(x))
if L.is_power_of(2):
x = ZZ("0x"+x).digits(base=2,padto=4*L)
x = ZZ("0x" + x).digits(base=2, padto=4*L)
else:
raise ValueError("the length of the truth table must be a power of 2")
from types import GeneratorType
if isinstance(x, (list,tuple,GeneratorType)):
if isinstance(x, (list, tuple, GeneratorType)):
# initialisation from a truth table

# first, check the length
Expand Down Expand Up @@ -336,14 +336,15 @@ cdef class BooleanFunction(SageObject):
FiniteField_givaro = ()
if isinstance(K, FiniteField_givaro): # the ordering is not the same in this case
for u in K:
bitset_set_to(self._truth_table, ZZ(u._vector_().list(),2), (x(u)).trace())
bitset_set_to(self._truth_table,
ZZ(u._vector_().list(), 2), (x(u)).trace())
else:
for i,u in enumerate(K):
for i, u in enumerate(K):
bitset_set_to(self._truth_table, i, (x(u)).trace())
elif isinstance(x, BooleanFunction):
self._nvariables = x.nvariables()
bitset_init(self._truth_table, <mp_bitcnt_t> (1<<self._nvariables))
bitset_copy(self._truth_table,(<BooleanFunction>x)._truth_table)
bitset_copy(self._truth_table, (<BooleanFunction>x)._truth_table)
else:
raise TypeError("unable to init the Boolean function")

Expand Down Expand Up @@ -507,7 +508,7 @@ cdef class BooleanFunction(SageObject):
bitset_copy(anf, self._truth_table)
reed_muller(anf.bits, ZZ(anf.limbs).exact_log(2))
from sage.rings.polynomial.pbori.pbori import BooleanPolynomialRing
R = BooleanPolynomialRing(self._nvariables,"x")
R = BooleanPolynomialRing(self._nvariables, "x")
G = R.gens()
P = R(0)

Expand All @@ -517,7 +518,7 @@ cdef class BooleanFunction(SageObject):
inf = i*sizeof(long)*8
sup = min((i+1)*sizeof(long)*8, (1<<self._nvariables))
for j in range(inf, sup):
if bitset_in(anf,j):
if bitset_in(anf, j):
m = R(1)
for k in range(self._nvariables):
if (j>>k)&1:
Expand Down Expand Up @@ -592,9 +593,9 @@ cdef class BooleanFunction(SageObject):
if format == 'bin':
return tuple(self)
if format == 'int':
return tuple(map(int,self))
return tuple(map(int, self))
if format == 'hex':
S = ZZ(self.truth_table(),2).str(16)
S = ZZ(self.truth_table(), 2).str(16)
S = "0"*((1<<(self._nvariables-2)) - len(S)) + S
return S
raise ValueError("unknown output format")
Expand Down Expand Up @@ -713,7 +714,7 @@ cdef class BooleanFunction(SageObject):
(0, -4, 0, 4, 0, 4, 0, 4)
"""
cdef long *temp
cdef mp_bitcnt_t i,n
cdef mp_bitcnt_t i, n

if self._walsh_hadamard_transform is None:
n = self._truth_table.size
Expand Down Expand Up @@ -1010,7 +1011,7 @@ cdef class BooleanFunction(SageObject):
"""
# NOTE: this is a toy implementation
from sage.rings.polynomial.polynomial_ring_constructor import BooleanPolynomialRing_constructor
R = BooleanPolynomialRing_constructor(self._nvariables,'x')
R = BooleanPolynomialRing_constructor(self._nvariables, 'x')
G = R.gens()
r = [R(1)]

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

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

cdef long i
for i in range(1, d+1):
Expand All @@ -1036,23 +1038,20 @@ cdef class BooleanFunction(SageObject):
cdef long j
cdef mp_bitcnt_t v

for i,m in enumerate(r):
for i, m in enumerate(r):
t = BooleanFunction(m)
for j,v in enumerate(s):
for j, v in enumerate(s):
sig_check()
M[i,j] = bitset_in(t._truth_table,v)
M[i, j] = bitset_in(t._truth_table, v)

kg = M.kernel().gens()

if kg:
res = sum([kg[0][i]*ri for i,ri in enumerate(r)])
res = sum([kg[0][i]*ri for i, ri in enumerate(r)])
else:
res = None

if dim:
return res, len(kg)
else:
return res
return (res, len(kg)) if dim else res

def algebraic_immunity(self, annihilator=False):
"""
Expand Down Expand Up @@ -1483,5 +1482,5 @@ def random_boolean_function(n):
T[0] = B._truth_table[0]
for i in range(T.limbs):
sig_check()
T.bits[i] = r.randrange(0,Integer(1)<<(sizeof(unsigned long)*8))
T.bits[i] = r.randrange(0, Integer(1)<<(sizeof(unsigned long)*8))
return B
16 changes: 8 additions & 8 deletions src/sage/geometry/polyhedron/combinatorial_polyhedron/base.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1467,14 +1467,14 @@ cdef class CombinatorialPolyhedron(SageObject):

if add_equations and names:
return tuple(
((f(self._ridges.get(i).first),) + self.equations(),
(f(self._ridges.get(i).second),) + self.equations())
for i in range (n_ridges))
else:
return tuple(
(f(self._ridges.get(i).first),
f(self._ridges.get(i).second))
for i in range (n_ridges))
((f(self._ridges.get(i).first),) + self.equations(),
(f(self._ridges.get(i).second),) + self.equations())
for i in range(n_ridges))

return tuple(
(f(self._ridges.get(i).first),
f(self._ridges.get(i).second))
for i in range(n_ridges))

@cached_method
def facet_adjacency_matrix(self, algorithm=None):
Expand Down
8 changes: 4 additions & 4 deletions src/sage/modules/vector_integer_sparse.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ cdef Py_ssize_t mpz_binary_search0(mpz_t* v, Py_ssize_t n, mpz_t x) noexcept:
j = n-1
while i<=j:
if i == j:
if mpz_cmp(v[i],x) == 0:
if mpz_cmp(v[i], x) == 0:
return i
return -1
k = (i+j)/2
c = mpz_cmp(v[k],x)
c = mpz_cmp(v[k], x)
if c > 0: # v[k] > x
j = k-1
elif c < 0: # v[k] < x
Expand Down Expand Up @@ -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
return -1
i = 0
j = n-1
while i<=j:
while i <= j:
if i == j:
c = mpz_cmp(v[i],x)
c = mpz_cmp(v[i], x)
if c == 0: # v[i] == x
ins[0] = i
return i
Expand Down
2 changes: 1 addition & 1 deletion src/sage/modules/vector_mod2_dense.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ cdef class Vector_mod2_dense(free_module_element.FreeModuleElement):
K = self.base_ring()
z = K.zero()
o = K.one()
cdef list switch = [z,o]
cdef list switch = [z, o]
for i in range(d):
v[i] = switch[mzd_read_bit(self._entries, 0, i)]
return v
Expand Down
10 changes: 5 additions & 5 deletions src/sage/modules/vector_rational_sparse.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ cdef Py_ssize_t mpq_binary_search0(mpq_t* v, Py_ssize_t n, mpq_t x) noexcept:
j = n-1
while i<=j:
if i == j:
if mpq_equal(v[i],x):
if mpq_equal(v[i], x):
return i
return -1
k = (i+j)/2
c = mpq_cmp(v[k],x)
c = mpq_cmp(v[k], x)
if c > 0: # v[k] > x
j = k-1
elif c < 0: # v[k] < x
Expand Down Expand Up @@ -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
j = n-1
while i<=j:
if i == j:
c = mpq_cmp(v[i],x)
c = mpq_cmp(v[i], x)
if c == 0: # v[i] == x
ins[0] = i
return i
Expand Down Expand Up @@ -147,7 +147,7 @@ cdef int mpq_vector_get_entry(mpq_t ans, mpq_vector* v, Py_ssize_t n) except -1:
cdef Py_ssize_t m
m = binary_search0(v.positions, v.num_nonzero, n)
if m == -1:
mpq_set_si(ans, 0,1)
mpq_set_si(ans, 0, 1)
return 0
mpq_set(ans, v.entries[m])
return 0
Expand Down Expand Up @@ -279,7 +279,7 @@ cdef int add_mpq_vector_init(mpq_vector* sum,

mpq_init(tmp)
# Do not do the multiply if the multiple is 1.
do_multiply = mpq_cmp_si(multiple, 1,1)
do_multiply = mpq_cmp_si(multiple, 1, 1)

z = sum
# ALGORITHM:
Expand Down
2 changes: 1 addition & 1 deletion src/sage/modules/with_basis/indexed_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ cdef class IndexedFreeModuleElement(ModuleElement):
zero = free_module.base_ring().zero()
if sparse:
if order is None:
order = {k: i for i,k in enumerate(self._parent.get_order())}
order = {k: i for i, k in enumerate(self._parent.get_order())}
return free_module.element_class(free_module,
{order[k]: c for k, c in d.items()},
coerce=True, copy=False)
Expand Down
Loading
Loading