-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Expose sparse NNLS to Python * Add test for nnls * Bump version * ci: install scipy
- Loading branch information
1 parent
693fb40
commit 05f4b1c
Showing
5 changed files
with
205 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import unittest | ||
import numpy as np | ||
import photospline | ||
|
||
|
||
class TestNNLS(unittest.TestCase): | ||
def setUp(self): | ||
try: | ||
from scipy import sparse # type: ignore[import] | ||
except ImportError: | ||
raise unittest.SkipTest("test requires scipy") | ||
|
||
self.A = np.array([[1, 0], [1, 0], [0, 1]]) | ||
self.Asp = sparse.csc_matrix(self.A) | ||
self.b = np.array([2, 1, 1]) | ||
|
||
def testSparseIsSparse(self): | ||
self.assertEqual(len(self.Asp.data), 3) | ||
|
||
def testImplementationMatchesScipy(self): | ||
from scipy import optimize # type: ignore[import] | ||
|
||
np.testing.assert_allclose( | ||
photospline.nnls(self.Asp, self.b), | ||
optimize.nnls(self.A, self.b)[0], | ||
err_msg="sparse result does not aggree with dense", | ||
) | ||
|
||
|
||
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