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

first sketch of cython-lint workflow #204

Merged
merged 5 commits into from
Aug 30, 2024
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
26 changes: 26 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Linting

on: [push, pull_request]

jobs:
lint:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.11", "3.12"]
steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
pip install uv
uv pip install cython-lint --upgrade --system

- name: cython-lint
run: |
cython-lint src/
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ content-type = "text/markdown"
requires = ["meson-python>=0.13", "cython>=3.0,<3.1"]
build-backend = "mesonpy"

[tool.cython-lint]
max-line-length = 120
ignore = ['E114','E117','E127','E128','E129','E202','E221','E222','E231','E261','E262','E265','E302','E303','E306','E501','E701','E703','E711','E722','E731','E741','E743','W391']
exclude = 'src/flint/flintlib/.*'

[tool.spin]
package = "flint"

Expand Down
3 changes: 1 addition & 2 deletions src/flint/pyflint.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
Python wrapper for FLINT and Arb.
"""

cimport flint
# cimport flint
cimport libc.stdlib
cimport cython

from flint.flint_base.flint_context cimport thectx

Expand Down
20 changes: 10 additions & 10 deletions src/flint/types/acb.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ cdef any_as_acb_or_notimplemented(x):
return NotImplemented
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)
"""

# 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
Expand Down Expand Up @@ -2387,7 +2387,7 @@ cdef class acb(flint_scalar):
of terms to add in the hypergeometric series. This is just a tuning
parameter: a rigorous error bound is computed regardless of *n*.
"""
cdef long i, p, q, prec
cdef long i, p, q
cdef acb_ptr aa, bb
a = [any_as_acb(t) for t in a]
b = [any_as_acb(t) for t in b]
Expand Down
2 changes: 0 additions & 2 deletions src/flint/types/acb_mat.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ cdef class acb_mat(flint_mat):
return u

def __truediv__(s, t):
cdef acb_mat u
if typecheck(s, acb_mat):
s, t = acb_mat_coerce_scalar(s, t)
if s is NotImplemented:
Expand Down Expand Up @@ -597,7 +596,6 @@ cdef class acb_mat(flint_mat):
return u

def __richcmp__(s, t, int op):
cdef int stype, ttype
cdef bint res
if not (op == 2 or op == 3):
raise ValueError("comparing matrices")
Expand Down
2 changes: 1 addition & 1 deletion src/flint/types/acb_poly.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ cdef class acb_poly(flint_poly):
ValueError: roots() failed to converge: insufficient precision, or squareful input

"""
cdef long prec, initial_prec, target_prec, isolated, maxiter, deg, i
cdef long prec, initial_prec, isolated, maxiter, deg, i
cdef acb_ptr roots
cdef acb_poly_t tmp
deg = s.degree()
Expand Down
3 changes: 1 addition & 2 deletions src/flint/types/acb_series.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ from flint.types.acb cimport acb
from flint.types.fmpz_poly cimport fmpz_poly
from flint.types.fmpq_poly cimport fmpq_poly
from flint.types.arb_poly cimport arb_poly
from flint.types.arb_poly cimport arb_poly_set_list
from flint.types.acb_poly cimport acb_poly_set_list
from flint.types.arb cimport arb
from flint.types.acb_poly cimport acb_poly
Expand Down Expand Up @@ -629,7 +628,7 @@ cdef class acb_series(flint_series):
of terms to add in the hypergeometric series. This is just a tuning
parameter: a rigorous error bound is computed regardless of *n*.
"""
cdef long i, p, q, prec, cap
cdef long i, p, q, cap
cdef acb_poly_struct * aa
cdef acb_poly_struct * bb
a = [acb_series(t) for t in a]
Expand Down
6 changes: 3 additions & 3 deletions src/flint/types/arb.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ from flint.flint_base.flint_context cimport getprec
from flint.flint_base.flint_context cimport thectx
from flint.flint_base.flint_base cimport flint_scalar
from flint.utils.typecheck cimport typecheck
from flint.utils.conversion cimport chars_from_str, str_from_chars, _str_trunc
from flint.utils.conversion cimport chars_from_str, str_from_chars
from flint.types.fmpz cimport fmpz_set_pylong
from flint.types.arf cimport arf
from flint.types.fmpq cimport fmpq
Expand Down Expand Up @@ -43,7 +43,7 @@ cdef arb_from_str(str s):
raise ValueError("invalid string for arb()")

cdef arb_set_mpmath_mpf(arb_t x, obj):
sgn, man, exp, bc = obj
sgn, man, exp, _ = obj

if not man:
if not exp:
Expand Down Expand Up @@ -2171,7 +2171,7 @@ cdef class arb(flint_scalar):
>>> showgood(lambda: arb(5).hypgeom([1,2,3],[5,4.5,6],regularized=True), dps=25)
3.886189282817193519132054e-5
"""
cdef long i, p, q, prec
cdef long i, p, q
cdef arb_ptr aa, bb
a = [any_as_arb(t) for t in a]
b = [any_as_arb(t) for t in b]
Expand Down
3 changes: 0 additions & 3 deletions src/flint/types/arb_mat.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ cdef class arb_mat(flint_mat):
return u

def __rmul__(s, t):
cdef arb_mat u
c, d = arb_mat_coerce_scalar(s, t)
if c is not NotImplemented:
return c._scalar_mul_(d)
Expand All @@ -317,7 +316,6 @@ cdef class arb_mat(flint_mat):
return u

def __truediv__(s, t):
cdef arb_mat u
s, t = arb_mat_coerce_scalar(s, t)
if s is NotImplemented:
return s
Expand Down Expand Up @@ -669,7 +667,6 @@ cdef class arb_mat(flint_mat):
return u

def __richcmp__(s, t, int op):
cdef int stype, ttype
cdef bint res
if not (op == 2 or op == 3):
raise ValueError("comparing matrices")
Expand Down
1 change: 0 additions & 1 deletion src/flint/types/arb_poly.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ from flint.types.acb_poly cimport acb_poly

from flint.flintlib.arb cimport *
from flint.flintlib.arb_poly cimport *
cimport cython
cimport libc.stdlib

cdef arb_poly_coerce_operands(x, y):
Expand Down
1 change: 0 additions & 1 deletion src/flint/types/arf.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ cdef class arf:
return man, exp

def _repr_str(self):
cdef fmpz man, exp
if arf_is_zero(self.val):
return "0.0"
elif arf_is_finite(self.val):
Expand Down
1 change: 0 additions & 1 deletion src/flint/types/dirichlet.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ cdef class dirichlet_char(object):
cdef fmpz m
cdef ulong v
m = fmpz(n) % self.G.q
expo = self.G.exponent()
v = dirichlet_chi(self.G.val, self.val, fmpz_get_ui(m.val))
if v == DIRICHLET_CHI_NULL:
return None
Expand Down
3 changes: 1 addition & 2 deletions src/flint/types/fmpq.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ from flint.types.fmpz cimport fmpz
from flint.types.fmpz cimport any_as_fmpz

from flint.flintlib.flint cimport FMPZ_UNKNOWN, FMPZ_TMP, FMPZ_REF
from flint.flintlib.fmpz cimport fmpz_set, fmpz_one, fmpz_t
from flint.flintlib.fmpz cimport fmpz_set, fmpz_one
from flint.flintlib.fmpz cimport fmpz_is_zero, fmpz_sgn
from flint.flintlib.fmpz cimport fmpz_fdiv_q, fmpz_bits
from flint.flintlib.fmpz cimport fmpz_cdiv_q
Expand Down Expand Up @@ -470,7 +470,6 @@ cdef class fmpq(flint_scalar):
cdef int ntype = FMPZ_UNKNOWN
cdef fmpq v
cdef int success
cdef long e

assert z is None

Expand Down
7 changes: 1 addition & 6 deletions src/flint/types/fmpq_mat.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ from flint.flint_base.flint_base cimport flint_mat
from flint.utils.typecheck cimport typecheck
from flint.types.fmpq_poly cimport fmpq_poly
from flint.types.fmpq cimport any_as_fmpq
from flint.types.fmpz_poly cimport fmpz_poly
from flint.types.fmpq_poly cimport fmpq_poly_set_list
from flint.types.fmpz cimport any_as_fmpz

from flint.flintlib.fmpz_mat cimport fmpz_mat_nrows, fmpz_mat_ncols
from flint.flintlib.fmpq cimport fmpq_set,fmpq_numref, fmpq_denref
from flint.flintlib.fmpq_poly cimport fmpq_poly_init, fmpq_poly_clear
from flint.flintlib.fmpq_poly cimport fmpq_poly_init
from flint.flintlib.fmpq_mat cimport *

cimport cython
Expand Down Expand Up @@ -233,7 +231,6 @@ cdef class fmpq_mat(flint_mat):
return u

def __mul__(s, t):
cdef fmpz_mat u
if typecheck(t, fmpq_mat):
return (<fmpq_mat>s).__mul_fmpq_mat(t)
elif typecheck(t, fmpz_mat):
Expand All @@ -248,7 +245,6 @@ cdef class fmpq_mat(flint_mat):
return NotImplemented

def __rmul__(s, t):
cdef fmpz_mat u
if typecheck(t, fmpz_mat):
return (<fmpq_mat>s).__mul_r_fmpz_mat(t)
else:
Expand Down Expand Up @@ -433,7 +429,6 @@ cdef class fmpq_mat(flint_mat):
60
"""
cdef fmpz_mat num
cdef fmpz_den
num = fmpz_mat(self.nrows(), self.ncols())
den = fmpz()
fmpq_mat_get_fmpz_mat_matwise(num.val, den.val, self.val)
Expand Down
4 changes: 1 addition & 3 deletions src/flint/types/fmpq_mpoly.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ from flint.flintlib.fmpq_mpoly cimport (
fmpq_mpoly_gen,
fmpq_mpoly_get_coeff_fmpq_fmpz,
fmpq_mpoly_get_str_pretty,
fmpq_mpoly_get_term,
fmpq_mpoly_get_term_coeff_fmpq,
fmpq_mpoly_get_term_exp_fmpz,
fmpq_mpoly_integral,
Expand All @@ -48,7 +47,6 @@ from flint.flintlib.fmpq_mpoly cimport (
fmpq_mpoly_pow_fmpz,
fmpq_mpoly_push_term_fmpq_ffmpz,
fmpq_mpoly_reduce,
fmpq_mpoly_scalar_div_fmpq,
fmpq_mpoly_scalar_mul_fmpq,
fmpq_mpoly_set,
fmpq_mpoly_set_coeff_fmpq_fmpz,
Expand Down Expand Up @@ -609,7 +607,7 @@ cdef class fmpq_mpoly(flint_mpoly):
fmpq_mpoly res
fmpq_mpoly_ctx res_ctx
fmpq_mpoly_vec C
slong i, nvars = self.ctx.nvars(), nargs = len(args)
slong nvars = self.ctx.nvars(), nargs = len(args)

if nargs < nvars:
raise ValueError("not enough arguments provided")
Expand Down
4 changes: 0 additions & 4 deletions src/flint/types/fmpq_poly.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,12 @@ cdef class fmpq_poly(flint_poly):
return r

def __floordiv__(s, t):
cdef fmpq_poly r
t = any_as_fmpq_poly(t)
if t is NotImplemented:
return t
return s._floordiv_(t)

def __rfloordiv__(s, t):
cdef fmpq_poly r
t = any_as_fmpq_poly(t)
if t is NotImplemented:
return t
Expand All @@ -309,14 +307,12 @@ cdef class fmpq_poly(flint_poly):
return r

def __mod__(s, t):
cdef fmpq_poly r
t = any_as_fmpq_poly(t)
if t is NotImplemented:
return t
return s._mod_(t)

def __rmod__(s, t):
cdef fmpq_poly r
t = any_as_fmpq_poly(t)
if t is NotImplemented:
return t
Expand Down
3 changes: 0 additions & 3 deletions src/flint/types/fmpz.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ cdef class fmpz(flint_scalar):
fmpz_clear(self.val)

def __init__(self, *args):
cdef long x
if not args:
return
elif len(args) != 1:
Expand Down Expand Up @@ -123,7 +122,6 @@ cdef class fmpz(flint_scalar):

def __richcmp__(s, t, int op):
cdef bint res = 0
cdef long tl
cdef fmpz_struct tval[1]
cdef fmpz_struct * sval
cdef int ttype
Expand Down Expand Up @@ -1019,7 +1017,6 @@ cdef class fmpz(flint_scalar):
ttype = fmpz_set_any_ref(tval, other)
if ttype == FMPZ_UNKNOWN:
raise TypeError("input must be an integer")
u = fmpz.__new__(fmpz)
v = fmpz_jacobi(self.val, tval)
if ttype == FMPZ_TMP:
fmpz_clear(tval)
Expand Down
2 changes: 0 additions & 2 deletions src/flint/types/fmpz_mat.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ from flint.types.fmpz cimport fmpz
from flint.types.fmpz_poly cimport fmpz_poly
from flint.types.fmpq_mat cimport fmpq_mat
from flint.types.fmpz cimport any_as_fmpz
from flint.types.fmpq cimport fmpq
from flint.pyflint cimport global_random_state
from flint.types.fmpq cimport any_as_fmpq
cimport cython
Expand Down Expand Up @@ -252,7 +251,6 @@ cdef class fmpz_mat(flint_mat):
cdef fmpz_mat u
cdef fmpz_mat_struct *sval
cdef fmpz_mat_struct *tval
cdef int ttype
if typecheck(t, fmpz_mat):
sval = &(<fmpz_mat>s).val[0]
tval = &(<fmpz_mat>t).val[0]
Expand Down
3 changes: 0 additions & 3 deletions src/flint/types/fmpz_mod.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ from flint.types.fmpz cimport(
any_as_fmpz,
fmpz_get_intlong
)
cimport cython
cimport libc.stdlib

from flint.utils.flint_exceptions import DomainError
Expand Down Expand Up @@ -341,8 +340,6 @@ cdef class fmpz_mod(flint_scalar):
>>> g.discrete_log(a)
123
"""
cdef bint is_prime

# Ensure that the modulus is prime
if not self.ctx.is_prime():
raise NotImplementedError("algorithm assumes modulus is prime")
Expand Down
Loading
Loading