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

Release 0.3.10 #552

Merged
merged 17 commits into from
Jun 23, 2024
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
15 changes: 3 additions & 12 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,9 @@ jobs:
if: ${{ github.event_name == 'pull_request' }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
os: [ubuntu-latest, macos-13, windows-latest]
python-version: [3.7, 3.8, 3.9, '3.10', 3.11, 3.12]
# https://github.com/actions/runner-images/issues/9770#issuecomment-2085623315
exclude: # Python < v3.8 does not support Apple Silicon ARM64
- python-version: "3.7"
os: macos-latest
- python-version: "3.8"
os: macos-latest
include: # So run those legacy versions on Intel CPUs
- python-version: "3.7"
os: macos-13
- python-version: "3.8"
os: macos-13
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -153,6 +143,7 @@ jobs:
include: # So run those legacy versions on Intel CPUs
- python-version: "3.7"
os: macos-13
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
Expand Down
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
<a href="https://pypi.org/project/galois"><img src="https://img.shields.io/pypi/wheel/galois"></a>
<a href="https://pypistats.org/packages/galois"><img src="https://img.shields.io/pypi/dm/galois"></a>
<a href="https://pypi.org/project/galois"><img src="https://img.shields.io/pypi/l/galois"></a>
<a href="https://twitter.com/galois_py"><img src="https://img.shields.io/static/v1?label=follow&message=@galois_py&color=blue&logo=twitter"></a>
</div>

<div align=center>
<a href="https://github.com/mhostetter/galois/actions/workflows/docs.yaml"><img src="https://github.com/mhostetter/galois/actions/workflows/docs.yaml/badge.svg"></a>
<a href="https://github.com/mhostetter/galois/actions/workflows/lint.yaml"><img src="https://github.com/mhostetter/galois/actions/workflows/lint.yaml/badge.svg"></a>
<a href="https://github.com/mhostetter/galois/actions/workflows/build.yaml"><img src="https://github.com/mhostetter/galois/actions/workflows/build.yaml/badge.svg"></a>
<a href="https://github.com/mhostetter/galois/actions/workflows/test.yaml"><img src="https://github.com/mhostetter/galois/actions/workflows/test.yaml/badge.svg"></a>
<a href="https://github.com/mhostetter/galois/actions/workflows/lint.yaml"><img src="https://github.com/mhostetter/galois/actions/workflows/lint.yaml/badge.svg?branch=main"></a>
<a href="https://github.com/mhostetter/galois/actions/workflows/build.yaml"><img src="https://github.com/mhostetter/galois/actions/workflows/build.yaml/badge.svg?branch=main"></a>
<a href="https://github.com/mhostetter/galois/actions/workflows/test.yaml"><img src="https://github.com/mhostetter/galois/actions/workflows/test.yaml/badge.svg?branch=main"></a>
<a href="https://codecov.io/gh/mhostetter/galois"><img src="https://codecov.io/gh/mhostetter/galois/branch/main/graph/badge.svg?token=3FJML79ZUK"></a>
<a href="https://twitter.com/galois_py"><img src="https://img.shields.io/static/v1?label=follow&message=@galois_py&color=blue&logo=twitter"></a>
</div>

The `galois` library is a Python 3 package that extends NumPy arrays to operate over finite fields.
Expand Down Expand Up @@ -78,7 +76,7 @@ Import the `galois` package in Python.
In [1]: import galois

In [2]: galois.__version__
Out[2]: '0.3.9'
Out[2]: '0.3.10'
```

### Create a [`FieldArray`](https://mhostetter.github.io/galois/latest/api/galois.FieldArray/) subclass
Expand Down
51 changes: 41 additions & 10 deletions docs/_static/extra.css
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
/* Set the colors for the light theme */
[data-md-color-scheme="default"] {
/* [data-md-color-scheme="default"] {
--md-primary-fg-color: #344FA1;
--md-accent-fg-color: #4564C3;
}
} */

/* Set the colors for the dark theme */
[data-md-color-scheme="slate"] {
/* [data-md-color-scheme="slate"] {
--md-primary-fg-color: #EAA915;
--md-accent-fg-color: #EEBA44;
}
} */

[data-md-color-scheme="slate"] .md-header {
/* [data-md-color-scheme="slate"] .md-header {
background-color: #344FA1;
}

[data-md-color-scheme="slate"] .md-tabs {
background-color: #344FA1;
}
} */

/* @media screen and (max-width: 76.1875em) */
.md-nav--primary .md-nav__title[for=__drawer] {
/* .md-nav--primary .md-nav__title[for=__drawer] {
background-color: #344FA1;
}

.md-source {
background-color: #344FA1;
}
} */

/* Fix line numbers in code blocks */
.linenos {
Expand All @@ -35,7 +35,7 @@

/* Override md-tab-set colors. */
.md-typeset .tabbed-labels {
--md-accent-fg-color: var(--md-primary-fg-color);
--md-accent-fg-color: var(--md-typeset-a-color);
}

/* Modify Sphinx Immaterial python-apigen linkable parameter coloring. */
Expand All @@ -49,6 +49,37 @@

/* Override announcement banner colors */
.md-banner {
background-color: var(--md-typeset-mark-color);
background-color: var(--md-default-bg-color--lighter);
color: var(--md-default-fg-color);
}

/* Change the object info colors. */
[data-md-color-scheme="default"] {
/* --objinfo-icon-fg-default: var(--md-code-hl-keyword-color); */
/* Properties */
--objinfo-icon-fg-alias: var(--md-code-hl-constant-color);
/* Classes */
--objinfo-icon-fg-data: var(--md-code-hl-string-color);
/* Functions, methods */
--objinfo-icon-fg-procedure: var(--md-code-hl-keyword-color);
/* Parameters (function/method arguments) */
--objinfo-icon-fg-sub-data: var(--md-code-hl-function-color);
}

[data-md-color-scheme="slate"] {
/* --objinfo-icon-fg-default: var(--md-code-hl-keyword-color); */
/* Properties */
--objinfo-icon-fg-alias: var(--md-code-hl-constant-color);
/* Classes */
--objinfo-icon-fg-data: var(--md-code-hl-string-color);
/* Functions, methods */
--objinfo-icon-fg-procedure: var(--md-code-hl-keyword-color);
/* Parameters (function/method arguments) */
--objinfo-icon-fg-sub-data: var(--md-code-hl-function-color);
}

/* Change the "class" and "property" label colors. */
.md-typeset dl.objdesc>dt .property {
color: var(--md-code-hl-constant-color);
font-style: italic;
}
2 changes: 1 addition & 1 deletion docs/_templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% block announce %}
<p>
Enjoying the library? Give us a
<span class="md-icon si-icon-inline octicons_star-16"></span>
<span class="md-icon si-icon-inline fontawesome_regular_star"></span>
on
<a class="reference external" href="https://github.com/mhostetter/galois">GitHub</a>.
</p>
Expand Down
63 changes: 61 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@
{
"media": "(prefers-color-scheme: light)",
"scheme": "default",
"primary": "indigo",
"accent": "indigo",
"toggle": {
"icon": "material/weather-night",
"name": "Switch to dark mode",
Expand All @@ -167,6 +169,8 @@
{
"media": "(prefers-color-scheme: dark)",
"scheme": "slate",
"primary": "black",
"accent": "indigo",
"toggle": {
"icon": "material/weather-sunny",
"name": "Switch to light mode",
Expand Down Expand Up @@ -279,17 +283,72 @@
]

sphinx_immaterial_custom_admonitions = [
{
"name": "note",
"title": "Note",
"classes": ["collapsible"],
"icon": "fontawesome/solid/pencil",
"override": True,
},
{
"name": "warning",
"title": "Warning",
"classes": ["collapsible"],
"icon": "fontawesome/solid/triangle-exclamation",
"override": True,
},
{
"name": "info",
"icon": "fontawesome/solid/circle-info",
"override": True,
},
{
"name": "tip",
"icon": "fontawesome/regular/lightbulb",
"override": True,
},
{
"name": "abstract",
"icon": "fontawesome/regular/file-lines",
"override": True,
},
{
"name": "important",
"icon": "fontawesome/solid/bolt",
"override": True,
},
{
"name": "example",
"icon": "fontawesome/solid/terminal",
"override": True,
},
{
"name": "quote",
"icon": "fontawesome/solid/quote-left",
"override": True,
},
{
"name": "seealso",
"title": "See also",
"classes": ["collapsible"],
"icon": "fontawesome/regular/eye",
"icon": "fontawesome/solid/magnifying-glass",
"color": (108, 117, 125), # --sd-color-secondary
"override": True,
},
{
"name": "versionadded",
"icon": "fontawesome/solid/code-commit",
"override": True,
},
{
"name": "versionchanged",
"icon": "fontawesome/solid/code-branch",
"override": True,
},
{
# This needs to be defined here so the icon is available when referenced in _templates/base.html
"name": "star",
"icon": "octicons/star-16",
"icon": "fontawesome/regular/star",
"color": (255, 233, 3), # Gold
},
{
Expand Down
11 changes: 6 additions & 5 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
<a href="https://pypi.org/project/galois"><img src="https://img.shields.io/pypi/wheel/galois"></a>
<a href="https://pypistats.org/packages/galois"><img src="https://img.shields.io/pypi/dm/galois"></a>
<a href="https://pypi.org/project/galois"><img src="https://img.shields.io/pypi/l/galois"></a>
<a href="https://twitter.com/galois_py"><img src="https://img.shields.io/static/v1?label=follow&message=@galois_py&color=blue&logo=twitter"></a>
<a href="https://github.com/mhostetter/galois/actions/workflows/docs.yaml"><img src="https://github.com/mhostetter/galois/actions/workflows/docs.yaml/badge.svg"></a>
<a href="https://github.com/mhostetter/galois/actions/workflows/lint.yaml"><img src="https://github.com/mhostetter/galois/actions/workflows/lint.yaml/badge.svg"></a>
<a href="https://github.com/mhostetter/galois/actions/workflows/build.yaml"><img src="https://github.com/mhostetter/galois/actions/workflows/build.yaml/badge.svg"></a>
<a href="https://github.com/mhostetter/galois/actions/workflows/test.yaml"><img src="https://github.com/mhostetter/galois/actions/workflows/test.yaml/badge.svg"></a>
</div>
<div align=center>
<a href="https://github.com/mhostetter/galois/actions/workflows/lint.yaml"><img src="https://github.com/mhostetter/galois/actions/workflows/lint.yaml/badge.svg?branch=main"></a>
<a href="https://github.com/mhostetter/galois/actions/workflows/build.yaml"><img src="https://github.com/mhostetter/galois/actions/workflows/build.yaml/badge.svg?branch=main"></a>
<a href="https://github.com/mhostetter/galois/actions/workflows/test.yaml"><img src="https://github.com/mhostetter/galois/actions/workflows/test.yaml/badge.svg?branch=main"></a>
<a href="https://codecov.io/gh/mhostetter/galois"><img src="https://codecov.io/gh/mhostetter/galois/branch/main/graph/badge.svg?token=3FJML79ZUK"></a>
<a href="https://twitter.com/galois_py"><img src="https://img.shields.io/static/v1?label=follow&message=@galois_py&color=blue&logo=twitter"></a>
</div>

The :obj:`galois` library is a Python 3 package that extends NumPy arrays to operate over finite fields.
Expand Down
12 changes: 12 additions & 0 deletions docs/release-notes/v0.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,15 @@ tocdepth: 2

- Justin Charlong ([@jcharlong](https://github.com/jcharlong))
- Matt Hostetter ([@mhostetter](https://github.com/mhostetter))

## v0.3.10

*Released June 23, 2024*

### Changes

- Added support for `ufunc_mode="python-calculate"` for all fields. ([#551](https://github.com/mhostetter/galois/pull/551))

### Contributors

- Matt Hostetter ([@mhostetter](https://github.com/mhostetter))
5 changes: 3 additions & 2 deletions src/galois/_domains/_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,10 @@ def compile(cls, mode: Literal["auto", "jit-lookup", "jit-calculate", "python-ca
- `"jit-calculate"`: JIT compiles arithmetic ufuncs to use explicit calculation. The `"jit-calculate"`
mode is designed for large fields that cannot or should not store lookup tables in RAM. Generally,
the `"jit-calculate"` mode is slower than `"jit-lookup"`.
- `"python-calculate"`: Uses pure-Python ufuncs with explicit calculation. This is reserved for fields
- `"python-calculate"`: Uses pure-Python ufuncs with explicit calculation. This is intended for fields
whose elements cannot be represented with :obj:`numpy.int64` and instead use :obj:`numpy.object_`
with Python :obj:`int` (which has arbitrary precision).
with Python :obj:`int` (which has arbitrary precision). However, this mode can be used for any
field, enabling the code to run without Numba JIT compilation.
"""
verify_isinstance(mode, str)
if not mode in ["auto", "jit-lookup", "jit-calculate", "python-calculate"]:
Expand Down
2 changes: 1 addition & 1 deletion src/galois/_domains/_calculate.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ def set_calculate_globals(self):
ORDER = self.field.order
MULTIPLY = self.field._multiply.ufunc
POSITIVE_POWER = self.field._positive_power.ufunc
SUBFIELD_RECIPROCAL = self.field.prime_subfield._reciprocal.ufunc
SUBFIELD_RECIPROCAL = getattr(self.field.prime_subfield._reciprocal, self.field.ufunc_mode.replace("-", "_"))

@staticmethod
def calculate(a: int) -> int:
Expand Down
4 changes: 2 additions & 2 deletions src/galois/_domains/_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ def __init__(cls, name, bases, namespace, **kwargs):
cls._ufunc_modes = ["python-calculate"]
elif cls._order <= 2**20:
cls._default_ufunc_mode = "jit-lookup"
cls._ufunc_modes = ["jit-lookup", "jit-calculate"]
cls._ufunc_modes = ["jit-lookup", "jit-calculate", "python-calculate"]
else:
cls._default_ufunc_mode = "jit-calculate"
cls._ufunc_modes = ["jit-lookup", "jit-calculate"]
cls._ufunc_modes = ["jit-lookup", "jit-calculate", "python-calculate"]
cls._ufunc_mode = None # This is set in the first call to compile

cls._name = "Undefined" # Needs overridden
Expand Down
2 changes: 2 additions & 0 deletions src/galois/_domains/_ufunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,8 @@ def __call__(self, ufunc, method, inputs, kwargs, meta):
inputs = list(inputs) + [int(self.field.primitive_element)]
inputs, kwargs = self._view_inputs_as_ndarray(inputs, kwargs)
output = getattr(self.ufunc, method)(*inputs, **kwargs)
if output.dtype == np.object_:
output = output.astype(int)
return output


Expand Down
7 changes: 5 additions & 2 deletions src/galois/_fields/_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,9 +510,10 @@ def compile(cls, mode: Literal["auto", "jit-lookup", "jit-calculate", "python-ca
- `"jit-calculate"`: JIT compiles arithmetic ufuncs to use explicit calculation. The `"jit-calculate"`
mode is designed for large fields that cannot or should not store lookup tables in RAM. Generally,
the `"jit-calculate"` mode is slower than `"jit-lookup"`.
- `"python-calculate"`: Uses pure-Python ufuncs with explicit calculation. This is reserved for fields
- `"python-calculate"`: Uses pure-Python ufuncs with explicit calculation. This is intended for fields
whose elements cannot be represented with :obj:`numpy.int64` and instead use :obj:`numpy.object_`
with Python :obj:`int` (which has arbitrary precision).
with Python :obj:`int` (which has arbitrary precision). However, this mode can be used for any
field, enabling the code to run without Numba JIT compilation.

Group:
Arithmetic compilation
Expand Down Expand Up @@ -1730,6 +1731,8 @@ def log(self, base: ElementLike | ArrayLike | None = None) -> int | np.ndarray:

if np.isscalar(output):
output = int(output)
if output.dtype == np.object_:
output = output.astype(int)

return output

Expand Down
7 changes: 4 additions & 3 deletions src/galois/_fields/_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,10 @@ def GF(
- `"jit-calculate"`: JIT compiles arithmetic ufuncs to use explicit calculation. The `"jit-calculate"`
mode is designed for large fields that cannot or should not store lookup tables in RAM. Generally, the
`"jit-calculate"` mode is slower than `"jit-lookup"`.
- `"python-calculate"`: Uses pure-Python ufuncs with explicit calculation. This is reserved for fields
whose elements cannot be represented with :obj:`numpy.int64` and instead use :obj:`numpy.object_` with
Python :obj:`int` (which has arbitrary precision).
- `"python-calculate"`: Uses pure-Python ufuncs with explicit calculation. This is intended for fields
whose elements cannot be represented with :obj:`numpy.int64` and instead use :obj:`numpy.object_`
with Python :obj:`int` (which has arbitrary precision). However, this mode can be used for any
field, enabling the code to run without Numba JIT compilation.

repr: The field element representation. This can be modified after class construction with the
:func:`~galois.FieldArray.repr` method. See :doc:`/basic-usage/element-representation` for a further
Expand Down
2 changes: 1 addition & 1 deletion src/galois/_fields/_gf2.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,5 @@ class factory :func:`~galois.GF`.


GF2._default_ufunc_mode = "jit-calculate"
GF2._ufunc_modes = ["jit-calculate"]
GF2._ufunc_modes = ["jit-calculate", "python-calculate"]
GF2.compile("auto")
5 changes: 4 additions & 1 deletion tests/fields/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
FIELDS_DIFF_MODES = [
# Binary field
pytest.param("GF(2)-jit-calculate"),
pytest.param("GF(2)-python-calculate"),
# Binary extension fields
pytest.param("GF(2^2)-jit-lookup"),
pytest.param("GF(2^2)-jit-calculate"),
Expand All @@ -52,8 +53,10 @@
# Prime fields
pytest.param("GF(5)-jit-lookup"),
pytest.param("GF(5)-jit-calculate"),
pytest.param("GF(5)-python-calculate"),
pytest.param("GF(7)-jit-lookup"),
pytest.param("GF(7)-jit-calculate"),
pytest.param("GF(7)-python-calculate"),
pytest.param("GF(31)-jit-lookup"),
pytest.param("GF(31)-jit-calculate"),
pytest.param("GF(3191)-jit-lookup"),
Expand All @@ -76,7 +79,7 @@ def construct_field(folder):
ufunc_mode = "auto"

if folder == "GF(2)":
GF = galois.GF2
GF = galois.GF(2, compile=ufunc_mode)

elif folder == "GF(5)":
GF = galois.GF(5, compile=ufunc_mode)
Expand Down
Loading
Loading