-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Nathaniel Starkman <nstarman@users.noreply.github.com>
- Loading branch information
1 parent
5e85c6a
commit b89ded5
Showing
6 changed files
with
181 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
"""Benchmark tests for quaxified jax.""" | ||
|
||
import jax | ||
import pytest | ||
|
||
import unxt as u | ||
|
||
LENGTH = u.dimension("length") | ||
|
||
|
||
@pytest.fixture | ||
def func_dimension_is_length(): | ||
return lambda x: u.dimension(x) == LENGTH | ||
|
||
|
||
@pytest.fixture | ||
def func_dimension_of_length(): | ||
return lambda x: u.dimension_of(x) == LENGTH | ||
|
||
|
||
##################################################################### | ||
# `dimension` | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"args", | ||
[ | ||
(u.dimension("length"),), # -> Dimension('length') | ||
("length",), # -> Dimension('length') | ||
], | ||
) | ||
@pytest.mark.benchmark(group="dimensions", warmup=False) | ||
def test_dimension(args): | ||
"""Test calling `unxt.dimension`.""" | ||
_ = u.dimension(*args) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"args", | ||
[ | ||
(u.dimension("length"),), # -> Dimension('length') | ||
("length",), # -> Dimension('length') | ||
], | ||
) | ||
@pytest.mark.benchmark(group="dimensions", warmup=True) | ||
def test_dimension_execute(func_dimension_is_length, args): | ||
"""Test the speed of calling the function.""" | ||
_ = jax.block_until_ready(func_dimension_is_length(*args)) | ||
|
||
|
||
##################################################################### | ||
# `dimension_of` | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"args", | ||
[ | ||
(u.dimension("length"),), # -> Dimension('length') | ||
(u.unit("m"),), # -> Dimension('length') | ||
(u.Quantity(1, "m"),), # -> Dimension('length') | ||
(2,), # -> None | ||
], | ||
) | ||
@pytest.mark.benchmark(group="dimensions", warmup=False) | ||
def test_dimension_of(args): | ||
"""Test calling `unxt.dimension_of`.""" | ||
_ = u.dimension_of(*args) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"args", | ||
[ | ||
(u.Quantity(1, "m"),), # -> Dimension('length') | ||
], | ||
) | ||
@pytest.mark.benchmark(group="dimensions", warmup=False) | ||
def test_dimension_of_jit_compile(func_dimension_of_length, args): | ||
"""Test the speed of jitting.""" | ||
_ = jax.jit(func_dimension_of_length).lower(*args).compile() | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"args", | ||
[ | ||
(u.dimension("length"),), # -> Dimension('length') | ||
(u.unit("m"),), # -> Dimension('length') | ||
(u.Quantity(1, "m"),), # -> Dimension('length') | ||
(2,), # -> None | ||
], | ||
) | ||
@pytest.mark.benchmark(group="dimensions", warmup=True) | ||
def test_dimension_of_execute(func_dimension_of_length, args): | ||
"""Test the speed of calling the function.""" | ||
_ = jax.block_until_ready(func_dimension_of_length(*args)) |
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,78 @@ | ||
"""Benchmark tests for `unxt.units`.""" | ||
|
||
import jax | ||
import pytest | ||
|
||
import unxt as u | ||
|
||
METER = u.unit("m") | ||
|
||
|
||
@pytest.fixture | ||
def func_unit_is_length(): | ||
return lambda x: u.unit(x) == METER | ||
|
||
|
||
@pytest.fixture | ||
def func_unit_of_length(): | ||
return lambda x: u.unit_of(x) == METER | ||
|
||
|
||
##################################################################### | ||
# `unit` | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"args", | ||
[ | ||
(u.unit("meter"),), # -> Unit('meter') | ||
("meter",), # -> Unit('meter') | ||
], | ||
) | ||
@pytest.mark.benchmark(group="units", warmup=False) | ||
def test_unit(args): | ||
"""Test calling `unxt.unit`.""" | ||
_ = u.unit(*args) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"args", | ||
[ | ||
(u.unit("meter"),), # -> Unit('meter') | ||
("meter",), # -> Unit('meter') | ||
], | ||
) | ||
@pytest.mark.benchmark(group="units", warmup=True) | ||
def test_unit_execute(func_unit_is_length, args): | ||
"""Test the speed of calling the function.""" | ||
_ = jax.block_until_ready(func_unit_is_length(*args)) | ||
|
||
|
||
##################################################################### | ||
# `unit_of` | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"args", | ||
[ | ||
(u.unit("meter"),), # -> Unit('meter') | ||
(u.Quantity(1, "m"),), # -> Unit('meter') | ||
(2,), | ||
], | ||
) | ||
@pytest.mark.benchmark(group="units", warmup=False) | ||
def test_unit_of(args): | ||
"""Test calling `unxt.unit_of`.""" | ||
_ = u.unit_of(*args) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"args", | ||
[ | ||
(u.Quantity(1, "m"),), # -> Unit('meter') | ||
], | ||
) | ||
@pytest.mark.benchmark(group="units", warmup=False) | ||
def test_unit_of_jit_compile(func_unit_of_length, args): | ||
"""Test the speed of jitting a function.""" | ||
_ = jax.jit(func_unit_of_length).lower(*args).compile() |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.