Error when taking max value of Eigen tensor
I am trying to get the max value of an Eigen tensor, something equivalent to
max(max(max(T)))
in MATLAB. The thing is I got a case that works for me:
1 2 3 4 5 6 7 8 9 10
|
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> AbsMaxAsTensor = MaxTest.abs().maximum();
double Max = AbsMaxAsTensor(0);
std::cout << "Maximum = " << Max << std::endl;
| |
However, now when I try to apply this in a function as the following,
1 2 3 4
|
double vMaxArr[10];
Eigen::Tensor<double, 0> AbsMaxAsTensor = Test.maximum();
vMaxArr[0] = AbsMaxAsTensor(0);
| |
where Test is passed to the function as
Eigen::Tensor<std::complex<double>, 3>& Test
Then I get the error:
1 2 3 4 5
|
error: cannot convert ‘Eigen::TensorEvaluator<Eigen::Tensor<double, 0>, Eigen::DefaultDevice>::EvaluatorPointerType’ {aka ‘double*’} to ‘Eigen::TensorReductionEvaluatorBase<const Eigen::TensorReductionOp<Eigen::internal::MaxReducer<std::complex<double>, 0>, const Eigen::DimensionList<long int, 3>, const Eigen::Tensor<std::complex<double>, 3>, Eigen::MakePointer>, Eigen::DefaultDevice>::EvaluatorPointerType’ {aka ‘std::complex<double>*’}
152 | return m_rightImpl.evalSubExprsIfNeeded(m_leftImpl.data());
| ^
| |
| Eigen::TensorEvaluator<Eigen::Tensor<double, 0>, Eigen::DefaultDevice>::EvaluatorPointerType {aka double*}
| |
I am not sure what the issue is?
Looks like you forgot to call
abs in line 3
Maybe it should read
3 4
|
Eigen::Tensor<double, 0> AbsMaxAsTensor = Test.abs().maximum();
vMaxArr[0] = AbsMaxAsTensor(0);
| |
Last edited on
@mbozzi
But I am trying to just get the maximum value without the absolute value if possible.
where Test is passed to the function as Eigen::Tensor<std::complex<double>, 3>& Test |
You can’t take the maximum of a complex number - it would make no sense.
It does make sense to take the maximum of a real number, which is what you would get by applying abs() first.
@lastchance
Thanks! I am confusing myself A LOT because I am using MATLAB to contrast and compare.
Topic archived. No new replies allowed.