support arcsinh arctanh

This commit is contained in:
fengyihang 2022-10-25 14:44:08 +08:00
parent d8463c0547
commit 3240bb2b74
8 changed files with 138 additions and 0 deletions

View File

@ -0,0 +1,6 @@
mindspore.Tensor.arcsinh
=========================
.. py:method:: mindspore.Tensor.arcsinh()
参考 `Tensor.asinh() <https://www.mindspore.cn/docs/zh-CN/master/api_python/mindspore/Tensor/mindspore.Tensor.asinh.html>`_

View File

@ -0,0 +1,6 @@
mindspore.Tensor.arctanh
=========================
.. py:method:: mindspore.Tensor.arctanh()
参考 `Tensor.atanh() <https://www.mindspore.cn/docs/zh-CN/master/api_python/mindspore/Tensor/mindspore.Tensor.atanh.html>`_

View File

@ -71,8 +71,10 @@ mindspore.Tensor
mindspore.Tensor.asin
mindspore.Tensor.addmv
mindspore.Tensor.asinh
mindspore.Tensor.arcsinh
mindspore.Tensor.atan
mindspore.Tensor.atanh
mindspore.Tensor.arctanh
mindspore.Tensor.atan2
mindspore.Tensor.bernoulli
mindspore.Tensor.bitwise_and

View File

@ -311,8 +311,10 @@ BuiltInTypeMap &GetMethodMap() {
{"asin", std::string("asin")}, // asin()
{"addmv", std::string("addmv")}, // addmv()
{"asinh", std::string("asinh")}, // asinh()
{"arcsinh", std::string("asinh")}, // arcsinh()
{"atan", std::string("atan")}, // atan()
{"atanh", std::string("atanh")}, // atanh()
{"arctanh", std::string("atanh")}, // arctanh()
{"bmm", std::string("bmm")}, // bmm()
{"value", std::string("value_")}, // P.Load(param, U)
{"to", std::string("to")}, // to()

View File

@ -3226,6 +3226,13 @@ def asinh(x):
return F.asinh(x)
def arcsinh(x):
r"""
Computes inverse hyperbolic sine of the input element-wise.
"""
return F.asinh(x)
def atan(x):
r"""
Computes inverse tangent of the input element-wise.
@ -3240,6 +3247,13 @@ def atanh(x):
return F.atanh(x)
def arctanh(x):
r"""
Computes inverse hyperbolic tangent of the input element-wise.
"""
return F.atanh(x)
def bmm(input_x, mat2):
r"""
Computes matrix multiplication between two tensors by batch.

View File

@ -5847,6 +5847,14 @@ class Tensor(Tensor_):
self._init_check()
return tensor_operator_registry.get('asinh')(self)
def arcsinh(self):
r"""
See `Tensor.asinh()
<https://www.mindspore.cn/docs/zh-CN/master/api_python/mindspore/Tensor/mindspore.Tensor.asinh.html>`_.
"""
self._init_check()
return tensor_operator_registry.get('asinh')(self)
def atan(self):
r"""
Computes the trigonometric inverse tangent of the input element-wise.
@ -5902,6 +5910,14 @@ class Tensor(Tensor_):
self._init_check()
return tensor_operator_registry.get('atanh')(self)
def arctanh(self):
r"""
See `Tensor.atanh()
<https://www.mindspore.cn/docs/zh-CN/master/api_python/mindspore/Tensor/mindspore.Tensor.atanh.html>`_.
"""
self._init_check()
return tensor_operator_registry.get('atanh')(self)
def bmm(self, mat2):
r"""
Computes matrix multiplication between two tensors by batch.

View File

@ -0,0 +1,46 @@
# Copyright 2022 Huawei Technologies Co., Ltd
#
# 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 numpy as np
import pytest
import mindspore as ms
import mindspore.nn as nn
from mindspore import Tensor
class Arcsinh(nn.Cell):
def construct(self, x):
return x.arcsinh()
@pytest.mark.level0
@pytest.mark.platform_x86_cpu
@pytest.mark.platform_arm_cpu
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@pytest.mark.env_onecard
@pytest.mark.parametrize('mode', [ms.GRAPH_MODE, ms.PYNATIVE_MODE])
def test_tensor_arcsinh(mode):
"""
Feature: tensor.arcsinh
Description: Verify the result of arcsinh
Expectation: success
"""
ms.set_context(mode=mode)
x = Tensor(np.array([-5.0, 1.5, 3.0, 100.0]), ms.float32)
net = Arcsinh()
output = net(x)
expect_output = [-2.3124382, 1.1947632, 1.8184465, 5.298342]
assert np.allclose(output.asnumpy(), expect_output)

View File

@ -0,0 +1,46 @@
# Copyright 2022 Huawei Technologies Co., Ltd
#
# 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 numpy as np
import pytest
import mindspore as ms
import mindspore.nn as nn
from mindspore import Tensor
class Arctanh(nn.Cell):
def construct(self, x):
return x.arctanh()
@pytest.mark.level0
@pytest.mark.platform_x86_cpu
@pytest.mark.platform_arm_cpu
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@pytest.mark.env_onecard
@pytest.mark.parametrize('mode', [ms.GRAPH_MODE, ms.PYNATIVE_MODE])
def test_tensor_arctanh(mode):
"""
Feature: tensor.arctanh
Description: Verify the result of arctanh
Expectation: success
"""
ms.set_context(mode=mode)
x = Tensor(np.array([0, -0.5]), ms.float32)
net = Arctanh()
output = net(x)
expect_output = [0., -0.54930615]
assert np.allclose(output.asnumpy(), expect_output)