diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/eltwise_grad_cpu_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/cpu/eltwise_grad_cpu_kernel.cc index fd044e60f73..5780d1e546d 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/eltwise_grad_cpu_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/eltwise_grad_cpu_kernel.cc @@ -170,7 +170,7 @@ template void EltWiseGradCPUKernel::AsinhGrad(const T *input1, const T *input2, T *out, size_t start, size_t end) const { for (size_t i = start; i < end; i++) { T dividend = input2[i]; - T divisor = sqrt(1 + input1[i] * input1[i]); + T divisor = cosh(input1[i]); if (divisor == 0) { if (dividend == 0) { out[i] = std::numeric_limits::quiet_NaN(); @@ -191,7 +191,7 @@ template void EltWiseGradCPUKernel::AcoshGrad(const T *input1, const T *input2, T *out, size_t start, size_t end) const { for (size_t i = start; i < end; i++) { T dividend = input2[i]; - T divisor = sqrt(input1[i] * input1[i] - 1); + T divisor = sinh(input1[i]); if (divisor == 0) { if (dividend == 0) { out[i] = std::numeric_limits::quiet_NaN(); diff --git a/tests/st/ops/cpu/test_acosh_grad_op.py b/tests/st/ops/cpu/test_acosh_grad_op.py index 033cd8067e8..15dd3aaa1c8 100644 --- a/tests/st/ops/cpu/test_acosh_grad_op.py +++ b/tests/st/ops/cpu/test_acosh_grad_op.py @@ -37,10 +37,10 @@ class NetAcoshGrad(nn.Cell): @pytest.mark.platform_x86_cpu @pytest.mark.env_onecard def test_acosh_grad(): - x = np.array([5, 4, 3]).astype('float32') + out = np.array([5, 4, 3]).astype('float32') dy = np.array([1, 0, -1]).astype('float32') acosh_grad = NetAcoshGrad() - output = acosh_grad(Tensor(x), Tensor(dy)) + output = acosh_grad(Tensor(out), Tensor(dy)) print(output) - expect = dy / np.sqrt(x * x - 1) + expect = dy / np.sinh(out) assert np.allclose(output.asnumpy(), expect) diff --git a/tests/st/ops/cpu/test_asinh_grad_op.py b/tests/st/ops/cpu/test_asinh_grad_op.py index 916d74b9eca..ef0bc25798e 100644 --- a/tests/st/ops/cpu/test_asinh_grad_op.py +++ b/tests/st/ops/cpu/test_asinh_grad_op.py @@ -37,10 +37,10 @@ class NetAsinhGrad(nn.Cell): @pytest.mark.platform_x86_cpu @pytest.mark.env_onecard def test_asinh_grad(): - x = np.array([-0.5, 0, 0.5]).astype('float32') + out = np.array([-0.5, 0, 0.5]).astype('float32') dy = np.array([1, 0, -1]).astype('float32') asinh_grad = NetAsinhGrad() - output = asinh_grad(Tensor(x), Tensor(dy)) + output = asinh_grad(Tensor(out), Tensor(dy)) print(output) - expect = dy / np.sqrt(1 + x * x) + expect = dy / np.cosh(out) assert np.allclose(output.asnumpy(), expect)