diff --git a/pyproject.toml b/pyproject.toml index bfd3dee8..5cab8aa6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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] diff --git a/src/flint/flint_base/flint_base.pyx b/src/flint/flint_base/flint_base.pyx index 7c3c2292..2771c023 100644 --- a/src/flint/flint_base/flint_base.pyx +++ b/src/flint/flint_base/flint_base.pyx @@ -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() diff --git a/src/flint/functions/showgood.pyx b/src/flint/functions/showgood.pyx index ac7a87fd..107142d8 100644 --- a/src/flint/functions/showgood.pyx +++ b/src/flint/functions/showgood.pyx @@ -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 @@ -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: diff --git a/src/flint/test/test_all.py b/src/flint/test/test_all.py index fd7373b9..9494302f 100644 --- a/src/flint/test/test_all.py +++ b/src/flint/test/test_all.py @@ -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 @@ -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 @@ -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) @@ -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) diff --git a/src/flint/types/acb.pyx b/src/flint/types/acb.pyx index 15819309..efd94f3a 100644 --- a/src/flint/types/acb.pyx +++ b/src/flint/types/acb.pyx @@ -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: @@ -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, - (z).val, (tau).val, r + 1, getprec()) + (z).val, (tau).val, r + 1, getprec()) acb_set((t1).val, T1 + r) acb_set((t2).val, T2 + r) acb_set((t3).val, T3 + r) @@ -1556,7 +1547,7 @@ cdef class acb(flint_scalar): if abc: flags |= 16 acb_hypgeom_2f1((u).val, (a).val, (b).val, (c).val, - (self).val, flags, getprec()) + (self).val, flags, getprec()) return u def chebyshev_t(s, n): @@ -1764,7 +1755,7 @@ cdef class acb(flint_scalar): w = acb.__new__(acb) z = acb.__new__(acb) acb_hypgeom_airy((u).val, (v).val, - (w).val, (z).val, (s).val, getprec()) + (w).val, (z).val, (s).val, getprec()) return u, v, w, z def lambertw(s, branch=0, bint left=False, bint middle=False): @@ -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*. @@ -2752,7 +2743,7 @@ cdef class acb(flint_scalar): Hpos = acb.__new__(acb) Hneg = acb.__new__(acb) acb_hypgeom_coulomb((F).val, (G).val, (Hpos).val, (Hneg).val, - (l).val, (eta).val, (self).val, getprec()) + (l).val, (eta).val, (self).val, getprec()) return F, G, Hpos, Hneg def coulomb_f(self, l, eta): @@ -2768,7 +2759,7 @@ cdef class acb(flint_scalar): eta = any_as_acb(eta) F = acb.__new__(acb) acb_hypgeom_coulomb((F).val, NULL, NULL, NULL, - (l).val, (eta).val, (self).val, getprec()) + (l).val, (eta).val, (self).val, getprec()) return F def coulomb_g(self, l, eta): @@ -2784,5 +2775,5 @@ cdef class acb(flint_scalar): eta = any_as_acb(eta) G = acb.__new__(acb) acb_hypgeom_coulomb(NULL, (G).val, NULL, NULL, - (l).val, (eta).val, (self).val, getprec()) + (l).val, (eta).val, (self).val, getprec()) return G diff --git a/src/flint/types/acb_mat.pyx b/src/flint/types/acb_mat.pyx index 86609696..3c0eb187 100644 --- a/src/flint/types/acb_mat.pyx +++ b/src/flint/types/acb_mat.pyx @@ -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: diff --git a/src/flint/types/acb_poly.pyx b/src/flint/types/acb_poly.pyx index 712c5980..0c2cdaa9 100644 --- a/src/flint/types/acb_poly.pyx +++ b/src/flint/types/acb_poly.pyx @@ -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) @@ -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((q).val, (r).val, - (s).val, (t).val, getprec()): + (s).val, (t).val, getprec()): return q else: raise ZeroDivisionError("acb_poly leading coefficient must be nonzero") @@ -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((q).val, (r).val, - (s).val, (t).val, getprec()): + (s).val, (t).val, getprec()): return r else: raise ZeroDivisionError("acb_poly leading coefficient must be nonzero") @@ -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((q).val, (r).val, - (s).val, (t).val, getprec()): + (s).val, (t).val, getprec()): return q, r else: raise ZeroDivisionError("acb_poly leading coefficient must be nonzero") diff --git a/src/flint/types/acb_series.pyx b/src/flint/types/acb_series.pyx index c422b781..6fe65740 100644 --- a/src/flint/types/acb_series.pyx +++ b/src/flint/types/acb_series.pyx @@ -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((F).val, (G).val, (Hpos).val, (Hneg).val, - (l).val, (eta).val, (self).val, cap, getprec()) + acb_hypgeom_coulomb_series((F).val, (G).val, (Hpos).val, + (Hneg).val, (l).val, (eta).val, + (self).val, cap, getprec()) (F).prec = cap (G).prec = cap (Hpos).prec = cap @@ -747,7 +748,7 @@ cdef class acb_series(flint_series): cap = min(cap, (self).prec) F = acb_series.__new__(acb_series) acb_hypgeom_coulomb_series((F).val, NULL, NULL, NULL, - (l).val, (eta).val, (self).val, cap, getprec()) + (l).val, (eta).val, (self).val, cap, getprec()) (F).prec = cap return F @@ -759,7 +760,7 @@ cdef class acb_series(flint_series): cap = min(cap, (self).prec) G = acb_series.__new__(acb_series) acb_hypgeom_coulomb_series(NULL, (G).val, NULL, NULL, - (l).val, (eta).val, (self).val, cap, getprec()) + (l).val, (eta).val, (self).val, cap, getprec()) (G).prec = cap return G diff --git a/src/flint/types/arb.pyx b/src/flint/types/arb.pyx index 30b38b74..4ae8fa45 100644 --- a/src/flint/types/arb.pyx +++ b/src/flint/types/arb.pyx @@ -192,8 +192,8 @@ cdef class arb(flint_scalar): if rad is not None: rad = arb(rad) arb_add_error(self.val, (rad).val) - #rad = arf(rad) - #arb_add_error_arf(self.val, (rad).val) + # rad = arf(rad) + # arb_add_error_arf(self.val, (rad).val) cpdef bint is_zero(self): return arb_is_zero(self.val) @@ -1629,7 +1629,7 @@ cdef class arb(flint_scalar): w = arb.__new__(arb) z = arb.__new__(arb) arb_hypgeom_airy((u).val, (v).val, - (w).val, (z).val, (s).val, getprec()) + (w).val, (z).val, (s).val, getprec()) return u, v, w, z @staticmethod @@ -2281,7 +2281,7 @@ cdef class arb(flint_scalar): if abc: flags |= 16 arb_hypgeom_2f1((u).val, (a).val, (b).val, (c).val, - (self).val, flags, getprec()) + (self).val, flags, getprec()) return u @staticmethod @@ -2622,7 +2622,7 @@ cdef class arb(flint_scalar): F = arb.__new__(arb) G = arb.__new__(arb) arb_hypgeom_coulomb((F).val, (G).val, - (l).val, (eta).val, (self).val, getprec()) + (l).val, (eta).val, (self).val, getprec()) return F, G def coulomb_f(self, l, eta): @@ -2638,7 +2638,7 @@ cdef class arb(flint_scalar): eta = any_as_arb(eta) F = arb.__new__(arb) arb_hypgeom_coulomb((F).val, NULL, - (l).val, (eta).val, (self).val, getprec()) + (l).val, (eta).val, (self).val, getprec()) return F def coulomb_g(self, l, eta): @@ -2654,5 +2654,5 @@ cdef class arb(flint_scalar): eta = any_as_arb(eta) G = arb.__new__(arb) arb_hypgeom_coulomb(NULL, (G).val, - (l).val, (eta).val, (self).val, getprec()) + (l).val, (eta).val, (self).val, getprec()) return G diff --git a/src/flint/types/arb_poly.pyx b/src/flint/types/arb_poly.pyx index 6c69745d..4f80ba98 100644 --- a/src/flint/types/arb_poly.pyx +++ b/src/flint/types/arb_poly.pyx @@ -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) @@ -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((q).val, (r).val, - (s).val, (t).val, getprec()): + (s).val, (t).val, getprec()): return q else: raise ZeroDivisionError("arb_poly leading coefficient must be nonzero") @@ -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((q).val, (r).val, - (s).val, (t).val, getprec()): + (s).val, (t).val, getprec()): return r else: raise ZeroDivisionError("arb_poly leading coefficient must be nonzero") @@ -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((q).val, (r).val, - (s).val, (t).val, getprec()): + (s).val, (t).val, getprec()): return q, r else: raise ZeroDivisionError("arb_poly leading coefficient must be nonzero") diff --git a/src/flint/types/arb_series.pyx b/src/flint/types/arb_series.pyx index ac61475a..9d0ebe5e 100644 --- a/src/flint/types/arb_series.pyx +++ b/src/flint/types/arb_series.pyx @@ -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((F).val, (G).val, - (l).val, (eta).val, (self).val, cap, getprec()) + (l).val, (eta).val, (self).val, cap, getprec()) (F).prec = cap (G).prec = cap return F, G @@ -710,7 +710,7 @@ cdef class arb_series(flint_series): cap = min(cap, (self).prec) F = arb_series.__new__(arb_series) arb_hypgeom_coulomb_series((F).val, NULL, - (l).val, (eta).val, (self).val, cap, getprec()) + (l).val, (eta).val, (self).val, cap, getprec()) (F).prec = cap return F @@ -722,7 +722,7 @@ cdef class arb_series(flint_series): cap = min(cap, (self).prec) G = arb_series.__new__(arb_series) arb_hypgeom_coulomb_series(NULL, (G).val, - (l).val, (eta).val, (self).val, cap, getprec()) + (l).val, (eta).val, (self).val, cap, getprec()) (G).prec = cap return G @@ -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)) diff --git a/src/flint/types/fmpq.pyx b/src/flint/types/fmpq.pyx index 669d79d2..c4569426 100644 --- a/src/flint/types/fmpq.pyx +++ b/src/flint/types/fmpq.pyx @@ -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: diff --git a/src/flint/types/fmpq_mat.pyx b/src/flint/types/fmpq_mat.pyx index 5f56440f..0daf80dd 100644 --- a/src/flint/types/fmpq_mat.pyx +++ b/src/flint/types/fmpq_mat.pyx @@ -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((t).val), - fmpq_mat_ncols((t).val)) + fmpq_mat_ncols((t).val)) if algorithm is None: if fmpq_mat_nrows(self.val) < 25: result = fmpq_mat_solve_fraction_free(u.val, self.val, (t).val) diff --git a/src/flint/types/fmpq_series.pyx b/src/flint/types/fmpq_series.pyx index 086e2c8b..9dd59fbe 100644 --- a/src/flint/types/fmpq_series.pyx +++ b/src/flint/types/fmpq_series.pyx @@ -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) diff --git a/src/flint/types/fmpz.pyx b/src/flint/types/fmpz.pyx index e5b6f4cb..71270b75 100644 --- a/src/flint/types/fmpz.pyx +++ b/src/flint/types/fmpz.pyx @@ -77,7 +77,7 @@ cdef class fmpz(flint_scalar): if typecheck(val, fmpz): fmpz_set(self.val, (val).val) else: - if fmpz_set_any_ref(self.val, val) == FMPZ_UNKNOWN: # XXX + if fmpz_set_any_ref(self.val, val) == FMPZ_UNKNOWN: # XXX if typecheck(val, str): if fmpz_set_str(self.val, chars_from_str(val), 10) != 0: raise ValueError("invalid string for fmpz") @@ -527,45 +527,29 @@ cdef class fmpz(flint_scalar): fmpz_clear(tval) return u - # This is the correct code when fmpz_or is fixed (in flint 3.0.0) - # - #def __or__(self, other): - # cdef fmpz_struct tval[1] - # cdef int ttype = FMPZ_UNKNOWN - # ttype = fmpz_set_any_ref(tval, other) - # if ttype == FMPZ_UNKNOWN: - # return NotImplemented - # u = fmpz.__new__(fmpz) - # fmpz_or((u).val, self.val, tval) - # if ttype == FMPZ_TMP: - # fmpz_clear(tval) - # return u - # - #def __ror__(self, other): - # cdef fmpz_struct tval[1] - # cdef int ttype = FMPZ_UNKNOWN - # ttype = fmpz_set_any_ref(tval, other) - # if ttype == FMPZ_UNKNOWN: - # return NotImplemented - # u = fmpz.__new__(fmpz) - # fmpz_or((u).val, tval, self.val) - # if ttype == FMPZ_TMP: - # fmpz_clear(tval) - # return u - def __or__(self, other): - if typecheck(other, fmpz): - other = int(other) - if typecheck(other, int): - return fmpz(int(self) | other) - else: + cdef fmpz_struct tval[1] + cdef int ttype = FMPZ_UNKNOWN + ttype = fmpz_set_any_ref(tval, other) + if ttype == FMPZ_UNKNOWN: return NotImplemented + u = fmpz.__new__(fmpz) + fmpz_or((u).val, self.val, tval) + if ttype == FMPZ_TMP: + fmpz_clear(tval) + return u def __ror__(self, other): - if typecheck(other, int): - return fmpz(other | int(self)) - else: + cdef fmpz_struct tval[1] + cdef int ttype = FMPZ_UNKNOWN + ttype = fmpz_set_any_ref(tval, other) + if ttype == FMPZ_UNKNOWN: return NotImplemented + u = fmpz.__new__(fmpz) + fmpz_or((u).val, tval, self.val) + if ttype == FMPZ_TMP: + fmpz_clear(tval) + return u def __xor__(self, other): cdef fmpz_struct tval[1] diff --git a/src/flint/types/fmpz_mat.pyx b/src/flint/types/fmpz_mat.pyx index 8c4a29ac..e2d6444f 100644 --- a/src/flint/types/fmpz_mat.pyx +++ b/src/flint/types/fmpz_mat.pyx @@ -548,7 +548,7 @@ cdef class fmpz_mat(flint_mat): else: u = fmpz_mat.__new__(fmpz_mat) fmpz_mat_init(u.val, fmpz_mat_nrows((t).val), - fmpz_mat_ncols((t).val)) + fmpz_mat_ncols((t).val)) d = fmpz.__new__(fmpz) result = fmpz_mat_solve(u.val, d.val, self.val, (t).val) if not fmpz_is_pm1(d.val): diff --git a/src/flint/types/fmpz_mod_mat.pxd b/src/flint/types/fmpz_mod_mat.pxd index 085a523d..bf76f93b 100644 --- a/src/flint/types/fmpz_mod_mat.pxd +++ b/src/flint/types/fmpz_mod_mat.pxd @@ -14,7 +14,7 @@ cdef class fmpz_mod_mat(flint_mat): cdef void _init_empty(self, slong m, slong n, list args) cdef void _init_empty_ctx(self, slong m, slong n, fmpz_mod_ctx ctx) cdef void _init_from_list(self, slong m, slong n, list entries, list args) - #cdef void _init_from_matrix(self, flint_mat M, list args) + # cdef void _init_from_matrix(self, flint_mat M, list args) cdef void _init_from_matrix(self, M, list args) cdef fmpz_mod_ctx _parse_args(self, list args) cdef fmpz_mod_mat _new(self, slong m, slong n, fmpz_mod_ctx ctx) diff --git a/src/flint/types/fmpz_mod_poly.pyx b/src/flint/types/fmpz_mod_poly.pyx index 0e1b579b..69e17e71 100644 --- a/src/flint/types/fmpz_mod_poly.pyx +++ b/src/flint/types/fmpz_mod_poly.pyx @@ -39,7 +39,7 @@ cdef class fmpz_mod_poly_ctx: # Allow context to be made from fmpz_mod_ctx if typecheck(mod, fmpz_mod_ctx): self.mod = mod - else: # Otherwise attempt to create context from moduli + else: # Otherwise attempt to create context from moduli self.mod = fmpz_mod_ctx(mod) def modulus(self): @@ -579,7 +579,7 @@ cdef class fmpz_mod_poly(flint_poly): fmpz_mod_poly_shift_left( res.val, self.val, n, self.ctx.mod.val ) - else: # do nothing, just copy self + else: # do nothing, just copy self fmpz_mod_poly_set( res.val, self.val, self.ctx.mod.val ) @@ -612,7 +612,7 @@ cdef class fmpz_mod_poly(flint_poly): fmpz_mod_poly_shift_right( res.val, self.val, n, self.ctx.mod.val ) - else: # do nothing, just copy self + else: # do nothing, just copy self fmpz_mod_poly_set( res.val, self.val, self.ctx.mod.val ) @@ -1004,9 +1004,9 @@ cdef class fmpz_mod_poly(flint_poly): length = fmpz_mod_poly_degree(self.val, self.ctx.mod.val) res = self.ctx.new_ctype_poly() - if n <= 0: # return zero + if n <= 0: # return zero return res - elif n > length: # do nothing + elif n > length: # do nothing fmpz_mod_poly_set( res.val, self.val, self.ctx.mod.val ) @@ -1186,7 +1186,7 @@ cdef class fmpz_mod_poly(flint_poly): # For larger exponents we need to cast e to an fmpz first e_fmpz = any_as_fmpz(e) if e_fmpz is NotImplemented: - raise TypeError(f"exponent cannot be cast to an fmpz type: {e = }") + raise TypeError(f"exponent cannot be cast to an fmpz type: {e}") # To optimise powering, we precompute the inverse of the reverse of the modulus if mod_rev_inv is not None: @@ -1716,7 +1716,7 @@ cdef class fmpz_mod_poly(flint_poly): self.val, self.ctx.mod.val ) if n > n_max: - raise ValueError(f"Cannot deflate with {n = }, maximum allowed value is {n_max = }") + raise ValueError(f"Cannot deflate with n = {n}, maximum allowed value is n_max = {n_max}") res = self.ctx.new_ctype_poly() fmpz_mod_poly_deflate( diff --git a/src/flint/types/fmpz_series.pyx b/src/flint/types/fmpz_series.pyx index 4689e7e8..d7ac00ef 100644 --- a/src/flint/types/fmpz_series.pyx +++ b/src/flint/types/fmpz_series.pyx @@ -22,8 +22,8 @@ cdef fmpz_series_coerce_operands(x, y): return x, fmpz_series(y) if isinstance(y, (fmpq, fmpq_poly, fmpq_series)): return fmpq_series(x), fmpq_series(y) - #if isinstance(y, (nmod, nmod_poly, nmod_series)): - # return nmod_series(x), nmod_series(y) + # 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) if isinstance(y, (complex, acb, acb_poly, acb_series)): diff --git a/src/flint/types/fq_default.pxd b/src/flint/types/fq_default.pxd index 178c6169..02692281 100644 --- a/src/flint/types/fq_default.pxd +++ b/src/flint/types/fq_default.pxd @@ -15,11 +15,11 @@ cpdef enum fq_default_type: These can be manually selected, or type: `fq_default_ctx.DEFAULT` can be used for the implementation to be automatically decided by Flint (default), """ - DEFAULT = 0 - FQ_ZECH = 1 - FQ_NMOD = 2 - FQ = 3 - NMOD = 4 + DEFAULT = 0 + FQ_ZECH = 1 + FQ_NMOD = 2 + FQ = 3 + NMOD = 4 FMPZ_MOD = 5 cdef class fq_default_ctx: diff --git a/src/flint/types/fq_default.pyx b/src/flint/types/fq_default.pyx index 6b6e2bee..637a86c0 100644 --- a/src/flint/types/fq_default.pyx +++ b/src/flint/types/fq_default.pyx @@ -56,9 +56,9 @@ cdef class fq_default_ctx: # Now fq_type should be an int between 0, 5 if not typecheck(fq_type, int): - raise TypeError(f"{fq_type = } is invalid") + raise TypeError(f"fq_type = {fq_type} is invalid") if fq_type < 0 or fq_type > 5: - raise ValueError(f"{fq_type = } should be between 0 and 5") + raise ValueError(f"fq_type = {fq_type} should be between 0 and 5") return fq_type @@ -129,14 +129,14 @@ cdef class fq_default_ctx: # c_from_order expects the characteristic to be fmpz type prime = any_as_fmpz(p) if prime is NotImplemented: - raise TypeError(f"cannot coerce {p = } to type fmpz") + raise TypeError(f"cannot coerce p = {p} to type fmpz") if check_prime and not prime.is_prime(): raise ValueError("characteristic is not prime") # the degree must be strictly positive if d < 1: - raise ValueError(f"the degree must be positive, got {d = }") + raise ValueError(f"the degree must be positive, got d = {d}") fq_default_ctx_init_type(self.val, (prime).val, d, self.var, fq_type) self._initialized = True diff --git a/src/flint/types/fq_default_poly.pyx b/src/flint/types/fq_default_poly.pyx index 982607e8..ec2dfe83 100644 --- a/src/flint/types/fq_default_poly.pyx +++ b/src/flint/types/fq_default_poly.pyx @@ -31,7 +31,7 @@ cdef class fq_default_poly_ctx: # Allow context to be made from fq_default_ctx if len(args) == 1 and typecheck(args[0], fq_default_ctx): self.field = args[0] - else: # Otherwise attempt to create context from moduli + else: # Otherwise attempt to create context from moduli self.field = fq_default_ctx(*args, **kwargs) cdef set_list_as_fq_default_poly(self, fq_default_poly_t poly, val): @@ -47,7 +47,7 @@ cdef class fq_default_poly_ctx: # First coerce the list element as an fq_default type v = self.field.any_as_fq_default(val[i]) if v is NotImplemented: - raise TypeError(f"unsupported coefficient in list: {val[i] = }, {type(val[i]) = }") + raise TypeError(f"unsupported coefficient in list: val[i] = {val[i]}, type(val[i] = {type(val[i])}") # Set the coefficient of the polynomial fq_default_poly_set_coeff( @@ -431,9 +431,9 @@ cdef class fq_default_poly(flint_poly): length = fq_default_poly_degree(self.val, self.ctx.field.val) res = self.ctx.new_ctype_poly() - if n <= 0: # return zero + if n <= 0: # return zero return res - elif n > length: # do nothing + elif n > length: # do nothing fq_default_poly_set( res.val, self.val, self.ctx.field.val ) @@ -453,7 +453,7 @@ cdef class fq_default_poly(flint_poly): x^2 + 55*x + 109 """ cdef fq_default_poly res - res = self.ctx.new_ctype_poly() + res = self.ctx.new_ctype_poly() fq_default_poly_make_monic( res.val, self.val, self.ctx.field.val ) @@ -563,7 +563,7 @@ cdef class fq_default_poly(flint_poly): def __neg__(self): cdef fq_default_poly res - res = self.ctx.new_ctype_poly() + res = self.ctx.new_ctype_poly() fq_default_poly_neg( res.val, self.val, self.ctx.field.val ) @@ -576,7 +576,7 @@ cdef class fq_default_poly(flint_poly): if other is NotImplemented: return NotImplemented - res = self.ctx.new_ctype_poly() + res = self.ctx.new_ctype_poly() fq_default_poly_add( res.val, self.val, (other).val, self.ctx.field.val ) @@ -592,7 +592,7 @@ cdef class fq_default_poly(flint_poly): if other is NotImplemented: return NotImplemented - res = self.ctx.new_ctype_poly() + res = self.ctx.new_ctype_poly() fq_default_poly_sub( res.val, self.val, (other).val, self.ctx.field.val ) @@ -605,7 +605,7 @@ cdef class fq_default_poly(flint_poly): if other is NotImplemented: return NotImplemented - res = self.ctx.new_ctype_poly() + res = self.ctx.new_ctype_poly() fq_default_poly_sub( res.val, (other).val, self.val, self.ctx.field.val ) @@ -613,7 +613,7 @@ cdef class fq_default_poly(flint_poly): def __mul__(self, other): cdef fq_default_poly res - res = self.ctx.new_ctype_poly() + res = self.ctx.new_ctype_poly() # First try scalar multiplication if not typecheck(other, fq_default_poly): @@ -766,7 +766,7 @@ cdef class fq_default_poly(flint_poly): def __truediv__(self, other): cdef fq_default_poly res - res = self.ctx.new_ctype_poly() + res = self.ctx.new_ctype_poly() # First try scalar division if not typecheck(other, fq_default_poly): @@ -854,7 +854,7 @@ cdef class fq_default_poly(flint_poly): if other.is_zero(): raise ZeroDivisionError("Cannot compute remainder modulo 0") - res = self.ctx.new_ctype_poly() + res = self.ctx.new_ctype_poly() fq_default_poly_rem( res.val, self.val, (other).val, self.ctx.field.val ) @@ -870,7 +870,7 @@ cdef class fq_default_poly(flint_poly): if other is NotImplemented: return NotImplemented - res = self.ctx.new_ctype_poly() + res = self.ctx.new_ctype_poly() fq_default_poly_rem( res.val, (other).val, self.val, self.ctx.field.val ) @@ -923,7 +923,7 @@ cdef class fq_default_poly(flint_poly): fq_default_poly_shift_left( res.val, self.val, n, self.ctx.field.val ) - else: # do nothing, just copy self + else: # do nothing, just copy self fq_default_poly_set( res.val, self.val, self.ctx.field.val ) @@ -956,7 +956,7 @@ cdef class fq_default_poly(flint_poly): fq_default_poly_shift_right( res.val, self.val, n, self.ctx.field.val ) - else: # do nothing, just copy self + else: # do nothing, just copy self fq_default_poly_set( res.val, self.val, self.ctx.field.val ) @@ -1324,7 +1324,7 @@ cdef class fq_default_poly(flint_poly): """ G, S, _ = self.xgcd(other) if not G.is_one(): - raise ValueError(f"polynomial has no inverse modulo {other = }") + raise ValueError(f"polynomial has no inverse modulo other = {other}") return S # ==================================== @@ -1638,7 +1638,7 @@ cdef class fq_default_poly(flint_poly): self.val, self.ctx.field.val ) if n > n_max: - raise ValueError(f"Cannot deflate with {n = }, maximum allowed value is {n_max = }") + raise ValueError(f"Cannot deflate with n = {n}, maximum allowed value is n_max = {n_max}") res = self.ctx.new_ctype_poly() fq_default_poly_deflate( diff --git a/src/flint/types/nmod_mat.pyx b/src/flint/types/nmod_mat.pyx index fc5b36ba..5a54cdce 100644 --- a/src/flint/types/nmod_mat.pyx +++ b/src/flint/types/nmod_mat.pyx @@ -100,7 +100,7 @@ cdef class nmod_mat(flint_mat): val = args[0] if typecheck(val, fmpz_mat): nmod_mat_init(self.val, fmpz_mat_nrows((val).val), - fmpz_mat_ncols((val).val), mod) + fmpz_mat_ncols((val).val), mod) fmpz_mat_get_nmod_mat(self.val, (val).val) elif isinstance(val, (list, tuple)): m = len(val) @@ -198,7 +198,7 @@ cdef class nmod_mat(flint_mat): i, j = index if i < 0 or i >= self.nrows() or j < 0 or j >= self.ncols(): raise IndexError("index %i,%i exceeds matrix dimensions" % (i, j)) - x = nmod(nmod_mat_entry(self.val, i, j), self.modulus()) # XXX: slow + x = nmod(nmod_mat_entry(self.val, i, j), self.modulus()) # XXX: slow return x def __setitem__(self, index, value): @@ -387,7 +387,7 @@ cdef class nmod_mat(flint_mat): raise ValueError("matrix must be square") u = nmod_mat.__new__(nmod_mat) nmod_mat_init(u.val, nmod_mat_nrows(self.val), - nmod_mat_ncols(self.val), self.val.mod.n) + nmod_mat_ncols(self.val), self.val.mod.n) if not nmod_mat_inv(u.val, self.val): raise ZeroDivisionError("matrix is singular") return u @@ -404,7 +404,7 @@ cdef class nmod_mat(flint_mat): cdef nmod_mat u u = nmod_mat.__new__(nmod_mat) nmod_mat_init(u.val, nmod_mat_ncols(self.val), - nmod_mat_nrows(self.val), self.val.mod.n) + nmod_mat_nrows(self.val), self.val.mod.n) nmod_mat_transpose(u.val, self.val) return u @@ -441,7 +441,7 @@ cdef class nmod_mat(flint_mat): raise ValueError("need a square system and compatible right hand side") u = nmod_mat.__new__(nmod_mat) nmod_mat_init(u.val, nmod_mat_nrows((t).val), - nmod_mat_ncols((t).val), self.val.mod.n) + nmod_mat_ncols((t).val), self.val.mod.n) result = nmod_mat_solve(u.val, self.val, (t).val) if not result: raise ZeroDivisionError("singular matrix in solve()") diff --git a/src/flint/types/nmod_poly.pyx b/src/flint/types/nmod_poly.pyx index 020448b2..b9259676 100644 --- a/src/flint/types/nmod_poly.pyx +++ b/src/flint/types/nmod_poly.pyx @@ -38,7 +38,7 @@ cdef nmod_poly_set_list(nmod_poly_t poly, list val): cdef long i, n cdef nmod_t mod cdef mp_limb_t v - nmod_init(&mod, nmod_poly_modulus(poly)) # XXX + nmod_init(&mod, nmod_poly_modulus(poly)) # XXX n = PyList_GET_SIZE(val) nmod_poly_fit_length(poly, n) for i from 0 <= i < n: @@ -262,7 +262,7 @@ cdef class nmod_poly(flint_poly): 45*x^4 + 23*x^3 + 159*x^2 + 151*x + 110 """ if n <= 0: - raise ValueError(f"{n = } must be positive") + raise ValueError(f"n = {n} must be positive") if self.is_zero(): raise ValueError("cannot invert the zero element") @@ -315,11 +315,11 @@ cdef class nmod_poly(flint_poly): cdef nmod_poly res g = any_as_nmod_poly(other, self.val.mod) if g is NotImplemented: - raise TypeError(f"cannot convert {other = } to nmod_poly") + raise TypeError(f"cannot convert other = {other} to nmod_poly") h = any_as_nmod_poly(modulus, self.val.mod) if h is NotImplemented: - raise TypeError(f"cannot convert {modulus = } to nmod_poly") + raise TypeError(f"cannot convert modulus = {modulus} to nmod_poly") if modulus.is_zero(): raise ZeroDivisionError("cannot reduce modulo zero") @@ -549,7 +549,7 @@ cdef class nmod_poly(flint_poly): # For larger exponents we need to cast e to an fmpz first e_fmpz = any_as_fmpz(e) if e_fmpz is NotImplemented: - raise TypeError(f"exponent cannot be cast to an fmpz type: {e = }") + raise TypeError(f"exponent cannot be cast to an fmpz type: {e}") # To optimise powering, we precompute the inverse of the reverse of the modulus if mod_rev_inv is not None: @@ -676,7 +676,7 @@ cdef class nmod_poly(flint_poly): for 0 <= i < fac.num: u = nmod_poly.__new__(nmod_poly) nmod_poly_init_preinv((u).val, - (self).val.mod.n, (self).val.mod.ninv) + (self).val.mod.n, (self).val.mod.ninv) nmod_poly_set((u).val, &fac.p[i]) exp = fac.exp[i] res[i] = (u, exp)