-
Notifications
You must be signed in to change notification settings - Fork 11
ENH: Free-threading support #330
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,14 @@ | |
from __future__ import annotations | ||
|
||
from enum import Enum | ||
from typing import Any | ||
|
||
__all__ = ["Backend"] | ||
import numpy as np | ||
import pytest | ||
|
||
__all__ = ["NUMPY_VERSION", "Backend"] | ||
|
||
NUMPY_VERSION = tuple(int(v) for v in np.__version__.split(".")[:3]) # pyright: ignore[reportUnknownArgumentType] | ||
|
||
|
||
class Backend(Enum): # numpydoc ignore=PR02 | ||
|
@@ -30,12 +36,6 @@ class Backend(Enum): # numpydoc ignore=PR02 | |
JAX = "jax.numpy" | ||
JAX_GPU = "jax.numpy:gpu" | ||
|
||
def __str__(self) -> str: # type: ignore[explicit-override] # pyright: ignore[reportImplicitOverride] # numpydoc ignore=RT01 | ||
"""Pretty-print parameterized test names.""" | ||
return ( | ||
self.name.lower().replace("_gpu", ":gpu").replace("_readonly", ":readonly") | ||
) | ||
|
||
@property | ||
def modname(self) -> str: # numpydoc ignore=RT01 | ||
"""Module name to be imported.""" | ||
|
@@ -44,3 +44,29 @@ def modname(self) -> str: # numpydoc ignore=RT01 | |
def like(self, *others: Backend) -> bool: # numpydoc ignore=PR01,RT01 | ||
"""Check if this backend uses the same module as others.""" | ||
return any(self.modname == other.modname for other in others) | ||
|
||
def pytest_param(self) -> Any: # type: ignore[explicit-any] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pytest.mark.ParameterSet is not exported |
||
""" | ||
Backend as a pytest parameter | ||
|
||
Returns | ||
------- | ||
pytest.mark.ParameterSet | ||
""" | ||
id_ = ( | ||
self.name.lower().replace("_gpu", ":gpu").replace("_readonly", ":readonly") | ||
) | ||
|
||
marks = [] | ||
if self.like(Backend.ARRAY_API_STRICT): | ||
marks.append( | ||
pytest.mark.skipif( | ||
NUMPY_VERSION < (1, 26), | ||
reason="array_api_strict is untested on NumPy <1.26", | ||
) | ||
) | ||
if self.like(Backend.DASK, Backend.JAX): | ||
# Monkey-patched by lazy_xp_function | ||
marks.append(pytest.mark.thread_unsafe) | ||
|
||
return pytest.param(self, id=id_, marks=marks) # pyright: ignore[reportUnknownArgumentType] |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would appreciate a second review from someone for the changes in this file. All looks fine to me from a non-expert perspective, though. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The whole library has 1 stateful class,
at
, which has trivial state. So no point adding tests beyond those ofpytest-run-parallel
.Where we are thread-unsafe, in
lazy_xp_function
, it is clearly documented, so I believe this should qualify for the Stable badge?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ngoldbaum perhaps you could confirm?