Skip to content

Commit 1a429b0

Browse files
committed
typ: add type annotations for fmpz_mod and fmpz_mod_mpoly
All _mpoly types are now fully typed.
1 parent 47e4ba9 commit 1a429b0

File tree

7 files changed

+817
-532
lines changed

7 files changed

+817
-532
lines changed

src/flint/flint_base/flint_base.pyi

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#
22
#
33
#
4-
from typing import Generic, TypeVar, Iterator, Iterable, Any, Final, Self, Mapping
4+
from typing import Generic, TypeVar, Iterator, Iterable, Any, Final, Self, Mapping, Sequence
5+
from abc import abstractmethod
56
import enum
67

78

@@ -10,7 +11,7 @@ FLINT_RELEASE: Final[int]
1011

1112

1213
Telem = TypeVar('Telem', bound=flint_scalar)
13-
Telem_coerce = TypeVar('Telem_coerce')
14+
Telem_coerce = TypeVar('Telem_coerce', contravariant=True)
1415
Tmpoly = TypeVar('Tmpoly', bound=flint_mpoly)
1516
Tctx = TypeVar('Tctx', bound=flint_mpoly_context)
1617

@@ -59,25 +60,22 @@ class flint_mpoly(flint_elem, Generic[Tctx, Telem, Telem_coerce]):
5960

6061
def leading_coefficient(self) -> Telem: ...
6162
def to_dict(self) -> dict[tuple[int, ...], Telem]: ...
62-
def terms(self) -> Iterable[tuple[tuple[int, ...], Telem]]: ...
6363

6464
def is_one(self) -> bool: ...
6565
def is_zero(self) -> bool: ...
6666
def is_constant(self) -> bool: ...
6767

6868
def __len__(self) -> int: ...
69+
def __getitem__(self, index: tuple[int, ...]) -> Telem: ...
70+
def __setitem__(self, index: tuple[int, ...], coeff: Telem | Telem_coerce | int) -> None: ...
71+
def __iter__(self) -> Iterable[tuple[int, ...]]: ...
72+
def __contains__(self, index: tuple[int, ...]) -> bool: ...
73+
6974
def coefficient(self, i: int) -> Telem: ...
7075
def monomial(self, i: int) -> tuple[int, ...]: ...
71-
76+
def terms(self) -> Iterable[tuple[tuple[int, ...], Telem]]: ...
7277
def monoms(self) -> list[tuple[int, ...]]: ...
7378
def coeffs(self) -> list[Telem]: ...
74-
def __getitem__(self, index: tuple[int, ...]) -> Telem: ...
75-
def __setitem__(self, index: tuple[int, ...], coeff: Telem | Telem_coerce | int) -> None: ...
76-
77-
def subs(self, mapping: dict[str | int, Telem | Telem_coerce | int]) -> Self: ...
78-
def compose(self, *args: Self, ctx: Tctx | None = None) -> Self: ...
79-
80-
def __call__(self, *args: Telem | Telem_coerce) -> Telem: ...
8179

8280
def __pos__(self) -> Self: ...
8381
def __neg__(self) -> Self: ...
@@ -97,8 +95,34 @@ class flint_mpoly(flint_elem, Generic[Tctx, Telem, Telem_coerce]):
9795
def __rdivmod__(self, other: Telem | Telem_coerce | int) -> tuple[Self, Self]: ...
9896
def __pow__(self, other: Telem | Telem_coerce | int) -> Self: ...
9997
def __rpow__(self, other: Telem | Telem_coerce | int) -> Self: ...
100-
def __iter__(self) -> Iterable[tuple[int, ...]]: ...
101-
def __contains__(self, index: tuple[int, ...]) -> bool: ...
98+
99+
def iadd(self, other: Telem | Telem_coerce | int) -> None: ...
100+
def isub(self, other: Telem | Telem_coerce | int) -> None: ...
101+
def imul(self, other: Telem | Telem_coerce | int) -> None: ...
102+
103+
def gcd(self, other: Self) -> Self: ...
104+
def term_content(self) -> Self: ...
105+
106+
def factor(self) -> tuple[Telem, Sequence[tuple[Self, int]]]: ...
107+
def factor_squarefree(self) -> tuple[Telem, Sequence[tuple[Self, int]]]: ...
108+
109+
def sqrt(self) -> Self: ...
110+
111+
def resultant(self, other: Self, var: str | int) -> Self: ...
112+
def discriminant(self, var: str | int) -> Self: ...
113+
114+
def deflation_index(self) -> tuple[list[int], list[int]]: ...
115+
def deflation(self) -> tuple[Self, list[int]]: ...
116+
def deflation_monom(self) -> tuple[Self, list[int], Self]: ...
117+
118+
def inflate(self, N: list[int]) -> Self: ...
119+
def deflate(self, N: list[int]) -> Self: ...
120+
121+
def subs(self, mapping: dict[str | int, Telem | Telem_coerce | int]) -> Self: ...
122+
def compose(self, *args: Self, ctx: Tctx | None = None) -> Self: ...
123+
def __call__(self, *args: Telem | Telem_coerce) -> Telem: ...
124+
125+
def derivative(self, var: str | int) -> Self: ...
102126

103127
def unused_gens(self) -> tuple[str, ...]: ...
104128

@@ -114,18 +138,18 @@ class flint_mpoly_context(flint_elem, Generic[Tmpoly, Telem, Telem_coerce]):
114138
def nvars(self) -> int: ...
115139
def ordering(self) -> Ordering: ...
116140

117-
def gen(self, i: int) -> Tmpoly: ...
118-
def from_dict(self, d: Mapping[tuple[int, ...], Telem_coerce]) -> Tmpoly: ...
119-
def constant(self, z: Telem_coerce) -> Tmpoly: ...
141+
def gen(self, i: int, /) -> Tmpoly: ...
142+
def from_dict(self, d: Mapping[tuple[int, ...], Telem_coerce], /) -> Tmpoly: ...
143+
def constant(self, z: Telem_coerce, /) -> Tmpoly: ...
120144

121-
def name(self, i: int) -> str: ...
145+
def name(self, i: int, /) -> str: ...
122146
def names(self) -> tuple[str]: ...
123147
def gens(self) -> tuple[Tmpoly, ...]: ...
124-
def variable_to_index(self, var: str) -> int: ...
148+
def variable_to_index(self, var: str, /) -> int: ...
125149
def term(self, coeff: Telem_coerce | None = None, exp_vec: Iterable[int] | None = None) -> Tmpoly: ...
126-
def drop_gens(self, gens: Iterable[str | int]) -> Self: ...
127-
def append_gens(self, gens: Iterable[str | int]) -> Self: ...
128-
def infer_generator_mapping(self, ctx: flint_mpoly_context) -> dict[int, int]: ...
150+
def drop_gens(self, gens: Iterable[str | int], /) -> Self: ...
151+
def append_gens(self, gens: Iterable[str | int], /) -> Self: ...
152+
def infer_generator_mapping(self, ctx: flint_mpoly_context, /) -> dict[int, int]: ...
129153

130154
@classmethod
131155
def from_context(cls,
@@ -134,3 +158,8 @@ class flint_mpoly_context(flint_elem, Generic[Tmpoly, Telem, Telem_coerce]):
134158
ordering: Ordering | str = Ordering.lex,
135159
) -> Sctx:
136160
...
161+
162+
163+
class flint_mod_mpoly_context(flint_mpoly_context[Tmpoly, Telem, Telem_coerce]):
164+
@abstractmethod
165+
def modulus(self) -> int: ...

0 commit comments

Comments
 (0)