Skip to content

Commit f82dde8

Browse files
committed
fmpz_mat: add type stubs
1 parent ce20933 commit f82dde8

4 files changed

Lines changed: 73 additions & 7 deletions

File tree

src/flint/test/test_all.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,9 @@ def test_fmpq_mat():
10991099
assert (Q(1,1,[1]) != 1) is True
11001100
assert (1 == Q(1,1,[1])) is False
11011101
assert (1 != Q(1,1,[1])) is True
1102+
marker = object()
1103+
assert (Q(1,1,[1]) == marker) is False
1104+
assert (Q(1,1,[1]) != marker) is True
11021105
assert Q(1,2,[3,4]) * 2 == Q(1,2,[6,8])
11031106
assert Q(1,2,[3,4]) * flint.fmpq(1,3) == Q(1,2,[1,flint.fmpq(4,3)])
11041107
assert Q(1,2,[3,4]) * flint.fmpq(5,3) == Q(1,2,[5,flint.fmpq(20,3)])
@@ -1110,6 +1113,7 @@ def test_fmpq_mat():
11101113
assert M ** 1 == M
11111114
assert M ** 2 == Q([[7,10],[15,22]])
11121115
assert M ** 12 == Q([[138067399, 201223170],[301834755, 439902154]])
1116+
assert raises(lambda: pow(M, 2, 3), TypeError)
11131117
M = Q([[1,2],[2,4]])
11141118
assert raises(lambda: M ** -1, ZeroDivisionError)
11151119
assert Q(1,2,[3,4]) / 2 == Q(1,2,[flint.fmpq(3,2),2])
@@ -1169,6 +1173,9 @@ def set_bad(i):
11691173
X = Q([[1,2],[3,4]])
11701174
B = A*X
11711175
assert A.solve(B) == X
1176+
I25 = Q([[1 if i == j else 0 for j in range(25)] for i in range(25)])
1177+
X25 = Q.hilbert(25, 2)
1178+
assert I25.solve(X25) == X25
11721179
for algorithm in None, "fflu", "dixon":
11731180
assert A.solve(B, algorithm=algorithm) == X
11741181
assert raises(lambda: A.solve(B, algorithm="invalid"), ValueError)

src/flint/types/fmpq_mat.pyi

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

src/flint/types/fmpq_mat.pyx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,6 @@ cdef class fmpq_mat(flint_mat):
100100
cdef bint r
101101
if op != 2 and op != 3:
102102
raise TypeError("matrices cannot be ordered")
103-
s = any_as_fmpq_mat(s)
104-
if t is NotImplemented:
105-
return s
106103
t = any_as_fmpq_mat(t)
107104
if t is NotImplemented:
108105
return t
@@ -269,9 +266,6 @@ cdef class fmpq_mat(flint_mat):
269266
def __truediv__(s, t):
270267
return fmpq_mat._div_(s, t)
271268

272-
def __div__(s, t):
273-
return fmpq_mat._div_(s, t)
274-
275269
def inv(self):
276270
"""
277271
Returns the inverse matrix of *self*.

src/flint/types/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pyfiles = [
1414
'fmpq_poly.pyi',
1515
'fmpq_series.pyi',
1616
'fmpq_mpoly.pyi',
17-
# 'fmpq_mat.pyi',
17+
'fmpq_mat.pyi',
1818
'fmpq_vec.pyi',
1919

2020
'nmod.pyi',

0 commit comments

Comments
 (0)