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

[doc] Guard values with "ti.approx" in "docs/write_test.rst" to allow FP-error tolerance #1911

Merged
merged 7 commits into from
Oct 3, 2020
2 changes: 1 addition & 1 deletion docs/arithmetics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Trigonometric functions
.. function:: ti.tan(x)
.. function:: ti.asin(x)
.. function:: ti.acos(x)
.. function:: ti.atan2(x, y)
.. function:: ti.atan2(y, x)
.. function:: ti.tanh(x)

Other arithmetic functions
Expand Down
28 changes: 14 additions & 14 deletions docs/write_test.rst
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ We may test against different input values using the ``@pytest.mark.parametrize`

r[None] = x
foo()
assert r[None] == math.log10(x)
assert ti.approx(r[None]) == math.log10(x)

Use a comma-separated list for multiple input values:

Expand All @@ -164,20 +164,20 @@ Use a comma-separated list for multiple input values:
import pytest
import math

@pytest.mark.parametrize('x,y', [(1, 2), (1, 3), (2, 1)])
@pytest.mark.parametrize('y,x', [(1, 2), (1, 3), (2, 1)])
@ti.test()
def test_atan2(x, y):
def test_atan2(y, x):
r = ti.field(ti.f32, ())
s = ti.field(ti.f32, ())

@ti.kernel
def foo():
r[None] = ti.atan2(r[None])
r[None] = ti.atan2(r[None], s[None])

r[None] = x
s[None] = y
r[None] = y
s[None] = x
foo()
assert r[None] == math.atan2(x, y)
assert ti.approx(r[None]) == math.atan2(y, x)

Use two separate ``parametrize`` to test **all combinations** of input arguments:

Expand All @@ -187,22 +187,22 @@ Use two separate ``parametrize`` to test **all combinations** of input arguments
import pytest
import math

@pytest.mark.parametrize('x', [1, 2])
@pytest.mark.parametrize('y', [1, 2])
# same as: .parametrize('x,y', [(1, 1), (1, 2), (2, 1), (2, 2)])
@pytest.mark.parametrize('x', [1, 2])
# same as: .parametrize('y,x', [(1, 1), (1, 2), (2, 1), (2, 2)])
@ti.test()
def test_atan2(x, y):
def test_atan2(y, x):
r = ti.field(ti.f32, ())
s = ti.field(ti.f32, ())

@ti.kernel
def foo():
r[None] = ti.atan2(r[None])
r[None] = ti.atan2(r[None], s[None])

r[None] = x
s[None] = y
r[None] = y
s[None] = x
foo()
assert r[None] == math.atan2(x, y)
assert ti.approx(r[None]) == math.atan2(y, x)

Specifying ``ti.init`` configurations
*************************************
Expand Down