math test updated

This commit is contained in:
Nicolas 2025-11-07 16:01:33 +01:00
parent b2a9e8cf9e
commit 1441dd56bc
1 changed files with 12 additions and 9 deletions

View File

@ -101,14 +101,14 @@ def test_trig_precision():
def test_arcus_trig_precision():
test_vals = [0.0, 0.01, 0.1, 0.5, 0.7, 0.9, 0.95,
-0.01, -0.1, -0.5, -0.7, -0.9, 0.95]
test_vals = [0.0, 0.0001, 0.1, 0.5, -0.7, 0.9, 0.95, 1.0,
-0.0001, -0.1, -0.5, -0.7, -0.9, -0.95, -1.0]
ret_test = [r for v in test_vals for r in (cp.asin(variable(v)),
cp.acos(variable(v)),
cp.atan(variable(v)),
cp.atan2(variable(v), variable(0.7)),
cp.atan2(variable(v), variable(-0.2)))]
cp.atan2(variable(ma.cos(v)), variable(-0.2)))]
ret_refe = [r for v in test_vals for r in (ma.asin(v),
ma.acos(v),
ma.atan(v),
@ -118,16 +118,21 @@ def test_arcus_trig_precision():
tg = Target()
tg.compile(ret_test)
tg.run()
#flag = False
for i, (test, ref) in enumerate(zip(ret_test, ret_refe)):
func_name = ['asin', 'acos', 'atan', 'atan2[1]', 'atan2[2]'][i % 5]
assert isinstance(test, cp.variable)
val = tg.read_value(test)
print(f"+ Result of {func_name}: {val}; reference: {ref}")
#assert val == pytest.approx(ref, abs=1e-5), f"Result of {func_name} for input {test_vals[i // 5]} does not match: {val} and reference: {ref}" # pyright: ignore[reportUnknownMemberType]
if not val == pytest.approx(ref, abs=1e-5): # pyright: ignore[reportUnknownMemberType]
if not val == pytest.approx(ref, abs=1e-2): # pyright: ignore[reportUnknownMemberType]
warnings.warn(f"Result of {func_name} for input {test_vals[i // 5]} does not match: {val} and reference: {ref}", UserWarning)
#print(f"F Result of {func_name} is {val} (ref: {ref}) for x={test_vals[i // 5]}")
#flag = True
#else:
# print(f"+ Result of {func_name} is {val} (ref: {ref}) for x={test_vals[i // 5]}")
#assert not flag, "Error"
def test_sqrt_precision():
@ -153,10 +158,8 @@ def test_log_exp_precision():
test_vals = [0.1, 0.5, 0.9, 0.999, 1.0, 8.8, 12.0
-0.1, -0.5, -0.9, -0.999, -1.0, 8.8, 12.0]
ret_test = [r for v in test_vals for r in (cp.log(variable(abs(v))),
cp.exp(variable(v)))]
ret_refe = [r for v in test_vals for r in (ma.log(abs(v)),
ma.exp(v))]
ret_test = [r for v in test_vals for r in (cp.log(variable(ma.exp(v))), cp.exp(variable(v)))]
ret_refe = [r for v in test_vals for r in (v, ma.exp(v))]
tg = Target()
tg.compile(ret_test)