I have the following script
#include <iostream>
#include <unsupported/Eigen/CXX11/Tensor>
int main() {
using namespace Eigen;
Tensor<std::complex<double>, 4> xi1st(3, 3, 3, 3);
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
for (int k = 0; k < 3; ++k) {
for (int l = 0; l < 3; ++l) {
xi1st(i, j, k, l) = std::complex<double>(i + j + k + l, i - j + k - l);
}
}
}
}
int i = 1, j = 1, k = 1;
auto xi1st_slice = xi1st.slice(Eigen::array<Index, 4>({0, i, j, k}), Eigen::array<Index, 4>({3, 1, 1, 1}));
auto xi1st_conj = xi1st_slice.conjugate();
std::complex<double> xi1st_sum = xi1st_conj.sum();
std::cout << "xi1st_sum: " << xi1st_sum << std::endl;
return 0;
}
Which generates the compile error
<source>: In function 'int main()':
<source>:31:52: error: conversion from 'const Eigen::TensorReductionOp<Eigen::internal::SumReducer<std::complex<double> >, const Eigen::DimensionList<long int, 4>, const Eigen::TensorCwiseUnaryOp<Eigen::internal::scalar_conjugate_op<std::complex<double> >, const Eigen::TensorSlicingOp<const std::array<long int, 4>, const std::array<long int, 4>, Eigen::Tensor<std::complex<double>, 4> > >, Eigen::MakePointer>' to non-scalar type 'std::complex<double>' requested
31 | std::complex<double> xi1st_sum = xi1st_conj.sum();
| ~~~~~~~~~~~~~~^~
Compiler returned: 1
I can’t find a way to extract my scalar from the .sum()
operation. Ideally I would like to just chain everything in a single command, but even doing it step by step seems to be causing problems, what are we missing here?