Skip to content

Commit

Permalink
Guard hitlet entropy test from numerical errors (#772)
Browse files Browse the repository at this point in the history
* Guard hitlet entropy test from numerical errors

Avoid waveforms for which normalization is not reliable in float32

* Restore NaN assert for zero waveforms

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: Dacheng Xu <dx2227@columbia.edu>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people committed Nov 14, 2023
1 parent c88daf8 commit a9d4ebb
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion tests/test_hitlet.py
Expand Up @@ -464,7 +464,16 @@ def test_conditional_entropy(data, size_template_and_ind_max_template):

# Test 1.: Flat template and no data:
e1 = strax.conditional_entropy(hitlet, "flat")[0]
if np.sum(data):

sum_data = np.sum(data)
if sum_data:
if np.abs(sum_data) < 1e-4 * np.ptp(data):
# Normalizing may cause significant float32 numerical errors.
# Do not run any tests: this data is unsuitable for testing since
# slight numpy <-> numba implementation differences could cause
# failures that are actually harmless.
return

d = data
d = d / np.sum(d)
m = d > 0
Expand Down

0 comments on commit a9d4ebb

Please sign in to comment.