Skip to content

Commit

Permalink
Convert Tuple[a, b] to tuple[a, b]
Browse files Browse the repository at this point in the history
  • Loading branch information
mhostetter committed Sep 11, 2022
1 parent 0a4ec79 commit 3aefcea
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 48 deletions.
6 changes: 3 additions & 3 deletions src/galois/_codes/_bch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from __future__ import annotations

import math
from typing import Tuple, List, Type, overload
from typing import List, Type, overload
from typing_extensions import Literal

import numba
Expand Down Expand Up @@ -54,7 +54,7 @@ def _check_and_compute_field(


@export
def bch_valid_codes(n: int, t_min: int = 1) -> List[Tuple[int, int, int]]:
def bch_valid_codes(n: int, t_min: int = 1) -> List[tuple[int, int, int]]:
r"""
Returns a list of :math:`(n, k, t)` tuples of valid primitive binary BCH codes.
Expand Down Expand Up @@ -577,7 +577,7 @@ def detect(self, codeword: ArrayLike) -> np.bool_ | np.ndarray:
def decode(self, codeword: ArrayLike, errors: Literal[False] = False) -> GF2:
...
@overload
def decode(self, codeword: ArrayLike, errors: Literal[True]) -> Tuple[GF2, np.integer | np.ndarray]:
def decode(self, codeword: ArrayLike, errors: Literal[True]) -> tuple[GF2, np.integer | np.ndarray]:
...
def decode(self, codeword, errors=False):
r"""
Expand Down
4 changes: 2 additions & 2 deletions src/galois/_codes/_reed_solomon.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
from __future__ import annotations

from typing import Tuple, Type, overload
from typing import Type, overload
from typing_extensions import Literal

import numba
Expand Down Expand Up @@ -466,7 +466,7 @@ def detect(self, codeword: ArrayLike) -> np.bool_ | np.ndarray:
def decode(self, codeword: ArrayLike, errors: Literal[False] = False) -> FieldArray:
...
@overload
def decode(self, codeword: ArrayLike, errors: Literal[True]) -> Tuple[FieldArray, np.integer | np.ndarray]:
def decode(self, codeword: ArrayLike, errors: Literal[True]) -> tuple[FieldArray, np.integer | np.ndarray]:
...
def decode(self, codeword, errors=False):
r"""
Expand Down
8 changes: 4 additions & 4 deletions src/galois/_domains/_linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""
from __future__ import annotations

from typing import Tuple, Type, TYPE_CHECKING
from typing import Type, TYPE_CHECKING

import numba
from numba import int64
Expand Down Expand Up @@ -245,7 +245,7 @@ class row_reduce_jit(Function):
Converts the matrix into its row-reduced echelon form using Gaussian elimination.
"""

def __call__(self, A: Array, ncols: int | None = None) -> Tuple[Array, int]:
def __call__(self, A: Array, ncols: int | None = None) -> tuple[Array, int]:
verify_isinstance(A, self.field)
if not A.ndim == 2:
raise ValueError(f"Only 2-D matrices can be converted to reduced row echelon form, not {A.ndim}-D.")
Expand Down Expand Up @@ -284,7 +284,7 @@ class lu_decompose_jit(Function):
Decomposes the matrix into its LU decomposition.
"""

def __call__(self, A: Array) -> Tuple[Array, Array]:
def __call__(self, A: Array) -> tuple[Array, Array]:
verify_isinstance(A, self.field)
if not A.ndim == 2:
raise ValueError(f"Argument `A` must be a 2-D matrix, not have shape {A.shape}.")
Expand Down Expand Up @@ -316,7 +316,7 @@ class plu_decompose_jit(Function):
Decomposes the matrix into its PLU decomposition.
"""

def __call__(self, A: Array) -> Tuple[Array, Array, Array, int]:
def __call__(self, A: Array) -> tuple[Array, Array, Array, int]:
verify_isinstance(A, self.field)
if not A.ndim == 2:
raise ValueError(f"Argument `A` must be a 2-D matrix, not have shape {A.shape}.")
Expand Down
5 changes: 2 additions & 3 deletions src/galois/_fields/_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""
from __future__ import annotations

from typing import Tuple
from typing_extensions import Literal

import numpy as np
Expand Down Expand Up @@ -1023,7 +1022,7 @@ def row_reduce(self, ncols: int | None = None) -> FieldArray:
A_rre, _ = _linalg.row_reduce_jit(type(self))(self, ncols=ncols)
return A_rre

def lu_decompose(self) -> Tuple[FieldArray, FieldArray]:
def lu_decompose(self) -> tuple[FieldArray, FieldArray]:
r"""
Decomposes the input array into the product of lower and upper triangular matrices.
Expand Down Expand Up @@ -1055,7 +1054,7 @@ def lu_decompose(self) -> Tuple[FieldArray, FieldArray]:
L, U = _linalg.lu_decompose_jit(field)(A)
return L, U

def plu_decompose(self) -> Tuple[FieldArray, FieldArray, FieldArray]:
def plu_decompose(self) -> tuple[FieldArray, FieldArray, FieldArray]:
r"""
Decomposes the input array into the product of lower and upper triangular matrices using partial pivoting.
Expand Down
5 changes: 3 additions & 2 deletions src/galois/_math.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""
A module containing math and arithmetic routines on integers. Some of these functions are polymorphic and wrapped in `_polymorphic.py`.
"""
from __future__ import annotations

import math
import sys
from typing import Tuple

from ._helper import export, verify_isinstance

Expand All @@ -19,7 +20,7 @@ def gcd(a: int, b: int) -> int:
return math.gcd(a, b)


def egcd(a: int, b: int) -> Tuple[int, int, int]:
def egcd(a: int, b: int) -> tuple[int, int, int]:
"""
This function is wrapped and documented in `_polymorphic.egcd()`.
"""
Expand Down
12 changes: 7 additions & 5 deletions src/galois/_polymorphic.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""
A module that contains polymorphic math functions that work on integers and polynomials.
"""
from typing import Tuple, List, Sequence, overload
from __future__ import annotations

from typing import List, Sequence, overload

import numpy as np

Expand Down Expand Up @@ -99,10 +101,10 @@ def gcd(a, b):


@overload
def egcd(a: int, b: int) -> Tuple[int, int, int]:
def egcd(a: int, b: int) -> tuple[int, int, int]:
...
@overload
def egcd(a: Poly, b: Poly) -> Tuple[Poly, Poly, Poly]:
def egcd(a: Poly, b: Poly) -> tuple[Poly, Poly, Poly]:
...
@export
def egcd(a, b):
Expand Down Expand Up @@ -532,10 +534,10 @@ def crt(remainders, moduli):
###############################################################################

@overload
def factors(value: int) -> Tuple[List[int], List[int]]:
def factors(value: int) -> tuple[List[int], List[int]]:
...
@overload
def factors(value: Poly) -> Tuple[List[Poly], List[int]]:
def factors(value: Poly) -> tuple[List[Poly], List[int]]:
...
@export
def factors(value):
Expand Down
4 changes: 1 addition & 3 deletions src/galois/_polys/_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
"""
from __future__ import annotations

from typing import Tuple


def add(a: int, b: int) -> int:
"""
Expand Down Expand Up @@ -47,7 +45,7 @@ def multiply(a: int, b: int) -> int:
return c


def divmod(a: int, b: int) -> Tuple[int, int]: # pylint: disable=redefined-builtin
def divmod(a: int, b: int) -> tuple[int, int]: # pylint: disable=redefined-builtin
"""
a(x) = q(x)*b(x) + r(x)
"""
Expand Down
4 changes: 2 additions & 2 deletions src/galois/_polys/_conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
from __future__ import annotations

from typing import Tuple, List
from typing import List

import numpy as np

Expand Down Expand Up @@ -129,7 +129,7 @@ def sparse_poly_to_str(degrees: List[int], coeffs: List[int], poly_var: str = "x
return " + ".join(x) if x else "0"


def str_to_sparse_poly(poly_str: str) -> Tuple[List[int], List[int]]:
def str_to_sparse_poly(poly_str: str) -> tuple[List[int], List[int]]:
"""
Converts the polynomial string into its non-zero degrees and coefficients.
"""
Expand Down
4 changes: 1 addition & 3 deletions src/galois/_polys/_dense.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
"""
from __future__ import annotations

from typing import Tuple

import numba
from numba import int64, uint64
import numpy as np
Expand Down Expand Up @@ -70,7 +68,7 @@ class divmod_jit(Function):
Algorithm:
a(x) = q(x)*b(x) + r(x)
"""
def __call__(self, a: Array, b: Array) -> Tuple[Array, Array]:
def __call__(self, a: Array, b: Array) -> tuple[Array, Array]:
verify_isinstance(a, self.field)
verify_isinstance(b, self.field)

Expand Down
4 changes: 2 additions & 2 deletions src/galois/_polys/_functions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
A module with functions for polynomials over Galois fields.
"""
from typing import Tuple
from __future__ import annotations

import numpy as np

Expand Down Expand Up @@ -34,7 +34,7 @@ def gcd(a: Poly, b: Poly) -> Poly:
return r2


def egcd(a: Poly, b: Poly) -> Tuple[Poly, Poly, Poly]:
def egcd(a: Poly, b: Poly) -> tuple[Poly, Poly, Poly]:
"""
This function is wrapped and documented in `_polymorphic.egcd()`.
"""
Expand Down
18 changes: 9 additions & 9 deletions src/galois/_polys/_poly.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
from __future__ import annotations

from typing import Tuple, List, Sequence, Type, overload
from typing import List, Sequence, Type, overload
from typing_extensions import Literal

import numpy as np
Expand Down Expand Up @@ -705,7 +705,7 @@ def reverse(self) -> Poly:
def roots(self, multiplicity: Literal[False] = False) -> Array:
...
@overload
def roots(self, multiplicity: Literal[True]) -> Tuple[Array, np.ndarray]:
def roots(self, multiplicity: Literal[True]) -> tuple[Array, np.ndarray]:
...
def roots(self, multiplicity=False):
r"""
Expand Down Expand Up @@ -788,7 +788,7 @@ def roots(self, multiplicity=False):
multiplicities = np.array([_root_multiplicity(self, root) for root in roots])
return roots, multiplicities

def square_free_factors(self) -> Tuple[List[Poly], List[int]]:
def square_free_factors(self) -> tuple[List[Poly], List[int]]:
r"""
Factors the monic polynomial :math:`f(x)` into a product of square-free polynomials.
Expand Down Expand Up @@ -884,7 +884,7 @@ def square_free_factors(self) -> Tuple[List[Poly], List[int]]:

return list(factors_), list(multiplicities)

def distinct_degree_factors(self) -> Tuple[List[Poly], List[int]]:
def distinct_degree_factors(self) -> tuple[List[Poly], List[int]]:
r"""
Factors the monic, square-free polynomial :math:`f(x)` into a product of polynomials whose irreducible factors all have
the same degree.
Expand Down Expand Up @@ -1077,7 +1077,7 @@ def equal_degree_factors(self, degree: int) -> List[Poly]:

return factors_

def factors(self) -> Tuple[List[Poly], List[int]]:
def factors(self) -> tuple[List[Poly], List[int]]:
r"""
Computes the irreducible factors of the non-constant, monic polynomial :math:`f(x)`.
Expand Down Expand Up @@ -1863,7 +1863,7 @@ def __rmul__(self, other: Poly | Array | int) -> Poly:
c = _dense.multiply(a, b)
return Poly(c, field=self.field)

def __divmod__(self, other: Poly | Array) -> Tuple[Poly, Poly]:
def __divmod__(self, other: Poly | Array) -> tuple[Poly, Poly]:
_check_input_is_poly(other, self.field)
types = [getattr(self, "_type", None), getattr(other, "_type", None)]

Expand All @@ -1878,7 +1878,7 @@ def __divmod__(self, other: Poly | Array) -> Tuple[Poly, Poly]:
q, r = _dense.divmod_jit(self.field)(a, b)
return Poly(q, field=self.field), Poly(r, field=self.field)

def __rdivmod__(self, other: Poly | Array) -> Tuple[Poly, Poly]:
def __rdivmod__(self, other: Poly | Array) -> tuple[Poly, Poly]:
_check_input_is_poly(other, self.field)
types = [getattr(self, "_type", None), getattr(other, "_type", None)]

Expand Down Expand Up @@ -2139,7 +2139,7 @@ def is_monic(self) -> bool:
return self.nonzero_coeffs[0] == 1


def _convert_coeffs(coeffs: ArrayLike, field: Type[Array] | None = None) -> Tuple[Array, Type[Array]]:
def _convert_coeffs(coeffs: ArrayLike, field: Type[Array] | None = None) -> tuple[Array, Type[Array]]:
"""
Converts the coefficient-like input into a Galois field array based on the `field` keyword argument.
"""
Expand Down Expand Up @@ -2278,7 +2278,7 @@ def _convert_to_integer(a: Poly | Array | int, field: Type[Array]) -> int:
return int(a)


def _convert_to_sparse_coeffs(a: Poly | Array | int, field: Type[Array]) -> Tuple[np.ndarray, Array]:
def _convert_to_sparse_coeffs(a: Poly | Array | int, field: Type[Array]) -> tuple[np.ndarray, Array]:
"""
Convert the polynomial or finite field scalar into its non-zero degrees and coefficients.
"""
Expand Down
10 changes: 5 additions & 5 deletions src/galois/_polys/_sparse.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"""
A module containing polynomial arithmetic for polynomials with sparse coefficients.
"""
from typing import Tuple
from __future__ import annotations

import numpy as np

from .._domains import Array


def add(a_degrees: np.ndarray, a_coeffs: Array, b_degrees: np.ndarray, b_coeffs: Array) -> Tuple[np.ndarray, Array]:
def add(a_degrees: np.ndarray, a_coeffs: Array, b_degrees: np.ndarray, b_coeffs: Array) -> tuple[np.ndarray, Array]:
"""
c(x) = a(x) + b(x)
"""
Expand All @@ -21,15 +21,15 @@ def add(a_degrees: np.ndarray, a_coeffs: Array, b_degrees: np.ndarray, b_coeffs:
return np.array(list(c.keys())), field(list(c.values()))


def negative(a_degrees: np.ndarray, a_coeffs: Array) -> Tuple[np.ndarray, Array]:
def negative(a_degrees: np.ndarray, a_coeffs: Array) -> tuple[np.ndarray, Array]:
"""
c(x) = -a(x)
a(x) + -a(x) = 0
"""
return a_degrees, -a_coeffs


def subtract(a_degrees: np.ndarray, a_coeffs: Array, b_degrees: np.ndarray, b_coeffs: Array) -> Tuple[np.ndarray, Array]:
def subtract(a_degrees: np.ndarray, a_coeffs: Array, b_degrees: np.ndarray, b_coeffs: Array) -> tuple[np.ndarray, Array]:
"""
c(x) = a(x) - b(x)
"""
Expand All @@ -43,7 +43,7 @@ def subtract(a_degrees: np.ndarray, a_coeffs: Array, b_degrees: np.ndarray, b_co
return np.array(list(c.keys())), field(list(c.values()))


def multiply(a_degrees: np.ndarray, a_coeffs: Array, b_degrees: np.ndarray, b_coeffs: Array) -> Tuple[np.ndarray, Array]:
def multiply(a_degrees: np.ndarray, a_coeffs: Array, b_degrees: np.ndarray, b_coeffs: Array) -> tuple[np.ndarray, Array]:
"""
c(x) = a(x) * b(x)
c(x) = a(x) * b = a(x) + ... + a(x)
Expand Down
Loading

0 comments on commit 3aefcea

Please sign in to comment.