Skip to content

Commit

Permalink
add num bad option to comapre with numpy
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanMarx committed Feb 6, 2025
1 parent 13267b8 commit 555f119
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def compare_against_numpy():
of the time
"""

def compare(value, expected):
def compare(value, expected, num_bad: int = 0):
sigma = 0.01
prob = 0.99999
N = np.prod(expected.shape)
Expand All @@ -28,7 +28,7 @@ def compare(value, expected):

# TODO: eventually we should track down
# and address the underlying cause
assert isclose.sum() - np.prod(isclose.shape) <= 1
assert isclose.sum() - np.prod(isclose.shape) <= num_bad

return compare

Expand Down
6 changes: 3 additions & 3 deletions tests/test_spectral.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def test_fast_spectral_density(
# that components higher than the first two are correct
torch_result = torch_result[..., 2:]
scipy_result = scipy_result[..., 2:]
compare_against_numpy(torch_result, scipy_result)
compare_against_numpy(torch_result, scipy_result, num_bad=1)

# make sure we catch any calls with too many dimensions
if ndim == 3:
Expand Down Expand Up @@ -260,7 +260,7 @@ def test_fast_spectral_density_with_y(

torch_result = torch_result[..., 2:]
scipy_result = scipy_result[..., 2:]
compare_against_numpy(torch_result, scipy_result)
compare_against_numpy(torch_result, scipy_result, num_bad=1)
_shape_checks(ndim, y_ndim, x, y, fsd)


Expand Down Expand Up @@ -322,7 +322,7 @@ def test_spectral_density(
window=signal.windows.hann(nperseg, False),
average=average,
)
compare_against_numpy(torch_result, scipy_result)
compare_against_numpy(torch_result, scipy_result, num_bad=1)

# make sure we catch any calls with too many dimensions
if ndim == 3:
Expand Down

0 comments on commit 555f119

Please sign in to comment.