From 3d43a00f82df1ddf2fb835dcf28560a4623326b5 Mon Sep 17 00:00:00 2001 From: WangYizhang01 <1739601638@qq.com> Date: Fri, 21 May 2021 22:08:10 +0800 Subject: [PATCH 01/18] init atanh --- oneflow/python/nn/modules/math_atanh.py | 37 +++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 oneflow/python/nn/modules/math_atanh.py diff --git a/oneflow/python/nn/modules/math_atanh.py b/oneflow/python/nn/modules/math_atanh.py new file mode 100644 index 00000000000..ae47150e0d8 --- /dev/null +++ b/oneflow/python/nn/modules/math_atanh.py @@ -0,0 +1,37 @@ +class Ceil(Module): + def __init__(self) -> None: + super().__init__() + self._op = flow.builtin_op("ceil").Input("x").Output("y").Build() + + def forward(self, x): + return self._op(x)[0] + + + +@oneflow_export("ceil") +@register_tensor_op("ceil") +@experimental_api +def ceil_op(x): + r"""ceil(input, out=None) -> Tensor + + Returns a new tensor with the ceil of the elements of :attr:`input`, + the smallest integer greater than or equal to each element. + + .. math:: + \text{out}_{i} = \left\lceil \text{input}_{i} \right\rceil = \left\lfloor \text{input}_{i} \right\rfloor + 1 + + Args: + input (Tensor): the input tensor. + out (Tensor, optional): the output tensor. + + Example:: + + >>> a = torch.randn(4) + >>> a + tensor([-0.6341, -1.4208, -1.0900, 0.5826]) + >>> torch.ceil(a) + tensor([-0., -1., -1., 1.]) + Type: builtin_function_or_method + + """ + return Ceil()(x) \ No newline at end of file From 1bddb9c7ab2c9dc2e944154db30b920d1d3a4919 Mon Sep 17 00:00:00 2001 From: WangYizhang01 <1739601638@qq.com> Date: Mon, 24 May 2021 20:43:27 +0800 Subject: [PATCH 02/18] add atanh --- oneflow/python/nn/modules/atanh.py | 65 +++++++++++++++++++++++ oneflow/python/nn/modules/math_atanh.py | 37 ------------- oneflow/python/test/modules/test_atanh.py | 53 ++++++++++++++++++ 3 files changed, 118 insertions(+), 37 deletions(-) create mode 100644 oneflow/python/nn/modules/atanh.py delete mode 100644 oneflow/python/nn/modules/math_atanh.py create mode 100644 oneflow/python/test/modules/test_atanh.py diff --git a/oneflow/python/nn/modules/atanh.py b/oneflow/python/nn/modules/atanh.py new file mode 100644 index 00000000000..8f5dd5cb92d --- /dev/null +++ b/oneflow/python/nn/modules/atanh.py @@ -0,0 +1,65 @@ +""" +Copyright 2020 The OneFlow Authors. All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" +import oneflow as flow + +from oneflow.python.oneflow_export import oneflow_export, experimental_api +from oneflow.python.framework.tensor import register_tensor_op +from oneflow.python.nn.module import Module + + +class Atanh(Module): + def __init__(self): + super().__init__() + self._op = flow.builtin_op("atanh").Input("x").Output("y").Build() + + def forward(self, x): + return self._op(x)[0] + + +@oneflow_export("atanh") +@register_tensor_op("atanh") +@experimental_api +def atanh_op(x): + r"""Returns a new tensor with the inverse hyperbolic tangent of the elements of :attr:`input`. + + .. math:: + \text{out}_{i} = \atanh^{-1}(\text{input}_{i}) + Args: + input (Tensor): the input tensor. + + For example: + + .. code-block:: python + + import oneflow as flow + import numpy as np + import oneflow.typing as tp + + + @flow.global_function() + def atanh_Job(x: tp.Numpy.Placeholder((3,)) + ) -> tp.Numpy: + return flow.math.atanh(x) + + + x = np.array([0.5, 0.6, 0.7]).astype(np.float32) + out = atanh_Job(x) + + # out [0.54930615 0.6931472 0.8673005 ] + + """ + + return Atanh()(x) \ No newline at end of file diff --git a/oneflow/python/nn/modules/math_atanh.py b/oneflow/python/nn/modules/math_atanh.py deleted file mode 100644 index ae47150e0d8..00000000000 --- a/oneflow/python/nn/modules/math_atanh.py +++ /dev/null @@ -1,37 +0,0 @@ -class Ceil(Module): - def __init__(self) -> None: - super().__init__() - self._op = flow.builtin_op("ceil").Input("x").Output("y").Build() - - def forward(self, x): - return self._op(x)[0] - - - -@oneflow_export("ceil") -@register_tensor_op("ceil") -@experimental_api -def ceil_op(x): - r"""ceil(input, out=None) -> Tensor - - Returns a new tensor with the ceil of the elements of :attr:`input`, - the smallest integer greater than or equal to each element. - - .. math:: - \text{out}_{i} = \left\lceil \text{input}_{i} \right\rceil = \left\lfloor \text{input}_{i} \right\rfloor + 1 - - Args: - input (Tensor): the input tensor. - out (Tensor, optional): the output tensor. - - Example:: - - >>> a = torch.randn(4) - >>> a - tensor([-0.6341, -1.4208, -1.0900, 0.5826]) - >>> torch.ceil(a) - tensor([-0., -1., -1., 1.]) - Type: builtin_function_or_method - - """ - return Ceil()(x) \ No newline at end of file diff --git a/oneflow/python/test/modules/test_atanh.py b/oneflow/python/test/modules/test_atanh.py new file mode 100644 index 00000000000..b03742262ab --- /dev/null +++ b/oneflow/python/test/modules/test_atanh.py @@ -0,0 +1,53 @@ +""" +Copyright 2020 The OneFlow Authors. All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" +import unittest +from collections import OrderedDict + +import numpy as np + +import oneflow.experimental as flow +from test_util import GenArgList + +def _test_atanh_impl(test_case, shape, device): + np_input = np.random.randn(*shape) + of_input = flow.Tensor( + np_input, dtype=flow.float32, device=flow.device(device), requires_grad=True + ) + + of_out = flow.atanh(of_input) + # np_out = np.arctanh(np_input) + # test_case.assertTrue(np.allclose(of_out.numpy(), np_out, 1e-4, 1e-4)) + + of_out = of_out.sum() + of_out.backward() + # test_case.assertTrue(np.allclose(of_input.grad.numpy(), np_out, 1e-4, 1e-4)) + + +@unittest.skipIf( + not flow.unittest.env.eager_execution_enabled(), + ".numpy() doesn't work in lazy mode", +) +class TestAtanh(flow.unittest.TestCase): + def test_atanh(test_case): + arg_dict = OrderedDict() + arg_dict["shape"] = [(2, 3), (2, 4, 5, 6)] + arg_dict["device"] = ["cpu", "cuda"] + for arg in GenArgList(arg_dict): + _test_atanh_impl(test_case, *arg) + + +if __name__ == "__main__": + unittest.main() \ No newline at end of file From 4f9d9e835b42246d3fbd77b0bda1494c8544f44e Mon Sep 17 00:00:00 2001 From: WangYizhang01 <1739601638@qq.com> Date: Mon, 24 May 2021 20:53:58 +0800 Subject: [PATCH 03/18] add /n in the tail' --- oneflow/python/nn/modules/atanh.py | 3 ++- oneflow/python/test/modules/test_atanh.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/oneflow/python/nn/modules/atanh.py b/oneflow/python/nn/modules/atanh.py index 8f5dd5cb92d..967c9618834 100644 --- a/oneflow/python/nn/modules/atanh.py +++ b/oneflow/python/nn/modules/atanh.py @@ -62,4 +62,5 @@ def atanh_Job(x: tp.Numpy.Placeholder((3,)) """ - return Atanh()(x) \ No newline at end of file + return Atanh()(x) + \ No newline at end of file diff --git a/oneflow/python/test/modules/test_atanh.py b/oneflow/python/test/modules/test_atanh.py index b03742262ab..7fd5e659fda 100644 --- a/oneflow/python/test/modules/test_atanh.py +++ b/oneflow/python/test/modules/test_atanh.py @@ -50,4 +50,5 @@ def test_atanh(test_case): if __name__ == "__main__": - unittest.main() \ No newline at end of file + unittest.main() + \ No newline at end of file From 17d3f7a93dc3123ac286c779a04b1c77996a7fd9 Mon Sep 17 00:00:00 2001 From: WangYizhang01 <1739601638@qq.com> Date: Wed, 26 May 2021 17:44:27 +0800 Subject: [PATCH 04/18] update atanh --- oneflow/python/nn/modules/atanh.py | 66 ----------------------- oneflow/python/nn/modules/math_ops.py | 45 ++++++++++++++++ oneflow/python/test/modules/test_atanh.py | 11 ++-- 3 files changed, 51 insertions(+), 71 deletions(-) delete mode 100644 oneflow/python/nn/modules/atanh.py diff --git a/oneflow/python/nn/modules/atanh.py b/oneflow/python/nn/modules/atanh.py deleted file mode 100644 index 967c9618834..00000000000 --- a/oneflow/python/nn/modules/atanh.py +++ /dev/null @@ -1,66 +0,0 @@ -""" -Copyright 2020 The OneFlow Authors. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" -import oneflow as flow - -from oneflow.python.oneflow_export import oneflow_export, experimental_api -from oneflow.python.framework.tensor import register_tensor_op -from oneflow.python.nn.module import Module - - -class Atanh(Module): - def __init__(self): - super().__init__() - self._op = flow.builtin_op("atanh").Input("x").Output("y").Build() - - def forward(self, x): - return self._op(x)[0] - - -@oneflow_export("atanh") -@register_tensor_op("atanh") -@experimental_api -def atanh_op(x): - r"""Returns a new tensor with the inverse hyperbolic tangent of the elements of :attr:`input`. - - .. math:: - \text{out}_{i} = \atanh^{-1}(\text{input}_{i}) - Args: - input (Tensor): the input tensor. - - For example: - - .. code-block:: python - - import oneflow as flow - import numpy as np - import oneflow.typing as tp - - - @flow.global_function() - def atanh_Job(x: tp.Numpy.Placeholder((3,)) - ) -> tp.Numpy: - return flow.math.atanh(x) - - - x = np.array([0.5, 0.6, 0.7]).astype(np.float32) - out = atanh_Job(x) - - # out [0.54930615 0.6931472 0.8673005 ] - - """ - - return Atanh()(x) - \ No newline at end of file diff --git a/oneflow/python/nn/modules/math_ops.py b/oneflow/python/nn/modules/math_ops.py index 0b9ae33e781..c49028f2466 100644 --- a/oneflow/python/nn/modules/math_ops.py +++ b/oneflow/python/nn/modules/math_ops.py @@ -948,3 +948,48 @@ def pow_op(tensor, exponent): """ return Pow()(tensor, exponent) + + +class Atanh(Module): + def __init__(self): + super().__init__() + self._op = flow.builtin_op("atanh").Input("x").Output("y").Build() + + def forward(self, x): + return self._op(x)[0] + + +@oneflow_export("atanh") +@register_tensor_op("atanh") +@experimental_api +def atanh_op(x): + r"""Returns a new tensor with the inverse hyperbolic tangent of the elements of :attr:`input`. + + .. math:: + \text{out}_{i} = \tanh^{-1}(\text{input}_{i}) + Args: + input (Tensor): the input tensor. + + For example: + + .. code-block:: python + + import oneflow as flow + import numpy as np + import oneflow.typing as tp + + + @flow.global_function() + def atanh_Job(x: tp.Numpy.Placeholder((3,)) + ) -> tp.Numpy: + return flow.math.atanh(x) + + + x = np.array([0.5, 0.6, 0.7]).astype(np.float32) + out = atanh_Job(x) + + # out [0.54930615 0.6931472 0.8673005 ] + + """ + + return Atanh()(x) diff --git a/oneflow/python/test/modules/test_atanh.py b/oneflow/python/test/modules/test_atanh.py index 7fd5e659fda..129a0041be0 100644 --- a/oneflow/python/test/modules/test_atanh.py +++ b/oneflow/python/test/modules/test_atanh.py @@ -16,24 +16,26 @@ import unittest from collections import OrderedDict +# import math import numpy as np import oneflow.experimental as flow from test_util import GenArgList def _test_atanh_impl(test_case, shape, device): - np_input = np.random.randn(*shape) + np_input = np.random.random(size=shape) of_input = flow.Tensor( np_input, dtype=flow.float32, device=flow.device(device), requires_grad=True ) of_out = flow.atanh(of_input) - # np_out = np.arctanh(np_input) - # test_case.assertTrue(np.allclose(of_out.numpy(), np_out, 1e-4, 1e-4)) + np_out = np.arctanh(np_input) + test_case.assertTrue(np.allclose(of_out.numpy(), np_out, 1e-4, 1e-4, equal_nan=True)) of_out = of_out.sum() of_out.backward() - # test_case.assertTrue(np.allclose(of_input.grad.numpy(), np_out, 1e-4, 1e-4)) + np_out_grad = 1.0 / (1 - np.square(np_input)) + test_case.assertTrue(np.allclose(of_input.grad.numpy(), np_out_grad, 1e-4, 1e-4, equal_nan=True)) @unittest.skipIf( @@ -51,4 +53,3 @@ def test_atanh(test_case): if __name__ == "__main__": unittest.main() - \ No newline at end of file From c1cc17a13c9471ed0a43f9776029ef20c3d79a3a Mon Sep 17 00:00:00 2001 From: WangYizhang01 <1739601638@qq.com> Date: Fri, 28 May 2021 10:53:30 +0800 Subject: [PATCH 05/18] format --- oneflow/python/test/modules/test_atanh.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/oneflow/python/test/modules/test_atanh.py b/oneflow/python/test/modules/test_atanh.py index 129a0041be0..7e5e7673fd2 100644 --- a/oneflow/python/test/modules/test_atanh.py +++ b/oneflow/python/test/modules/test_atanh.py @@ -22,6 +22,7 @@ import oneflow.experimental as flow from test_util import GenArgList + def _test_atanh_impl(test_case, shape, device): np_input = np.random.random(size=shape) of_input = flow.Tensor( @@ -30,12 +31,16 @@ def _test_atanh_impl(test_case, shape, device): of_out = flow.atanh(of_input) np_out = np.arctanh(np_input) - test_case.assertTrue(np.allclose(of_out.numpy(), np_out, 1e-4, 1e-4, equal_nan=True)) + test_case.assertTrue( + np.allclose(of_out.numpy(), np_out, 1e-4, 1e-4, equal_nan=True) + ) of_out = of_out.sum() of_out.backward() np_out_grad = 1.0 / (1 - np.square(np_input)) - test_case.assertTrue(np.allclose(of_input.grad.numpy(), np_out_grad, 1e-4, 1e-4, equal_nan=True)) + test_case.assertTrue( + np.allclose(of_input.grad.numpy(), np_out_grad, 1e-4, 1e-4, equal_nan=True) + ) @unittest.skipIf( From cd3da5433483d6fd0d325c199704de3257585302 Mon Sep 17 00:00:00 2001 From: WangYizhang01 <1739601638@qq.com> Date: Fri, 28 May 2021 14:44:33 +0800 Subject: [PATCH 06/18] add tan --- oneflow/python/nn/modules/math_ops.py | 49 ++++++++++++++++++- oneflow/python/test/modules/test_atanh.py | 1 - oneflow/python/test/modules/test_tan.py | 59 +++++++++++++++++++++++ 3 files changed, 106 insertions(+), 3 deletions(-) create mode 100644 oneflow/python/test/modules/test_tan.py diff --git a/oneflow/python/nn/modules/math_ops.py b/oneflow/python/nn/modules/math_ops.py index ab88df2bde3..5d6b3691bea 100644 --- a/oneflow/python/nn/modules/math_ops.py +++ b/oneflow/python/nn/modules/math_ops.py @@ -960,6 +960,51 @@ def pow_op(tensor, exponent): return Pow()(tensor, exponent) +class Tan(Module): + def __init__(self): + super().__init__() + self._op = flow.builtin_op("tan").Input("x").Output("y").Build() + + def forward(self, x): + return self._op(x)[0] + + +@oneflow_export("tan") +@register_tensor_op("tan") +@experimental_api +def tan_op(input): + r"""Returns the tan value of the elements of :attr:`input`. + + .. math:: + \text{out}_{i} = \tan(\text{input}_{i}) + Args: + input (Tensor): the input tensor. + + For example: + + .. code-block:: python + + import oneflow as flow + import numpy as np + import oneflow.typing as tp + + + @flow.global_function() + def tan_Job(x: tp.Numpy.Placeholder((3,)) + ) -> tp.Numpy: + return flow.math.tan(x) + + + x = np.array([-1/4*np.pi, 0, 1/4*np.pi]).astype(np.float32) + out = tan_Job(x) + + # out [-1. 0. 1.] + + """ + + return Tan()(input) + + class Atanh(Module): def __init__(self): super().__init__() @@ -972,7 +1017,7 @@ def forward(self, x): @oneflow_export("atanh") @register_tensor_op("atanh") @experimental_api -def atanh_op(x): +def atanh_op(input): r"""Returns a new tensor with the inverse hyperbolic tangent of the elements of :attr:`input`. .. math:: @@ -1002,4 +1047,4 @@ def atanh_Job(x: tp.Numpy.Placeholder((3,)) """ - return Atanh()(x) + return Atanh()(input) diff --git a/oneflow/python/test/modules/test_atanh.py b/oneflow/python/test/modules/test_atanh.py index 7e5e7673fd2..c790f80d3cb 100644 --- a/oneflow/python/test/modules/test_atanh.py +++ b/oneflow/python/test/modules/test_atanh.py @@ -16,7 +16,6 @@ import unittest from collections import OrderedDict -# import math import numpy as np import oneflow.experimental as flow diff --git a/oneflow/python/test/modules/test_tan.py b/oneflow/python/test/modules/test_tan.py new file mode 100644 index 00000000000..5e3adc37a27 --- /dev/null +++ b/oneflow/python/test/modules/test_tan.py @@ -0,0 +1,59 @@ +""" +Copyright 2020 The OneFlow Authors. All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" +import unittest +from collections import OrderedDict + +import numpy as np + +import oneflow.experimental as flow +from test_util import GenArgList + + +def _test_tan_impl(test_case, shape, device): + np_input = np.random.random(size=shape) + of_input = flow.Tensor( + np_input, dtype=flow.float32, device=flow.device(device), requires_grad=True + ) + + of_out = flow.tan(of_input) + np_out = np.tan(np_input) + test_case.assertTrue( + np.allclose(of_out.numpy(), np_out, 1e-4, 1e-4, equal_nan=True) + ) + + of_out = of_out.sum() + of_out.backward() + np_out_grad = 1 + np.square(np_out) + test_case.assertTrue( + np.allclose(of_input.grad.numpy(), np_out_grad, 1e-4, 1e-4, equal_nan=True) + ) + + +@unittest.skipIf( + not flow.unittest.env.eager_execution_enabled(), + ".numpy() doesn't work in lazy mode", +) +class TestTan(flow.unittest.TestCase): + def test_tan(test_case): + arg_dict = OrderedDict() + arg_dict["shape"] = [(2, 3), (2, 4, 5, 6)] + arg_dict["device"] = ["cpu", "cuda"] + for arg in GenArgList(arg_dict): + _test_tan_impl(test_case, *arg) + + +if __name__ == "__main__": + unittest.main() From 408a109c5d59748eede22c2637df471168721e62 Mon Sep 17 00:00:00 2001 From: WangYizhang01 <1739601638@qq.com> Date: Fri, 28 May 2021 15:32:10 +0800 Subject: [PATCH 07/18] add test_square.py test_sqrt.py --- oneflow/python/nn/modules/math_ops.py | 32 +++--------- oneflow/python/test/modules/test_sqrt.py | 59 ++++++++++++++++++++++ oneflow/python/test/modules/test_square.py | 59 ++++++++++++++++++++++ 3 files changed, 126 insertions(+), 24 deletions(-) create mode 100644 oneflow/python/test/modules/test_sqrt.py create mode 100644 oneflow/python/test/modules/test_square.py diff --git a/oneflow/python/nn/modules/math_ops.py b/oneflow/python/nn/modules/math_ops.py index 5d6b3691bea..07965b363d2 100644 --- a/oneflow/python/nn/modules/math_ops.py +++ b/oneflow/python/nn/modules/math_ops.py @@ -986,19 +986,11 @@ def tan_op(input): import oneflow as flow import numpy as np - import oneflow.typing as tp - - @flow.global_function() - def tan_Job(x: tp.Numpy.Placeholder((3,)) - ) -> tp.Numpy: - return flow.math.tan(x) - - - x = np.array([-1/4*np.pi, 0, 1/4*np.pi]).astype(np.float32) - out = tan_Job(x) - - # out [-1. 0. 1.] + np_arr = np.array([-1/4*np.pi, 0, 1/4*np.pi]).astype(np.float32) + input = flow.Tensor(np_arr) + output = flow.tan(input) # output [-1. 0. 1.] + # equal to np.tan(np_arr) """ @@ -1031,19 +1023,11 @@ def atanh_op(input): import oneflow as flow import numpy as np - import oneflow.typing as tp - - @flow.global_function() - def atanh_Job(x: tp.Numpy.Placeholder((3,)) - ) -> tp.Numpy: - return flow.math.atanh(x) - - - x = np.array([0.5, 0.6, 0.7]).astype(np.float32) - out = atanh_Job(x) - - # out [0.54930615 0.6931472 0.8673005 ] + np_arr = np.array([0.5, 0.6, 0.7]).astype(np.float32) + input = flow.Tensor(np_arr) + output = flow.atanh(input) # out [0.54930615 0.6931472 0.8673005 ] + # equal to np.arctanh(np_arr) """ diff --git a/oneflow/python/test/modules/test_sqrt.py b/oneflow/python/test/modules/test_sqrt.py new file mode 100644 index 00000000000..3d8a295f7f0 --- /dev/null +++ b/oneflow/python/test/modules/test_sqrt.py @@ -0,0 +1,59 @@ +""" +Copyright 2020 The OneFlow Authors. All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" +import unittest +from collections import OrderedDict + +import numpy as np + +import oneflow.experimental as flow +from test_util import GenArgList + + +def _test_sqrt_impl(test_case, shape, device): + np_input = np.random.random(size=shape) + of_input = flow.Tensor( + np_input, dtype=flow.float32, device=flow.device(device), requires_grad=True + ) + + of_out = flow.sqrt(of_input) + np_out = np.sqrt(np_input) + test_case.assertTrue( + np.allclose(of_out.numpy(), np_out, 1e-4, 1e-4, equal_nan=True) + ) + + of_out = of_out.sum() + of_out.backward() + np_out_grad = 1.0 / (2 * np_out) + test_case.assertTrue( + np.allclose(of_input.grad.numpy(), np_out_grad, 1e-4, 1e-4, equal_nan=True) + ) + + +@unittest.skipIf( + not flow.unittest.env.eager_execution_enabled(), + ".numpy() doesn't work in lazy mode", +) +class TestSqrt(flow.unittest.TestCase): + def test_sqrt(test_case): + arg_dict = OrderedDict() + arg_dict["shape"] = [(2, 3), (2, 4, 5, 6)] + arg_dict["device"] = ["cpu", "cuda"] + for arg in GenArgList(arg_dict): + _test_sqrt_impl(test_case, *arg) + + +if __name__ == "__main__": + unittest.main() diff --git a/oneflow/python/test/modules/test_square.py b/oneflow/python/test/modules/test_square.py new file mode 100644 index 00000000000..3715b12f040 --- /dev/null +++ b/oneflow/python/test/modules/test_square.py @@ -0,0 +1,59 @@ +""" +Copyright 2020 The OneFlow Authors. All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" +import unittest +from collections import OrderedDict + +import numpy as np + +import oneflow.experimental as flow +from test_util import GenArgList + + +def _test_square_impl(test_case, shape, device): + np_input = np.random.random(size=shape) + of_input = flow.Tensor( + np_input, dtype=flow.float32, device=flow.device(device), requires_grad=True + ) + + of_out = flow.square(of_input) + np_out = np.square(np_input) + test_case.assertTrue( + np.allclose(of_out.numpy(), np_out, 1e-4, 1e-4, equal_nan=True) + ) + + of_out = of_out.sum() + of_out.backward() + np_out_grad = 2 * np_input + test_case.assertTrue( + np.allclose(of_input.grad.numpy(), np_out_grad, 1e-4, 1e-4, equal_nan=True) + ) + + +@unittest.skipIf( + not flow.unittest.env.eager_execution_enabled(), + ".numpy() doesn't work in lazy mode", +) +class TestSquare(flow.unittest.TestCase): + def test_square(test_case): + arg_dict = OrderedDict() + arg_dict["shape"] = [(2, 3), (2, 4, 5, 6)] + arg_dict["device"] = ["cpu", "cuda"] + for arg in GenArgList(arg_dict): + _test_square_impl(test_case, *arg) + + +if __name__ == "__main__": + unittest.main() From 26163dcc27c2e6f48554b804ea137f37b74ffff5 Mon Sep 17 00:00:00 2001 From: WangYizhang01 <1739601638@qq.com> Date: Mon, 31 May 2021 09:34:03 +0800 Subject: [PATCH 08/18] update test_atanh grad --- oneflow/python/test/modules/test_atanh.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oneflow/python/test/modules/test_atanh.py b/oneflow/python/test/modules/test_atanh.py index c790f80d3cb..4af9cddbc09 100644 --- a/oneflow/python/test/modules/test_atanh.py +++ b/oneflow/python/test/modules/test_atanh.py @@ -36,7 +36,7 @@ def _test_atanh_impl(test_case, shape, device): of_out = of_out.sum() of_out.backward() - np_out_grad = 1.0 / (1 - np.square(np_input)) + np_out_grad = 1.0 / (1.0 - np.square(np_input)) test_case.assertTrue( np.allclose(of_input.grad.numpy(), np_out_grad, 1e-4, 1e-4, equal_nan=True) ) From 99493c0f2a1a65d2c383d2b171b907c63c5de510 Mon Sep 17 00:00:00 2001 From: WangYizhang01 <1739601638@qq.com> Date: Mon, 31 May 2021 15:14:19 +0800 Subject: [PATCH 09/18] update test_tensor.py --- docs/source/experimental.rst | 6 ++ oneflow/python/nn/modules/math_ops.py | 11 ++++ oneflow/python/test/modules/test_atanh.py | 21 ++++++- oneflow/python/test/modules/test_sqrt.py | 59 ------------------ oneflow/python/test/modules/test_square.py | 59 ------------------ oneflow/python/test/tensor/test_tensor.py | 69 ++++++++++++++++++++++ 6 files changed, 106 insertions(+), 119 deletions(-) delete mode 100644 oneflow/python/test/modules/test_sqrt.py delete mode 100644 oneflow/python/test/modules/test_square.py diff --git a/docs/source/experimental.rst b/docs/source/experimental.rst index 67c2de778ab..8a32595b57e 100644 --- a/docs/source/experimental.rst +++ b/docs/source/experimental.rst @@ -126,3 +126,9 @@ Experimental features .. autofunction:: oneflow.experimental.nn.Upsample .. autofunction:: oneflow.experimental.nn.UpsamplingNearest2d .. autofunction:: oneflow.experimental.nn.UpsamplingBilinear2d +.. autofunction:: oneflow.experimental.atanh +.. autofunction:: oneflow.experimental.Tensor.atanh +.. autofunction:: oneflow.experimental.arctanh +.. autofunction:: oneflow.experimental.Tensor.arctanh +.. autofunction:: oneflow.experimental.tan +.. autofunction:: oneflow.experimental.Tensor.tan diff --git a/oneflow/python/nn/modules/math_ops.py b/oneflow/python/nn/modules/math_ops.py index 07965b363d2..0b883cc7a4a 100644 --- a/oneflow/python/nn/modules/math_ops.py +++ b/oneflow/python/nn/modules/math_ops.py @@ -1032,3 +1032,14 @@ def atanh_op(input): """ return Atanh()(input) + +@oneflow_export("arctanh") +@register_tensor_op("arctanh") +@experimental_api +def arctanh_op(input): + r""" + + Alias for :func:`oneflow.experimental.arctanh` + """ + + return Atanh()(input) diff --git a/oneflow/python/test/modules/test_atanh.py b/oneflow/python/test/modules/test_atanh.py index 4af9cddbc09..d257726ae66 100644 --- a/oneflow/python/test/modules/test_atanh.py +++ b/oneflow/python/test/modules/test_atanh.py @@ -23,7 +23,7 @@ def _test_atanh_impl(test_case, shape, device): - np_input = np.random.random(size=shape) + np_input = np.random.random(shape) of_input = flow.Tensor( np_input, dtype=flow.float32, device=flow.device(device), requires_grad=True ) @@ -41,6 +41,24 @@ def _test_atanh_impl(test_case, shape, device): np.allclose(of_input.grad.numpy(), np_out_grad, 1e-4, 1e-4, equal_nan=True) ) +def _test_arctanh_impl(test_case, shape, device): + np_input = np.random.random(shape) + of_input = flow.Tensor( + np_input, dtype=flow.float32, device=flow.device(device), requires_grad=True + ) + + of_out = flow.arctanh(of_input) + np_out = np.arctanh(np_input) + test_case.assertTrue( + np.allclose(of_out.numpy(), np_out, 1e-4, 1e-4, equal_nan=True) + ) + + of_out = of_out.sum() + of_out.backward() + np_out_grad = 1.0 / (1.0 - np.square(np_input)) + test_case.assertTrue( + np.allclose(of_input.grad.numpy(), np_out_grad, 1e-4, 1e-4, equal_nan=True) + ) @unittest.skipIf( not flow.unittest.env.eager_execution_enabled(), @@ -53,6 +71,7 @@ def test_atanh(test_case): arg_dict["device"] = ["cpu", "cuda"] for arg in GenArgList(arg_dict): _test_atanh_impl(test_case, *arg) + _test_arctanh_impl(test_case, *arg) if __name__ == "__main__": diff --git a/oneflow/python/test/modules/test_sqrt.py b/oneflow/python/test/modules/test_sqrt.py deleted file mode 100644 index 3d8a295f7f0..00000000000 --- a/oneflow/python/test/modules/test_sqrt.py +++ /dev/null @@ -1,59 +0,0 @@ -""" -Copyright 2020 The OneFlow Authors. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" -import unittest -from collections import OrderedDict - -import numpy as np - -import oneflow.experimental as flow -from test_util import GenArgList - - -def _test_sqrt_impl(test_case, shape, device): - np_input = np.random.random(size=shape) - of_input = flow.Tensor( - np_input, dtype=flow.float32, device=flow.device(device), requires_grad=True - ) - - of_out = flow.sqrt(of_input) - np_out = np.sqrt(np_input) - test_case.assertTrue( - np.allclose(of_out.numpy(), np_out, 1e-4, 1e-4, equal_nan=True) - ) - - of_out = of_out.sum() - of_out.backward() - np_out_grad = 1.0 / (2 * np_out) - test_case.assertTrue( - np.allclose(of_input.grad.numpy(), np_out_grad, 1e-4, 1e-4, equal_nan=True) - ) - - -@unittest.skipIf( - not flow.unittest.env.eager_execution_enabled(), - ".numpy() doesn't work in lazy mode", -) -class TestSqrt(flow.unittest.TestCase): - def test_sqrt(test_case): - arg_dict = OrderedDict() - arg_dict["shape"] = [(2, 3), (2, 4, 5, 6)] - arg_dict["device"] = ["cpu", "cuda"] - for arg in GenArgList(arg_dict): - _test_sqrt_impl(test_case, *arg) - - -if __name__ == "__main__": - unittest.main() diff --git a/oneflow/python/test/modules/test_square.py b/oneflow/python/test/modules/test_square.py deleted file mode 100644 index 3715b12f040..00000000000 --- a/oneflow/python/test/modules/test_square.py +++ /dev/null @@ -1,59 +0,0 @@ -""" -Copyright 2020 The OneFlow Authors. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" -import unittest -from collections import OrderedDict - -import numpy as np - -import oneflow.experimental as flow -from test_util import GenArgList - - -def _test_square_impl(test_case, shape, device): - np_input = np.random.random(size=shape) - of_input = flow.Tensor( - np_input, dtype=flow.float32, device=flow.device(device), requires_grad=True - ) - - of_out = flow.square(of_input) - np_out = np.square(np_input) - test_case.assertTrue( - np.allclose(of_out.numpy(), np_out, 1e-4, 1e-4, equal_nan=True) - ) - - of_out = of_out.sum() - of_out.backward() - np_out_grad = 2 * np_input - test_case.assertTrue( - np.allclose(of_input.grad.numpy(), np_out_grad, 1e-4, 1e-4, equal_nan=True) - ) - - -@unittest.skipIf( - not flow.unittest.env.eager_execution_enabled(), - ".numpy() doesn't work in lazy mode", -) -class TestSquare(flow.unittest.TestCase): - def test_square(test_case): - arg_dict = OrderedDict() - arg_dict["shape"] = [(2, 3), (2, 4, 5, 6)] - arg_dict["device"] = ["cpu", "cuda"] - for arg in GenArgList(arg_dict): - _test_square_impl(test_case, *arg) - - -if __name__ == "__main__": - unittest.main() diff --git a/oneflow/python/test/tensor/test_tensor.py b/oneflow/python/test/tensor/test_tensor.py index 664bec50f73..432c2626585 100644 --- a/oneflow/python/test/tensor/test_tensor.py +++ b/oneflow/python/test/tensor/test_tensor.py @@ -477,6 +477,75 @@ def test_construct_small_tensor(test_case): test_case.assertEqual(tensor.dtype, flow.float32) test_case.assertTrue(np.allclose(tensor.numpy(), np.array(scalar), 1e-4, 1e-4)) + @unittest.skipIf( + not flow.unittest.env.eager_execution_enabled(), + "numpy doesn't work in lazy mode", + ) + def test_tensor_atanh(test_case): + np_input = np.random.random((2,3)) + of_input = flow.Tensor( + np_input, dtype=flow.float32, requires_grad=True + ) + + of_out = of_input.atanh() + np_out = np.arctanh(np_input) + test_case.assertTrue( + np.allclose(of_out.numpy(), np_out, 1e-4, 1e-4, equal_nan=True) + ) + + of_out = of_out.sum() + of_out.backward() + np_out_grad = 1.0 / (1.0 - np.square(np_input)) + test_case.assertTrue( + np.allclose(of_input.grad.numpy(), np_out_grad, 1e-4, 1e-4, equal_nan=True) + ) + + @unittest.skipIf( + not flow.unittest.env.eager_execution_enabled(), + "numpy doesn't work in lazy mode", + ) + def test_tensor_arctanh(test_case): + np_input = np.random.random((2,3)) + of_input = flow.Tensor( + np_input, dtype=flow.float32, requires_grad=True + ) + + of_out = of_input.arctanh() + np_out = np.arctanh(np_input) + test_case.assertTrue( + np.allclose(of_out.numpy(), np_out, 1e-4, 1e-4, equal_nan=True) + ) + + of_out = of_out.sum() + of_out.backward() + np_out_grad = 1.0 / (1.0 - np.square(np_input)) + test_case.assertTrue( + np.allclose(of_input.grad.numpy(), np_out_grad, 1e-4, 1e-4, equal_nan=True) + ) + + @unittest.skipIf( + not flow.unittest.env.eager_execution_enabled(), + "numpy doesn't work in lazy mode", + ) + def test_tensor_tan(test_case): + np_input = np.random.random((2,3)) + of_input = flow.Tensor( + np_input, dtype=flow.float32, requires_grad=True + ) + + of_out = of_input.tan() + np_out = np.tan(np_input) + test_case.assertTrue( + np.allclose(of_out.numpy(), np_out, 1e-4, 1e-4, equal_nan=True) + ) + + of_out = of_out.sum() + of_out.backward() + np_out_grad = 1 + np.square(np_out) + test_case.assertTrue( + np.allclose(of_input.grad.numpy(), np_out_grad, 1e-4, 1e-4, equal_nan=True) + ) + if __name__ == "__main__": unittest.main() From 0e7a84839088d330c13d269df2774620292c830b Mon Sep 17 00:00:00 2001 From: WangYizhang01 <1739601638@qq.com> Date: Mon, 31 May 2021 16:25:20 +0800 Subject: [PATCH 10/18] add doctest --- oneflow/python/nn/modules/math_ops.py | 28 +++++++++++++-------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/oneflow/python/nn/modules/math_ops.py b/oneflow/python/nn/modules/math_ops.py index 0b883cc7a4a..6a5b06c90ee 100644 --- a/oneflow/python/nn/modules/math_ops.py +++ b/oneflow/python/nn/modules/math_ops.py @@ -984,14 +984,13 @@ def tan_op(input): .. code-block:: python - import oneflow as flow - import numpy as np - - np_arr = np.array([-1/4*np.pi, 0, 1/4*np.pi]).astype(np.float32) - input = flow.Tensor(np_arr) - output = flow.tan(input) # output [-1. 0. 1.] - # equal to np.tan(np_arr) + >>> import oneflow as flow + >>> import numpy as np + >>> np_arr = np.array([-1/4*np.pi, 0, 1/4*np.pi]).astype(np.float32) + >>> input = flow.Tensor(np_arr) + >>> output = flow.tan(input) + [-1. 0. 1.] """ return Tan()(input) @@ -1021,14 +1020,13 @@ def atanh_op(input): .. code-block:: python - import oneflow as flow - import numpy as np - - np_arr = np.array([0.5, 0.6, 0.7]).astype(np.float32) - input = flow.Tensor(np_arr) - output = flow.atanh(input) # out [0.54930615 0.6931472 0.8673005 ] - # equal to np.arctanh(np_arr) + >>> import oneflow as flow + >>> import numpy as np + >>> np_arr = np.array([0.5, 0.6, 0.7]).astype(np.float32) + >>> input = flow.Tensor(np_arr) + >>> output = flow.atanh(input) + [0.54930615 0.6931472 0.8673005 ] """ return Atanh()(input) @@ -1039,7 +1037,7 @@ def atanh_op(input): def arctanh_op(input): r""" - Alias for :func:`oneflow.experimental.arctanh` + Alias for :func:`oneflow.experimental.atanh` """ return Atanh()(input) From 7ee49fe06fc25609d29712fc6be5ae79a17da81f Mon Sep 17 00:00:00 2001 From: WangYizhang01 <1739601638@qq.com> Date: Thu, 3 Jun 2021 12:39:30 +0800 Subject: [PATCH 11/18] update --- oneflow/python/nn/modules/math_ops.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/oneflow/python/nn/modules/math_ops.py b/oneflow/python/nn/modules/math_ops.py index 6a5b06c90ee..1311933d085 100644 --- a/oneflow/python/nn/modules/math_ops.py +++ b/oneflow/python/nn/modules/math_ops.py @@ -984,12 +984,13 @@ def tan_op(input): .. code-block:: python - >>> import oneflow as flow + >>> import oneflow.experimental as flow >>> import numpy as np - + >>> flow.enable_eager_execution() >>> np_arr = np.array([-1/4*np.pi, 0, 1/4*np.pi]).astype(np.float32) >>> input = flow.Tensor(np_arr) >>> output = flow.tan(input) + >>> print(output.numpy()) [-1. 0. 1.] """ @@ -1020,12 +1021,13 @@ def atanh_op(input): .. code-block:: python - >>> import oneflow as flow + >>> import oneflow.experimental as flow >>> import numpy as np - + >>> flow.enable_eager_execution() >>> np_arr = np.array([0.5, 0.6, 0.7]).astype(np.float32) >>> input = flow.Tensor(np_arr) >>> output = flow.atanh(input) + >>> print(output.numpy()) [0.54930615 0.6931472 0.8673005 ] """ @@ -1041,3 +1043,9 @@ def arctanh_op(input): """ return Atanh()(input) + + +if __name__ == "__main__": + import doctest + + doctest.testmod() From 954e61b0e4a97d3efafb40009eea68543266ebb8 Mon Sep 17 00:00:00 2001 From: WangYizhang01 <1739601638@qq.com> Date: Fri, 4 Jun 2021 09:08:01 +0800 Subject: [PATCH 12/18] split tensor --- oneflow/python/nn/modules/math_ops.py | 36 ++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/oneflow/python/nn/modules/math_ops.py b/oneflow/python/nn/modules/math_ops.py index 1311933d085..f02440d0d91 100644 --- a/oneflow/python/nn/modules/math_ops.py +++ b/oneflow/python/nn/modules/math_ops.py @@ -968,9 +968,7 @@ def __init__(self): def forward(self, x): return self._op(x)[0] - @oneflow_export("tan") -@register_tensor_op("tan") @experimental_api def tan_op(input): r"""Returns the tan value of the elements of :attr:`input`. @@ -996,6 +994,17 @@ def tan_op(input): return Tan()(input) +@register_tensor_op("tan") +@experimental_api +def tan_op_tensor(input): + r""" + tan() -> Tensor + See :func:`oneflow.experimental.tan` + + """ + + return Tan()(input) + class Atanh(Module): def __init__(self): @@ -1007,7 +1016,6 @@ def forward(self, x): @oneflow_export("atanh") -@register_tensor_op("atanh") @experimental_api def atanh_op(input): r"""Returns a new tensor with the inverse hyperbolic tangent of the elements of :attr:`input`. @@ -1033,8 +1041,18 @@ def atanh_op(input): return Atanh()(input) +@register_tensor_op("atanh") +@experimental_api +def atanh_op_tensor(x): + r""" + atanh() -> Tensor + See :func:`oneflow.experimental.atanh` + + """ + + return Atanh()(x) + @oneflow_export("arctanh") -@register_tensor_op("arctanh") @experimental_api def arctanh_op(input): r""" @@ -1044,6 +1062,16 @@ def arctanh_op(input): return Atanh()(input) +@register_tensor_op("arctanh") +@experimental_api +def arctanh_op_tensor(input): + r""" + + Alias for :func:`oneflow.experimental.atanh` + """ + + return Atanh()(input) + if __name__ == "__main__": import doctest From 4afb156685b34eea06a9d0b02fd71ddf10844257 Mon Sep 17 00:00:00 2001 From: WangYizhang01 <1739601638@qq.com> Date: Fri, 4 Jun 2021 10:38:24 +0800 Subject: [PATCH 13/18] add 3 dim testcase --- oneflow/python/test/modules/test_atanh.py | 2 +- oneflow/python/test/modules/test_tan.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/oneflow/python/test/modules/test_atanh.py b/oneflow/python/test/modules/test_atanh.py index d257726ae66..202ae07d8cd 100644 --- a/oneflow/python/test/modules/test_atanh.py +++ b/oneflow/python/test/modules/test_atanh.py @@ -67,7 +67,7 @@ def _test_arctanh_impl(test_case, shape, device): class TestAtanh(flow.unittest.TestCase): def test_atanh(test_case): arg_dict = OrderedDict() - arg_dict["shape"] = [(2, 3), (2, 4, 5, 6)] + arg_dict["shape"] = [(2, 3), (2,3,4), (2, 4, 5, 6)] arg_dict["device"] = ["cpu", "cuda"] for arg in GenArgList(arg_dict): _test_atanh_impl(test_case, *arg) diff --git a/oneflow/python/test/modules/test_tan.py b/oneflow/python/test/modules/test_tan.py index 5e3adc37a27..6f3ef92d472 100644 --- a/oneflow/python/test/modules/test_tan.py +++ b/oneflow/python/test/modules/test_tan.py @@ -49,7 +49,7 @@ def _test_tan_impl(test_case, shape, device): class TestTan(flow.unittest.TestCase): def test_tan(test_case): arg_dict = OrderedDict() - arg_dict["shape"] = [(2, 3), (2, 4, 5, 6)] + arg_dict["shape"] = [(2, 3), (2,3,4), (2, 4, 5, 6)] arg_dict["device"] = ["cpu", "cuda"] for arg in GenArgList(arg_dict): _test_tan_impl(test_case, *arg) From ac076fb95cd8421f4e2e34339c7b147e93d577e3 Mon Sep 17 00:00:00 2001 From: WangYizhang01 <1739601638@qq.com> Date: Fri, 4 Jun 2021 12:59:35 +0800 Subject: [PATCH 14/18] resolve conflict --- oneflow/python/nn/modules/atanh.py | 92 ++++++++++++++++++++ oneflow/python/nn/modules/math_ops.py | 119 -------------------------- oneflow/python/nn/modules/tan.py | 71 +++++++++++++++ 3 files changed, 163 insertions(+), 119 deletions(-) create mode 100644 oneflow/python/nn/modules/atanh.py create mode 100644 oneflow/python/nn/modules/tan.py diff --git a/oneflow/python/nn/modules/atanh.py b/oneflow/python/nn/modules/atanh.py new file mode 100644 index 00000000000..b92ac034d70 --- /dev/null +++ b/oneflow/python/nn/modules/atanh.py @@ -0,0 +1,92 @@ +""" +Copyright 2020 The OneFlow Authors. All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" +import oneflow as flow +from oneflow.python.oneflow_export import oneflow_export, experimental_api +from oneflow.python.nn.module import Module +from oneflow.python.framework.tensor import register_tensor_op + + +class Atanh(Module): + def __init__(self): + super().__init__() + self._op = flow.builtin_op("atanh").Input("x").Output("y").Build() + + def forward(self, x): + return self._op(x)[0] + + +@oneflow_export("atanh") +@experimental_api +def atanh_op(input): + r"""Returns a new tensor with the inverse hyperbolic tangent of the elements of :attr:`input`. + + .. math:: + \text{out}_{i} = \tanh^{-1}(\text{input}_{i}) + Args: + input (Tensor): the input tensor. + + For example: + + .. code-block:: python + + >>> import oneflow.experimental as flow + >>> import numpy as np + >>> flow.enable_eager_execution() + >>> np_arr = np.array([0.5, 0.6, 0.7]).astype(np.float32) + >>> input = flow.Tensor(np_arr) + >>> output = flow.atanh(input) + >>> print(output.numpy()) + [0.54930615 0.6931472 0.8673005 ] + """ + + return Atanh()(input) + +@register_tensor_op("atanh") +@experimental_api +def atanh_op_tensor(x): + r""" + atanh() -> Tensor + See :func:`oneflow.experimental.atanh` + + """ + + return Atanh()(x) + +@oneflow_export("arctanh") +@experimental_api +def arctanh_op(input): + r""" + + Alias for :func:`oneflow.experimental.atanh` + """ + + return Atanh()(input) + +@register_tensor_op("arctanh") +@experimental_api +def arctanh_op_tensor(input): + r""" + + Alias for :func:`oneflow.experimental.atanh` + """ + + return Atanh()(input) + + +if __name__ == "__main__": + import doctest + + doctest.testmod() diff --git a/oneflow/python/nn/modules/math_ops.py b/oneflow/python/nn/modules/math_ops.py index f02440d0d91..d372f90b111 100644 --- a/oneflow/python/nn/modules/math_ops.py +++ b/oneflow/python/nn/modules/math_ops.py @@ -958,122 +958,3 @@ def pow_op(tensor, exponent): """ return Pow()(tensor, exponent) - - -class Tan(Module): - def __init__(self): - super().__init__() - self._op = flow.builtin_op("tan").Input("x").Output("y").Build() - - def forward(self, x): - return self._op(x)[0] - -@oneflow_export("tan") -@experimental_api -def tan_op(input): - r"""Returns the tan value of the elements of :attr:`input`. - - .. math:: - \text{out}_{i} = \tan(\text{input}_{i}) - Args: - input (Tensor): the input tensor. - - For example: - - .. code-block:: python - - >>> import oneflow.experimental as flow - >>> import numpy as np - >>> flow.enable_eager_execution() - >>> np_arr = np.array([-1/4*np.pi, 0, 1/4*np.pi]).astype(np.float32) - >>> input = flow.Tensor(np_arr) - >>> output = flow.tan(input) - >>> print(output.numpy()) - [-1. 0. 1.] - """ - - return Tan()(input) - -@register_tensor_op("tan") -@experimental_api -def tan_op_tensor(input): - r""" - tan() -> Tensor - See :func:`oneflow.experimental.tan` - - """ - - return Tan()(input) - - -class Atanh(Module): - def __init__(self): - super().__init__() - self._op = flow.builtin_op("atanh").Input("x").Output("y").Build() - - def forward(self, x): - return self._op(x)[0] - - -@oneflow_export("atanh") -@experimental_api -def atanh_op(input): - r"""Returns a new tensor with the inverse hyperbolic tangent of the elements of :attr:`input`. - - .. math:: - \text{out}_{i} = \tanh^{-1}(\text{input}_{i}) - Args: - input (Tensor): the input tensor. - - For example: - - .. code-block:: python - - >>> import oneflow.experimental as flow - >>> import numpy as np - >>> flow.enable_eager_execution() - >>> np_arr = np.array([0.5, 0.6, 0.7]).astype(np.float32) - >>> input = flow.Tensor(np_arr) - >>> output = flow.atanh(input) - >>> print(output.numpy()) - [0.54930615 0.6931472 0.8673005 ] - """ - - return Atanh()(input) - -@register_tensor_op("atanh") -@experimental_api -def atanh_op_tensor(x): - r""" - atanh() -> Tensor - See :func:`oneflow.experimental.atanh` - - """ - - return Atanh()(x) - -@oneflow_export("arctanh") -@experimental_api -def arctanh_op(input): - r""" - - Alias for :func:`oneflow.experimental.atanh` - """ - - return Atanh()(input) - -@register_tensor_op("arctanh") -@experimental_api -def arctanh_op_tensor(input): - r""" - - Alias for :func:`oneflow.experimental.atanh` - """ - - return Atanh()(input) - - -if __name__ == "__main__": - import doctest - - doctest.testmod() diff --git a/oneflow/python/nn/modules/tan.py b/oneflow/python/nn/modules/tan.py new file mode 100644 index 00000000000..724667b3b59 --- /dev/null +++ b/oneflow/python/nn/modules/tan.py @@ -0,0 +1,71 @@ +""" +Copyright 2020 The OneFlow Authors. All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" +import oneflow as flow +from oneflow.python.oneflow_export import oneflow_export, experimental_api +from oneflow.python.nn.module import Module +from oneflow.python.framework.tensor import register_tensor_op + + +class Tan(Module): + def __init__(self): + super().__init__() + self._op = flow.builtin_op("tan").Input("x").Output("y").Build() + + def forward(self, x): + return self._op(x)[0] + +@oneflow_export("tan") +@experimental_api +def tan_op(input): + r"""Returns the tan value of the elements of :attr:`input`. + + .. math:: + \text{out}_{i} = \tan(\text{input}_{i}) + Args: + input (Tensor): the input tensor. + + For example: + + .. code-block:: python + + >>> import oneflow.experimental as flow + >>> import numpy as np + >>> flow.enable_eager_execution() + >>> np_arr = np.array([-1/4*np.pi, 0, 1/4*np.pi]).astype(np.float32) + >>> input = flow.Tensor(np_arr) + >>> output = flow.tan(input) + >>> print(output.numpy()) + [-1. 0. 1.] + """ + + return Tan()(input) + +@register_tensor_op("tan") +@experimental_api +def tan_op_tensor(input): + r""" + tan() -> Tensor + See :func:`oneflow.experimental.tan` + + """ + + return Tan()(input) + + +if __name__ == "__main__": + import doctest + + doctest.testmod() From 3a32727dc59ed695d872d94c13af5b411c518017 Mon Sep 17 00:00:00 2001 From: oneflow-ci-bot Date: Fri, 4 Jun 2021 05:11:32 +0000 Subject: [PATCH 15/18] auto format by CI --- oneflow/python/nn/modules/atanh.py | 7 +++++-- oneflow/python/nn/modules/tan.py | 6 ++++-- oneflow/python/test/modules/test_atanh.py | 4 +++- oneflow/python/test/modules/test_tan.py | 2 +- oneflow/python/test/tensor/test_tensor.py | 18 ++++++------------ 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/oneflow/python/nn/modules/atanh.py b/oneflow/python/nn/modules/atanh.py index b92ac034d70..c8dce813189 100644 --- a/oneflow/python/nn/modules/atanh.py +++ b/oneflow/python/nn/modules/atanh.py @@ -54,6 +54,7 @@ def atanh_op(input): return Atanh()(input) + @register_tensor_op("atanh") @experimental_api def atanh_op_tensor(x): @@ -65,6 +66,7 @@ def atanh_op_tensor(x): return Atanh()(x) + @oneflow_export("arctanh") @experimental_api def arctanh_op(input): @@ -75,6 +77,7 @@ def arctanh_op(input): return Atanh()(input) + @register_tensor_op("arctanh") @experimental_api def arctanh_op_tensor(input): @@ -87,6 +90,6 @@ def arctanh_op_tensor(input): if __name__ == "__main__": - import doctest + import doctest - doctest.testmod() + doctest.testmod() diff --git a/oneflow/python/nn/modules/tan.py b/oneflow/python/nn/modules/tan.py index 724667b3b59..4c070db6b7f 100644 --- a/oneflow/python/nn/modules/tan.py +++ b/oneflow/python/nn/modules/tan.py @@ -27,6 +27,7 @@ def __init__(self): def forward(self, x): return self._op(x)[0] + @oneflow_export("tan") @experimental_api def tan_op(input): @@ -53,6 +54,7 @@ def tan_op(input): return Tan()(input) + @register_tensor_op("tan") @experimental_api def tan_op_tensor(input): @@ -66,6 +68,6 @@ def tan_op_tensor(input): if __name__ == "__main__": - import doctest + import doctest - doctest.testmod() + doctest.testmod() diff --git a/oneflow/python/test/modules/test_atanh.py b/oneflow/python/test/modules/test_atanh.py index 202ae07d8cd..cadedcbbf3f 100644 --- a/oneflow/python/test/modules/test_atanh.py +++ b/oneflow/python/test/modules/test_atanh.py @@ -41,6 +41,7 @@ def _test_atanh_impl(test_case, shape, device): np.allclose(of_input.grad.numpy(), np_out_grad, 1e-4, 1e-4, equal_nan=True) ) + def _test_arctanh_impl(test_case, shape, device): np_input = np.random.random(shape) of_input = flow.Tensor( @@ -60,6 +61,7 @@ def _test_arctanh_impl(test_case, shape, device): np.allclose(of_input.grad.numpy(), np_out_grad, 1e-4, 1e-4, equal_nan=True) ) + @unittest.skipIf( not flow.unittest.env.eager_execution_enabled(), ".numpy() doesn't work in lazy mode", @@ -67,7 +69,7 @@ def _test_arctanh_impl(test_case, shape, device): class TestAtanh(flow.unittest.TestCase): def test_atanh(test_case): arg_dict = OrderedDict() - arg_dict["shape"] = [(2, 3), (2,3,4), (2, 4, 5, 6)] + arg_dict["shape"] = [(2, 3), (2, 3, 4), (2, 4, 5, 6)] arg_dict["device"] = ["cpu", "cuda"] for arg in GenArgList(arg_dict): _test_atanh_impl(test_case, *arg) diff --git a/oneflow/python/test/modules/test_tan.py b/oneflow/python/test/modules/test_tan.py index 6f3ef92d472..25bd6b8ff4c 100644 --- a/oneflow/python/test/modules/test_tan.py +++ b/oneflow/python/test/modules/test_tan.py @@ -49,7 +49,7 @@ def _test_tan_impl(test_case, shape, device): class TestTan(flow.unittest.TestCase): def test_tan(test_case): arg_dict = OrderedDict() - arg_dict["shape"] = [(2, 3), (2,3,4), (2, 4, 5, 6)] + arg_dict["shape"] = [(2, 3), (2, 3, 4), (2, 4, 5, 6)] arg_dict["device"] = ["cpu", "cuda"] for arg in GenArgList(arg_dict): _test_tan_impl(test_case, *arg) diff --git a/oneflow/python/test/tensor/test_tensor.py b/oneflow/python/test/tensor/test_tensor.py index 2dc3d1fac01..fddf484ced5 100644 --- a/oneflow/python/test/tensor/test_tensor.py +++ b/oneflow/python/test/tensor/test_tensor.py @@ -761,10 +761,8 @@ def test_pow_tensor_function(test_case): "numpy doesn't work in lazy mode", ) def test_tensor_atanh(test_case): - np_input = np.random.random((2,3)) - of_input = flow.Tensor( - np_input, dtype=flow.float32, requires_grad=True - ) + np_input = np.random.random((2, 3)) + of_input = flow.Tensor(np_input, dtype=flow.float32, requires_grad=True) of_out = of_input.atanh() np_out = np.arctanh(np_input) @@ -784,10 +782,8 @@ def test_tensor_atanh(test_case): "numpy doesn't work in lazy mode", ) def test_tensor_arctanh(test_case): - np_input = np.random.random((2,3)) - of_input = flow.Tensor( - np_input, dtype=flow.float32, requires_grad=True - ) + np_input = np.random.random((2, 3)) + of_input = flow.Tensor(np_input, dtype=flow.float32, requires_grad=True) of_out = of_input.arctanh() np_out = np.arctanh(np_input) @@ -807,10 +803,8 @@ def test_tensor_arctanh(test_case): "numpy doesn't work in lazy mode", ) def test_tensor_tan(test_case): - np_input = np.random.random((2,3)) - of_input = flow.Tensor( - np_input, dtype=flow.float32, requires_grad=True - ) + np_input = np.random.random((2, 3)) + of_input = flow.Tensor(np_input, dtype=flow.float32, requires_grad=True) of_out = of_input.tan() np_out = np.tan(np_input) From d726d7b3dbe3e8839a45034e114a66f4ca45dd98 Mon Sep 17 00:00:00 2001 From: aajjjtntn <68228554+aajjjtntn@users.noreply.github.com> Date: Fri, 4 Jun 2021 15:10:33 +0800 Subject: [PATCH 16/18] Update test_atanh.py use arg_dict[test_fun"] --- oneflow/python/test/modules/test_atanh.py | 88 ++++++++++++++++++----- 1 file changed, 69 insertions(+), 19 deletions(-) diff --git a/oneflow/python/test/modules/test_atanh.py b/oneflow/python/test/modules/test_atanh.py index cadedcbbf3f..b082413efab 100644 --- a/oneflow/python/test/modules/test_atanh.py +++ b/oneflow/python/test/modules/test_atanh.py @@ -22,43 +22,87 @@ from test_util import GenArgList -def _test_atanh_impl(test_case, shape, device): - np_input = np.random.random(shape) +def _test_atan(test_case, shape, device): + np_input = np.random.randn(*shape) of_input = flow.Tensor( np_input, dtype=flow.float32, device=flow.device(device), requires_grad=True ) - of_out = flow.atanh(of_input) - np_out = np.arctanh(np_input) + of_out = flow.atan(of_input) + np_out = np.arctan(np_input) test_case.assertTrue( - np.allclose(of_out.numpy(), np_out, 1e-4, 1e-4, equal_nan=True) + np.allclose(of_out.numpy(), np_out, 1e-5, 1e-5, equal_nan=True) ) of_out = of_out.sum() of_out.backward() - np_out_grad = 1.0 / (1.0 - np.square(np_input)) + np_out_grad = 1 / (1 + np_input ** 2) + + test_case.assertTrue( + np.allclose(of_input.grad.numpy(), np_out_grad, 1e-5, 1e-5, equal_nan=True) + ) + + +def _test_tensor_atan(test_case, shape, device): + np_input = np.random.randn(*shape) + of_input = flow.Tensor( + np_input, dtype=flow.float32, device=flow.device(device), requires_grad=True + ) + + of_out = of_input.atan() + np_out = np.arctan(np_input) + test_case.assertTrue( + np.allclose(of_out.numpy(), np_out, 1e-5, 1e-5, equal_nan=True) + ) + + of_out = of_out.sum() + of_out.backward() + np_out_grad = 1 / (1 + np_input ** 2) + test_case.assertTrue( - np.allclose(of_input.grad.numpy(), np_out_grad, 1e-4, 1e-4, equal_nan=True) + np.allclose(of_input.grad.numpy(), np_out_grad, 1e-5, 1e-5, equal_nan=True) ) -def _test_arctanh_impl(test_case, shape, device): - np_input = np.random.random(shape) +def _test_arctan(test_case, shape, device): + np_input = np.random.randn(*shape) of_input = flow.Tensor( np_input, dtype=flow.float32, device=flow.device(device), requires_grad=True ) - of_out = flow.arctanh(of_input) - np_out = np.arctanh(np_input) + of_out = flow.arctan(of_input) + np_out = np.arctan(np_input) test_case.assertTrue( - np.allclose(of_out.numpy(), np_out, 1e-4, 1e-4, equal_nan=True) + np.allclose(of_out.numpy(), np_out, 1e-5, 1e-5, equal_nan=True) ) of_out = of_out.sum() of_out.backward() - np_out_grad = 1.0 / (1.0 - np.square(np_input)) + np_out_grad = 1 / (1 + np_input ** 2) + test_case.assertTrue( - np.allclose(of_input.grad.numpy(), np_out_grad, 1e-4, 1e-4, equal_nan=True) + np.allclose(of_input.grad.numpy(), np_out_grad, 1e-5, 1e-5, equal_nan=True) + ) + + +def _test_tensor_arctan(test_case, shape, device): + np_input = np.random.randn(*shape) + of_input = flow.Tensor( + np_input, dtype=flow.float32, device=flow.device(device), requires_grad=True + ) + + of_out = of_input.arctan() + np_out = np.arctan(np_input) + test_case.assertTrue( + np.allclose(of_out.numpy(), np_out, 1e-5, 1e-5, equal_nan=True) + ) + + of_out = of_out.sum() + of_out.backward() + np_out_grad = 1 / (1 + np_input ** 2) + + test_case.assertTrue( + np.allclose(of_input.grad.numpy(), np_out_grad, 1e-5, 1e-5, equal_nan=True) ) @@ -66,15 +110,21 @@ def _test_arctanh_impl(test_case, shape, device): not flow.unittest.env.eager_execution_enabled(), ".numpy() doesn't work in lazy mode", ) -class TestAtanh(flow.unittest.TestCase): - def test_atanh(test_case): +class TestAtan(flow.unittest.TestCase): + def test_atan(test_case): arg_dict = OrderedDict() - arg_dict["shape"] = [(2, 3), (2, 3, 4), (2, 4, 5, 6)] + arg_dict["test_fun"] = [ + _test_atan, + _test_tensor_atan, + _test_arctan, + _test_tensor_arctan, + ] + arg_dict["shape"] = [(2,), (2, 3), (2, 4, 5, 6)] arg_dict["device"] = ["cpu", "cuda"] for arg in GenArgList(arg_dict): - _test_atanh_impl(test_case, *arg) - _test_arctanh_impl(test_case, *arg) + arg[0](test_case, *arg[1:]) if __name__ == "__main__": unittest.main() + From c9275bc9a360133a13f09e045fcb73ac261e289f Mon Sep 17 00:00:00 2001 From: jackalcooper Date: Fri, 4 Jun 2021 15:35:10 +0800 Subject: [PATCH 17/18] Revert "Update test_atanh.py" This reverts commit d726d7b3dbe3e8839a45034e114a66f4ca45dd98. --- oneflow/python/test/modules/test_atanh.py | 88 +++++------------------ 1 file changed, 19 insertions(+), 69 deletions(-) diff --git a/oneflow/python/test/modules/test_atanh.py b/oneflow/python/test/modules/test_atanh.py index b082413efab..cadedcbbf3f 100644 --- a/oneflow/python/test/modules/test_atanh.py +++ b/oneflow/python/test/modules/test_atanh.py @@ -22,87 +22,43 @@ from test_util import GenArgList -def _test_atan(test_case, shape, device): - np_input = np.random.randn(*shape) +def _test_atanh_impl(test_case, shape, device): + np_input = np.random.random(shape) of_input = flow.Tensor( np_input, dtype=flow.float32, device=flow.device(device), requires_grad=True ) - of_out = flow.atan(of_input) - np_out = np.arctan(np_input) + of_out = flow.atanh(of_input) + np_out = np.arctanh(np_input) test_case.assertTrue( - np.allclose(of_out.numpy(), np_out, 1e-5, 1e-5, equal_nan=True) + np.allclose(of_out.numpy(), np_out, 1e-4, 1e-4, equal_nan=True) ) of_out = of_out.sum() of_out.backward() - np_out_grad = 1 / (1 + np_input ** 2) - - test_case.assertTrue( - np.allclose(of_input.grad.numpy(), np_out_grad, 1e-5, 1e-5, equal_nan=True) - ) - - -def _test_tensor_atan(test_case, shape, device): - np_input = np.random.randn(*shape) - of_input = flow.Tensor( - np_input, dtype=flow.float32, device=flow.device(device), requires_grad=True - ) - - of_out = of_input.atan() - np_out = np.arctan(np_input) - test_case.assertTrue( - np.allclose(of_out.numpy(), np_out, 1e-5, 1e-5, equal_nan=True) - ) - - of_out = of_out.sum() - of_out.backward() - np_out_grad = 1 / (1 + np_input ** 2) - + np_out_grad = 1.0 / (1.0 - np.square(np_input)) test_case.assertTrue( - np.allclose(of_input.grad.numpy(), np_out_grad, 1e-5, 1e-5, equal_nan=True) + np.allclose(of_input.grad.numpy(), np_out_grad, 1e-4, 1e-4, equal_nan=True) ) -def _test_arctan(test_case, shape, device): - np_input = np.random.randn(*shape) +def _test_arctanh_impl(test_case, shape, device): + np_input = np.random.random(shape) of_input = flow.Tensor( np_input, dtype=flow.float32, device=flow.device(device), requires_grad=True ) - of_out = flow.arctan(of_input) - np_out = np.arctan(np_input) + of_out = flow.arctanh(of_input) + np_out = np.arctanh(np_input) test_case.assertTrue( - np.allclose(of_out.numpy(), np_out, 1e-5, 1e-5, equal_nan=True) + np.allclose(of_out.numpy(), np_out, 1e-4, 1e-4, equal_nan=True) ) of_out = of_out.sum() of_out.backward() - np_out_grad = 1 / (1 + np_input ** 2) - + np_out_grad = 1.0 / (1.0 - np.square(np_input)) test_case.assertTrue( - np.allclose(of_input.grad.numpy(), np_out_grad, 1e-5, 1e-5, equal_nan=True) - ) - - -def _test_tensor_arctan(test_case, shape, device): - np_input = np.random.randn(*shape) - of_input = flow.Tensor( - np_input, dtype=flow.float32, device=flow.device(device), requires_grad=True - ) - - of_out = of_input.arctan() - np_out = np.arctan(np_input) - test_case.assertTrue( - np.allclose(of_out.numpy(), np_out, 1e-5, 1e-5, equal_nan=True) - ) - - of_out = of_out.sum() - of_out.backward() - np_out_grad = 1 / (1 + np_input ** 2) - - test_case.assertTrue( - np.allclose(of_input.grad.numpy(), np_out_grad, 1e-5, 1e-5, equal_nan=True) + np.allclose(of_input.grad.numpy(), np_out_grad, 1e-4, 1e-4, equal_nan=True) ) @@ -110,21 +66,15 @@ def _test_tensor_arctan(test_case, shape, device): not flow.unittest.env.eager_execution_enabled(), ".numpy() doesn't work in lazy mode", ) -class TestAtan(flow.unittest.TestCase): - def test_atan(test_case): +class TestAtanh(flow.unittest.TestCase): + def test_atanh(test_case): arg_dict = OrderedDict() - arg_dict["test_fun"] = [ - _test_atan, - _test_tensor_atan, - _test_arctan, - _test_tensor_arctan, - ] - arg_dict["shape"] = [(2,), (2, 3), (2, 4, 5, 6)] + arg_dict["shape"] = [(2, 3), (2, 3, 4), (2, 4, 5, 6)] arg_dict["device"] = ["cpu", "cuda"] for arg in GenArgList(arg_dict): - arg[0](test_case, *arg[1:]) + _test_atanh_impl(test_case, *arg) + _test_arctanh_impl(test_case, *arg) if __name__ == "__main__": unittest.main() - From 55d54c9747174cc2fa7dbc42870d8340f2243ba7 Mon Sep 17 00:00:00 2001 From: jackalcooper Date: Fri, 4 Jun 2021 19:13:01 +0800 Subject: [PATCH 18/18] fix --- oneflow/python/nn/modules/atanh.py | 4 ++-- oneflow/python/nn/modules/tan.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/oneflow/python/nn/modules/atanh.py b/oneflow/python/nn/modules/atanh.py index c8dce813189..57ee341f551 100644 --- a/oneflow/python/nn/modules/atanh.py +++ b/oneflow/python/nn/modules/atanh.py @@ -61,7 +61,7 @@ def atanh_op_tensor(x): r""" atanh() -> Tensor See :func:`oneflow.experimental.atanh` - + """ return Atanh()(x) @@ -92,4 +92,4 @@ def arctanh_op_tensor(input): if __name__ == "__main__": import doctest - doctest.testmod() + doctest.testmod(raise_on_error=True) diff --git a/oneflow/python/nn/modules/tan.py b/oneflow/python/nn/modules/tan.py index 4c070db6b7f..118e6788734 100644 --- a/oneflow/python/nn/modules/tan.py +++ b/oneflow/python/nn/modules/tan.py @@ -61,7 +61,7 @@ def tan_op_tensor(input): r""" tan() -> Tensor See :func:`oneflow.experimental.tan` - + """ return Tan()(input) @@ -70,4 +70,4 @@ def tan_op_tensor(input): if __name__ == "__main__": import doctest - doctest.testmod() + doctest.testmod(raise_on_error=True)