Tensor .select() with mixed tensor/scalar arguments
Submitted by Tobias Wood
Assigned to Nobody
Link to original bugzilla bug (#1772)
Version: 3.4 (development)
Description
As discussed on the mailing list, the following program does not compile:
#include <unsupported/Eigen/CXX11/Tensor>
int main(const int argc, const char *const argv[])
{
Eigen::Tensor<float, 2> ft_A(2, 4), ft_B(2, 4), ft_result(2, 4);
ft_A.setRandom();
ft_B.setZero();
ft_result = (ft_A < 0.5f).select(ft_A, ft_B);
ft_result = (ft_A < 0.5f).select(ft_A, 0.f);
}
The first call to ft_result compiles fine, but the second does not because the second argument is a scalar.
Further notes from Christoph:
Your code works fine with Eigen::ArrayXXf
instead of
Eigen::Tensor<float,2>
, so making this work for Tensor as well would
not be a bad idea. Feel free to open a bug for that.
As a workaround, you can write:
ft_result = (ft_A < 0.5f).select(ft_A, ft_A.constant(0.0f));
This is also inconsistent with the Array-API, where you would need to
write (instead of ft_A.constant(0.0f)
):
ArrayXXf::Constant(0.0f, ft_A.rows(), ft_A.cols());