Skip to content

some fixes for E272 in pyx files #39566

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

Merged
merged 2 commits into from
Feb 28, 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
3 changes: 2 additions & 1 deletion src/sage/coding/codecan/codecan.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,8 @@ cdef class PartitionRefinementLinearCode(PartitionRefinement_generic):
else:
P = remaining_inner_group.column_blocks(self._best_candidate)
for p in P:
x = S(v=[ F.primitive_element() if i in p else F.one() for i in range(self._n) ])
x = S(v=[F.primitive_element() if i in p else F.one()
for i in range(self._n)])
self._autom_group_generators.append(transp_inv * x * self._transporter)
self._inner_group_stabilizer_order = (len(F) - 1) ** len(P)

Expand Down
4 changes: 2 additions & 2 deletions src/sage/combinat/designs/designs_pyx.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -948,12 +948,12 @@ cpdef _OA_cache_set(int k, int n, truth_value):
_OA_cache_size = new_cache_size

if truth_value is True:
_OA_cache[n].max_true = k if k>_OA_cache[n].max_true else _OA_cache[n].max_true
_OA_cache[n].max_true = k if k>_OA_cache[n].max_true else _OA_cache[n].max_true
elif truth_value is Unknown:
_OA_cache[n].min_unknown = k if k<_OA_cache[n].min_unknown else _OA_cache[n].min_unknown
_OA_cache[n].max_unknown = k if k>_OA_cache[n].max_unknown else _OA_cache[n].max_unknown
else:
_OA_cache[n].min_false = k if k<_OA_cache[n].min_false else _OA_cache[n].min_false
_OA_cache[n].min_false = k if k<_OA_cache[n].min_false else _OA_cache[n].min_false

cpdef _OA_cache_get(int k, int n):
r"""
Expand Down
24 changes: 12 additions & 12 deletions src/sage/combinat/designs/orthogonal_arrays_find_recursive.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,10 @@ cpdef find_construction_3_5(int k, int n):
for s in range(min(i+1,nn)):
for r in range(max(0,i-nn-s), min(s+1,i-s+1,nn)):
t = i - r - s
if ((nn-r-1)*(nn-s) < t and
(r==0 or is_available(k,r)) and
(s==0 or is_available(k,s)) and
(t==0 or is_available(k,t))):
if ((nn-r-1)*(nn-s) < t and
(r==0 or is_available(k, r)) and
(s==0 or is_available(k, s)) and
(t==0 or is_available(k, t))):
from sage.combinat.designs.orthogonal_arrays_build_recursive import construction_3_5
return construction_3_5, (k,nn,mm,r,s,t)

Expand Down Expand Up @@ -481,15 +481,15 @@ cpdef find_q_x(int k, int n):
x = (n-q**2+q-2)/(2-q)
if (x < q and
0 < x and
n == (q-1)*(q-x)+x+2 and
is_available(k+1,q-x-1) and
is_available(k+1,q-x+1) and
n == (q-1)*(q-x)+x+2 and
is_available(k+1, q-x-1) and
is_available(k+1, q-x+1) and
# The next is always True, because q is a prime power
# is_available(k+1,q) and
is_available(k, x+2 ) and
is_available(k, x+2 ) and
smallInteger(q).is_prime_power()):
from sage.combinat.designs.orthogonal_arrays_build_recursive import construction_q_x
return construction_q_x, (k,q,x)
return construction_q_x, (k, q, x)
return False

cpdef find_thwart_lemma_3_5(int k, int N):
Expand Down Expand Up @@ -865,11 +865,11 @@ def int_as_sum(int value, list S, int k_max):
vv = v-i
if vv == 0:
return D[v] + (i,)
if (vv > 0 and # The new integer i is too big
if (vv > 0 and # The new integer i is too big
vv <= j*max_value and # The new integer i is too small
vv not in D and # We had it in D already
vv not in D and # We had it in D already
vv not in new_D): # We had it in new_D already
new_D[vv] = D[v]+(i,)
new_D[vv] = D[v] + (i,)
if not new_D:
break
D.update(new_D)
Expand Down
18 changes: 9 additions & 9 deletions src/sage/geometry/polyhedron/combinatorial_polyhedron/base.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,22 @@ import numbers
from memory_allocator cimport MemoryAllocator
from cysignals.memory cimport check_calloc, sig_free

from sage.graphs.graph import Graph
from sage.geometry.polyhedron.base import Polyhedron_base
from sage.graphs.graph import Graph
from sage.geometry.polyhedron.base import Polyhedron_base
from sage.geometry.lattice_polytope import LatticePolytopeClass
from sage.geometry.cone import ConvexRationalPolyhedralCone
from sage.structure.element import Matrix
from sage.matrix.matrix_dense cimport Matrix_dense
from sage.misc.misc import is_iterator
from sage.geometry.cone import ConvexRationalPolyhedralCone
from sage.structure.element import Matrix
from sage.matrix.matrix_dense cimport Matrix_dense
from sage.misc.misc import is_iterator
from .conversions import (incidence_matrix_to_bit_rep_of_facets,
incidence_matrix_to_bit_rep_of_Vrep,
facets_tuple_to_bit_rep_of_facets,
facets_tuple_to_bit_rep_of_Vrep)
from sage.geometry.polyhedron.combinatorial_polyhedron.conversions cimport Vrep_list_to_bit_rep
from sage.misc.cachefunc import cached_method
from sage.misc.cachefunc import cached_method

from sage.rings.integer cimport smallInteger
from cysignals.signals cimport sig_check
from sage.rings.integer cimport smallInteger
from cysignals.signals cimport sig_check

from sage.geometry.polyhedron.combinatorial_polyhedron.face_data_structure cimport face_len_atoms, face_init, face_free
from sage.geometry.polyhedron.combinatorial_polyhedron.face_iterator cimport iter_t, parallel_f_vector
Expand Down
7 changes: 4 additions & 3 deletions src/sage/graphs/graph_decompositions/slice_decomposition.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,10 @@ cdef class SliceDecomposition(SageObject):

# Translate the results with the actual vertices of the graph
self.sigma = tuple(Gbackend.vertex_label(v_int) for v_int in sigma)
self.sigma_inv = {v: i for i, v in enumerate(self.sigma)}
self.lex_label = {i: tuple(Gbackend.vertex_label(v_int) for v_int in lli)
for i, lli in enumerate(lex_label)}
self.sigma_inv = {v: i for i, v in enumerate(self.sigma)}
self.lex_label = {i: tuple(Gbackend.vertex_label(v_int)
for v_int in lli)
for i, lli in enumerate(lex_label)}

def __eq__(self, other):
"""
Expand Down
8 changes: 4 additions & 4 deletions src/sage/graphs/strongly_regular_db.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3295,11 +3295,11 @@ def _check_database():
if _brouwer_database[params]['status'] != "impossible":
raise RuntimeError("Brouwer's db does not seem to know that {} in unfeasible".format(params))
comment = _brouwer_database[params]['comments']
if ('Krein' in comment or
if ('Krein' in comment or
'Absolute' in comment or
'Conf' in comment or
'mu=1' in comment or
'&mu;=2' in comment):
'Conf' in comment or
'mu=1' in comment or
'&mu;=2' in comment):
continue
raise RuntimeError("We detected that {} was unfeasible, but maybe we should not have".format(params))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ cdef aut_gp_and_can_lab *allocate_agcl_output(int n) noexcept:
output.relabeling = <int *> sig_malloc(n*sizeof(int))
output.generators = <int *> sig_malloc(2*n*n*sizeof(int))
output.size_of_generator_array = 2*n*n
if output.group is NULL or \
if output.group is NULL or \
output.relabeling is NULL or \
output.generators is NULL:
deallocate_agcl_output(output)
Expand Down
14 changes: 7 additions & 7 deletions src/sage/groups/perm_gps/partn_ref/data_structures.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -617,17 +617,17 @@ cdef StabilizerChain *SC_new(int n, bint init_gens=True) noexcept:
SC.OP_scratch = OP_new(n)
# bitset_init without the MemoryError:
cdef long limbs = (default_num_bits - 1)/(8*sizeof(unsigned long)) + 1
SC.gen_used.size = default_num_bits
SC.gen_is_id.size = default_num_bits
SC.gen_used.limbs = limbs
SC.gen_used.size = default_num_bits
SC.gen_is_id.size = default_num_bits
SC.gen_used.limbs = limbs
SC.gen_is_id.limbs = limbs
SC.gen_used.bits = <mp_limb_t*>sig_malloc(limbs * sizeof(mp_limb_t))
SC.gen_is_id.bits = <mp_limb_t*>sig_malloc(limbs * sizeof(mp_limb_t))
SC.gen_used.bits = <mp_limb_t*>sig_malloc(limbs * sizeof(mp_limb_t))
SC.gen_is_id.bits = <mp_limb_t*>sig_malloc(limbs * sizeof(mp_limb_t))

# check for allocation failures
if int_array is NULL or int_ptrs is NULL or \
if int_array is NULL or int_ptrs is NULL or \
SC.gen_used.bits is NULL or SC.gen_is_id.bits is NULL or \
SC.OP_scratch is NULL:
SC.OP_scratch is NULL:
sig_free(int_array)
sig_free(int_ptrs)
SC_dealloc(SC)
Expand Down
20 changes: 10 additions & 10 deletions src/sage/groups/perm_gps/partn_ref/double_coset.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -213,24 +213,24 @@ cdef dc_work_space *allocate_dc_work_space(int n) noexcept:
return NULL

work_space.degree = n
int_array = <int *> sig_malloc((n*n + # for perm_stack
int_array = <int *> sig_malloc((n*n + # for perm_stack
5*n # for int_array
)*sizeof(int))
work_space.group1 = SC_new(n)
work_space.group2 = SC_new(n)
work_space.current_ps = PS_new(n,0)
work_space.first_ps = PS_new(n,0)
work_space.current_ps = PS_new(n, 0)
work_space.first_ps = PS_new(n, 0)
work_space.bitset_array = <bitset_t *> sig_calloc((n + 2*len_of_fp_and_mcr + 1), sizeof(bitset_t))
work_space.orbits_of_subgroup = OP_new(n)
work_space.perm_stack = NULL

if int_array is NULL or \
work_space.group1 is NULL or \
work_space.group2 is NULL or \
work_space.current_ps is NULL or \
work_space.first_ps is NULL or \
work_space.bitset_array is NULL or \
work_space.orbits_of_subgroup is NULL:
if int_array is NULL or \
work_space.group1 is NULL or \
work_space.group2 is NULL or \
work_space.current_ps is NULL or \
work_space.first_ps is NULL or \
work_space.bitset_array is NULL or \
work_space.orbits_of_subgroup is NULL:
sig_free(int_array)
deallocate_dc_work_space(work_space)
return NULL
Expand Down
4 changes: 2 additions & 2 deletions src/sage/groups/perm_gps/partn_ref/refinement_sets.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -643,8 +643,8 @@ cdef int allocate_subset_gen_2(int degree, int max_size, iterator *it) noexcept:
cgd.iterator_stack[i].data = allocate_sgd(degree)
cgd.iterator_stack[i].next = &subset_generator_next
if cgd.iterator_stack[i].data is NULL or \
cgd.object_stack[i] is NULL or \
cgd.parent_stack[i] is NULL:
cgd.object_stack[i] is NULL or \
cgd.parent_stack[i] is NULL:
for j from 0 <= j <= i:
deallocate_sgd(cgd.iterator_stack[i].data)
free_subset(cgd.object_stack[i])
Expand Down
8 changes: 4 additions & 4 deletions src/sage/libs/mpmath/ext_main.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,7 @@ cdef class Context:
if kwargs:
if 'prec' in kwargs:
opts.prec = int(kwargs['prec'])
if 'dps' in kwargs:
if 'dps' in kwargs:
opts.prec = libmp.dps_to_prec(int(kwargs['dps']))
if 'rounding' in kwargs:
opts.rounding = rndmode_from_python(kwargs['rounding'])
Expand Down Expand Up @@ -1350,7 +1350,7 @@ cdef class Context:
opts.rounding = global_opts.rounding
if kwargs:
if 'prec' in kwargs: opts.prec = int(kwargs['prec'])
if 'dps' in kwargs: opts.prec = libmp.dps_to_prec(int(kwargs['dps']))
if 'dps' in kwargs: opts.prec = libmp.dps_to_prec(int(kwargs['dps']))
if 'rounding' in kwargs: opts.rounding = rndmode_from_python(kwargs['rounding'])
if typx == 1:
if MPF_sgn(&tmp_opx_re) < 0:
Expand Down Expand Up @@ -1435,7 +1435,7 @@ cdef class wrapped_libmp_function:
rounding = rndmode_to_python(global_opts.rounding)
if kwargs:
if 'prec' in kwargs: prec = int(kwargs['prec'])
if 'dps' in kwargs: prec = libmp.dps_to_prec(int(kwargs['dps']))
if 'dps' in kwargs: prec = libmp.dps_to_prec(int(kwargs['dps']))
if 'rounding' in kwargs: rounding = kwargs['rounding']
typx = MPF_set_any(&tmp_opx_re, &tmp_opx_im, x, global_opts, 1)
if typx == 1:
Expand Down Expand Up @@ -1846,7 +1846,7 @@ cdef class mpf(mpf_base):
opts = global_opts
if kwargs:
if 'prec' in kwargs: opts.prec = int(kwargs['prec'])
if 'dps' in kwargs: opts.prec = libmp.dps_to_prec(int(kwargs['dps']))
if 'dps' in kwargs: opts.prec = libmp.dps_to_prec(int(kwargs['dps']))
if 'rounding' in kwargs: opts.rounding = rndmode_from_python(kwargs['rounding'])
if MPF_set_any(&self.value, &self.value, x, opts, 1) != 1:
raise TypeError
Expand Down
4 changes: 2 additions & 2 deletions src/sage/matrix/matrix_cyclo_dense.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1383,14 +1383,14 @@ cdef class Matrix_cyclo_dense(Matrix_dense):
p = previous_prime(MAX_MODULUS)
prod = 1
v = []
#A, denom = self._matrix._clear_denom()
# A, denom = self._matrix._clear_denom()
# TODO: this might be stupidly slow
denom = self._matrix.denominator()
A._matrix = <Matrix_rational_dense>(denom*self._matrix)
bound = A._charpoly_bound()
L_last = 0
while prod <= bound:
while (n >= 2 and p % n != 1) or denom % p == 0:
while (n >= 2 and p % n != 1) or denom % p == 0:
if p == 2:
raise RuntimeError("we ran out of primes in multimodular charpoly algorithm.")
p = previous_prime(p)
Expand Down
2 changes: 1 addition & 1 deletion src/sage/modules/vector_rational_dense.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ cdef class Vector_rational_dense(free_module_element.FreeModuleElement):
r = right
z = self._new_c()
cdef Py_ssize_t i
for i in range(self._degree):
for i in range(self._degree):
mpq_mul(z._entries[i], self._entries[i], r._entries[i])
return z

Expand Down
8 changes: 4 additions & 4 deletions src/sage/numerical/backends/glpk_backend.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2981,8 +2981,8 @@ cdef class GLPKBackend(GenericBackend):

i = glp_eval_tab_row(self.lp, k + 1, c_indices, c_values)

indices = [c_indices[j+1] - 1 for j in range(i)]
values = [c_values[j+1] for j in range(i)]
indices = [c_indices[j + 1] - 1 for j in range(i)]
values = [c_values[j + 1] for j in range(i)]
return (indices, values)

cpdef eval_tab_col(self, int k):
Expand Down Expand Up @@ -3079,8 +3079,8 @@ cdef class GLPKBackend(GenericBackend):

i = glp_eval_tab_col(self.lp, k + 1, c_indices, c_values)

indices = [c_indices[j+1] - 1 for j in range(i)]
values = [c_values[j+1] for j in range(i)]
indices = [c_indices[j + 1] - 1 for j in range(i)]
values = [c_values[j + 1] for j in range(i)]
return (indices, values)

def __dealloc__(self):
Expand Down
4 changes: 2 additions & 2 deletions src/sage/numerical/mip.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2894,8 +2894,8 @@ cdef class MixedIntegerLinearProgram(SageObject):
"""
d = {}
for v in L:
for id,coeff in v.iteritems():
d[id] = coeff + d.get(id,0)
for id, coeff in v.iteritems():
d[id] = coeff + d.get(id, 0)
return self.linear_functions_parent()(d)

def get_backend(self):
Expand Down
8 changes: 4 additions & 4 deletions src/sage/stats/hmm/chmm.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ AUTHOR:
- William Stein, 2010-03
"""

#*****************************************************************************
# ***************************************************************************
# Copyright (C) 2010 William Stein <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
# http://www.gnu.org/licenses/
#*****************************************************************************
# https://www.gnu.org/licenses/
# ***************************************************************************

from cpython.object cimport PyObject_RichCompare
from libc.math cimport log, sqrt, exp, isnormal, isfinite, M_PI
cdef double sqrt2pi = sqrt(2*M_PI)
from cysignals.signals cimport sig_on, sig_off

from sage.misc.flatten import flatten
from sage.misc.flatten import flatten
from sage.structure.element import Matrix

from sage.stats.time_series cimport TimeSeries
Expand Down
12 changes: 6 additions & 6 deletions src/sage/stats/hmm/util.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@ Hidden Markov Models -- Utility functions

AUTHOR:

- William Stein, 2010-03
- William Stein, 2010-03
"""

#############################################################################
# ##########################################################################
# Copyright (C) 2010 William Stein <[email protected]>
# Distributed under the terms of the GNU General Public License (GPL) v2+.
# The full text of the GPL is available at:
# http://www.gnu.org/licenses/
#############################################################################
# https://www.gnu.org/licenses/
# ##########################################################################


from sage.structure.element import Matrix
from sage.misc.flatten import flatten
from sage.misc.flatten import flatten


cdef class HMM_Util:
"""
Expand Down Expand Up @@ -123,7 +124,6 @@ cdef class HMM_Util:
This function is used internally by the ``__init__`` methods of
Hidden Markov Models to make a transition matrix from ``A``.


INPUT:

- ``A`` -- matrix, list, list of lists, or :class:`TimeSeries`
Expand Down
Loading