Skip to content

Commit

Permalink
Merge pull request #211 from GiacomoPope/linting_fixes
Browse files Browse the repository at this point in the history
Small changes to please cython-lint
  • Loading branch information
oscarbenjamin authored Sep 2, 2024
2 parents be0e410 + 5c75f51 commit 397d973
Show file tree
Hide file tree
Showing 24 changed files with 137 additions and 144 deletions.
19 changes: 18 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,25 @@ requires = ["meson-python>=0.13", "cython>=3.0,<3.1"]
build-backend = "mesonpy"

[tool.cython-lint]
# E129 visually indented line with same indent as next logical line
# Reasoning: this rule is a little controversial
# (see https://github.com/PyCQA/pycodestyle/issues/386)
# and we ignore it to avoid needing additional indentation after
# long logical statements.
#
# E501 line too long (128 > 120 characters)
# Reasoning: this is a work in progress and will be enforced once a line length
# and refactor has taken place. See issue #214
#
# E741 ambiguous variable name
# Reasoning: many places it makes sense to use l or other letters as variable
# names as it is standard in mathematical notation.
#
# E743 ambiguous function definition
# Reasoning: this is a work in progress and will be enforced after #210 is
# resolved.
max-line-length = 120
ignore = ['E128','E129','E202','E221','E222','E261','E262','E265','E501','E731','E741','E743']
ignore = ['E129','E501','E741','E743']
exclude = 'src/flint/flintlib/.*'

[tool.spin]
Expand Down
4 changes: 3 additions & 1 deletion src/flint/flint_base/flint_base.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,9 @@ cdef class flint_mat(flint_elem):
def repr(self):
# XXX
return "%s(%i, %i, [%s])" % (type(self).__name__,
self.nrows(), self.ncols(), (", ".join(map(str, self.entries()))))
self.nrows(),
self.ncols(),
", ".join(map(str, self.entries())))

def str(self, *args, **kwargs):
tab = self.table()
Expand Down
5 changes: 3 additions & 2 deletions src/flint/functions/showgood.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ cdef goodstr(x):


def good(func, slong prec=0, slong maxprec=0, slong dps=0,
slong maxdps=0, slong padding=10, bint verbose=False, bint show=False, bint parts=True, metric=None):
slong maxdps=0, slong padding=10, bint verbose=False,
bint show=False, bint parts=True, metric=None):
"""
Evaluates *func*, automatically increasing the precision to get
a result accurate to the current working precision (or the
Expand Down Expand Up @@ -81,7 +82,7 @@ def good(func, slong prec=0, slong maxprec=0, slong dps=0,
maxprec = 10 * prec + 100

if metric == "abssum":
metric = lambda L: sum(abs(c) for c in L)
def metric(L): return sum(abs(c) for c in L)

# for printing
if dps == 0:
Expand Down
8 changes: 4 additions & 4 deletions src/flint/test/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -1921,7 +1921,7 @@ def test_fmpz_mod_poly():
R_other = fmpz_mod_poly_ctx(F_other)

assert raises(lambda: fmpz_mod_poly(1, "A"), TypeError) # Need a valid context
assert raises(lambda: R(R_other([1,2,3])), ValueError), f"{R(R_other([1,2,3])) = }" # moduli must match
assert raises(lambda: R(R_other([1,2,3])), ValueError) # moduli must match
assert raises(lambda: R(F_other(2)), ValueError) # moduli must match
assert raises(lambda: R([F(1), F_other(2)]), ValueError) # moduli must match
assert raises(lambda: R([F(1), "A"]), TypeError) # need to be able to cast to fmpz_mod
Expand Down Expand Up @@ -2120,7 +2120,7 @@ def test_fmpz_mod_poly():
assert raises(lambda: f % f_bad, ValueError)
assert raises(lambda: 123 % f_bad, DomainError)
assert raises(lambda: f % "AAA", TypeError)
assert raises(lambda: tuple() % f, TypeError), f'{"AAA" % f = }'
assert raises(lambda: tuple() % f, TypeError)

assert f % 1 == 0
assert R_test.one() % 1 == 0
Expand Down Expand Up @@ -2550,7 +2550,7 @@ def test_polys():
assert P([S(1)]) == P([1]) == P(P([1])) == P(1)

assert raises(lambda: P([None]), TypeError)
assert raises(lambda: P(object()), TypeError), f"{P(object()) = }"
assert raises(lambda: P(object()), TypeError)
assert raises(lambda: P(None), TypeError)
assert raises(lambda: P(None, None), TypeError)
assert raises(lambda: P([1,2], None), TypeError)
Expand Down Expand Up @@ -2903,7 +2903,7 @@ def quick_poly():
assert ctx.constant(1) == mpoly({(0, 0): 1}) == P(1, ctx=ctx)

assert raises(lambda: P([None]), TypeError)
assert raises(lambda: P(object()), TypeError), f"{P(object()) = }"
assert raises(lambda: P(object()), TypeError)
assert raises(lambda: P(None), TypeError)
assert raises(lambda: P(None, None), TypeError)
assert raises(lambda: P([1,2], None), TypeError)
Expand Down
27 changes: 9 additions & 18 deletions src/flint/types/acb.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,6 @@ cdef any_as_acb_or_notimplemented(x):
return t


# cdef any_as_arb_or_acb(x):
# if typecheck(x, arb) or typecheck(x, acb):
# return x
# try:
# return arb(x)
# except (TypeError, ValueError):
# return acb(x)


# Copied with modifications from sage/rings/complex_arb.pyx
@cython.internal
cdef class IntegrationContext:
Expand Down Expand Up @@ -1210,7 +1201,7 @@ cdef class acb(flint_scalar):
T3 = _acb_vec_init(r + 3)
T4 = _acb_vec_init(r + 4)
acb_modular_theta_jet(T1, T2, T3, T4,
(<acb>z).val, (<acb>tau).val, r + 1, getprec())
(<acb>z).val, (<acb>tau).val, r + 1, getprec())
acb_set((<acb>t1).val, T1 + r)
acb_set((<acb>t2).val, T2 + r)
acb_set((<acb>t3).val, T3 + r)
Expand Down Expand Up @@ -1556,7 +1547,7 @@ cdef class acb(flint_scalar):
if abc:
flags |= 16
acb_hypgeom_2f1((<acb>u).val, (<acb>a).val, (<acb>b).val, (<acb>c).val,
(<acb>self).val, flags, getprec())
(<acb>self).val, flags, getprec())
return u

def chebyshev_t(s, n):
Expand Down Expand Up @@ -1764,7 +1755,7 @@ cdef class acb(flint_scalar):
w = acb.__new__(acb)
z = acb.__new__(acb)
acb_hypgeom_airy((<acb>u).val, (<acb>v).val,
(<acb>w).val, (<acb>z).val, (<acb>s).val, getprec())
(<acb>w).val, (<acb>z).val, (<acb>s).val, getprec())
return u, v, w, z

def lambertw(s, branch=0, bint left=False, bint middle=False):
Expand Down Expand Up @@ -2621,9 +2612,9 @@ cdef class acb(flint_scalar):

@staticmethod
def integral(func, a, b, params=None,
rel_tol=None, abs_tol=None,
deg_limit=None, eval_limit=None, depth_limit=None,
use_heap=None, verbose=None):
rel_tol=None, abs_tol=None,
deg_limit=None, eval_limit=None, depth_limit=None,
use_heap=None, verbose=None):
r"""
Computes the integral `\int_a^b f(x) dx` where the integrand
*f* is defined by *func*.
Expand Down Expand Up @@ -2752,7 +2743,7 @@ cdef class acb(flint_scalar):
Hpos = acb.__new__(acb)
Hneg = acb.__new__(acb)
acb_hypgeom_coulomb((<acb>F).val, (<acb>G).val, (<acb>Hpos).val, (<acb>Hneg).val,
(<acb>l).val, (<acb>eta).val, (<acb>self).val, getprec())
(<acb>l).val, (<acb>eta).val, (<acb>self).val, getprec())
return F, G, Hpos, Hneg

def coulomb_f(self, l, eta):
Expand All @@ -2768,7 +2759,7 @@ cdef class acb(flint_scalar):
eta = any_as_acb(eta)
F = acb.__new__(acb)
acb_hypgeom_coulomb((<acb>F).val, NULL, NULL, NULL,
(<acb>l).val, (<acb>eta).val, (<acb>self).val, getprec())
(<acb>l).val, (<acb>eta).val, (<acb>self).val, getprec())
return F

def coulomb_g(self, l, eta):
Expand All @@ -2784,5 +2775,5 @@ cdef class acb(flint_scalar):
eta = any_as_acb(eta)
G = acb.__new__(acb)
acb_hypgeom_coulomb(NULL, (<acb>G).val, NULL, NULL,
(<acb>l).val, (<acb>eta).val, (<acb>self).val, getprec())
(<acb>l).val, (<acb>eta).val, (<acb>self).val, getprec())
return G
14 changes: 7 additions & 7 deletions src/flint/types/acb_mat.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -775,29 +775,29 @@ cdef class acb_mat(flint_mat):
if n != 0:
if algorithm == "approx":
acb_mat_approx_eig_qr(acb_mat_entry(E.val, 0, 0),
LP, RP, s.val, magp, maxiter, getprec())
LP, RP, s.val, magp, maxiter, getprec())
else:
acb_mat_approx_eig_qr(acb_mat_entry(E.val, 0, 0),
NULL, RP, s.val, magp, maxiter, getprec())
NULL, RP, s.val, magp, maxiter, getprec())
if multiple:
if left or right:
raise NotImplementedError("eigenvectors not supported with multiple=True")
if algorithm == "rump":
success = acb_mat_eig_multiple_rump(acb_mat_entry(E.val, 0, 0),
s.val, acb_mat_entry(E.val, 0, 0), RP, prec)
s.val, acb_mat_entry(E.val, 0, 0), RP, prec)
else:
success = acb_mat_eig_multiple(acb_mat_entry(E.val, 0, 0),
s.val, acb_mat_entry(E.val, 0, 0), RP, prec)
s.val, acb_mat_entry(E.val, 0, 0), RP, prec)
else:
if algorithm == "rump":
success = acb_mat_eig_simple_rump(acb_mat_entry(E.val, 0, 0),
LP, RP, s.val, acb_mat_entry(E.val, 0, 0), RP, prec)
LP, RP, s.val, acb_mat_entry(E.val, 0, 0), RP, prec)
elif algorithm == "vdhoeven_mourrain":
success = acb_mat_eig_simple_vdhoeven_mourrain(acb_mat_entry(E.val, 0, 0),
LP, RP, s.val, acb_mat_entry(E.val, 0, 0), RP, prec)
LP, RP, s.val, acb_mat_entry(E.val, 0, 0), RP, prec)
else:
success = acb_mat_eig_simple(acb_mat_entry(E.val, 0, 0),
LP, RP, s.val, acb_mat_entry(E.val, 0, 0), RP, prec)
LP, RP, s.val, acb_mat_entry(E.val, 0, 0), RP, prec)
if not (nonstop or success):
raise ValueError("failed to isolate eigenvalues (try higher prec, multiple=True for multiple eigenvalues, or nonstop=True to avoid the exception)")
if tol is not None:
Expand Down
8 changes: 4 additions & 4 deletions src/flint/types/acb_poly.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ cdef class acb_poly(flint_poly):
return u

def __pos__(self):
return self # ?
return self # ?

def __neg__(s):
u = acb_poly.__new__(acb_poly)
Expand Down Expand Up @@ -261,7 +261,7 @@ cdef class acb_poly(flint_poly):
q = acb_poly.__new__(acb_poly)
r = acb_poly.__new__(acb_poly)
if acb_poly_divrem((<acb_poly>q).val, (<acb_poly>r).val,
(<acb_poly>s).val, (<acb_poly>t).val, getprec()):
(<acb_poly>s).val, (<acb_poly>t).val, getprec()):
return q
else:
raise ZeroDivisionError("acb_poly leading coefficient must be nonzero")
Expand All @@ -281,7 +281,7 @@ cdef class acb_poly(flint_poly):
q = acb_poly.__new__(acb_poly)
r = acb_poly.__new__(acb_poly)
if acb_poly_divrem((<acb_poly>q).val, (<acb_poly>r).val,
(<acb_poly>s).val, (<acb_poly>t).val, getprec()):
(<acb_poly>s).val, (<acb_poly>t).val, getprec()):
return r
else:
raise ZeroDivisionError("acb_poly leading coefficient must be nonzero")
Expand All @@ -301,7 +301,7 @@ cdef class acb_poly(flint_poly):
q = acb_poly.__new__(acb_poly)
r = acb_poly.__new__(acb_poly)
if acb_poly_divrem((<acb_poly>q).val, (<acb_poly>r).val,
(<acb_poly>s).val, (<acb_poly>t).val, getprec()):
(<acb_poly>s).val, (<acb_poly>t).val, getprec()):
return q, r
else:
raise ZeroDivisionError("acb_poly leading coefficient must be nonzero")
Expand Down
9 changes: 5 additions & 4 deletions src/flint/types/acb_series.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -731,8 +731,9 @@ cdef class acb_series(flint_series):
G = acb_series.__new__(acb_series)
Hpos = acb_series.__new__(acb_series)
Hneg = acb_series.__new__(acb_series)
acb_hypgeom_coulomb_series((<acb_series>F).val, (<acb_series>G).val, (<acb_series>Hpos).val, (<acb_series>Hneg).val,
(<acb>l).val, (<acb>eta).val, (<acb_series>self).val, cap, getprec())
acb_hypgeom_coulomb_series((<acb_series>F).val, (<acb_series>G).val, (<acb_series>Hpos).val,
(<acb_series>Hneg).val, (<acb>l).val, (<acb>eta).val,
(<acb_series>self).val, cap, getprec())
(<acb_series>F).prec = cap
(<acb_series>G).prec = cap
(<acb_series>Hpos).prec = cap
Expand All @@ -747,7 +748,7 @@ cdef class acb_series(flint_series):
cap = min(cap, (<acb_series>self).prec)
F = acb_series.__new__(acb_series)
acb_hypgeom_coulomb_series((<acb_series>F).val, NULL, NULL, NULL,
(<acb>l).val, (<acb>eta).val, (<acb_series>self).val, cap, getprec())
(<acb>l).val, (<acb>eta).val, (<acb_series>self).val, cap, getprec())
(<acb_series>F).prec = cap
return F

Expand All @@ -759,7 +760,7 @@ cdef class acb_series(flint_series):
cap = min(cap, (<acb_series>self).prec)
G = acb_series.__new__(acb_series)
acb_hypgeom_coulomb_series(NULL, (<acb_series>G).val, NULL, NULL,
(<acb>l).val, (<acb>eta).val, (<acb_series>self).val, cap, getprec())
(<acb>l).val, (<acb>eta).val, (<acb_series>self).val, cap, getprec())
(<acb_series>G).prec = cap
return G

Expand Down
14 changes: 7 additions & 7 deletions src/flint/types/arb.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ cdef class arb(flint_scalar):
if rad is not None:
rad = arb(rad)
arb_add_error(self.val, (<arb>rad).val)
#rad = arf(rad)
#arb_add_error_arf(self.val, (<arf>rad).val)
# rad = arf(rad)
# arb_add_error_arf(self.val, (<arf>rad).val)

cpdef bint is_zero(self):
return arb_is_zero(self.val)
Expand Down Expand Up @@ -1629,7 +1629,7 @@ cdef class arb(flint_scalar):
w = arb.__new__(arb)
z = arb.__new__(arb)
arb_hypgeom_airy((<arb>u).val, (<arb>v).val,
(<arb>w).val, (<arb>z).val, (<arb>s).val, getprec())
(<arb>w).val, (<arb>z).val, (<arb>s).val, getprec())
return u, v, w, z

@staticmethod
Expand Down Expand Up @@ -2281,7 +2281,7 @@ cdef class arb(flint_scalar):
if abc:
flags |= 16
arb_hypgeom_2f1((<arb>u).val, (<arb>a).val, (<arb>b).val, (<arb>c).val,
(<arb>self).val, flags, getprec())
(<arb>self).val, flags, getprec())
return u

@staticmethod
Expand Down Expand Up @@ -2622,7 +2622,7 @@ cdef class arb(flint_scalar):
F = arb.__new__(arb)
G = arb.__new__(arb)
arb_hypgeom_coulomb((<arb>F).val, (<arb>G).val,
(<arb>l).val, (<arb>eta).val, (<arb>self).val, getprec())
(<arb>l).val, (<arb>eta).val, (<arb>self).val, getprec())
return F, G

def coulomb_f(self, l, eta):
Expand All @@ -2638,7 +2638,7 @@ cdef class arb(flint_scalar):
eta = any_as_arb(eta)
F = arb.__new__(arb)
arb_hypgeom_coulomb((<arb>F).val, NULL,
(<arb>l).val, (<arb>eta).val, (<arb>self).val, getprec())
(<arb>l).val, (<arb>eta).val, (<arb>self).val, getprec())
return F

def coulomb_g(self, l, eta):
Expand All @@ -2654,5 +2654,5 @@ cdef class arb(flint_scalar):
eta = any_as_arb(eta)
G = arb.__new__(arb)
arb_hypgeom_coulomb(NULL, (<arb>G).val,
(<arb>l).val, (<arb>eta).val, (<arb>self).val, getprec())
(<arb>l).val, (<arb>eta).val, (<arb>self).val, getprec())
return G
8 changes: 4 additions & 4 deletions src/flint/types/arb_poly.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ cdef class arb_poly(flint_poly):
return u

def __pos__(self):
return self # ?
return self # ?

def __neg__(s):
u = arb_poly.__new__(arb_poly)
Expand Down Expand Up @@ -258,7 +258,7 @@ cdef class arb_poly(flint_poly):
q = arb_poly.__new__(arb_poly)
r = arb_poly.__new__(arb_poly)
if arb_poly_divrem((<arb_poly>q).val, (<arb_poly>r).val,
(<arb_poly>s).val, (<arb_poly>t).val, getprec()):
(<arb_poly>s).val, (<arb_poly>t).val, getprec()):
return q
else:
raise ZeroDivisionError("arb_poly leading coefficient must be nonzero")
Expand All @@ -278,7 +278,7 @@ cdef class arb_poly(flint_poly):
q = arb_poly.__new__(arb_poly)
r = arb_poly.__new__(arb_poly)
if arb_poly_divrem((<arb_poly>q).val, (<arb_poly>r).val,
(<arb_poly>s).val, (<arb_poly>t).val, getprec()):
(<arb_poly>s).val, (<arb_poly>t).val, getprec()):
return r
else:
raise ZeroDivisionError("arb_poly leading coefficient must be nonzero")
Expand All @@ -298,7 +298,7 @@ cdef class arb_poly(flint_poly):
q = arb_poly.__new__(arb_poly)
r = arb_poly.__new__(arb_poly)
if arb_poly_divrem((<arb_poly>q).val, (<arb_poly>r).val,
(<arb_poly>s).val, (<arb_poly>t).val, getprec()):
(<arb_poly>s).val, (<arb_poly>t).val, getprec()):
return q, r
else:
raise ZeroDivisionError("arb_poly leading coefficient must be nonzero")
Expand Down
Loading

0 comments on commit 397d973

Please sign in to comment.