I am trying to find the maximum value of an Eigen tensor. I know how to do this using Eigen matrices but obviously this is not working for a tensor:
Example
static const int nx = 4;
static const int ny = 4;
static const int nz = 4;
Eigen::Tensor<double, 3> Test(nx,ny,nz);
Test.setZero();
Eigen::Tensor<double, 3> MaxTest(nx,ny,nz);
MaxTest.setZero();
MaxTest = Test.maxCoeff();
Usually for an Eigen matrix I would do the following:
MaxTest = Test.array().maxCoeff();
But this is not working, instead I get the error:
class "Eigen::Tensor<std::complex<double>, 3, 0, Eigen::DenseIndex>" has no member "maxCoeff"
Is there another way to get the maximum value of this tensor? Something equivalent to max(max(max(tensor)))
in MATLAB.
CodePudding user response:
You can use maximum()
, see the documentation:
static const int nx = 4;
static const int ny = 4;
static const int nz = 4;
Eigen::Tensor<double, 3> MaxTest(nx,ny,nz);
MaxTest.setZero();
Eigen::Tensor<double, 0> MaxAsTensor = MaxTest.maximum();
double Max = MaxAsTensor(0);
std::cout << "Maximum = " << max_dbl << std::endl;