Skip to content

Commit db112c5

Browse files
committed
nmod_mat.pyx: add type annotations
1 parent f82dde8 commit db112c5

4 files changed

Lines changed: 74 additions & 4 deletions

File tree

src/flint/test/test_all.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,6 +1594,7 @@ def test_nmod_mat():
15941594
assert str(M(2,2,[1,2,3,4],17)) == '[1, 2]\n[3, 4]'
15951595
assert repr(M(2,2,[1,2,3,4],17)) == '[1, 2]\n[3, 4]'
15961596
assert M(1,2,[3,4],17) / 3 == M(1,2,[3,4],17) * (~G(3,17))
1597+
assert raises(lambda: pow(M([[1]],17), 2, 3), NotImplementedError)
15971598
assert M(2,2,[1,2,3,4], 17).inv().det() == ~(M(2,2,[1,2,3,4], 17).det())
15981599
assert M(2,2,[1,2,3,4], 17).inv().inv() == M(2,2,[1,2,3,4], 17)
15991600
assert M(2,2,[0,1,2,3],17) * M(2, 2, [2,3,4,5], 17) == M(2,2,[4,5,16,4],17)
@@ -1611,6 +1612,11 @@ def test_nmod_mat():
16111612
assert (M([[1]],17) != M([[1]],13)) is True
16121613
assert (M([[1]],17) == None) is False
16131614
assert (M([[1]],17) != None) is True
1615+
class _nmod_mat_subclass(M):
1616+
pass
1617+
1618+
assert raises(lambda: M([[1]],3) + _nmod_mat_subclass([[1]],5), ValueError)
1619+
assert raises(lambda: M([[1]],3) - _nmod_mat_subclass([[1]],5), ValueError)
16141620
M2 = M.randtest(3,4,5)
16151621
assert all(0 <= int(x) < 5 for x in M2.entries())
16161622
assert (M2.nrows(), M2.ncols()) == (3, 4)

src/flint/types/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pyfiles = [
2020
'nmod.pyi',
2121
'nmod_poly.pyi',
2222
'nmod_mpoly.pyi',
23-
# 'nmod_mat.pyi',
23+
'nmod_mat.pyi',
2424
# 'nmod_series.pyi',
2525

2626
'fmpz_mod.pyi',

src/flint/types/nmod_mat.pyi

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
from __future__ import annotations
2+
3+
from collections.abc import Iterable, Iterator, Sequence
4+
from typing import overload
5+
6+
from flint.flint_base.flint_base import flint_mat
7+
from flint.types.fmpz import fmpz
8+
from flint.types.fmpz_mat import fmpz_mat
9+
from flint.types.nmod import inmod, nmod
10+
from flint.types.nmod_poly import nmod_poly
11+
12+
_str = str
13+
14+
inmod_mat = nmod_mat | fmpz_mat | Sequence[Sequence[inmod]]
15+
16+
17+
class nmod_mat(flint_mat[nmod]):
18+
@overload
19+
def __init__(self, val: nmod_mat, /) -> None: ...
20+
@overload
21+
def __init__(self, val: fmpz_mat | Sequence[Sequence[inmod]], mod: int, /) -> None: ...
22+
@overload
23+
def __init__(self, m: int, n: int, mod: int, /) -> None: ...
24+
@overload
25+
def __init__(self, m: int, n: int, entries: Iterable[inmod], mod: int, /) -> None: ...
26+
27+
def __bool__(self) -> bool: ...
28+
def __eq__(self, other: object, /) -> bool: ...
29+
def __ne__(self, other: object, /) -> bool: ...
30+
31+
def nrows(self) -> int: ...
32+
def ncols(self) -> int: ...
33+
def modulus(self) -> int: ...
34+
@classmethod
35+
def randtest(cls, m: int, n: int, mod: int, /) -> nmod_mat: ...
36+
37+
def __getitem__(self, index: tuple[int, int], /) -> nmod: ...
38+
def __setitem__(self, index: tuple[int, int], value: inmod, /) -> None: ...
39+
def __iter__(self) -> Iterator[nmod]: ...
40+
def entries(self) -> list[nmod]: ...
41+
def table(self) -> list[list[nmod]]: ...
42+
def tolist(self) -> list[list[nmod]]: ...
43+
44+
def repr(self) -> _str: ...
45+
def __str__(self) -> _str: ...
46+
def __repr__(self) -> _str: ...
47+
48+
def __pos__(self) -> nmod_mat: ...
49+
def __neg__(self) -> nmod_mat: ...
50+
def __add__(self, other: inmod_mat, /) -> nmod_mat: ...
51+
def __radd__(self, other: inmod_mat, /) -> nmod_mat: ...
52+
def __sub__(self, other: inmod_mat, /) -> nmod_mat: ...
53+
def __rsub__(self, other: inmod_mat, /) -> nmod_mat: ...
54+
def __mul__(self, other: inmod_mat | inmod, /) -> nmod_mat: ...
55+
def __rmul__(self, other: inmod_mat | inmod, /) -> nmod_mat: ...
56+
def __truediv__(self, other: inmod, /) -> nmod_mat: ...
57+
def __pow__(self, exponent: int, modulo: None = None, /) -> nmod_mat: ...
58+
59+
def det(self) -> nmod: ...
60+
def inv(self) -> nmod_mat: ...
61+
def transpose(self) -> nmod_mat: ...
62+
def solve(self, other: inmod_mat, /) -> nmod_mat: ...
63+
def rref(self, inplace: bool = False, /) -> tuple[nmod_mat, int]: ...
64+
def rank(self) -> int: ...
65+
def nullspace(self) -> tuple[nmod_mat, int]: ...
66+
def charpoly(self) -> nmod_poly: ...
67+
def minpoly(self) -> nmod_poly: ...

src/flint/types/nmod_mat.pyx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,6 @@ cdef class nmod_mat(flint_mat):
358358
def __truediv__(s, t):
359359
return nmod_mat._div_(s, t)
360360

361-
def __div__(s, t):
362-
return nmod_mat._div_(s, t)
363-
364361
def det(self):
365362
"""
366363
Returns the determinant of self as an nmod.

0 commit comments

Comments
 (0)