From be1d7d7f3824503b9b19e150c1839d2dbb513999 Mon Sep 17 00:00:00 2001 From: Tony <864832769@qq.com> Date: Mon, 28 Sep 2020 19:39:43 +0800 Subject: [PATCH 1/5] [doc] Use "atan2(y, x)" instead of "atan2(x, y)" (#1816) --- docs/arithmetics.rst | 2 +- docs/write_test.rst | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/arithmetics.rst b/docs/arithmetics.rst index cfdd31985eadf..79c5e9ae2cf61 100644 --- a/docs/arithmetics.rst +++ b/docs/arithmetics.rst @@ -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 diff --git a/docs/write_test.rst b/docs/write_test.rst index d7fe9250cd5da..4ca0c53d2639b 100644 --- a/docs/write_test.rst +++ b/docs/write_test.rst @@ -166,7 +166,7 @@ Use a comma-separated list for multiple input values: @pytest.mark.parametrize('x,y', [(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, ()) @@ -177,7 +177,7 @@ Use a comma-separated list for multiple input values: r[None] = x s[None] = y foo() - assert r[None] == math.atan2(x, y) + assert r[None] == math.atan2(y, x) Use two separate ``parametrize`` to test **all combinations** of input arguments: @@ -191,7 +191,7 @@ Use two separate ``parametrize`` to test **all combinations** of input arguments @pytest.mark.parametrize('y', [1, 2]) # same as: .parametrize('x,y', [(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, ()) @@ -202,7 +202,7 @@ Use two separate ``parametrize`` to test **all combinations** of input arguments r[None] = x s[None] = y foo() - assert r[None] == math.atan2(x, y) + assert r[None] == math.atan2(y, x) Specifying ``ti.init`` configurations ************************************* From 73b5d9631ac9c91ee54ed792effbbcbe48417b2a Mon Sep 17 00:00:00 2001 From: Tony <864832769@qq.com> Date: Mon, 28 Sep 2020 20:39:40 +0800 Subject: [PATCH 2/5] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 彭于斌 <1931127624@qq.com> --- docs/write_test.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/write_test.rst b/docs/write_test.rst index 4ca0c53d2639b..e0d22ab433960 100644 --- a/docs/write_test.rst +++ b/docs/write_test.rst @@ -164,7 +164,7 @@ 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(y, x): r = ti.field(ti.f32, ()) @@ -189,7 +189,7 @@ Use two separate ``parametrize`` to test **all combinations** of input arguments @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)]) + # same as: .parametrize('y,x', [(1, 1), (1, 2), (2, 1), (2, 2)]) @ti.test() def test_atan2(y, x): r = ti.field(ti.f32, ()) @@ -199,8 +199,8 @@ Use two separate ``parametrize`` to test **all combinations** of input arguments def foo(): r[None] = ti.atan2(r[None]) - r[None] = x - s[None] = y + r[None] = y + s[None] = x foo() assert r[None] == math.atan2(y, x) From 50007467a5ea1e377c88b917da21ec037f45a08b Mon Sep 17 00:00:00 2001 From: Tony <864832769@qq.com> Date: Mon, 28 Sep 2020 20:47:03 +0800 Subject: [PATCH 3/5] [doc] Use "r[None] = ti.atan2(r[None], s[None])" instead of "r[None] = ti.atan2(r[None], s[None])" in "docs/write_test.rst" --- docs/write_test.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/write_test.rst b/docs/write_test.rst index e0d22ab433960..0a3f44edf3d3d 100644 --- a/docs/write_test.rst +++ b/docs/write_test.rst @@ -172,7 +172,7 @@ Use a comma-separated list for multiple input values: @ti.kernel def foo(): - r[None] = ti.atan2(r[None]) + r[None] = ti.atan2(r[None], s[None]) r[None] = x s[None] = y @@ -197,7 +197,7 @@ Use two separate ``parametrize`` to test **all combinations** of input arguments @ti.kernel def foo(): - r[None] = ti.atan2(r[None]) + r[None] = ti.atan2(r[None], s[None]) r[None] = y s[None] = x From aab77b4aceacd97b85323a0ffbcdc51b379ed24a Mon Sep 17 00:00:00 2001 From: Tony <864832769@qq.com> Date: Mon, 28 Sep 2020 20:47:03 +0800 Subject: [PATCH 4/5] [doc] Use "r[None] = ti.atan2(r[None], s[None])" instead of "r[None] = ti.atan2(r[None])" in "docs/write_test.rst" --- docs/write_test.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/write_test.rst b/docs/write_test.rst index e0d22ab433960..0a3f44edf3d3d 100644 --- a/docs/write_test.rst +++ b/docs/write_test.rst @@ -172,7 +172,7 @@ Use a comma-separated list for multiple input values: @ti.kernel def foo(): - r[None] = ti.atan2(r[None]) + r[None] = ti.atan2(r[None], s[None]) r[None] = x s[None] = y @@ -197,7 +197,7 @@ Use two separate ``parametrize`` to test **all combinations** of input arguments @ti.kernel def foo(): - r[None] = ti.atan2(r[None]) + r[None] = ti.atan2(r[None], s[None]) r[None] = y s[None] = x From f3df8ef68e030fe59906c548e7328e099cbb554a Mon Sep 17 00:00:00 2001 From: Tony <864832769@qq.com> Date: Wed, 30 Sep 2020 20:57:27 +0800 Subject: [PATCH 5/5] [doc] Use "ti.approx(r[None])" instead of some "r[None]" in "docs/write_test.rst" to make sure the test case scripts pass the assert sentence. --- docs/write_test.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/write_test.rst b/docs/write_test.rst index 0a3f44edf3d3d..225dd0c3ba69d 100644 --- a/docs/write_test.rst +++ b/docs/write_test.rst @@ -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: @@ -174,10 +174,10 @@ Use a comma-separated list for multiple input values: def foo(): 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(y, x) + assert ti.approx(r[None]) == math.atan2(y, x) Use two separate ``parametrize`` to test **all combinations** of input arguments: @@ -187,8 +187,8 @@ 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]) + @pytest.mark.parametrize('x', [1, 2]) # same as: .parametrize('y,x', [(1, 1), (1, 2), (2, 1), (2, 2)]) @ti.test() def test_atan2(y, x): @@ -202,7 +202,7 @@ Use two separate ``parametrize`` to test **all combinations** of input arguments r[None] = y s[None] = x foo() - assert r[None] == math.atan2(y, x) + assert ti.approx(r[None]) == math.atan2(y, x) Specifying ``ti.init`` configurations *************************************