Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions src/flint/flint_base/flint_base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ class flint_scalar(flint_elem):
def is_zero(self) -> bool: ...
def __pos__(self) -> Self: ...
def __neg__(self) -> Self: ...
def __add__(self, other: Self | int, /) -> Self: ...
def __add__(self, other: int, /) -> Self: ...
def __radd__(self, other: int, /) -> Self: ...
def __sub__(self, other: Self | int, /) -> Self: ...
def __sub__(self, other: int, /) -> Self: ...
def __rsub__(self, other: int, /) -> Self: ...
def __mul__(self, other: Self | int, /) -> Self: ...
def __mul__(self, other: int, /) -> Self: ...
def __rmul__(self, other: int, /) -> Self: ...
def __truediv__(self, other: Self | int, /) -> Self: ...
def __truediv__(self, other: int, /) -> Self: ...
def __rtruediv__(self, other: int, /) -> Self: ...
def __pow__(self, other: int, /) -> Self: ...
def __rpow__(self, other: int, /) -> Self: ...
Expand Down Expand Up @@ -90,15 +90,6 @@ class flint_poly(flint_elem, Generic[Telem]):
def complex_roots(self) -> list[Any]: ...
def derivative(self) -> Self: ...

class _flint_poly_exact(flint_poly[Telem]):
def sqrt(self) -> Self: ...
def gcd(self, other: Self | Telem, /) -> Self: ...
def xgcd(self, other: Self | Telem, /) -> tuple[Self, Self, Self]: ...
def factor(self) -> tuple[Telem, list[tuple[Self, int]]]: ...
def factor_squarefree(self) -> tuple[Telem, list[tuple[Self, int]]]: ...
def resultant(self, other: Self | Telem, /) -> Telem: ...
def deflation(self) -> tuple[Self, int]: ...

class Ordering(enum.Enum):
lex = "lex"
deglex = "deglex"
Expand Down
1 change: 1 addition & 0 deletions src/flint/flint_base/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pkgdir = 'flint/flint_base'

pyfiles = [
'__init__.py',
'flint_base.pyi',
]

exts = [
Expand Down
2 changes: 2 additions & 0 deletions src/flint/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ thisdir = 'flint'

pyfiles = [
'__init__.py',
'typing.py',
'py.typed',
]

exts = [
Expand Down
Empty file added src/flint/py.typed
Empty file.
42 changes: 17 additions & 25 deletions src/flint/test/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import random

import flint
import flint.typing as typ
import flint.flint_base.flint_base as flint_base
from flint.utils.flint_exceptions import DomainError, IncompatibleContextError

Expand All @@ -26,13 +27,10 @@ def raises(f, exception) -> bool:

if TYPE_CHECKING:
from typing import TypeIs
from flint.flint_base.flint_base import _flint_poly_exact


Tscalar = TypeVar('Tscalar', bound=flint_base.flint_scalar)
Tscalar_co = TypeVar('Tscalar_co', bound=flint_base.flint_scalar, covariant=True)
Tscalar_contra = TypeVar('Tscalar_contra', bound=flint_base.flint_scalar, contravariant=True)
Tpoly = TypeVar("Tpoly", bound='_flint_poly_exact')
Tmpoly = TypeVar('Tmpoly', bound=flint_base.flint_mpoly)
Tmpolyctx_co = TypeVar('Tmpolyctx_co', bound=flint_base.flint_mpoly_context, covariant=True)

Expand Down Expand Up @@ -2621,32 +2619,26 @@ def _all_polys() -> list[tuple[Any, Any, bool, flint.fmpz]]:
]


class _TPoly(Protocol[Tpoly, Tscalar_contra]):
def __call__(
self, x: Sequence[Tscalar_contra | int] | Tpoly | Tscalar_contra | int, /
) -> Tpoly: ...


class _Telem(Protocol[Tscalar]):
def __call__(self, x: int | Tscalar, /) -> Tscalar: ...


_PolyTestCase = tuple[_TPoly[Tpoly, Tscalar], _Telem[Tscalar], bool, flint.fmpz]
Tpoly = TypeVar("Tpoly", bound=typ.epoly_p)
Tc = TypeVar("Tc", bound=flint_base.flint_scalar)
TS = Callable[[Tc | int], Tc]
TP = Callable[[Tpoly | Sequence[Tc | int] | Tc | int], Tpoly]
_PolyTestCase = tuple[TP[Tpoly,Tc], TS[Tc], bool, flint.fmpz]


def _for_all_polys(test: Callable[[_PolyTestCase], None]) -> None:
"""Test all mpoly types with the given test function."""
# Spell it out like this so that a type checker can understand the types
# in the generics for each call of test().

fmpz: _Telem[flint.fmpz] = flint.fmpz
fmpq: _Telem[flint.fmpq] = flint.fmpq
fmpz_poly: _TPoly[flint.fmpz_poly, flint.fmpz] = flint.fmpz_poly
fmpq_poly: _TPoly[flint.fmpq_poly, flint.fmpq] = flint.fmpq_poly
fmpz: TS[flint.fmpz] = flint.fmpz
fmpq: TS[flint.fmpq] = flint.fmpq
fmpz_poly: TP[flint.fmpz_poly, flint.fmpz] = flint.fmpz_poly
fmpq_poly: TP[flint.fmpq_poly, flint.fmpq] = flint.fmpq_poly

def nmod_poly(
p: int,
) -> tuple[_TPoly[flint.nmod_poly, flint.nmod], _Telem[flint.nmod]]:
) -> tuple[TP[flint.nmod_poly, flint.nmod], TS[flint.nmod]]:
"""Make nmod poly and scalar constructors for modulus p."""

def poly(
Expand All @@ -2661,7 +2653,7 @@ def elem(x: int | flint.nmod = 0, /) -> flint.nmod:

def fmpz_mod_poly(
p: int,
) -> tuple[_TPoly[flint.fmpz_mod_poly, flint.fmpz_mod], _Telem[flint.fmpz_mod]]:
) -> tuple[TP[flint.fmpz_mod_poly, flint.fmpz_mod], TS[flint.fmpz_mod]]:
"""Make fmpz_mod poly and scalar constructors for modulus p."""
ectx = flint.fmpz_mod_ctx(p)
pctx = flint.fmpz_mod_poly_ctx(ectx)
Expand All @@ -2683,7 +2675,7 @@ def elem(x: int | flint.fmpz_mod = 0, /) -> flint.fmpz_mod:
def fq_default_poly(
p: int, k: int | None = None
) -> tuple[
_TPoly[flint.fq_default_poly, flint.fq_default], _Telem[flint.fq_default]
TP[flint.fq_default_poly, flint.fq_default], TS[flint.fq_default]
]:
"""Make fq_default poly and scalar constructors for field p^k."""
if k is None:
Expand Down Expand Up @@ -2740,7 +2732,7 @@ def wrapper():


@all_polys
def test_polys(args: _PolyTestCase[Tpoly, Tscalar]) -> None:
def test_polys(args: _PolyTestCase[typ.epoly_p[Tc], Tc]) -> None:
# To test type annotations, uncomment:
# P: type[flint.fmpq_poly]
# S: type[flint.fmpq]
Expand Down Expand Up @@ -2872,7 +2864,7 @@ def setbad(obj, i, val):

assert P([1, 2, 3]) + P([4, 5, 6]) == P([5, 7, 9])

for T in [int, S, flint.fmpz]:
for T in (int, S, flint.fmpz):
assert P([1, 2, 3]) + T(1) == P([2, 2, 3])
assert T(1) + P([1, 2, 3]) == P([2, 2, 3])

Expand All @@ -2881,7 +2873,7 @@ def setbad(obj, i, val):

assert P([1, 2, 3]) - P([4, 5, 6]) == P([-3, -3, -3])

for T in [int, S, flint.fmpz]:
for T in (int, S, flint.fmpz):
assert P([1, 2, 3]) - T(1) == P([0, 2, 3])
assert T(1) - P([1, 2, 3]) == P([0, -2, -3])

Expand All @@ -2890,7 +2882,7 @@ def setbad(obj, i, val):

assert P([1, 2, 3]) * P([4, 5, 6]) == P([4, 13, 28, 27, 18])

for T in [int, S, flint.fmpz]:
for T in (int, S, flint.fmpz):
assert P([1, 2, 3]) * T(2) == P([2, 4, 6])
assert T(2) * P([1, 2, 3]) == P([2, 4, 6])

Expand Down
4 changes: 2 additions & 2 deletions src/flint/types/fmpq_poly.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import overload, Any, Sequence
from flint.flint_base.flint_base import _flint_poly_exact
from flint.flint_base.flint_base import flint_poly
from flint.types.fmpz import fmpz, ifmpz
from flint.types.fmpq import fmpq, ifmpq
from flint.types.fmpz_poly import fmpz_poly, ifmpz_poly
Expand All @@ -8,7 +8,7 @@ from flint.types.fmpz_poly import fmpz_poly, ifmpz_poly
ifmpq_poly = fmpq_poly | ifmpq | ifmpz_poly


class fmpq_poly(_flint_poly_exact[fmpq]):
class fmpq_poly(flint_poly[fmpq]):
"""
The *fmpq_poly* type represents dense univariate polynomials
over the rational numbers. For efficiency reasons, an *fmpq_poly* is
Expand Down
4 changes: 2 additions & 2 deletions src/flint/types/fmpq_series.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any
from typing import Any, Sequence
from flint.flint_base.flint_base import flint_series
from flint.types.fmpz import fmpz, ifmpz
from flint.types.fmpq import fmpq, ifmpq
Expand All @@ -13,7 +13,7 @@ class fmpq_series(flint_series[fmpq]):
"""Approximate truncated power series with rational coefficients."""

def __init__(self,
val: list[int] | list[ifmpq] | ifmpq | ifmpq_series | None = None,
val: Sequence[ifmpq] | ifmpq | ifmpq_series | None = None,
den: ifmpz | None = None,
prec: int | None = None): ...

Expand Down
4 changes: 2 additions & 2 deletions src/flint/types/fmpz_mod_poly.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Literal, Sequence, overload

from flint.flint_base.flint_base import _flint_poly_exact
from flint.flint_base.flint_base import flint_poly
from flint.types.fmpz import fmpz
from flint.types.fmpz_poly import fmpz_poly
from flint.types.fmpz_mod import fmpz_mod, fmpz_mod_ctx, ifmpz, ifmpz_mod
Expand Down Expand Up @@ -32,7 +32,7 @@ class fmpz_mod_poly_ctx:
def __call__(self, val: ifmpz_mod_poly | list[ifmpz_mod]) -> fmpz_mod_poly: ...
def minpoly(self, vals: Sequence[ifmpz_mod]) -> fmpz_mod_poly: ...

class fmpz_mod_poly(_flint_poly_exact[fmpz_mod]):
class fmpz_mod_poly(flint_poly[fmpz_mod]):
"""
The *fmpz_mod_poly* type represents univariate polynomials
over integer modulo an arbitrary-size modulus.
Expand Down
4 changes: 2 additions & 2 deletions src/flint/types/fmpz_poly.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from typing import overload, Any, Sequence
from flint.flint_base.flint_base import _flint_poly_exact
from flint.flint_base.flint_base import flint_poly
from flint.types.fmpz import fmpz, ifmpz
from flint.types.fmpq import fmpq
from flint.types.fmpq_poly import fmpq_poly

ifmpz_poly = fmpz_poly | ifmpz

class fmpz_poly(_flint_poly_exact[fmpz]):
class fmpz_poly(flint_poly[fmpz]):
"""
The *fmpz_poly* type represents dense univariate polynomials over
the integers.
Expand Down
2 changes: 1 addition & 1 deletion src/flint/types/fmpz_series.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ifmpz_series = fmpz_series | ifmpz_poly
class fmpz_series(flint_series[fmpz]):

def __init__(self,
val: list[int] | list[ifmpz] | fmpz_series | fmpz_poly | ifmpz | None = None,
val: Sequence[ifmpz] | fmpz_series | fmpz_poly | ifmpz | None = None,
prec: int | None = None): ...

@property
Expand Down
4 changes: 2 additions & 2 deletions src/flint/types/fq_default_poly.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import overload, Sequence
from flint.flint_base.flint_base import _flint_poly_exact
from flint.flint_base.flint_base import flint_poly
from .fmpz import fmpz, ifmpz
from .fmpz_mod import fmpz_mod
from .fmpz_poly import fmpz_poly, ifmpz_poly
Expand Down Expand Up @@ -44,7 +44,7 @@ class fq_default_poly_ctx:
def __repr__(self) -> str: ...
def __call__(self, val: ifq_default_poly) -> fq_default_poly: ...

class fq_default_poly(_flint_poly_exact[fq_default]):
class fq_default_poly(flint_poly[fq_default]):
"""
The *fq_default_poly* type represents univariate polynomials
over a finite field.
Expand Down
51 changes: 47 additions & 4 deletions src/flint/types/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,63 @@ thisdir = 'flint/types'

pyfiles = [
'__init__.py',

'fmpz.pyi',
'fmpz_poly.pyi',
'fmpz_series.pyi',
'fmpz_mpoly.pyi',
# 'fmpz_mat.pyi',
# 'fmpz_vec.pyi',

'fmpq.pyi',
'fmpq_poly.pyi',
'fmpq_series.pyi',
'fmpq_mpoly.pyi',
# 'fmpq_mat.pyi',
# 'fmpq_vec.pyi',

'nmod.pyi',
'nmod_poly.pyi',
'nmod_mpoly.pyi',
# 'nmod_mat.pyi',
# 'nmod_series.pyi',

'fmpz_mod.pyi',
'fmpz_mod_poly.pyi',
'fmpz_mod_mpoly.pyi',
# 'fmpz_mod_mat.pyi',

'fq_default.pyi',
'fq_default_poly.pyi',

# 'arf.pyi',
#
# 'arb.pyi',
# 'arb_poly.pyi',
# 'arb_mat.pyi',
# 'arb_series.pyi',
#
# 'acb.pyi',
# 'acb_poly.pyi',
# 'acb_mat.pyi',
# 'acb_series.pyi',
#
# 'dirichlet.pyi',
#
# '_gr.pyi',
]

exts = [
'fmpz',
'fmpz_poly',
'fmpz_mpoly',
'fmpz_mat',
'fmpz_series',
'fmpz_vec',

'fmpq',
'fmpq_poly',
'fmpq_mpoly',
'fmpq_mat',
'fmpq_series',
'fmpq_vec',
Expand All @@ -25,6 +71,7 @@ exts = [

'fmpz_mod',
'fmpz_mod_poly',
'fmpz_mod_mpoly',
'fmpz_mod_mat',

'fq_default',
Expand All @@ -44,10 +91,6 @@ exts = [

'dirichlet',

'fmpz_mpoly',
'fmpz_mod_mpoly',
'fmpq_mpoly',

'_gr',
]

Expand Down
4 changes: 2 additions & 2 deletions src/flint/types/nmod_poly.pyi
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from typing import overload, Iterator, Sequence
from flint.flint_base.flint_base import _flint_poly_exact
from flint.flint_base.flint_base import flint_poly
from flint.types.nmod import inmod, nmod
from flint.types.fmpz_poly import fmpz_poly

inmod_poly = nmod_poly | fmpz_poly | inmod

class nmod_poly(_flint_poly_exact[nmod]):
class nmod_poly(flint_poly[nmod]):
"""Dense univariate polynomials over Z/nZ for word-size n."""

@overload
Expand Down
Loading
Loading