Skip to content

Commit

Permalink
Various lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarbenjamin committed Sep 1, 2024
1 parent ba2cec2 commit f102dea
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/flint/types/fmpz_mod_mat.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
3 changes: 3 additions & 0 deletions src/flint/types/nmod.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/flint/types/nmod.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions src/flint/types/nmod_mat.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
68 changes: 32 additions & 36 deletions src/flint/types/nmod_mat.pyx
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}"
Expand Down Expand Up @@ -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 = &(<nmod_mat>s).val[0]
if s.ctx.any_as_nmod(&c, t):
return (<nmod_mat>s).__mul_nmod(c)
u = s.ctx.any_as_nmod_mat(t)
Expand Down
6 changes: 6 additions & 0 deletions src/flint/types/nmod_poly.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 2 additions & 4 deletions src/flint/types/nmod_poly.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit f102dea

Please sign in to comment.