Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve type annotations #511

Open
wants to merge 28 commits into
base: release/0.4.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
acd8f10
Fix equations using `|`
mhostetter Jul 3, 2024
f49b458
Remove hyphens for adverbs ending in "ly"
mhostetter Jul 3, 2024
ff83d5e
Correct the error message for none prime power `order`
MrVeka Jul 5, 2024
5bf5c79
Add multithreading compatibility
Jul 5, 2024
a66828d
Fix typing of overloads
mhostetter May 13, 2023
5dfccd6
Remove `int`/`np.integer` equivalent inputs
mhostetter May 13, 2023
7f9586a
Fix decorators on top of `@property` type error
mhostetter Sep 30, 2023
7e5af63
Fix type annotations for globals
mhostetter Sep 30, 2023
7690a55
Ignore `numba` when static type checking
mhostetter Sep 30, 2023
45743a0
Make separate `berlekamp_decode_jit()` function
mhostetter Sep 30, 2023
7df83e8
Instruct `mypy` to ignore useless arithmetic methods
mhostetter Sep 30, 2023
2e91806
Fix abstract methods in `Function`
mhostetter Sep 30, 2023
a062b5b
Fix type hints for more globals
mhostetter Sep 30, 2023
1094fa4
Fix types for `Poly` classmethods
mhostetter Sep 30, 2023
303dc28
Allow `Function.implementation()` to not be redefined
mhostetter Sep 30, 2023
1be6893
Ignore weird metaclass type conflict
mhostetter Sep 30, 2023
04905a7
Fix types for polynomial arithmetic
mhostetter Sep 30, 2023
c0d1a5a
Fix types of int/str conversions
mhostetter Sep 30, 2023
190b9f3
Type `Array` indexed output
mhostetter Sep 30, 2023
149c901
Add `cast()` to output of NumPy functions
mhostetter Sep 30, 2023
dd6517a
Fix different types with same variable name
mhostetter Sep 30, 2023
93862a7
Fix types for poly conversions
mhostetter Sep 30, 2023
4432a16
Enable NumPy `mypy` plugin
mhostetter Sep 30, 2023
e300817
Use `npt.NDArray`
mhostetter Sep 30, 2023
e090ed8
Fix invalid `EGCD` reference
mhostetter Sep 30, 2023
e72953c
Auto fix in `pre-commit`
mhostetter Nov 4, 2023
0a78ae4
Fix various types with `cast()`
mhostetter Nov 4, 2023
e9fe21b
Fix lint errors
mhostetter Jul 5, 2024
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
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ repos:
rev: v0.4.7
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ The new ufuncs are written in pure Python and [just-in-time compiled](https://nu

## Features

- Supports all [Galois fields](https://mhostetter.github.io/galois/latest/api/galois.GF/) $\mathrm{GF}(p^m)$, even arbitrarily-large fields!
- Supports all [Galois fields](https://mhostetter.github.io/galois/latest/api/galois.GF/) $\mathrm{GF}(p^m)$, even arbitrarily large fields!
- [**Faster**](https://mhostetter.github.io/galois/latest/performance/prime-fields/) than native NumPy! `GF(x) * GF(y)` is faster than `(x * y) % p` for $\mathrm{GF}(p)$.
- Seamless integration with NumPy -- normal NumPy functions work on [`FieldArray`](https://mhostetter.github.io/galois/latest/api/galois.FieldArray/)s.
- Linear algebra over finite fields using normal [`np.linalg`](https://mhostetter.github.io/galois/latest/basic-usage/array-arithmetic/#linear-algebra) functions.
Expand Down
4 changes: 2 additions & 2 deletions docs/basic-usage/array-arithmetic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ Advanced arithmetic
:collapsible:

The Discrete Fourier Transform (DFT) of size $n$ over the finite field $\mathrm{GF}(p^m)$ exists when
there exists a primitive $n$-th root of unity. This occurs when $n\ |\ p^m - 1$.
there exists a primitive $n$-th root of unity. This occurs when $n \mid p^m - 1$.

.. ipython-with-reprs:: int,poly,power

Expand All @@ -310,7 +310,7 @@ Advanced arithmetic
:collapsible:

The inverse Discrete Fourier Transform (DFT) of size $n$ over the finite field $\mathrm{GF}(p^m)$
exists when there exists a primitive $n$-th root of unity. This occurs when $n\ |\ p^m - 1$.
exists when there exists a primitive $n$-th root of unity. This occurs when $n \mid p^m - 1$.

.. ipython-with-reprs:: int,poly,power

Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ calculation (for memory savings).
Features
--------

- Supports all Galois fields $\mathrm{GF}(p^m)$, even arbitrarily-large fields!
- Supports all Galois fields $\mathrm{GF}(p^m)$, even arbitrarily large fields!
- **Faster** than native NumPy! `GF(x) * GF(y)` is faster than `(x * y) % p` for $\mathrm{GF}(p)$.
- Seamless integration with NumPy -- normal NumPy functions work on :obj:`~galois.FieldArray` instances.
- Linear algebra over finite fields using normal :obj:`numpy.linalg` functions.
Expand Down
10 changes: 5 additions & 5 deletions docs/release-notes/v0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ Poly(1, GF(2))
- Allow polynomial comparison with integers and field scalars. Now `galois.Poly([0]) == 0` and `galois.Poly([0]) == GF(0)` return `True` rather than raising `TypeError`.
- Support testing 0-degree polynomials for irreducibility and primitivity.
- Extend `crt()` to work over non co-prime moduli.
- Extend `prev_prime()` and `next_prime()` to work over arbitrarily-large inputs.
- Extend `prev_prime()` and `next_prime()` to work over arbitrarily large inputs.
- Allow negative integer inputs to `primes()`, `is_prime()`, `is_composite()`, `is_prime_power()`, `is_perfect_power()`, `is_square_free()`, `is_smooth()`, and `is_powersmooth()`.
- Fix various type hinting errors.
- Various other bug fixes.
Expand Down Expand Up @@ -715,8 +715,8 @@ Poly(1, GF(2))
- Moved `galois.square_free_factorization()` function into `Poly.square_free_factors()` method. ([#362](https://github.com/mhostetter/galois/pull/362))
- Moved `galois.distinct_degree_factorization()` function into `Poly.distinct_degree_factors()` method. ([#362](https://github.com/mhostetter/galois/pull/362))
- Moved `galois.equal_degree_factorization()` function into `Poly.equal_degree_factors()` method. ([#362](https://github.com/mhostetter/galois/pull/362))
- Moved `galois.is_irreducible()` function into `Poly.is_irreducible()` method. This is a method, not property, to indicate it is a computationally-expensive operation. ([#362](https://github.com/mhostetter/galois/pull/362))
- Moved `galois.is_primitive()` function into `Poly.is_primitive()` method. This is a method, not property, to indicate it is a computationally-expensive operation. ([#362](https://github.com/mhostetter/galois/pull/362))
- Moved `galois.is_irreducible()` function into `Poly.is_irreducible()` method. This is a method, not property, to indicate it is a computationally expensive operation. ([#362](https://github.com/mhostetter/galois/pull/362))
- Moved `galois.is_primitive()` function into `Poly.is_primitive()` method. This is a method, not property, to indicate it is a computationally expensive operation. ([#362](https://github.com/mhostetter/galois/pull/362))
- Moved `galois.is_monic()` function into `Poly.is_monic` property. ([#362](https://github.com/mhostetter/galois/pull/362))

### Changes
Expand All @@ -742,7 +742,7 @@ Poly(1, GF(2))
- Added `galois.get_printoptions()` function to return the current package-wide printing options. This is the equivalent of `np.get_printoptions()`. ([#363](https://github.com/mhostetter/galois/pull/363))
- Added `galois.printoptions()` context manager to modify printing options inside of a `with` statement. This is the equivalent of `np.printoptions()`. ([#363](https://github.com/mhostetter/galois/pull/363))
- Added a separate `Poly.factors()` method, in addition to the polymorphic `galois.factors()`. ([#362](https://github.com/mhostetter/galois/pull/362))
- Added a separate `Poly.is_square_free()` method, in addition to the polymorphic `galois.is_square_free()`. This is a method, not property, to indicate it is a computationally-expensive operation. ([#362](https://github.com/mhostetter/galois/pull/362))
- Added a separate `Poly.is_square_free()` method, in addition to the polymorphic `galois.is_square_free()`. This is a method, not property, to indicate it is a computationally expensive operation. ([#362](https://github.com/mhostetter/galois/pull/362))
- Fixed a bug (believed to be introduced in v0.0.26) where `Poly.degree` occasionally returned `np.int64` instead of `int`. This could cause overflow in certain large integer operations (e.g., computing $q^m$ when determining if a degree-$m$ polynomial over $\mathrm{GF}(q)$ is irreducible). When the integer overflowed, this created erroneous results. ([#360](https://github.com/mhostetter/galois/issues/360), [#361](https://github.com/mhostetter/galois/pull/361))
- Increased code coverage.

Expand All @@ -756,7 +756,7 @@ Poly(1, GF(2))

### Changes

- Added support for NumPy 1.22 with Numba 0.55.2. This allows users to upgrade NumPy and avoid recently-discovered vulnerabilities [CVE-2021-34141](https://nvd.nist.gov/vuln/detail/CVE-2021-34141), [CVE-2021-41496](https://nvd.nist.gov/vuln/detail/CVE-2021-41496), and [CVE-2021-41495](https://nvd.nist.gov/vuln/detail/CVE-2021-41495). ([#366](https://github.com/mhostetter/galois/pull/366))
- Added support for NumPy 1.22 with Numba 0.55.2. This allows users to upgrade NumPy and avoid recently discovered vulnerabilities [CVE-2021-34141](https://nvd.nist.gov/vuln/detail/CVE-2021-34141), [CVE-2021-41496](https://nvd.nist.gov/vuln/detail/CVE-2021-41496), and [CVE-2021-41495](https://nvd.nist.gov/vuln/detail/CVE-2021-41495). ([#366](https://github.com/mhostetter/galois/pull/366))
- Made `FieldArray.repr_table()` more compact. ([#367](https://github.com/mhostetter/galois/pull/367))
```ipython
In [2]: GF = galois.GF(3**3)
Expand Down
2 changes: 1 addition & 1 deletion docs/release-notes/v0.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ tocdepth: 2
Poly(x^9 + 3x^2 + 4, GF(7))
```
- Added a database of binary irreducible polynomials with degrees less than 10,000. These polynomials are
lexicographically-first and have the minimum number of non-zero terms. The database is accessed in
lexicographically first and have the minimum number of non-zero terms. The database is accessed in
`irreducible_poly()` when `terms="min"` and `method="min"`. ([#462](https://github.com/mhostetter/galois/pull/462))
```ipython
In [1]: import galois
Expand Down
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ ignore = [
[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401", "F403"]

[tool.mypy]
plugins = "numpy.typing.mypy_plugin"

[[tool.mypy.overrides]]
module = ["numba.*"]
ignore_missing_imports = true

[tool.pytest.ini_options]
minversion = "6.2"
addopts = "-s --showlocals"
Expand Down
Loading
Loading