-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: nstarman <[email protected]>
- Loading branch information
Showing
5 changed files
with
57 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
"""Quaxed :mod:`jax.scipy`.""" | ||
|
||
__all__ = [ | ||
"special", | ||
] | ||
__all__ = ["linalg", "special"] | ||
|
||
from . import special | ||
from . import linalg, special |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# ruff:noqa: F822 | ||
|
||
"""Quaxed :mod:`jax.scipy.linalg`.""" | ||
|
||
__all__ = [ | ||
"svd", | ||
] | ||
|
||
import sys | ||
from collections.abc import Callable | ||
from typing import Any | ||
|
||
import jax.scipy.linalg | ||
from quax import quaxify | ||
|
||
|
||
def __dir__() -> list[str]: | ||
return sorted(__all__) | ||
|
||
|
||
# TODO: better return type annotation | ||
def __getattr__(name: str) -> Callable[..., Any]: | ||
# Quaxify the func | ||
func = quaxify(getattr(jax.scipy.linalg, name)) | ||
|
||
# Cache the function in this module | ||
setattr(sys.modules[__name__], name, func) | ||
|
||
return func |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Test `quaxed.numpy`.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
"""Test with JAX inputs.""" | ||
|
||
import jax | ||
import jax.numpy as jnp | ||
|
||
import quaxed | ||
|
||
|
||
def test_dir(): | ||
"""Test the `__dir__` method.""" | ||
assert quaxed.scipy.linalg.__dir__() == quaxed.scipy.linalg.__all__ | ||
|
||
|
||
def test_svd(): | ||
"""Test `quaxed.scipy.linalg.svd`.""" | ||
assert hasattr(jax.scipy.linalg, "svd") | ||
assert hasattr(quaxed.scipy.linalg, "svd") | ||
|
||
x = jnp.array([[1, 2], [3, 4]]) | ||
got = quaxed.scipy.linalg.svd(x, compute_uv=False) | ||
expected = jax.scipy.linalg.svd(x, compute_uv=False) | ||
|
||
assert jnp.array_equal(got, expected) |