-
Notifications
You must be signed in to change notification settings - Fork 2
feat: Add GPU-accelerated operations via PyTorch #13
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 all commits
989ee57
20d29bf
6364c26
27c2394
58d4f56
897d642
6c74bfc
ab2d784
1af224e
ea628b2
5070944
6d0a9eb
f631653
a5ab654
d7cf017
66fd2e9
876d400
5fd466f
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 |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| """Unit tests for GPU block_reduce.""" | ||
|
|
||
| import numpy as np | ||
| import pytest | ||
| import sys | ||
| from skimage.measure import block_reduce as skimage_block_reduce | ||
|
|
||
| sys.path.insert(0, "src") | ||
|
|
||
| from tilefusion.utils import block_reduce | ||
|
|
||
|
|
||
| class TestBlockReduce: | ||
| """Test block_reduce GPU vs CPU equivalence.""" | ||
|
|
||
| def test_2d_basic(self, rng): | ||
| """Test 2D block reduce matches skimage.""" | ||
| arr = rng.random((256, 256)).astype(np.float32) | ||
|
||
| block_size = (4, 4) | ||
|
|
||
| result = block_reduce(arr, block_size, np.mean) | ||
| expected = skimage_block_reduce(arr, block_size, np.mean) | ||
|
|
||
| np.testing.assert_allclose(result, expected, rtol=1e-5) | ||
|
|
||
| def test_2d_large(self, rng): | ||
| """Test larger 2D array.""" | ||
| arr = rng.random((1024, 1024)).astype(np.float32) | ||
| block_size = (8, 8) | ||
|
|
||
| result = block_reduce(arr, block_size, np.mean) | ||
| expected = skimage_block_reduce(arr, block_size, np.mean) | ||
|
|
||
| np.testing.assert_allclose(result, expected, rtol=1e-5) | ||
|
|
||
| def test_3d_multichannel(self, rng): | ||
| """Test 3D array with channel dimension.""" | ||
| arr = rng.random((3, 256, 256)).astype(np.float32) | ||
| block_size = (1, 4, 4) | ||
|
|
||
| result = block_reduce(arr, block_size, np.mean) | ||
| expected = skimage_block_reduce(arr, block_size, np.mean) | ||
|
|
||
| np.testing.assert_allclose(result, expected, rtol=1e-5) | ||
|
|
||
| def test_output_shape(self, rng): | ||
| """Test output shape is correct.""" | ||
| arr = rng.random((512, 512)).astype(np.float32) | ||
| block_size = (4, 4) | ||
|
|
||
| result = block_reduce(arr, block_size, np.mean) | ||
|
|
||
| assert result.shape == (128, 128) | ||
|
|
||
| def test_non_divisible_shape(self, rng): | ||
| """Test block reduce with non-divisible dimensions.""" | ||
| arr = rng.random((100, 100)).astype(np.float32) | ||
| block_size = (8, 8) | ||
|
|
||
| result = block_reduce(arr, block_size, np.mean) | ||
| expected = skimage_block_reduce(arr, block_size, np.mean) | ||
|
|
||
| np.testing.assert_allclose(result, expected, rtol=1e-5) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| pytest.main([__file__, "-v"]) | ||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,136 @@ | ||||||||
| """Tests for CPU fallback paths and dtype preservation.""" | ||||||||
|
|
||||||||
| import numpy as np | ||||||||
| import pytest | ||||||||
| import sys | ||||||||
|
|
||||||||
| sys.path.insert(0, "src") | ||||||||
|
|
||||||||
|
Comment on lines
+5
to
+8
|
||||||||
| import sys | |
| sys.path.insert(0, "src") |
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.
[Claude Code] Skipped - sys.path modification is a common pattern for testing src layout projects during development.
Copilot
AI
Jan 4, 2026
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 test uses rng.random() without specifying dtype, which defaults to float64, but then casts to float32. This is inefficient and could be simplified to rng.random((128, 128), dtype=np.float32) directly. The same pattern appears throughout this test file on multiple lines (23, 32, 40, 49, 56, 70, 78, 86, 87).
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.
[Claude Code] Skipped - low value change. The cast to float32 is explicit and doesn't affect test correctness.
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,102 @@ | ||||||||
| """Unit tests for GPU phase_cross_correlation (FFT).""" | ||||||||
|
|
||||||||
| import numpy as np | ||||||||
| import pytest | ||||||||
| import sys | ||||||||
|
|
||||||||
| sys.path.insert(0, "src") | ||||||||
|
|
||||||||
|
Comment on lines
+5
to
+8
|
||||||||
| import sys | |
| sys.path.insert(0, "src") |
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.
[Claude Code] Skipped - sys.path modification is a common pattern for testing src layout projects during development.
Copilot
AI
Jan 4, 2026
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 test uses rng.random() without specifying dtype, which defaults to float64, but then casts to float32. This is inefficient and could be simplified to rng.random((256, 256), dtype=np.float32) directly. The same pattern appears throughout this test file on multiple lines (18, 33, 42, 60, 82).
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.
[Claude Code] Skipped - low value change. The cast to float32 is explicit and doesn't affect test correctness.
Copilot
AI
Jan 5, 2026
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 test suite lacks tests for error conditions such as mismatched image shapes for phase_cross_correlation and compute_ssim. While the implementation doesn't currently validate shapes, adding negative tests would document expected behavior when invalid inputs are provided. Consider adding tests that verify the functions handle or reject mismatched shapes appropriately.
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.
[Claude Code] Skipped - negative tests for error conditions are nice-to-have but not critical for this PR.
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,64 @@ | ||||||||
| """Unit tests for GPU histogram matching.""" | ||||||||
|
|
||||||||
| import numpy as np | ||||||||
| import pytest | ||||||||
| import sys | ||||||||
|
|
||||||||
| sys.path.insert(0, "src") | ||||||||
|
|
||||||||
|
Comment on lines
+5
to
+8
|
||||||||
| import sys | |
| sys.path.insert(0, "src") |
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.
[Claude Code] Skipped - sys.path modification is a common pattern for testing src layout projects during development.
Copilot
AI
Jan 4, 2026
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 test uses rng.random() without specifying dtype, which defaults to float64, but then casts to float32. This is inefficient and could be simplified to rng.random((256, 256), dtype=np.float32) directly. The same pattern appears throughout this test file on multiple lines (18-19, 27-28, 40, 46-47, 53-54).
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.
[Claude Code] Skipped - low value change. The cast to float32 is explicit and doesn't affect test correctness.
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 test imports are not using the installed package but instead modifying sys.path to import from 'src'. This is inconsistent with test_utils.py which imports directly from tilefusion.utils. For consistency and to test the actual installed package, consider using the same import pattern as test_utils.py or ensure the package is installed in editable mode for testing.
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.
[Claude Code] Skipped - sys.path modification is a common pattern for testing src layout projects during development.