Re: [eigen] Tensor reduction with .all() or .any()

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


Thanks a lot, Antonio!

On Fri, Jun 10, 2022, at 17:18, Antonio Sanchez wrote:
It is a bool tensor, so cast<bool>() is a no-op (casts to a bool tensor again).  You want to access the actual boolean value.  For an n-d tensor, you do this via
tensor(idx1, ..., idxn).  For a 0-d (constant) tensor, that ends up just being tensor().

https://godbolt.org/z/zvxfx9Wff

On Fri, Jun 10, 2022 at 8:11 AM Alberto Luaces <eigen@xxxxxxxxxxxxxxxxxxxx> wrote:

That's very informative, thanks!

I realize that the std::cout call is working because Eigen::Tensor implements output routines to streams, and that is why your example works.

However, my aim was to use that _expression_ into a BOOST_TEST condition, and I'm unable to extract the bool value from it, even using Eigen::Tensor::cast<bool>:

https://godbolt.org/z/fjdh9Y4e3

On Fri, Jun 10, 2022, at 16:58, Antonio Sanchez wrote:
The `Eigen::Tensor<bool, 0>` should have worked.

On Fri, Jun 10, 2022 at 4:40 AM Alberto Luaces <eigen@xxxxxxxxxxxxxxxxxxxx> wrote:
Hello, I'm having problems trying to find if some condition is failing for any of the elements of a tensor:

Eigen::Tensor<double, 5> errors(21, 21, 21, 21, 21);

...

// This does not work
bool allTestsPassed = (errors < tolerance).all();

I have tried

Eigen::Tensor<bool, 0> allTestsPassed;

 and

Eigen::Tensor<bool, 1> allTestsPassed(1);

but I cannot get the result, either because there are compilation errors or either I have runtime size mismatches when assigning the value of allTestsPassed variable.

Thanks.

--
  Alberto



--
  Alberto



--
  Alberto




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/