-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from saudzahirr/Fix-unittest
Update unittest
- Loading branch information
Showing
11 changed files
with
175 additions
and
36 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
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,23 @@ | ||
import unittest | ||
import numpy as np | ||
from vonmises import eigen | ||
|
||
test_array = np.array( | ||
[ | ||
[10.0, -1.0, 2.0, 0.0], | ||
[-1.0, 11.0, -1.0, 3.0], | ||
[2.0, -1.0, 10.0, -1.0], | ||
[0.0, 3.0, -1.0, 8.0], | ||
] | ||
) | ||
|
||
|
||
class TestCompareEigenvalues(unittest.TestCase): | ||
def test_compare_eigenvalues(self): | ||
eigenvalues = eigen.eigenvalues(test_array) | ||
ref_eigenvalues = np.linalg.eigvals(test_array) | ||
self.assertTrue(np.allclose(eigenvalues, ref_eigenvalues, atol=1e-7)) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
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,35 @@ | ||
import unittest | ||
import numpy as np | ||
import numpy.testing as npt | ||
from vonmises import eigen | ||
|
||
test_matrix = np.array( | ||
[ | ||
[10.0, -1.0, 2.0, 0.0], | ||
[-1.0, 11.0, -1.0, 3.0], | ||
[2.0, -1.0, 10.0, -1.0], | ||
[0.0, 3.0, -1.0, 8.0], | ||
] | ||
) | ||
|
||
|
||
class TestEigenvalues(unittest.TestCase): | ||
def test_eigenvalues_and_eigenvectors(self): | ||
eigenvalues, eigenvectors = eigen.eigen(test_matrix) | ||
self.verify_eigen(test_matrix, eigenvalues, eigenvectors) | ||
|
||
def verify_eigen(self, matrix, eigenvalues, eigenvectors): | ||
for i in range(len(eigenvalues)): | ||
v = eigenvectors[:, i] | ||
c = eigenvalues[i] | ||
|
||
Av = np.dot(matrix, v) | ||
cv = c * v | ||
residual = np.linalg.norm(Av - cv) | ||
|
||
npt.assert_allclose(Av, cv, atol=1e-6) | ||
self.assertAlmostEqual(0, residual, places=8) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
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,25 @@ | ||
import unittest | ||
import numpy as np | ||
from vonmises import eigen | ||
|
||
test_array = np.array( | ||
[ | ||
[10.0, -1.0, 2.0, 0.0], | ||
[-1.0, 11.0, -1.0, 3.0], | ||
[2.0, -1.0, 10.0, -1.0], | ||
[0.0, 3.0, -1.0, 8.0], | ||
] | ||
) | ||
test_eigenvalues = np.array( | ||
[14.073477752817423, 10.819060924370755, 8.143435247151785, 5.964026075660039] | ||
) | ||
|
||
|
||
class TestEigenvalues(unittest.TestCase): | ||
def test_eigenvalues(self): | ||
eigenvalues = eigen.eigenvalues(test_array) | ||
self.assertTrue(np.allclose(eigenvalues, test_eigenvalues, atol=1e-7)) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
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,53 @@ | ||
import unittest | ||
import numpy as np | ||
from vonmises import eigen | ||
|
||
test_array = np.array( | ||
[ | ||
[10.0, -1.0, 2.0, 0.0], | ||
[-1.0, 11.0, -1.0, 3.0], | ||
[2.0, -1.0, 10.0, -1.0], | ||
[0.0, 3.0, -1.0, 8.0], | ||
] | ||
) | ||
test_eigenvectors = np.array( | ||
[ | ||
[ | ||
-0.3934745132662989, | ||
0.6233611125319993, | ||
-0.6404299749594337, | ||
-0.21551839356810434, | ||
], | ||
[ | ||
0.680207701966034, | ||
0.4912946824964888, | ||
0.2267043001245381, | ||
-0.4945221708293822, | ||
], | ||
[ | ||
-0.4613009870624494, | ||
0.5009327057718649, | ||
0.7078520091508445, | ||
0.1876522229135619, | ||
], | ||
[ | ||
0.4119425796529732, | ||
0.3451331375304617, | ||
-0.19339115962115574, | ||
0.8208448622167394, | ||
], | ||
] | ||
) | ||
|
||
|
||
class TestEigenvectors(unittest.TestCase): | ||
def test_eigenvectors(self): | ||
eigenvectors = eigen.eigenvectors(test_array) | ||
eigenvectors_abs = np.abs(eigenvectors) | ||
test_eigenvectors_abs = np.abs(test_eigenvectors) | ||
|
||
self.assertTrue(np.allclose(eigenvectors_abs, test_eigenvectors_abs, atol=1e-7)) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
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