mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-06-04 18:54:00 +08:00
Added a method to conjugate the content of a tensor or the result of a tensor expression.
This commit is contained in:
parent
17e93ba148
commit
de345eff2e
@ -170,6 +170,12 @@ class TensorBase<Derived, ReadOnlyAccessors>
|
||||
return unaryExpr(internal::scalar_abs_op<Scalar>());
|
||||
}
|
||||
|
||||
EIGEN_DEVICE_FUNC
|
||||
EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_conjugate_op<Scalar>, const Derived>
|
||||
conjugate() const {
|
||||
return unaryExpr(internal::scalar_conjugate_op<Scalar>());
|
||||
}
|
||||
|
||||
EIGEN_DEVICE_FUNC
|
||||
EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_pow_op<Scalar>, const Derived>
|
||||
pow(Scalar exponent) const {
|
||||
|
@ -48,6 +48,25 @@ static void test_abs()
|
||||
}
|
||||
|
||||
|
||||
static void test_conjugate()
|
||||
{
|
||||
Tensor<std::complex<float>, 1> data1(3);
|
||||
Tensor<std::complex<double>, 1> data2(3);
|
||||
Tensor<int, 1> data3(3);
|
||||
data1.setRandom();
|
||||
data2.setRandom();
|
||||
data3.setRandom();
|
||||
|
||||
Tensor<std::complex<float>, 1> conj1 = data1.conjugate();
|
||||
Tensor<std::complex<double>, 1> conj2 = data2.conjugate();
|
||||
Tensor<int, 1> conj3 = data3.conjugate();
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
VERIFY_IS_APPROX(conj1(i), std::conj(data1(i)));
|
||||
VERIFY_IS_APPROX(conj2(i), std::conj(data2(i)));
|
||||
VERIFY_IS_APPROX(conj3(i), data3(i));
|
||||
}
|
||||
}
|
||||
|
||||
static void test_contractions()
|
||||
{
|
||||
Tensor<std::complex<float>, 4> t_left(30, 50, 8, 31);
|
||||
@ -77,5 +96,6 @@ void test_cxx11_tensor_of_complex()
|
||||
{
|
||||
CALL_SUBTEST(test_additions());
|
||||
CALL_SUBTEST(test_abs());
|
||||
CALL_SUBTEST(test_conjugate());
|
||||
CALL_SUBTEST(test_contractions());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user