Skip to content

breaking lines after else: in pyx files #39393

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 4 commits into from
Feb 10, 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
49 changes: 28 additions & 21 deletions src/sage/coding/binary_code.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ cdef codeword *expand_to_ortho_basis(BinaryCode B, int n) noexcept:
i = k
word = <codeword>1 << k
k += 1
else: # NOTE THIS WILL NEVER HAPPEN AS CURRENTLY SET UP!
else: # NOTE THIS WILL NEVER HAPPEN AS CURRENTLY SET UP!
temp = (<codeword>1 << k) - 1
i = k
word = <codeword>1 << k
Expand Down Expand Up @@ -813,7 +813,7 @@ cdef class BinaryCode:
combination ^= (1 << j)
word ^= self_basis[j]

else: # isinstance(arg1, BinaryCode)
else: # isinstance(arg1, BinaryCode)
other_basis = other.basis
for i from 0 <= i < nrows-1:
self_basis[i] = other_basis[i]
Expand Down Expand Up @@ -2423,9 +2423,12 @@ cdef class PartitionStack:
cdef int *self_wd_lvls = self.wd_lvls
cdef int *self_wd_ents = self.wd_ents
while True:
if CG.is_one(self_wd_ents[wd_ptr], col): i += 1
if self_wd_lvls[wd_ptr] > k: wd_ptr += 1
else: break
if CG.is_one(self_wd_ents[wd_ptr], col):
i += 1
if self_wd_lvls[wd_ptr] > k:
wd_ptr += 1
else:
break
return i

def _wd_degree(self, C, wd, col_ptr, k):
Expand Down Expand Up @@ -3347,15 +3350,17 @@ cdef class BinaryCodeClassifier:
if qzb > 0: zb__Lambda_rho[k] = Lambda[k]
state = 3

elif state == 3: # attempt to rule out automorphisms while moving down the tree
elif state == 3: # attempt to rule out automorphisms while moving down the tree
# if k > hzf, then we know that nu currently does not look like zeta, the first
# terminal node encountered, thus there is no automorphism to discover. If qzb < 0,
# i.e. Lambda[k] < zb[k], then the indicator is not maximal, and we can't reach a
# canonical leaf. If neither of these is the case, then proceed to state 4.
if hzf__h_zeta <= k or qzb >= 0: state = 4
else: state = 6
if hzf__h_zeta <= k or qzb >= 0:
state = 4
else:
state = 6

elif state == 4: # at this point we have -not- ruled out the presence of automorphisms
elif state == 4: # at this point we have -not- ruled out the presence of automorphisms
if nu.is_discrete(k):
state = 7
continue # we have a terminal node, so process it
Expand All @@ -3365,17 +3370,18 @@ cdef class BinaryCodeClassifier:
# equal to its minimum element
v[k] = nu.new_first_smallest_nontrivial(k, W, self.Phi_size * k)
if not nu.sat_225(k): hh = k + 1
e[k] = 0 # see state 12 and 17
state = 2 # continue down the tree
e[k] = 0 # see state 12 and 17
state = 2 # continue down the tree

elif state == 5: # same as state 3, but in the case where we haven't yet defined zeta
# i.e. this is our first time down the tree. Once we get to the bottom,
# we will have zeta = nu = rho, so we do:
elif state == 5:
# same as state 3, but in the case where we haven't yet defined zeta
# i.e. this is our first time down the tree. Once we get to the bottom,
# we will have zeta = nu = rho, so we do:
zf__Lambda_zeta[k] = Lambda[k]
zb__Lambda_rho[k] = Lambda[k]
state = 4

elif state == 6: # at this stage, there is no reason to continue downward, so backtrack
elif state == 6: # at this stage, there is no reason to continue downward, so backtrack
j = k

# return to the longest ancestor nu[i] of nu that could have a
Expand All @@ -3396,9 +3402,10 @@ cdef class BinaryCodeClassifier:
else:
k = hh-1
# TODO: is the following line necessary?
if k == -1: k = 0
if k == -1:
k = 0

if hb > k:# update hb since we are backtracking
if hb > k: # update hb since we are backtracking
hb = k
# if j == hh, then all nodes lower than our current position are equivalent, so bail out
if j == hh:
Expand Down Expand Up @@ -3465,7 +3472,7 @@ cdef class BinaryCodeClassifier:

state = 10

elif state == 9: # nu is a better guess at the canonical label than rho
elif state == 9: # nu is a better guess at the canonical label than rho
rho = PartitionStack(nu)
k_rho = k
qzb = 0
Expand All @@ -3475,7 +3482,7 @@ cdef class BinaryCodeClassifier:
zb__Lambda_rho[k+1] = -1
state = 6

elif state == 10: # we have an automorphism to process
elif state == 10: # we have an automorphism to process
# increment l
if l < self.L-1: l += 1
# store information about the automorphism to Omega and Phi
Expand All @@ -3496,8 +3503,8 @@ cdef class BinaryCodeClassifier:
Omega[ii] ^= (1<<j) # so cancel
j = col_gamma[j] # cellmates
i += 1
while i < ncols and not Omega[ii]&(1<<i): # find minimal element
i += 1 # of next cell
while i < ncols and not Omega[ii]&(1<<i): # find minimal element
i += 1 # of next cell
i = 0
jj = self.radix
while i < nwords:
Expand Down
12 changes: 8 additions & 4 deletions src/sage/libs/mpmath/ext_impl.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1183,10 +1183,14 @@ cdef MPF_exp(MPF *y, MPF *x, MPopts opts):
cdef mpz_t t, u
cdef tuple w
if x.special:
if x.special == S_ZERO: MPF_set_si(y, 1)
elif x.special == S_NINF: MPF_set_zero(y)
elif x.special == S_INF: MPF_set_inf(y)
else: MPF_set_nan(y)
if x.special == S_ZERO:
MPF_set_si(y, 1)
elif x.special == S_NINF:
MPF_set_zero(y)
elif x.special == S_INF:
MPF_set_inf(y)
else:
MPF_set_nan(y)
return
wp = opts.prec + 14
sign = mpz_sgn(x.man) < 0
Expand Down
12 changes: 8 additions & 4 deletions src/sage/libs/mpmath/utils.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,15 @@ cpdef normalize(long sign, Integer man, exp, long bc, long prec, str rnd):
elif rnd == 'd':
mpz_fdiv_q_2exp(res.value, man.value, shift)
elif rnd == 'f':
if sign: mpz_cdiv_q_2exp(res.value, man.value, shift)
else: mpz_fdiv_q_2exp(res.value, man.value, shift)
if sign:
mpz_cdiv_q_2exp(res.value, man.value, shift)
else:
mpz_fdiv_q_2exp(res.value, man.value, shift)
elif rnd == 'c':
if sign: mpz_fdiv_q_2exp(res.value, man.value, shift)
else: mpz_cdiv_q_2exp(res.value, man.value, shift)
if sign:
mpz_fdiv_q_2exp(res.value, man.value, shift)
else:
mpz_cdiv_q_2exp(res.value, man.value, shift)
elif rnd == 'u':
mpz_cdiv_q_2exp(res.value, man.value, shift)
exp += shift
Expand Down
22 changes: 13 additions & 9 deletions src/sage/libs/singular/singular.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,18 @@ cdef Rational si2sa_QQ(number *n, number **nn, ring *_ring):

mpq_init(_z)

## Immediate integers handles carry the tag 'SR_INT', i.e. the last bit is 1.
## This distinguishes immediate integers from other handles which point to
## structures aligned on 4 byte boundaries and therefore have last bit zero.
## (The second bit is reserved as tag to allow extensions of this scheme.)
## Using immediates as pointers and dereferencing them gives address errors.
# Immediate integers handles carry the tag 'SR_INT', i.e. the last bit is 1.
# This distinguishes immediate integers from other handles which point to
# structures aligned on 4 byte boundaries and therefore have last bit zero.
# (The second bit is reserved as tag to allow extensions of this scheme.)
# Using immediates as pointers and dereferencing them gives address errors.
nom = nlGetNumerator(n, _ring.cf)
mpz_init(nom_z)

if (SR_HDL(nom) & SR_INT): mpz_set_si(nom_z, SR_TO_INT(nom))
else: mpz_set(nom_z,nom.z)
if SR_HDL(nom) & SR_INT:
mpz_set_si(nom_z, SR_TO_INT(nom))
else:
mpz_set(nom_z,nom.z)

mpq_set_num(_z,nom_z)
nlDelete(&nom,_ring.cf)
Expand All @@ -114,8 +116,10 @@ cdef Rational si2sa_QQ(number *n, number **nn, ring *_ring):
denom = nlGetDenom(n, _ring.cf)
mpz_init(denom_z)

if (SR_HDL(denom) & SR_INT): mpz_set_si(denom_z, SR_TO_INT(denom))
else: mpz_set(denom_z,denom.z)
if SR_HDL(denom) & SR_INT:
mpz_set_si(denom_z, SR_TO_INT(denom))
else:
mpz_set(denom_z,denom.z)

mpq_set_den(_z, denom_z)
nlDelete(&denom,_ring.cf)
Expand Down
Loading
Loading