diff --git a/unsupported/Eigen/CXX11/src/Tensor/README.md b/unsupported/Eigen/CXX11/src/Tensor/README.md index 2e785efcd..e4b5e2ec9 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/README.md +++ b/unsupported/Eigen/CXX11/src/Tensor/README.md @@ -886,6 +886,23 @@ containing the natural logarithms of the original tensor. Returns a tensor of the same type and dimensions as the original tensor containing the absolute values of the original tensor. +### arg() + +Returns a tensor with the same dimensions as the original tensor +containing the complex argument (phase angle) of the values of the +original tensor. + +### real() + +Returns a tensor with the same dimensions as the original tensor +containing the real part of the complex values of the original tensor. + +### imag() + +Returns a tensor with the same dimensions as the orginal tensor +containing the imaginary part of the complex values of the original +tensor. + ### pow(Scalar exponent) Returns a tensor of the same type and dimensions as the original tensor diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorBase.h b/unsupported/Eigen/CXX11/src/Tensor/TensorBase.h index 8eaf96a7b..3e07a6f99 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorBase.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorBase.h @@ -311,6 +311,12 @@ class TensorBase return unaryExpr(internal::scalar_abs_op()); } + EIGEN_DEVICE_FUNC + EIGEN_STRONG_INLINE const TensorCwiseUnaryOp, const Derived> + arg() const { + return unaryExpr(internal::scalar_arg_op()); + } + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const TensorCwiseUnaryOp, const Derived> clip(Scalar min, Scalar max) const { diff --git a/unsupported/test/cxx11_tensor_of_complex.cpp b/unsupported/test/cxx11_tensor_of_complex.cpp index 99e18076a..b2f5994dc 100644 --- a/unsupported/test/cxx11_tensor_of_complex.cpp +++ b/unsupported/test/cxx11_tensor_of_complex.cpp @@ -47,6 +47,20 @@ static void test_abs() } } +static void test_arg() +{ + Tensor, 1> data1(3); + Tensor, 1> data2(3); + data1.setRandom(); + data2.setRandom(); + + Tensor arg1 = data1.arg(); + Tensor arg2 = data2.arg(); + for (int i = 0; i < 3; ++i) { + VERIFY_IS_APPROX(arg1(i), std::arg(data1(i))); + VERIFY_IS_APPROX(arg2(i), std::arg(data2(i))); + } +} static void test_conjugate() { @@ -98,6 +112,7 @@ EIGEN_DECLARE_TEST(cxx11_tensor_of_complex) { CALL_SUBTEST(test_additions()); CALL_SUBTEST(test_abs()); + CALL_SUBTEST(test_arg()); CALL_SUBTEST(test_conjugate()); CALL_SUBTEST(test_contractions()); }