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

Small changes to please cython-lint #211

Merged
merged 12 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from 9 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
10 changes: 9 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,16 @@ requires = ["meson-python>=0.13", "cython>=3.0,<3.1"]
build-backend = "mesonpy"

[tool.cython-lint]
# We currently ignore
# E129 visually indented line with same indent as next logical line
# E202 whitespace before '}'
# E501 line too long (128 > 120 characters)
# E741 ambiguous variable name
# E743 ambiguous function definition
# TODO: E743 should be fixed, see issue #210
# E501 should be fixed once we decide line length
max-line-length = 120
ignore = ['E128','E129','E202','E221','E222','E261','E262','E265','E501','E731','E741','E743']
ignore = ['E129','E202','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
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think something should be kept in the comment here.

This is not how it works for arb and acb since +a rounds to context precision:

In [1]: from flint import *

In [2]: a = arb(10**50)

In [3]: a
Out[3]: 1.00000000000000e+50

In [4]: +a
Out[4]: [1.00000000000000e+50 +/- 3.40e+34]

In [5]: a.man_exp()
Out[5]: (88817841970012523233890533447265625, 50)

In [7]: (+a).mid().man_exp()
Out[7]: (4814824860968089, 114)

I assume that the comment here is a reminder that maybe this method should be changed to match by using acb_poly_set_round.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have reintroduced the comments


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
9 changes: 3 additions & 6 deletions src/flint/types/arb_series.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ cdef class arb_series(flint_series):
F = arb_series.__new__(arb_series)
G = arb_series.__new__(arb_series)
arb_hypgeom_coulomb_series((<arb_series>F).val, (<arb_series>G).val,
(<arb>l).val, (<arb>eta).val, (<arb_series>self).val, cap, getprec())
(<arb>l).val, (<arb>eta).val, (<arb_series>self).val, cap, getprec())
(<arb_series>F).prec = cap
(<arb_series>G).prec = cap
return F, G
Expand All @@ -710,7 +710,7 @@ cdef class arb_series(flint_series):
cap = min(cap, (<arb_series>self).prec)
F = arb_series.__new__(arb_series)
arb_hypgeom_coulomb_series((<arb_series>F).val, NULL,
(<arb>l).val, (<arb>eta).val, (<arb_series>self).val, cap, getprec())
(<arb>l).val, (<arb>eta).val, (<arb_series>self).val, cap, getprec())
(<arb_series>F).prec = cap
return F

Expand All @@ -722,7 +722,7 @@ cdef class arb_series(flint_series):
cap = min(cap, (<arb_series>self).prec)
G = arb_series.__new__(arb_series)
arb_hypgeom_coulomb_series(NULL, (<arb_series>G).val,
(<arb>l).val, (<arb>eta).val, (<arb_series>self).val, cap, getprec())
(<arb>l).val, (<arb>eta).val, (<arb_series>self).val, cap, getprec())
(<arb_series>G).prec = cap
return G

Expand Down Expand Up @@ -830,9 +830,6 @@ cdef class arb_series(flint_series):
v = f(arb_series([arb(m, r)]))
if v[0] != 0:
continue
#ctx.cap = 1
#fa = xsgn(f(arb_series(a))[0])
#fb = xsgn(f(arb_series(b))[0])
ctx.cap = 2
if fa * fb < 0 and f(arb_series([arb(m, r), 1]))[1] != 0:
roots.append((a, b))
Expand Down
2 changes: 1 addition & 1 deletion src/flint/types/fmpq.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ cdef class fmpq(flint_scalar):

def __init__(self, *args):
if not args:
return # zero
return # zero
elif len(args) == 2:
p, q = args
elif len(args) == 1:
Expand Down
2 changes: 1 addition & 1 deletion src/flint/types/fmpq_mat.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ cdef class fmpq_mat(flint_mat):
raise ValueError("need a square system and compatible right hand side")
u = fmpq_mat.__new__(fmpq_mat)
fmpq_mat_init(u.val, fmpq_mat_nrows((<fmpq_mat>t).val),
fmpq_mat_ncols((<fmpq_mat>t).val))
fmpq_mat_ncols((<fmpq_mat>t).val))
if algorithm is None:
if fmpq_mat_nrows(self.val) < 25:
result = fmpq_mat_solve_fraction_free(u.val, self.val, (<fmpq_mat>t).val)
Expand Down
2 changes: 1 addition & 1 deletion src/flint/types/fmpq_series.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ from flint.flintlib.fmpq_poly cimport *
cdef fmpq_series_coerce_operands(x, y):
if isinstance(y, (int, fmpz, fmpz_poly, fmpz_series, fmpq, fmpq_poly)):
return x, fmpq_series(y)
#if isinstance(y, (nmod, nmod_poly, nmod_series)):
# if isinstance(y, (nmod, nmod_poly, nmod_series)):
# return nmod_series(x), nmod_series(y)
if isinstance(y, (float, arb, arb_poly, arb_series)):
return arb_series(x), arb_series(y)
Expand Down
Loading
Loading