diff options
Diffstat (limited to 'tensorflow/cc/gradients/math_grad_test.cc')
-rw-r--r-- | tensorflow/cc/gradients/math_grad_test.cc | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/tensorflow/cc/gradients/math_grad_test.cc b/tensorflow/cc/gradients/math_grad_test.cc index 1653b04378..48b3ddbe90 100644 --- a/tensorflow/cc/gradients/math_grad_test.cc +++ b/tensorflow/cc/gradients/math_grad_test.cc @@ -48,6 +48,9 @@ class CWiseUnaryGradTest : public ::testing::Test { SINH, COSH, TANH, + ASINH, + ACOSH, + ATANH, SIGMOID, SIGN, SIN, @@ -122,6 +125,15 @@ class CWiseUnaryGradTest : public ::testing::Test { case TANH: y = Tanh(scope_, x); break; + case ASINH: + y = Asinh(scope_, x); + break; + case ACOSH: + y = Acosh(scope_, x); + break; + case ATANH: + y = Atanh(scope_, x); + break; case SIGMOID: y = Sigmoid(scope_, x); break; @@ -413,6 +425,76 @@ TEST_F(CWiseUnaryGradTest, Tanh_Complex) { TestCWiseGrad<complex64>(TANH, x_fn, dy_fn, dx_fn); } +TEST_F(CWiseUnaryGradTest, Asinh) { + auto x_fn = [this](const int i) { return RV({0, -1, 1, -2, 2, -3, 3}); }; + auto dy_fn = [this](const float x) { return x + RV({-2, 2, -3, 3, -4, 4}); }; + auto dx_fn = [this](const float x, const float dy) { + auto y = std::asinh(x); + return dy / std::cosh(y); + }; + TestCWiseGrad<float>(ASINH, x_fn, dy_fn, dx_fn); +} + +TEST_F(CWiseUnaryGradTest, Asinh_Complex) { + auto x_fn = [this](const int i) { + return CRV({{1, 0}, {0, 1}, {2, -1}, {1, 2}, {3, 4}}); + }; + auto dy_fn = [this](const complex64& x) { + return x + CRV({{-2, 2}, {-3, 3}, {1, -4}}); + }; + auto dx_fn = [this](const complex64& x, const complex64& dy) { + auto y = std::asinh(x); + return dy / conjugate(std::cosh(y)); + }; + TestCWiseGrad<complex64>(ASINH, x_fn, dy_fn, dx_fn); +} + +TEST_F(CWiseUnaryGradTest, Acosh) { + auto x_fn = [this](const int i) { return RV({1, 2, 3, 4, 5, 6, 7}); }; + auto dy_fn = [this](const float x) { return x + RV({8, 9, 10, 11, 12, 13, 14}); }; + auto dx_fn = [this](const float x, const float dy) { + auto y = std::acosh(x); + return dy / std::sinh(y); + }; + TestCWiseGrad<float>(ACOSH, x_fn, dy_fn, dx_fn); +} + +TEST_F(CWiseUnaryGradTest, Acosh_Complex) { + auto x_fn = [this](const int i) { + return CRV({{1, 1}, {2, 1}, {1, 4}, {1, 2}, {3, 4}}); + }; + auto dy_fn = [this](const complex64& x) { + return x + CRV({{2, 2}, {3, 3}, {1, 4}}); + }; + auto dx_fn = [this](const complex64& x, const complex64& dy) { + auto y = std::acosh(x); + return dy / conjugate(std::sinh(y)); + }; + TestCWiseGrad<complex64>(ACOSH, x_fn, dy_fn, dx_fn); +} + +TEST_F(CWiseUnaryGradTest, Atanh) { + auto x_fn = [this](const int i) { return RV({0, -0.5, 0.5, -0.1, 0.1}); }; + auto dy_fn = [this](const float x) { return x + RV({-2, 2, -3, 3, -4, 4}); }; + auto dx_fn = [this](const float x, const float dy) { + return dy * (1. / (1. - x * x)); + }; + TestCWiseGrad<float>(ATANH, x_fn, dy_fn, dx_fn); +} + +TEST_F(CWiseUnaryGradTest, Atanh_Complex) { + auto x_fn = [this](const int i) { + return CRV({{0.1, 0}, {0, 0.1}, {0.2, -0.1}, {0.1, 0.2}, {0.3, 0.4}}); + }; + auto dy_fn = [this](const complex64& x) { + return x + CRV({{-2, 2}, {-3, 3}, {1, -4}}); + }; + auto dx_fn = [this](const complex64& x, const complex64& dy) { + return dy / conjugate(one_ - x * x); + }; + TestCWiseGrad<complex64>(ATANH, x_fn, dy_fn, dx_fn); +} + TEST_F(CWiseUnaryGradTest, Sigmoid) { auto x_fn = [this](const int i) { return RV({0, -1, 1, -2, 2, -3, 3}); }; auto dy_fn = [this](const float x) { return x + RV({-2, 2, -3, 3, -4, 4}); }; |