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

Add random prime seeding #409

Merged
merged 6 commits into from
Aug 30, 2022
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
6 changes: 0 additions & 6 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@
# Need to build docs with Python 3.8 or higher for proper typing annotations, including from __future__ import annotations
assert sys.version_info.major == 3 and sys.version_info.minor >= 8

# Assign a build variable to the builtin module that inerts the @set_module decorator. This is done because set_module
# confuses Sphinx when parsing overloaded functions. When not building the documentation, the @set_module("galois")
# decorator works as intended.
import builtins
setattr(builtins, "__sphinx_build__", True)

import galois
import numpy

Expand Down
7 changes: 3 additions & 4 deletions docs/development/documentation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ The documentation dependencies are stored in `docs/requirements.txt`.

.. literalinclude:: ../requirements.txt
:caption: docs/requirements.txt
:language: txt

Install the documentation dependencies by passing the `-r` switch to `pip install`.

.. code-block:: sh
.. code-block:: console

$ python3 -m pip install -r docs/requirements.txt

Expand All @@ -24,7 +23,7 @@ Build the docs

The documentation is built by running the `sphinx-build` command.

.. code-block:: sh
.. code-block:: console

$ sphinx-build -b dirhtml -v docs/ docs/build/

Expand All @@ -36,7 +35,7 @@ Serve the docs
Since the site is built to use directories (`*/getting-started/` not `*/getting-started.html`), it is necessary
to serve the webpages locally with a webserver. This is easily done using the built-in Python `http` module.

.. code-block:: sh
.. code-block:: console

$ python3 -m http.server 8080 -d docs/build/

Expand Down
12 changes: 6 additions & 6 deletions docs/development/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Install from PyPI

The latest released version of :obj:`galois` can be installed from `PyPI <https://pypi.org/project/galois/>`_ using `pip`.

.. code-block:: sh
.. code-block:: console

$ python3 -m pip install galois

Expand All @@ -15,13 +15,13 @@ Install from GitHub

The latest code on `master` can be installed using `pip` in this way.

.. code-block:: sh
.. code-block:: console

$ python3 -m pip install git+https://github.com/mhostetter/galois.git

Or from a specific branch.

.. code-block:: sh
.. code-block:: console

$ python3 -m pip install git+https://github.com/mhostetter/galois.git@branch

Expand All @@ -33,13 +33,13 @@ fashion from a local folder. This allows any changes in the current directory to

Clone the repo wherever you'd like.

.. code-block:: sh
.. code-block:: console

$ git clone https://github.com/mhostetter/galois.git

Install the local folder using the `-e` or `--editable` flag.

.. code-block:: sh
.. code-block:: console

$ python3 -m pip install -e galois/

Expand All @@ -57,6 +57,6 @@ in `pyproject.toml`.

Install the development dependencies by passing the `[dev]` extras to `pip install`.

.. code-block:: sh
.. code-block:: console

$ python3 -m pip install galois[dev]
4 changes: 2 additions & 2 deletions docs/development/linter.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Install

First, `pylint` needs to be installed on your system. Easily install it by installing the development dependencies.

.. code-block:: sh
.. code-block:: console

$ python3 -m pip install .[dev]

Expand All @@ -29,7 +29,7 @@ Run from the command line

Run the linter manually from the command line.

.. code-block:: sh
.. code-block:: console

$ python3 -m pylint src/galois/

Expand Down
14 changes: 7 additions & 7 deletions docs/development/unit-tests.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Install

First, `pytest` needs to be installed on your system. Easily install it by installing the development dependencies.

.. code-block:: sh
.. code-block:: console

$ python3 -m pip install .[dev]

Expand All @@ -28,19 +28,19 @@ Run from the command line

Execute all of the unit tests manually from the command line.

.. code-block:: sh
.. code-block:: console

$ python3 -m pytest tests/

Or only run a specific test file.

.. code-block:: sh
.. code-block:: console

$ python3 -m pytest tests/test_math.py

Or only run a specific unit test.

.. code-block:: sh
.. code-block:: console

$ python3 -m pytest tests/test_math.py::test_gcd

Expand Down Expand Up @@ -69,14 +69,14 @@ The two primary third-party tools are `Sage <https://www.sagemath.org/>`_ and `S
Install Sage
............

.. code-block:: sh
.. code-block:: console

$ sudo apt install sagemath

Install SymPy
.............

.. code-block:: sh
.. code-block:: console

$ python3 -m pip install sympy

Expand All @@ -85,7 +85,7 @@ Generate test vectors

To re-generate the test vectors locally, run:

.. code-block:: sh
.. code-block:: console

$ python3 scripts/generate_int_test_vectors.py
$ python3 scripts/generate_field_test_vectors.py
Expand Down
2 changes: 1 addition & 1 deletion docs/getting-started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Install the package

The latest version of :obj:`galois` can be installed from `PyPI <https://pypi.org/project/galois/>`_ using `pip`.

.. code-block:: sh
.. code-block:: console

$ python3 -m pip install galois

Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ If this library was useful to you in your research, please cite us. Following th

.. tab-item:: BibTeX

.. code-block:: TeX
.. code-block:: latex

@software{Hostetter_Galois_2020,
title = {{Galois: A performant NumPy extension for Galois fields}},
Expand Down
10 changes: 5 additions & 5 deletions docs/performance/benchmarks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Install dependencies

First, `pytest` and `pytest-benchmark` must be installed on your system. Easily install them by installing the development dependencies.

.. code-block:: sh
.. code-block:: console

$ python3 -m pip install -r requirements-dev.txt

Expand All @@ -19,7 +19,7 @@ Create a benchmark
To create a benchmark, invoke `pytest` on the `benchmarks/` folder or a specific test set (e.g., `benchmarks/test_field_arithmetic.py`). It is also
advised to pass extra arguments to format the display `--benchmark-columns=min,max,mean,stddev,median` and `--benchmark-sort=name`.

.. code-block::
.. code-block:: console

$ python3 -m pytest benchmarks/test_field_arithmetic.py --benchmark-columns=min,max,mean,stddev,median --benchmark-sort=name
===================================================================== test session starts =====================================================================platform linux -- Python 3.8.10, pytest-4.6.9, py-1.8.1, pluggy-0.13.0
Expand Down Expand Up @@ -132,21 +132,21 @@ Compare with a previous benchmark
If you would like to compare the performance impact of a branch, first run a benchmark on `master` using the `--benchmark-save` option.
This will save the file `.benchmarks/0001_master.json`.

.. code-block::
.. code-block:: console

$ git checkout master
$ python3 -m pytest benchmarks/test_field_arithmetic.py --benchmark-save=master --benchmark-columns=min,max,mean,stddev,median --benchmark-sort=name

Next, run a benchmark on the branch under test while comparing against the benchmark from `master`.

.. code-block::
.. code-block:: console

$ git checkout branch
$ python3 -m pytest benchmarks/test_field_arithmetic.py --benchmark-compare=0001_master --benchmark-columns=min,max,mean,stddev,median --benchmark-sort=name

Or, save a benchmark run from `branch` and compare it explicitly against the one from `master`. This benchmark run will save the file `.benchmarks/0001_branch.json`.

.. code-block::
.. code-block:: console

$ git checkout branch
$ python3 -m pytest benchmarks/test_field_arithmetic.py --benchmark-save=branch --benchmark-columns=min,max,mean,stddev,median --benchmark-sort=name
Expand Down
8 changes: 3 additions & 5 deletions src/galois/_codes/_bch.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from .._domains._function import Function
from .._fields import Field, FieldArray, GF2
from .._helper import set_module, verify_isinstance
from .._helper import export, verify_isinstance
from .._lfsr import berlekamp_massey_jit
from .._polys import Poly, matlab_primitive_poly
from .._polys._dense import roots_jit, divmod_jit
Expand All @@ -22,8 +22,6 @@

from ._cyclic import poly_to_generator_matrix, roots_to_parity_check_matrix

__all__ = ["BCH", "bch_valid_codes"]


def _check_and_compute_field(
n: int,
Expand Down Expand Up @@ -55,7 +53,7 @@ def _check_and_compute_field(
return GF


@set_module("galois")
@export
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 @@ -125,7 +123,7 @@ def bch_valid_codes(n: int, t_min: int = 1) -> List[Tuple[int, int, int]]:
return codes


@set_module("galois")
@export
class BCH:
r"""
A primitive, narrow-sense binary :math:`\textrm{BCH}(n, k)` code.
Expand Down
8 changes: 3 additions & 5 deletions src/galois/_codes/_cyclic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@
import numpy as np

from .._fields import FieldArray
from .._helper import set_module, verify_isinstance
from .._helper import export, verify_isinstance
from .._polys import Poly

__all__ = ["poly_to_generator_matrix", "roots_to_parity_check_matrix"]


@set_module("galois")
@export
def poly_to_generator_matrix(n: int, generator_poly: Poly, systematic: bool = True) -> FieldArray:
r"""
Converts the generator polynomial :math:`g(x)` into the generator matrix :math:`\mathbf{G}` for an :math:`[n, k]` cyclic code.
Expand Down Expand Up @@ -74,7 +72,7 @@ def poly_to_generator_matrix(n: int, generator_poly: Poly, systematic: bool = Tr
return G


@set_module("galois")
@export
def roots_to_parity_check_matrix(n: int, roots: FieldArray) -> FieldArray:
r"""
Converts the generator polynomial roots into the parity-check matrix :math:`\mathbf{H}` for an :math:`[n, k]` cyclic code.
Expand Down
8 changes: 3 additions & 5 deletions src/galois/_codes/_linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
import numpy as np

from .._fields import FieldArray
from .._helper import set_module, verify_isinstance
from .._helper import export, verify_isinstance

__all__ = ["generator_to_parity_check_matrix", "parity_check_to_generator_matrix"]


@set_module("galois")
@export
def generator_to_parity_check_matrix(G: FieldArray) -> FieldArray:
r"""
Converts the generator matrix :math:`\mathbf{G}` of a linear :math:`[n, k]` code into its parity-check matrix :math:`\mathbf{H}`.
Expand Down Expand Up @@ -54,7 +52,7 @@ def generator_to_parity_check_matrix(G: FieldArray) -> FieldArray:
return H


@set_module("galois")
@export
def parity_check_to_generator_matrix(H: FieldArray) -> FieldArray:
r"""
Converts the parity-check matrix :math:`\mathbf{H}` of a linear :math:`[n, k]` code into its generator matrix :math:`\mathbf{G}`.
Expand Down
6 changes: 2 additions & 4 deletions src/galois/_codes/_reed_solomon.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from .._domains._function import Function
from .._fields import Field, FieldArray
from .._helper import set_module, verify_isinstance
from .._helper import export, verify_isinstance
from .._lfsr import berlekamp_massey_jit
from .._polys import Poly, matlab_primitive_poly
from .._polys._dense import divmod_jit, roots_jit, evaluate_elementwise_jit
Expand All @@ -21,10 +21,8 @@

from ._cyclic import poly_to_generator_matrix, roots_to_parity_check_matrix

__all__ = ["ReedSolomon"]


@set_module("galois")
@export
class ReedSolomon:
r"""
A general :math:`\textrm{RS}(n, k)` code.
Expand Down
8 changes: 3 additions & 5 deletions src/galois/_domains/_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,16 @@

import numpy as np

from .._helper import set_module, verify_isinstance, SPHINX_BUILD
from .._helper import export, verify_isinstance
from ..typing import ElementLike, IterableLike, ArrayLike, ShapeLike, DTypeLike

from ._function import FunctionMixin
from ._linalg import LinalgFunctionMixin
from ._lookup import UFuncMixin
from ._meta import ArrayMeta

__all__ = ["Array"]


@set_module("galois")
@export
class Array(LinalgFunctionMixin, FunctionMixin, UFuncMixin, np.ndarray, metaclass=ArrayMeta):
r"""
An abstract :obj:`~numpy.ndarray` subclass over a Galois field or Galois ring.
Expand All @@ -42,7 +40,7 @@ def __new__(
order: Literal["K", "A", "C", "F"] = "K",
ndmin: int = 0
) -> Array:
if not SPHINX_BUILD and cls is Array:
if cls is Array:
raise NotImplementedError("Array is an abstract base class that cannot be directly instantiated. Instead, create a Array subclass for GF(p^m) arithmetic using `GF = galois.GF(p**m)` and instantiate an array using `x = GF(array_like)`.")

dtype = cls._get_dtype(dtype)
Expand Down
Loading