-
Notifications
You must be signed in to change notification settings - Fork 3
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
4 changed files
with
65 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
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
"""Test using Jax operations.""" | ||
|
||
from functools import partial | ||
|
||
import astropy.units as u | ||
import jax | ||
import pytest | ||
|
||
from jax_quantity import Quantity | ||
|
||
import coordinax as cx | ||
from coordinax._base import VECTOR_CLASSES | ||
from coordinax._utils import dataclass_items | ||
|
||
VECTOR_CLASSES_3D = [c for c in VECTOR_CLASSES if issubclass(c, cx.Abstract3DVector)] | ||
|
||
|
||
# TODO: cycle through all representations | ||
@pytest.fixture(params=VECTOR_CLASSES_3D) | ||
def q(request) -> cx.AbstractVector: | ||
"""Fixture for 3D Vectors.""" | ||
q = cx.Cartesian3DVector.constructor(Quantity([1, 2, 3], unit=u.kpc)) | ||
return q.represent_as(request.param) | ||
|
||
|
||
@partial(jax.jit, static_argnums=(1,)) | ||
def func(q: cx.AbstractVector, target: type[cx.AbstractVector]) -> cx.AbstractVector: | ||
return q.represent_as(target) | ||
|
||
|
||
@pytest.mark.parametrize("target", VECTOR_CLASSES_3D) | ||
def test_jax_through_representation( | ||
q: cx.AbstractVector, target: type[cx.AbstractVector] | ||
) -> None: | ||
"""Test using Jax operations through representation.""" | ||
newq = func(q, target) | ||
|
||
assert isinstance(newq, cx.AbstractVector) | ||
for k, f in dataclass_items(newq): | ||
assert isinstance(f, Quantity), k |