Download pywavelets/Test_PyWavelets.py from PythonSTB/pypi312: direct link, hf CLI and curl.
- Browser
- Download file 5.01 kB
-
https://huggingface.co/PythonSTB/pypi312/resolve/7d29bbe9757e514b3838e3538ff1b410882a641a/pywavelets/Test_PyWavelets.py
- Command line
-
hf download hf://PythonSTB/pypi312@7d29bbe9757e514b3838e3538ff1b410882a641a/pywavelets/Test_PyWavelets.py
-
curl -L -o Test_PyWavelets.py https://huggingface.co/PythonSTB/pypi312/resolve/7d29bbe9757e514b3838e3538ff1b410882a641a/pywavelets/Test_PyWavelets.py
5.01 kB
| """PyWavelets device test for Android Python STB. | |
| Generated by RIMI. | |
| Validates the pywavelets Android wheel (import name ``pywt``): | |
| import, version reporting, Wavelet objects, dwt/idwt + wavedec/waverec | |
| roundtrips, SWT roundtrip, 2D transforms, thresholding smoke, wavelist, | |
| and bundled data loading. | |
| Run on device (Scripts folder) AFTER installing: | |
| 1. numpy 2.5.2 Android wheel (from its own package folder), then | |
| 2. pywavelets-1.10.0-cp312-cp312-android_24_<arch>.whl (STANDALONE) | |
| Exit-code contract: prints [PASS]/[FAIL] per test, a summary line, and | |
| exits 0 only if every test passed (1 otherwise). | |
| """ | |
| import sys | |
| import traceback | |
| PASS = 0 | |
| FAIL = 0 | |
| FAILURES = [] | |
| def run(name, fn): | |
| global PASS, FAIL | |
| try: | |
| fn() | |
| except Exception as e: | |
| FAIL += 1 | |
| FAILURES.append(name) | |
| print("[FAIL] %s -- %s: %s" % (name, type(e).__name__, e)) | |
| traceback.print_exc() | |
| else: | |
| PASS += 1 | |
| print("[PASS] %s" % name) | |
| def test_import(): | |
| import pywt | |
| import numpy | |
| assert pywt is not None | |
| assert numpy is not None | |
| print(" pywt file:", pywt.__file__) | |
| print(" numpy:", numpy.__version__) | |
| def test_version(): | |
| import pywt | |
| # NOTE (upstream quirk): the 1.10.0 sdist ships util/version_utils.py | |
| # with MAJOR/MINOR/MICRO still at 1.8.0, so pywt.__version__ reports | |
| # '1.8.0' even in the official PyPI 1.10.0 wheels. Our wheel is | |
| # faithful to upstream here; the *wheel* version is 1.10.0 | |
| # (see pywavelets-1.10.0.dist-info). Only require a non-empty string. | |
| assert isinstance(pywt.__version__, str) and len(pywt.__version__) > 0 | |
| print(" pywt.__version__ =", pywt.__version__) | |
| def test_wavelet_object(): | |
| import pywt | |
| w = pywt.Wavelet("db1") | |
| assert w.name == "db1" | |
| assert w.dec_len == 2 and w.rec_len == 2 | |
| assert "haar" in pywt.wavelist(kind="discrete") or "haar" in pywt.wavelist() | |
| def test_wavelist(): | |
| import pywt | |
| wl = pywt.wavelist() | |
| for required in ("db1", "db2", "haar", "sym2"): | |
| assert required in wl, "missing wavelet %s" % required | |
| print(" %d wavelets listed" % len(wl)) | |
| def test_dwt_idwt_roundtrip(): | |
| import numpy as np | |
| import pywt | |
| x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]) | |
| cA, cD = pywt.dwt(x, "db1") | |
| y = pywt.idwt(cA, cD, "db1") | |
| assert np.allclose(x, y, atol=1e-12), "dwt/idwt roundtrip failed" | |
| def test_wavedec_waverec_roundtrip(): | |
| import numpy as np | |
| import pywt | |
| rng = np.random.RandomState(42) | |
| x = rng.randn(64) | |
| coeffs = pywt.wavedec(x, "db2", level=2) | |
| assert len(coeffs) == 3 # cA2, cD2, cD1 | |
| y = pywt.waverec(coeffs, "db2") | |
| assert np.allclose(x, y, atol=1e-10), "wavedec/waverec roundtrip failed" | |
| def test_swt_roundtrip(): | |
| import numpy as np | |
| import pywt | |
| x = np.arange(16, dtype=float) | |
| coeffs = pywt.swt(x, "haar", level=1) | |
| assert len(coeffs) == 1 | |
| cA, cD = coeffs[0] | |
| assert cA.shape == x.shape and cD.shape == x.shape | |
| y = pywt.iswt(coeffs, "haar") | |
| assert np.allclose(x, y, atol=1e-12), "swt/iswt roundtrip failed" | |
| def test_dwt2_idwt2_roundtrip(): | |
| import numpy as np | |
| import pywt | |
| x = np.arange(64, dtype=float).reshape(8, 8) | |
| coeffs = pywt.dwt2(x, "haar") | |
| cA, (cH, cV, cD) = coeffs | |
| assert cA.shape == (4, 4) | |
| y = pywt.idwt2(coeffs, "haar") | |
| assert np.allclose(x, y, atol=1e-12), "dwt2/idwt2 roundtrip failed" | |
| def test_threshold_smoke(): | |
| import numpy as np | |
| import pywt | |
| data = np.linspace(-2.0, 2.0, 32) | |
| t = pywt.threshold(data, 1.0, mode="soft") | |
| assert t.shape == data.shape | |
| assert abs(t[16]) < abs(data[16]) | |
| t_hard = pywt.threshold(data, 1.0, mode="hard") | |
| assert t_hard.shape == data.shape | |
| def test_data_camera(): | |
| import pywt | |
| arr = pywt.data.camera() | |
| assert arr.ndim == 2 and arr.shape[0] > 0 and arr.shape[1] > 0 | |
| print(" camera shape:", arr.shape) | |
| TESTS = [ | |
| ("import pywt + numpy", test_import), | |
| ("version string present", test_version), | |
| ("Wavelet object db1", test_wavelet_object), | |
| ("wavelist contents", test_wavelist), | |
| ("dwt/idwt roundtrip", test_dwt_idwt_roundtrip), | |
| ("wavedec/waverec roundtrip", test_wavedec_waverec_roundtrip), | |
| ("swt/iswt roundtrip", test_swt_roundtrip), | |
| ("dwt2/idwt2 roundtrip", test_dwt2_idwt2_roundtrip), | |
| ("threshold smoke", test_threshold_smoke), | |
| ("data.camera load", test_data_camera), | |
| ] | |
| def main(): | |
| print("PyWavelets device test (pywt) - Generated by RIMI") | |
| for name, fn in TESTS: | |
| run(name, fn) | |
| print("----------------------------------------") | |
| print("RESULT: %d passed, %d failed" % (PASS, FAIL)) | |
| if FAIL: | |
| print("FAILURES:", ", ".join(FAILURES)) | |
| return 1 | |
| print("ALL PASSED") | |
| return 0 | |
| if __name__ == "__main__": | |
| sys.exit(main()) | |