Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: Remove floating point equality assertions #2539

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions tests/test_symbolics.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from ctypes import c_void_p

import math
import sympy
import pytest
import numpy as np
Expand Down Expand Up @@ -620,8 +621,8 @@ def test_minmax_precision(dtype, expected):
# Check generated code -- ensure it's using the fp64 versions of min/max,
# that is fminf/fmaxf
assert all(i in str(op) for i in expected)

assert np.all(f.data == 6.0)
tolerance = 1e-8 if dtype is np.float32 else 1e-16
assert np.allclose(f.data, 6.0, rtol=tolerance)


@pytest.mark.parametrize('dtype,expected', [
Expand All @@ -643,7 +644,8 @@ def test_pow_precision(dtype, expected):
op.apply()

assert expected in str(op)
assert np.all(f.data == 8.0)
tolerance = 1e-8 if dtype is np.float32 else 1e-16
assert np.allclose(f.data, 8.0, rtol=tolerance)


@pytest.mark.parametrize('dtype,expected', [
Expand All @@ -665,7 +667,8 @@ def test_abs_precision(dtype, expected):
op.apply()

assert expected in str(op)
assert np.all(f.data == 1.0)
tolerance = 1e-8 if dtype is np.float32 else 1e-16
assert np.allclose(f.data, 1.0, rtol=tolerance)


class TestRelationsWithAssumptions:
Expand Down Expand Up @@ -705,7 +708,7 @@ def test_multibounds_op(self):
op.apply(time_M=5)
fnorm2 = norm(f)

assert fnorm == fnorm2
assert math.isclose(fnorm, fnorm2, rel_tol=1e-8)

@pytest.mark.parametrize('op, expr, assumptions, expected', [
([min, '[a, b, c, d]', '[]', 'Min(a, Min(b, Min(c, d)))']),
Expand Down
Loading