Download src/tests/test_exact_pairwise.py from CIIL/Anuvani-Diarization: direct link, hf CLI and curl.
- Browser
- Download file 1.86 kB
-
https://huggingface.co/CIIL/Anuvani-Diarization/resolve/main/src/tests/test_exact_pairwise.py
- Command line
-
hf download hf://CIIL/Anuvani-Diarization/src/tests/test_exact_pairwise.py
-
curl -L -o test_exact_pairwise.py https://huggingface.co/CIIL/Anuvani-Diarization/resolve/main/src/tests/test_exact_pairwise.py
1.86 kB
| # Copyright (c) 2026 The Anuvani-Diarization authors | |
| # SPDX-License-Identifier: MIT OR Apache-2.0 | |
| """numpy add-reduction (pairwise summation) vs diar_exact::pairwise, bitwise.""" | |
| import numpy as np | |
| from hypothesis import given, strategies as st | |
| from hypothesis.extra import numpy as hnp | |
| from conftest import bits_equal | |
| finite64 = st.floats(allow_nan=False, allow_infinity=False, width=64) | |
| any64 = st.floats(width=64) | |
| finite32 = st.floats(allow_nan=False, allow_infinity=False, width=32) | |
| def test_sum_f64_any(core, x): | |
| assert bits_equal(np.float64(core.sum_f64(x)), np.add.reduce(x)) | |
| def test_sum_f32(core, x): | |
| assert bits_equal(np.float32(core.sum_f32(x)), np.add.reduce(x)) | |
| def test_lengths_around_block_edges(core): | |
| rng = np.random.default_rng(0) | |
| for n in list(range(0, 300)) + [511, 512, 513, 1023, 1024, 1025, 4097, 8191, 8192, 8193, 70000]: | |
| for scale in (1.0, 1e-30, 1e30): | |
| x = (rng.standard_normal(n) * scale).astype(np.float64) | |
| assert bits_equal(np.float64(core.sum_f64(x)), np.add.reduce(x)), n | |
| y = x.astype(np.float32) | |
| assert bits_equal(np.float32(core.sum_f32(y)), np.add.reduce(y)), n | |
| def test_signed_zeros(core): | |
| for x in ([-0.0], [-0.0, -0.0], [-0.0] * 9, [-0.0] * 200, []): | |
| a = np.array(x, dtype=np.float64) | |
| assert bits_equal(np.float64(core.sum_f64(a)), np.add.reduce(a)) | |
| def test_sum_axes_f32(core, x): | |
| r1, r0 = core.sum_axes_f32(np.ascontiguousarray(x)) | |
| assert bits_equal(np.array(r1, dtype=np.float32), x.sum(axis=1)) | |
| assert bits_equal(np.array(r0, dtype=np.float32), x.sum(axis=0)) | |