From f102dea9d883ba9cb5e6652fc5f550aef0ee1c70 Mon Sep 17 00:00:00 2001 From: Oscar Benjamin Date: Sun, 1 Sep 2024 03:26:01 +0100 Subject: [PATCH] Various lint fixes --- src/flint/types/fmpz_mod_mat.pyx | 2 +- src/flint/types/nmod.pxd | 3 ++ src/flint/types/nmod.pyx | 2 +- src/flint/types/nmod_mat.pxd | 7 ++++ src/flint/types/nmod_mat.pyx | 68 +++++++++++++++----------------- src/flint/types/nmod_poly.pxd | 6 +++ src/flint/types/nmod_poly.pyx | 6 +-- 7 files changed, 52 insertions(+), 42 deletions(-) diff --git a/src/flint/types/fmpz_mod_mat.pyx b/src/flint/types/fmpz_mod_mat.pyx index c00659fe..c036dca1 100644 --- a/src/flint/types/fmpz_mod_mat.pyx +++ b/src/flint/types/fmpz_mod_mat.pyx @@ -413,7 +413,7 @@ cdef class fmpz_mod_mat(flint_mat): raise ZeroDivisionError("fmpz_mod_mat div: division by zero") else: raise DomainError("fmpz_mod_mat div: division by non-invertible element") - return self._scalarmul(other.inverse()) + return self._scalarmul(inv) def __add__(self, other): """``M + N``: Add two matrices.""" diff --git a/src/flint/types/nmod.pxd b/src/flint/types/nmod.pxd index 8349001e..9a6a04a3 100644 --- a/src/flint/types/nmod.pxd +++ b/src/flint/types/nmod.pxd @@ -12,13 +12,16 @@ cdef class nmod_ctx: @staticmethod cdef nmod_ctx any_as_nmod_ctx(obj) + @staticmethod cdef nmod_ctx _get_ctx(int mod) + @staticmethod cdef nmod_ctx _new_ctx(ulong mod) @cython.final cdef int any_as_nmod(self, mp_limb_t * val, obj) except -1 + @cython.final cdef nmod new_nmod(self) diff --git a/src/flint/types/nmod.pyx b/src/flint/types/nmod.pyx index 52fc8bff..82c0fe30 100644 --- a/src/flint/types/nmod.pyx +++ b/src/flint/types/nmod.pyx @@ -25,7 +25,7 @@ cdef dict _nmod_ctx_cache = {} @cython.no_gc cdef class nmod_ctx: """ - Context object for creating :class:`~.nmod` initalised + Context object for creating :class:`~.nmod` initalised with modulus :math:`N`. >>> ctx = nmod_ctx.new(17) diff --git a/src/flint/types/nmod_mat.pxd b/src/flint/types/nmod_mat.pxd index ac0d5bca..e5e69cc9 100644 --- a/src/flint/types/nmod_mat.pxd +++ b/src/flint/types/nmod_mat.pxd @@ -19,21 +19,28 @@ cdef class nmod_mat_ctx: @staticmethod cdef nmod_mat_ctx any_as_nmod_mat_ctx(obj) + @staticmethod cdef nmod_mat_ctx _get_ctx(int mod) + @staticmethod cdef nmod_mat_ctx _new_ctx(ulong mod) @cython.final cdef int any_as_nmod(self, mp_limb_t * val, obj) except -1 + @cython.final cdef any_as_nmod_mat(self, obj) + @cython.final cdef nmod new_nmod(self) + @cython.final cdef nmod_poly new_nmod_poly(self) + @cython.final cdef nmod_mat new_nmod_mat(self, ulong m, ulong n) + @cython.final cdef nmod_mat new_nmod_mat_copy(self, nmod_mat other) diff --git a/src/flint/types/nmod_mat.pyx b/src/flint/types/nmod_mat.pyx index e3b7dd13..6448ae0b 100644 --- a/src/flint/types/nmod_mat.pyx +++ b/src/flint/types/nmod_mat.pyx @@ -1,7 +1,6 @@ cimport cython from flint.flintlib.flint cimport ulong, mp_limb_t -from flint.flintlib.nmod cimport nmod_t from flint.flintlib.fmpz_mat cimport fmpz_mat_nrows, fmpz_mat_ncols from flint.flintlib.fmpz_mat cimport fmpz_mat_get_nmod_mat @@ -123,7 +122,6 @@ cdef class nmod_mat_ctx: cdef any_as_nmod_mat(self, obj): """Convert obj to nmod_mat or return NotImplemented.""" cdef nmod_mat r - cdef mp_limb_t v if typecheck(obj, nmod_mat): return obj @@ -181,38 +179,38 @@ cdef class nmod_mat_ctx: """ return self._is_prime - #def zero(self, slong m, slong n): - # """Return the zero ``nmod_mat``. - # - # >>> ctx = nmod_mat_ctx.new(17) - # >>> ctx.zero(2, 3) - # [0, 0, 0] - # [0, 0, 0] - - # """ - # cdef nmod_mat r = self.new_nmod_mat() - # nmod_mat_zero(r.val) - # return r - - #def one(self, slong m, slong n=-1): - # """Return the one ``nmod_mat``. - - # >>> ctx = nmod_mat_ctx.new(17) - # >>> ctx.one(2) - # [1, 0] - # [0, 1] - # >>> ctx.one(2, 3) - # [1, 0, 0] - # [0, 1, 0] - - # """ - # cdef nmod_mat r = self.new_nmod_mat() - # if n == -1: - # n = m - # n = min(m, n) - # for i from 0 <= i < n: - # nmod_mat_set_entry(r.val, i, i, 1) - # return r + #def zero(self, slong m, slong n): + # """Return the zero ``nmod_mat``. + # + # >>> ctx = nmod_mat_ctx.new(17) + # >>> ctx.zero(2, 3) + # [0, 0, 0] + # [0, 0, 0] + + # """ + # cdef nmod_mat r = self.new_nmod_mat() + # nmod_mat_zero(r.val) + # return r + + #def one(self, slong m, slong n=-1): + # """Return the one ``nmod_mat``. + + # >>> ctx = nmod_mat_ctx.new(17) + # >>> ctx.one(2) + # [1, 0] + # [0, 1] + # >>> ctx.one(2, 3) + # [1, 0, 0] + # [0, 1, 0] + + # """ + # cdef nmod_mat r = self.new_nmod_mat() + # if n == -1: + # n = m + # n = min(m, n) + # for i from 0 <= i < n: + # nmod_mat_set_entry(r.val, i, i, 1) + # return r def __str__(self): return f"Context for nmod_mat with modulus: {self.mod.n}" @@ -491,9 +489,7 @@ cdef class nmod_mat(flint_mat): return r def __rmul__(s, t): - cdef nmod_mat_struct *sv cdef mp_limb_t c - sv = &(s).val[0] if s.ctx.any_as_nmod(&c, t): return (s).__mul_nmod(c) u = s.ctx.any_as_nmod_mat(t) diff --git a/src/flint/types/nmod_poly.pxd b/src/flint/types/nmod_poly.pxd index a10ef8c6..dde80357 100644 --- a/src/flint/types/nmod_poly.pxd +++ b/src/flint/types/nmod_poly.pxd @@ -17,19 +17,25 @@ cdef class nmod_poly_ctx: @staticmethod cdef nmod_poly_ctx any_as_nmod_poly_ctx(obj) + @staticmethod cdef nmod_poly_ctx _get_ctx(int mod) + @staticmethod cdef nmod_poly_ctx _new_ctx(ulong mod) @cython.final cdef nmod_poly_set_list(self, nmod_poly_t poly, list val) + @cython.final cdef int any_as_nmod(self, mp_limb_t * val, obj) except -1 + @cython.final cdef any_as_nmod_poly(self, obj) + @cython.final cdef nmod new_nmod(self) + @cython.final cdef nmod_poly new_nmod_poly(self) diff --git a/src/flint/types/nmod_poly.pyx b/src/flint/types/nmod_poly.pyx index fd69b68d..2cd97402 100644 --- a/src/flint/types/nmod_poly.pyx +++ b/src/flint/types/nmod_poly.pyx @@ -12,7 +12,6 @@ from flint.flintlib.nmod_vec cimport * from flint.flintlib.nmod_poly cimport * from flint.flintlib.nmod_poly_factor cimport * from flint.flintlib.fmpz_poly cimport fmpz_poly_get_nmod_poly -from flint.flintlib.ulong_extras cimport n_gcdinv, n_is_prime from flint.utils.flint_exceptions import DomainError @@ -104,7 +103,6 @@ cdef class nmod_poly_ctx: n = PyList_GET_SIZE(val) nmod_poly_fit_length(poly, n) for i from 0 <= i < n: - c = val[i] if self.any_as_nmod(&v, val[i]): nmod_poly_set_coeff_ui(poly, i, v) else: @@ -393,7 +391,7 @@ cdef class nmod_poly(flint_poly): raise ValueError(f"{n = } must be positive") if nmod_poly_get_coeff_ui(self.val, 0) == 0: - raise ZeroDivisionError(f"nmod_poly inverse_series_trunc: leading coefficient is zero") + raise ZeroDivisionError("nmod_poly inverse_series_trunc: leading coefficient is zero") if not self.ctx._is_prime: raise DomainError(f"nmod_poly inverse_series_trunc: modulus {self.ctx.mod.n} is not prime") @@ -840,7 +838,7 @@ cdef class nmod_poly(flint_poly): def sqrt(nmod_poly self): """Return exact square root or ``None``. """ - cdef nmod_poly + cdef nmod_poly res if not self.ctx._is_prime: raise DomainError(f"nmod_poly sqrt: modulus {self.ctx.mod.n} is not prime")