Skip to content

Commit

Permalink
Remove metaclasses from API
Browse files Browse the repository at this point in the history
  • Loading branch information
mhostetter committed Apr 22, 2022
1 parent 7a3a2e6 commit d036af6
Show file tree
Hide file tree
Showing 64 changed files with 3,422 additions and 3,362 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ The display representation of finite field elements can be set to either the int
or power (`"power"`) representation. The default representation is the integer representation since that is natural when
working with integer NumPy arrays.

Set the display mode by passing the `display` keyword argument to `galois.GF()` or by calling the `galois.FieldArrayClass.display()` method.
Set the display mode by passing the `display` keyword argument to `galois.GF()` or by calling the `galois.FieldArray.display()` method.
Choose whichever element representation is most convenient for you.

```python
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/test_field_arithmetic.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
A pytest module to benchmark Galois field array arithmetic.
A pytest module to benchmark FieldArray arithmetic.
"""
import pytest
import numpy as np
Expand Down
2 changes: 1 addition & 1 deletion docs/_templates/class.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
.. rubric:: {{ _('Attributes') }}
.. autosummary::
{% for item in attributes %}
{{ item }}
~{{ objname }}.{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}
Expand Down
3 changes: 1 addition & 2 deletions docs/api/galois-fields.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ Abstract base classes
:toctree:

FieldArray
FieldArrayClass

Pre-made Galois field array classes
Pre-made `FieldArray` subclasses
...................................

.. autosummary::
Expand Down
2 changes: 0 additions & 2 deletions docs/api/galois.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ Abstract base classes
:toctree:

Array
ArrayClass
FieldArray
FieldArrayClass

Classes
-------
Expand Down
6 changes: 6 additions & 0 deletions docs/api/transforms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ Number-theoretic transform

ntt
intt

Discrete Fourier transform
--------------------------

The DFT over arbitrary finite fields may be performed by invoking :func:`numpy.fft.fft` on a :obj:`FieldArray`. The same is
true for the inverse DFT and :func:`numpy.fft.ifft`. See :ref:`advanced arithmetic`.
203 changes: 198 additions & 5 deletions docs/basic-usage/array-arithmetic.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Array Arithmetic
================

After creating a :ref:`Galois field array class` and one or two :ref:`Galois field arrays <Galois field array>`,
nearly any arithmetic operation can be performed using normal NumPy ufuncs or Python operators.
After creating a :obj:`~galois.FieldArray` subclass and one or two arrays, nearly any arithmetic operation can be
performed using normal NumPy ufuncs or Python operators.

In the sections below, the finite field :math:`\mathrm{GF}(3^5)` and arrays :math:`x` and :math:`y` are used.

Expand Down Expand Up @@ -144,7 +144,7 @@ Expand any section for more details.
Ufunc methods
-------------

*Galois field arrays* support `NumPy ufunc methods <https://numpy.org/devdocs/reference/ufuncs.html#methods>`_. Ufunc methods allow
:obj:`~galois.FieldArray` instances support `NumPy ufunc methods <https://numpy.org/devdocs/reference/ufuncs.html#methods>`_. Ufunc methods allow
a user to apply a NumPy ufunc in a unique way across the target array. All arithmetic ufuncs are supported.

Expand any section for more details.
Expand Down Expand Up @@ -215,6 +215,8 @@ Expand any section for more details.
np.negative.at(x, [0, 1]); x
z[0:1] *= -1; z
.. _advanced arithmetic:

Advanced arithmetic
-------------------

Expand All @@ -239,7 +241,7 @@ Advanced arithmetic
X = np.fft.fft(x); X
np.fft.ifft(X)
See also :func:`~galois.ntt` and :obj:`~galois.FieldArrayClass.primitive_root_of_unity`.
See also :func:`~galois.ntt` and :obj:`~galois.FieldArray.primitive_root_of_unity`.

.. details:: Inverse FFT: `np.fft.ifft(X)`

Expand All @@ -256,4 +258,195 @@ Advanced arithmetic
X = np.fft.fft(x); X
np.fft.ifft(X)
See also :func:`~galois.ntt` and :obj:`~galois.FieldArrayClass.primitive_root_of_unity`.
See also :func:`~galois.ntt` and :obj:`~galois.FieldArray.primitive_root_of_unity`.

Linear algebra
--------------

Linear algebra on :obj:`~galois.FieldArray` arrays/matrices is supported through both native NumPy linear algebra functions
in :obj:`numpy.linalg` and additional linear algebra routines not included in NumPy.

Expand any section for more details.

.. details:: Dot product: `np.dot(a, b)`

.. ipython:: python
GF = galois.GF(31)
a = GF([29, 0, 2, 21]); a
b = GF([23, 5, 15, 12]); b
np.dot(a, b)
.. details:: Vector dot product: `np.vdot(a, b)`

.. ipython:: python
GF = galois.GF(31)
a = GF([29, 0, 2, 21]); a
b = GF([23, 5, 15, 12]); b
np.vdot(a, b)
.. details:: Inner product: `np.inner(a, b)`

.. ipython:: python
GF = galois.GF(31)
a = GF([29, 0, 2, 21]); a
b = GF([23, 5, 15, 12]); b
np.inner(a, b)
.. details:: Outer product: `np.outer(a, b)`

.. ipython:: python
GF = galois.GF(31)
a = GF([29, 0, 2, 21]); a
b = GF([23, 5, 15, 12]); b
np.outer(a, b)
.. details:: Matrix multiplication: `A @ B == np.matmul(A, B)`

.. ipython:: python
GF = galois.GF(31)
A = GF([[17, 25, 18, 8], [7, 9, 21, 15], [6, 16, 6, 30]]); A
B = GF([[8, 18], [22, 0], [7, 8], [20, 24]]); B
A @ B
np.matmul(A, B)
.. details:: Matrix exponentiation: `np.linalg.matrix_power(A, z)`

.. ipython:: python
GF = galois.GF(31)
A = GF([[14, 1, 5], [3, 23, 6], [24, 27, 4]]); A
np.linalg.matrix_power(A, 3)
A @ A @ A
.. details:: Matrix determinant: `np.linalg.det(A)`

.. ipython:: python
GF = galois.GF(31)
A = GF([[23, 11, 3, 3], [13, 6, 16, 4], [12, 10, 5, 3], [17, 23, 15, 28]]); A
np.linalg.det(A)
.. details:: Matrix rank: `np.linalg.matrix_rank(A, z)`

.. ipython:: python
GF = galois.GF(31)
A = GF([[23, 11, 3, 3], [13, 6, 16, 4], [12, 10, 5, 3], [17, 23, 15, 28]]); A
np.linalg.matrix_rank(A)
A.row_reduce()
.. details:: Matrix trace: `np.trace(A)`

.. ipython:: python
GF = galois.GF(31)
A = GF([[23, 11, 3, 3], [13, 6, 16, 4], [12, 10, 5, 3], [17, 23, 15, 28]]); A
np.trace(A)
A[0,0] + A[1,1] + A[2,2] + A[3,3]
.. details:: Solve a system of equations: `np.linalg.solve(A, b)`

.. ipython:: python
GF = galois.GF(31)
A = GF([[14, 21, 14, 28], [24, 22, 23, 23], [16, 30, 26, 18], [4, 23, 18, 3]]); A
b = GF([15, 11, 6, 29]); b
x = np.linalg.solve(A, b)
np.array_equal(A @ x, b)
.. details:: Matrix inverse: `np.linalg.inv(A)`

.. ipython:: python
GF = galois.GF(31)
A = GF([[14, 21, 14, 28], [24, 22, 23, 23], [16, 30, 26, 18], [4, 23, 18, 3]]); A
A_inv = np.linalg.inv(A); A_inv
A @ A_inv
Additional linear algebra
-------------------------

Below are additional linear algebra routines provided for :obj:`~galois.FieldArray` arrays/matrices that are
not included in NumPy.

.. details:: Row space: `A.row_space()`

.. ipython:: python
GF = galois.GF(31)
A = GF([[23, 11, 3, 3], [13, 6, 16, 4], [12, 10, 5, 3], [17, 23, 15, 28]]); A
A.row_space()
See :func:`~galois.FieldArray.row_space` for more details.

.. details:: Column space: `A.column_space()`

.. ipython:: python
GF = galois.GF(31)
A = GF([[23, 11, 3, 3], [13, 6, 16, 4], [12, 10, 5, 3], [17, 23, 15, 28]]); A
A.column_space()
See :func:`~galois.FieldArray.column_space` for more details.

.. details:: Left null space: `A.left_null_space()`

.. ipython:: python
GF = galois.GF(31)
A = GF([[23, 11, 3, 3], [13, 6, 16, 4], [12, 10, 5, 3], [17, 23, 15, 28]]); A
A.left_null_space()
See :func:`~galois.FieldArray.left_null_space` for more details.

.. details:: Null space: `A.null_space()`

.. ipython:: python
GF = galois.GF(31)
A = GF([[23, 11, 3, 3], [13, 6, 16, 4], [12, 10, 5, 3], [17, 23, 15, 28]]); A
A.null_space()
See :func:`~galois.FieldArray.null_space` for more details.

.. details:: Gaussian elimination: `A.row_reduce()`

.. ipython:: python
GF = galois.GF(31)
A = GF([[23, 11, 3, 3], [13, 6, 16, 4], [12, 10, 5, 3], [17, 23, 15, 28]]); A
A.row_reduce()
See :func:`~galois.FieldArray.row_reduce` for more details.

.. details:: LU decomposition: `A.lu_decompose()`

.. ipython:: python
GF = galois.GF(31)
A = GF([[4, 1, 24], [7, 6, 1], [11, 20, 2]]); A
L, U = A.lu_decompose()
L
U
np.array_equal(L @ U, A)
See :func:`~galois.FieldArray.lu_decompose` for more details.

.. details:: PLU decomposition: `A.plu_decompose()`

.. ipython:: python
GF = galois.GF(31)
A = GF([[15, 4, 11], [7, 6, 1], [11, 20, 2]]); A
P, L, U = A.plu_decompose()
P
L
U
np.array_equal(P @ L @ U, A)
See :func:`~galois.FieldArray.plu_decompose` for more details.
Loading

0 comments on commit d036af6

Please sign in to comment.