-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[New] Added test for extensions.c file.
- Loading branch information
1 parent
e57ec4e
commit a26d69f
Showing
1 changed file
with
44 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from unittest import TestCase, main | ||
|
||
import numpy as np | ||
|
||
from powerfit._extensions import rotate_grid3d | ||
|
||
|
||
class TestExtensions(TestCase): | ||
|
||
def test_rotate_grid3d(self): | ||
|
||
grid = np.zeros((4, 5, 6), dtype=np.float64) | ||
grid[0, 0, 0] = 1 | ||
grid[0, 0, 1] = 1 | ||
grid[0, 1, 1] = 1 | ||
grid[0, 0, 2] = 1 | ||
grid[0, 0, -1] = 1 | ||
grid[-1, 0, 0] = 1 | ||
# Identity rotation | ||
rotmat = np.asarray([[1, 0, 0], [0, 1, 0], [0, 0, 1]], dtype=np.float64) | ||
out = np.zeros_like(grid) | ||
rotate_grid3d(grid, rotmat, 2, out, True) | ||
self.assertTrue(np.allclose(out, grid)) | ||
|
||
# 90 degree rotation around Z-axis | ||
out.fill(0) | ||
rotmat = np.asarray([[0, -1, 0], [1, 0, 0], [0, 0, 1]], dtype=np.float64) | ||
rotate_grid3d(grid, rotmat, 2, out, False) | ||
# Build answer | ||
answer = np.zeros_like(out) | ||
answer[0, 0, 0] = 1 | ||
answer[0, 1, 0] = 1 | ||
answer[0, 1, -1] = 1 | ||
answer[0, 2, 0] = 1 | ||
answer[0, -1, 0] = 1 | ||
answer[-1, 0, 0] = 1 | ||
print grid | ||
print out | ||
self.assertTrue(np.allclose(answer, out)) | ||
|
||
|
||
|
||
if __name__ == '__main__': | ||
main() |