Download analysis/code/shared/test_fixed_point.py from ekwan16/MagNET: direct link, hf CLI and curl.
- Browser
- Download file 1.17 kB
-
https://huggingface.co/ekwan16/MagNET/resolve/fe222d1894afb2d954fe8d2e67e70731a006c8d2/analysis/code/shared/test_fixed_point.py
- Command line
-
hf download hf://ekwan16/MagNET@fe222d1894afb2d954fe8d2e67e70731a006c8d2/analysis/code/shared/test_fixed_point.py
-
curl -L -o test_fixed_point.py https://huggingface.co/ekwan16/MagNET/resolve/fe222d1894afb2d954fe8d2e67e70731a006c8d2/analysis/code/shared/test_fixed_point.py
1.17 kB
| import os | |
| import sys | |
| import numpy as np | |
| HERE = os.path.dirname(os.path.abspath(__file__)) | |
| sys.path.insert(0, HERE) | |
| import fixed_point as F # noqa: E402 | |
| def test_decode_int32_with_missing_marker(): | |
| values = np.array([10000, -2147483648, 25000], dtype=np.int32) | |
| out = F.decode_fixed_point(values) | |
| assert out[0] == 1.0 | |
| assert np.isnan(out[1]) | |
| assert out[2] == 2.5 | |
| def test_decode_int64_also_works(): | |
| # leveling_effect's existing test feeds int64, not just int32 -- the shared decoder must accept | |
| # any integer dtype, not just int32. | |
| values = np.array([10000, -2147483648, 25000], dtype=np.int64) | |
| out = F.decode_fixed_point(values) | |
| assert out[0] == 1.0 | |
| assert np.isnan(out[1]) | |
| assert out[2] == 2.5 | |
| def test_float_input_passes_through(): | |
| values = np.array([1.0, 2.5, float("nan")]) | |
| out = F.decode_fixed_point(values) | |
| assert out[0] == 1.0 | |
| assert out[1] == 2.5 | |
| assert np.isnan(out[2]) | |
| def test_custom_scale_and_marker(): | |
| values = np.array([100, -1], dtype=np.int32) | |
| out = F.decode_fixed_point(values, scale=100.0, missing_marker=-1) | |
| assert out[0] == 1.0 | |
| assert np.isnan(out[1]) | |