Skip to content

Commit

Permalink
sagemathgh-36369: partial cython-lint cleanup in padics/
Browse files Browse the repository at this point in the history
Cleaning `pyx` and `pxi` files in `padics`, following suggestions of
`cython-lint`

### 📝 Checklist

- [x] The title is concise, informative, and self-explanatory.
- [x] The description explains in detail what this PR is about.

URL: sagemath#36369
Reported by: Frédéric Chapoton
Reviewer(s): David Coudert
  • Loading branch information
Release Manager committed Oct 1, 2023
2 parents 2a0784e + d28bb84 commit 87c984b
Show file tree
Hide file tree
Showing 23 changed files with 108 additions and 124 deletions.
6 changes: 3 additions & 3 deletions build/pkgs/configure/checksums.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tarball=configure-VERSION.tar.gz
sha1=96468a2d2ec8ee319095f3d2abd73e5f1ec7829d
md5=87391217b5c82275e1cb581721877eec
cksum=370856230
sha1=2ad31d88aff33f460f6eb8876d023922a99f1a09
md5=49e2c61121662d65cba0c47139c28004
cksum=3145718679
2 changes: 1 addition & 1 deletion build/pkgs/configure/package-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
b01856309bcb0d25e9cf830da19fa1cdd24df2bf
536e6222a19653172cc3567dff6575f1fad99aac
12 changes: 6 additions & 6 deletions src/sage/rings/padics/CA_template.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ cdef class CAElement(pAdicTemplateElement):
self.absprec = aprec
else:
self.absprec = min(aprec, val + rprec)
if isinstance(x,CAElement) and x.parent() is self.parent():
if isinstance(x, CAElement) and x.parent() is self.parent():
cshift_notrunc(self.value, (<CAElement>x).value, 0, self.absprec, self.prime_pow, True)
else:
cconv(self.value, x, self.absprec, 0, self.prime_pow)
Expand Down Expand Up @@ -395,9 +395,8 @@ cdef class CAElement(pAdicTemplateElement):
creduce(q.value, q.value, q.absprec, q.prime_pow)
return q, r


def __pow__(CAElement self, _right, dummy):
"""
r"""
Exponentiation.
When ``right`` is divisible by `p` then one can get more
Expand Down Expand Up @@ -474,8 +473,8 @@ cdef class CAElement(pAdicTemplateElement):
return base.__pow__(-_right, dummy)
exact_exp = True
elif self.parent() is _right.parent():
## For extension elements, we need to switch to the
## fraction field sometimes in highly ramified extensions.
# For extension elements, we need to switch to the
# fraction field sometimes in highly ramified extensions.
exact_exp = (<CAElement>_right)._is_exact_zero()
pright = _right
else:
Expand Down Expand Up @@ -861,6 +860,7 @@ cdef class CAElement(pAdicTemplateElement):
"""
def tuple_recursive(l):
return tuple(tuple_recursive(x) for x in l) if isinstance(l, Iterable) else l

return (self.parent(), tuple_recursive(trim_zeros(list(self.expansion()))), self.precision_absolute())

def _teichmuller_set_unsafe(self):
Expand Down Expand Up @@ -1800,6 +1800,7 @@ cdef class pAdicConvert_CA_frac_field(Morphism):
self._zero = _slots['_zero']
Morphism._update_slots(self, _slots)


def unpickle_cae_v2(cls, parent, value, absprec):
r"""
Unpickle capped absolute elements.
Expand Down Expand Up @@ -1834,4 +1835,3 @@ def unpickle_cae_v2(cls, parent, value, absprec):
cunpickle(ans.value, value, ans.prime_pow)
ans.absprec = absprec
return ans

17 changes: 9 additions & 8 deletions src/sage/rings/padics/CR_template.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ cdef class CRElement(pAdicTemplateElement):
else:
self.relprec = min(rprec, aprec - val)
self.ordp = val
if isinstance(x,CRElement) and x.parent() is self.parent():
if isinstance(x, CRElement) and x.parent() is self.parent():
cshift_notrunc(self.unit, (<CRElement>x).unit, 0, self.relprec, self.prime_pow, True)
else:
cconv(self.unit, x, self.relprec, val, self.prime_pow)
Expand Down Expand Up @@ -678,8 +678,8 @@ cdef class CRElement(pAdicTemplateElement):
return base.__pow__(-_right, dummy)
exact_exp = True
elif self.parent() is _right.parent():
## For extension elements, we need to switch to the
## fraction field sometimes in highly ramified extensions.
# For extension elements, we need to switch to the
# fraction field sometimes in highly ramified extensions.
exact_exp = (<CRElement>_right)._is_exact_zero()
pright = _right
else:
Expand Down Expand Up @@ -732,7 +732,7 @@ cdef class CRElement(pAdicTemplateElement):
return ans

cdef pAdicTemplateElement _lshift_c(self, long shift):
"""
r"""
Multiplies by `\pi^{\mbox{shift}}`.
Negative shifts may truncate the result if the parent is not a
Expand Down Expand Up @@ -763,7 +763,7 @@ cdef class CRElement(pAdicTemplateElement):
return ans

cdef pAdicTemplateElement _rshift_c(self, long shift):
"""
r"""
Divides by ``\pi^{\mbox{shift}}``.
Positive shifts may truncate the result if the parent is not a
Expand Down Expand Up @@ -879,7 +879,6 @@ cdef class CRElement(pAdicTemplateElement):
q._normalize()
return q, r


def add_bigoh(self, absprec):
"""
Return a new element with absolute precision decreased to
Expand Down Expand Up @@ -1253,6 +1252,7 @@ cdef class CRElement(pAdicTemplateElement):
"""
def tuple_recursive(l):
return tuple(tuple_recursive(x) for x in l) if isinstance(l, list) else l

return (self.parent(), tuple_recursive(trim_zeros(list(self.expansion()))), self.valuation(), self.precision_relative())

def _teichmuller_set_unsafe(self):
Expand Down Expand Up @@ -1506,7 +1506,7 @@ cdef class CRElement(pAdicTemplateElement):
"""
# Since we keep this element normalized there's not much to do here.
if p is not None and p != self.parent().prime():
raise ValueError('ring (%s) residue field of the wrong characteristic'%self.parent())
raise ValueError('ring (%s) residue field of the wrong characteristic' % self.parent())
if exactzero((<CRElement>self).ordp):
raise ValueError("unit part of 0 not defined")
cdef Integer val = Integer.__new__(Integer)
Expand Down Expand Up @@ -1968,7 +1968,7 @@ cdef class pAdicConvert_CR_QQ(RingMap):
1/5
"""
cdef Rational ans = Rational.__new__(Rational)
cdef CRElement x = _x
cdef CRElement x = _x
if x.relprec == 0:
mpq_set_ui(ans.value, 0, 1)
else:
Expand Down Expand Up @@ -2522,6 +2522,7 @@ cdef class pAdicConvert_CR_frac_field(Morphism):
self._zero = _slots['_zero']
Morphism._update_slots(self, _slots)


def unpickle_cre_v2(cls, parent, unit, ordp, relprec):
"""
Unpickles a capped relative element.
Expand Down
10 changes: 5 additions & 5 deletions src/sage/rings/padics/FM_template.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ cdef class FMElement(pAdicTemplateElement):
polyt = type(self.prime_pow.modulus)
self.value = <celement>polyt.__new__(polyt)
cconstruct(self.value, self.prime_pow)
if isinstance(x,FMElement) and x.parent() is self.parent():
if isinstance(x, FMElement) and x.parent() is self.parent():
cshift_notrunc(self.value, (<FMElement>x).value, 0, 0, self.prime_pow, False)
else:
cconv(self.value, x, self.prime_pow.ram_prec_cap, 0, self.prime_pow)
Expand Down Expand Up @@ -346,7 +346,6 @@ cdef class FMElement(pAdicTemplateElement):
creduce(q.value, q.value, pcap, q.prime_pow)
return q, r


def __pow__(FMElement self, _right, dummy): # NOTE: dummy ignored, always use self.prime_pow.ram_prec_cap
"""
Exponentiation by an integer
Expand Down Expand Up @@ -381,7 +380,7 @@ cdef class FMElement(pAdicTemplateElement):
return ans

cdef pAdicTemplateElement _lshift_c(self, long shift):
"""
r"""
Multiplies self by `\pi^{shift}`.
If shift < -self.valuation(), digits will be truncated. See
Expand Down Expand Up @@ -428,7 +427,7 @@ cdef class FMElement(pAdicTemplateElement):
return ans

cdef pAdicTemplateElement _rshift_c(self, long shift):
"""
r"""
Divides by `\pi^{shift}`, and truncates.
Note that this operation will insert arbitrary digits (in
Expand Down Expand Up @@ -462,7 +461,7 @@ cdef class FMElement(pAdicTemplateElement):
return ans

def add_bigoh(self, absprec):
"""
r"""
Return a new element truncated modulo `\pi^{\mbox{absprec}}`.
INPUT:
Expand Down Expand Up @@ -1542,6 +1541,7 @@ cdef class pAdicConvert_FM_frac_field(Morphism):
self._zero = _slots['_zero']
Morphism._update_slots(self, _slots)


def unpickle_fme_v2(cls, parent, value):
"""
Unpickles a fixed-mod element.
Expand Down
20 changes: 10 additions & 10 deletions src/sage/rings/padics/FP_template.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ cdef class FPElement(pAdicTemplateElement):
self._set_infinity()
else:
self.ordp = val
if isinstance(x,FPElement) and x.parent() is self.parent():
if isinstance(x, FPElement) and x.parent() is self.parent():
ccopy(self.unit, (<FPElement>x).unit, self.prime_pow)
else:
cconv(self.unit, x, self.prime_pow.ram_prec_cap, val, self.prime_pow)
Expand Down Expand Up @@ -584,7 +584,6 @@ cdef class FPElement(pAdicTemplateElement):
q._normalize()
return q, r


def __pow__(FPElement self, _right, dummy): # NOTE: dummy ignored, always use self.prime_pow.ram_prec_cap
"""
Exponentiation by an integer
Expand Down Expand Up @@ -624,8 +623,8 @@ cdef class FPElement(pAdicTemplateElement):
_right = -_right
exact_exp = True
elif self.parent() is _right.parent():
## For extension elements, we need to switch to the
## fraction field sometimes in highly ramified extensions.
# For extension elements, we need to switch to the
# fraction field sometimes in highly ramified extensions.
exact_exp = (<FPElement>_right)._is_exact_zero()
pright = _right
else:
Expand Down Expand Up @@ -665,7 +664,7 @@ cdef class FPElement(pAdicTemplateElement):
return ans

cdef pAdicTemplateElement _lshift_c(self, long shift):
"""
r"""
Multiplies self by `\pi^{shift}`.
Negative shifts may truncate the result if the parent is not a
Expand Down Expand Up @@ -718,7 +717,7 @@ cdef class FPElement(pAdicTemplateElement):
return ans

cdef pAdicTemplateElement _rshift_c(self, long shift):
"""
r"""
Divides by `\pi^{shift}`.
Positive shifts may truncate the result if the parent is not a
Expand Down Expand Up @@ -772,7 +771,7 @@ cdef class FPElement(pAdicTemplateElement):

def _repr_(self, mode=None, do_latex=False):
"""
Returns a string representation of this element.
Return a string representation of this element.
INPUT:
Expand All @@ -794,7 +793,7 @@ cdef class FPElement(pAdicTemplateElement):
return self.parent()._printer.repr_gen(self, do_latex, mode=mode)

def add_bigoh(self, absprec):
"""
r"""
Return a new element truncated modulo `\pi^{\mbox{absprec}}`.
INPUT:
Expand Down Expand Up @@ -1221,7 +1220,7 @@ cdef class FPElement(pAdicTemplateElement):
ValueError: unit part of 0 and infinity not defined
"""
if p is not None and p != self.parent().prime():
raise ValueError('Ring (%s) residue field of the wrong characteristic.'%self.parent())
raise ValueError('Ring (%s) residue field of the wrong characteristic.' % self.parent())
if huge_val(self.ordp):
raise ValueError("unit part of 0 and infinity not defined")
cdef Integer valuation = PY_NEW(Integer)
Expand Down Expand Up @@ -1659,7 +1658,7 @@ cdef class pAdicConvert_FP_QQ(RingMap):
1/5
"""
cdef Rational ans = Rational.__new__(Rational)
cdef FPElement x = _x
cdef FPElement x = _x
if very_pos_val(x.ordp):
mpq_set_ui(ans.value, 0, 1)
elif very_neg_val(x.ordp):
Expand Down Expand Up @@ -2140,6 +2139,7 @@ cdef class pAdicConvert_FP_frac_field(Morphism):
self._zero = _slots['_zero']
Morphism._update_slots(self, _slots)


def unpickle_fpe_v2(cls, parent, unit, ordp):
"""
Unpickles a floating point element.
Expand Down
5 changes: 3 additions & 2 deletions src/sage/rings/padics/local_generic_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,9 @@ cdef class LocalGenericElement(CommutativeRingElement):
unramified_generator = self.parent()(self.parent().residue_field().gen()).lift_to_precision()
for c in islice(self.expansion(lift_mode=lift_mode), int(start), int(stop), int(k)):
genpow = 1
if not isinstance(c, list): c = [c] # relevant for the case of base-rings, or one-step
# eisenstein extensions
if not isinstance(c, list):
c = [c] # relevant for the case of base-rings, or one-step
# Eisenstein extensions
for d in c:
ans += d * genpow * ppow
genpow *= unramified_generator
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/padics/morphism.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ cdef class FrobeniusEndomorphism_padics(RingHomomorphism):
cdef long _power
cdef long _order

cpdef Element _call_(self,x)
cpdef Element _call_(self, x)
1 change: 0 additions & 1 deletion src/sage/rings/padics/morphism.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ cdef class FrobeniusEndomorphism_padics(RingHomomorphism):
sage: Frob._repr_short()
'Frob'
"""
name = self.domain().variable_name()
if self._power == 0:
s = "Identity"
elif self._power == 1:
Expand Down
19 changes: 10 additions & 9 deletions src/sage/rings/padics/padic_ZZ_pX_CA_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,6 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement):
cdef long self_ordp = self.valuation_c()
cdef long self_relprec = self.absprec - self_ordp
cdef long threshold # e / (p-1)
cdef long prime_long
cdef mpz_t tmp, tmp2
if mpz_fits_slong_p(self.prime_pow.prime.value) == 0:
threshold = 0
Expand Down Expand Up @@ -1399,7 +1398,6 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement):
"""
cdef pAdicZZpXCAElement right = <pAdicZZpXCAElement>_right
cdef pAdicZZpXCAElement ans
cdef long tmpL
cdef ZZ_pX_c tmpP
if self.absprec == 0 or right.absprec == 0:
return self._new_c(0)
Expand Down Expand Up @@ -1441,7 +1439,6 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement):
"""
cdef pAdicZZpXCAElement right = <pAdicZZpXCAElement>_right
cdef pAdicZZpXCAElement ans
cdef long tmpL
cdef ZZ_pX_c tmpP
if self.absprec == 0 or right.absprec == 0:
return self._new_c(0)
Expand Down Expand Up @@ -1824,7 +1821,7 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement):
True
"""
cdef pAdicZZpXCAElement ans
cdef long aprec, rprec
cdef long aprec
if absprec is not None and not isinstance(absprec, Integer):
absprec = Integer(absprec)
if absprec is None:
Expand Down Expand Up @@ -1977,9 +1974,9 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement):
cdef ZZ_pX_Modulus_c* m = self.prime_pow.get_modulus_capdiv(self.absprec)
cdef ZZ_pX_c x
ZZ_pX_SetX(x)
cdef Py_ssize_t i, j
cdef Py_ssize_t i
zero = int(0)
for i from 0 <= i < n:
for i in range(n):
curlist = cur.list()
L.extend(curlist + [zero]*(n - len(curlist)))
ZZ_pX_MulMod_pre(cur.x, cur.x, x, m[0])
Expand Down Expand Up @@ -2071,7 +2068,8 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement):
cdef long ordp = self.valuation_c()
cdef long rp = self.absprec - ordp
cdef long goal
if n is not None: goal = self.absprec - n
if n is not None:
goal = self.absprec - n
cdef pAdicZZpXCAElement v
if n is None:
L = []
Expand All @@ -2084,15 +2082,17 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement):
else:
v = self._new_c(rp)
cdef pAdicZZpXCAElement u = self.unit_part()
if u is self: u = self.__copy__()
if u is self:
u = self.__copy__()
while not ZZ_pX_IsZero(u.value):
v = self._new_c(rp)
self.prime_pow.teichmuller_set_c(&v.value, &u.value, rp)
if n is None:
L.append(v)
elif rp == goal:
return v
if rp == 1: break
if rp == 1:
break
ZZ_pX_sub(u.value, u.value, v.value)
rp -= 1
if self.prime_pow.e == 1:
Expand Down Expand Up @@ -2319,6 +2319,7 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement):
"""
return self.ext_p_list_precs(pos, self.absprec)


def make_ZZpXCAElement(parent, value, absprec, version):
"""
For pickling. Makes a ``pAdicZZpXCAElement`` with given ``parent``, ``value``, ``absprec``.
Expand Down
Loading

0 comments on commit 87c984b

Please sign in to comment.