Skip to content
This repository was archived by the owner on Oct 24, 2025. It is now read-only.
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
33 changes: 7 additions & 26 deletions .github/workflows/build-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.10"
python-version: "3.13"
cache: "pip"
cache-dependency-path: pyproject.toml
- name: Test pre-commit hooks
Expand All @@ -36,7 +36,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.10"
python-version: "3.13"
cache: "pip"
cache-dependency-path: pyproject.toml

Expand All @@ -49,46 +49,27 @@ jobs:
run: |
darglint src --strictness=short --ignore-raise=ValueError

tests-jax-latest:
tests:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v5

- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.10"
cache: "pip"
cache-dependency-path: pyproject.toml
strategy:
matrix:
python-version: ["3.10", "3.13"]

- name: Setup environment
run: |
python -m pip install --upgrade pip
pip install ".[tests,dev]"

- name: Run Python tests
run: |
pytest --cov=totypes tests

tests-jax-0_4_31:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v5

- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.10"
python-version: ${{ matrix.python-version }}
cache: "pip"
cache-dependency-path: pyproject.toml

- name: Setup environment
run: |
python -m pip install --upgrade pip
pip install ".[tests,dev]"
pip install --upgrade "jax==0.4.31"

- name: Run Python tests
run: |
Expand Down
18 changes: 16 additions & 2 deletions tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@


class BoundedArrayTest(unittest.TestCase):
def assertBoundedArraysEqual(self, a, b):
onp.testing.assert_array_equal(a.array, b.array)
onp.testing.assert_array_equal(a.lower_bound, b.lower_bound)
onp.testing.assert_array_equal(a.upper_bound, b.upper_bound)

@parameterized.expand([[(1, 5, 4, 3)], [(5, 1, 2)]])
def test_lower_bound_shape_validation(self, invalid_bound_shape):
with self.assertRaisesRegex(
Expand Down Expand Up @@ -46,10 +51,19 @@ def test_flatten_unflatten_single_array_jax(self):
)
leaves, treedef = jax.tree_util.tree_flatten(ba)
restored_ba = jax.tree_util.tree_unflatten(treedef, leaves)
onp.testing.assert_array_equal(ba, restored_ba)
self.assertBoundedArraysEqual(ba, restored_ba)


class Density2DArrayTest(unittest.TestCase):
def assertDensitiesEqual(self, a, b):
onp.testing.assert_array_equal(a.array, b.array)
onp.testing.assert_array_equal(a.fixed_solid, b.fixed_solid)
onp.testing.assert_array_equal(a.fixed_void, b.fixed_void)
self.assertEqual(a.minimum_width, b.minimum_width)
self.assertEqual(a.minimum_spacing, b.minimum_spacing)
self.assertEqual(a.periodic, b.periodic)
self.assertEqual(a.symmetries, b.symmetries)

def test_density_ndim_validation(self):
with self.assertRaisesRegex(ValueError, "`array` must be at least rank-2,"):
types.Density2DArray(
Expand Down Expand Up @@ -180,7 +194,7 @@ def test_flatten_unflatten_single_density(self):
)
leaves, treedef = jax.tree_util.tree_flatten(density)
restored_density = jax.tree_util.tree_unflatten(treedef, leaves)
onp.testing.assert_array_equal(density, restored_density)
self.assertDensitiesEqual(density, restored_density)

def test_broadcast_fixed_pixels(self):
density = types.Density2DArray(
Expand Down