-
Notifications
You must be signed in to change notification settings - Fork 26
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 #17 from LCAV/tests
Add unit tests, and update numpy.
- Loading branch information
Showing
9 changed files
with
119 additions
and
15 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,9 @@ | ||
Install `pytest` | ||
``` | ||
pip install pytest | ||
``` | ||
And then run | ||
``` | ||
pytest test/ | ||
``` | ||
to run all tests. |
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 numpy as np | ||
from lensless.io import load_data | ||
from lensless import GradientDescient, NesterovGradientDescent, FISTA, ADMM, APGD | ||
|
||
|
||
psf_fp = "data/psf/tape_rgb.png" | ||
data_fp = "data/raw_data/thumbs_up_rgb.png" | ||
downsample = 16 | ||
n_iter = 5 | ||
disp = None | ||
|
||
|
||
def test_algo(): | ||
for algo in [GradientDescient, NesterovGradientDescent, FISTA, ADMM, APGD]: | ||
for gray in [True, False]: | ||
for dtype in [np.float32, np.float64]: | ||
psf, data = load_data( | ||
psf_fp=psf_fp, | ||
data_fp=data_fp, | ||
downsample=downsample, | ||
plot=False, | ||
gray=gray, | ||
dtype=dtype, | ||
) | ||
recon = algo(psf, dtype=dtype) | ||
recon.set_data(data) | ||
res = recon.apply(n_iter=n_iter, disp_iter=None, plot=False) | ||
if gray: | ||
assert len(psf.shape) == 2 | ||
else: | ||
assert len(psf.shape) == 3 | ||
assert res.dtype == dtype, f"Got {res.dtype}, expected {dtype}" | ||
|
||
|
||
test_algo() |
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,29 @@ | ||
from lensless.io import load_data | ||
import numpy as np | ||
|
||
psf_fp = "data/psf/tape_rgb.png" | ||
data_fp = "data/raw_data/thumbs_up_rgb.png" | ||
downsample = 8 | ||
|
||
|
||
def test_load_data(): | ||
for gray in [True, False]: | ||
for dtype in [np.float32, np.float64]: | ||
psf, data = load_data( | ||
psf_fp=psf_fp, | ||
data_fp=data_fp, | ||
downsample=downsample, | ||
plot=False, | ||
gray=gray, | ||
dtype=dtype, | ||
) | ||
if gray: | ||
assert len(psf.shape) == 2 | ||
else: | ||
assert len(psf.shape) == 3 | ||
assert psf.shape == data.shape | ||
assert psf.dtype == dtype, dtype | ||
assert data.dtype == dtype, dtype | ||
|
||
|
||
test_load_data() |