Fix vectorized reductions for Eigen::half

Fixes compiler errors in expressions that look like

  Eigen::Matrix<Eigen::half, 3, 1>::Random().maxCoeff()

The error comes from the code that creates the initial value for
vectorized reductions. The fix is to specify the scalar type of the
reduction's initial value.

The cahnge is necessary for Eigen::half because unlike other types,
Eigen::half scalars cannot be implicitly created from integers.
This commit is contained in:
Alex Druinsky 2021-10-20 16:03:12 -07:00
parent 99600bd1a6
commit d0e3791b1a

View File

@ -56,12 +56,17 @@ struct packetwise_redux_traits
/* Value to be returned when size==0 , by default let's return 0 */
template<typename PacketType,typename Func>
EIGEN_DEVICE_FUNC
PacketType packetwise_redux_empty_value(const Func& ) { return pset1<PacketType>(0); }
PacketType packetwise_redux_empty_value(const Func& ) {
const typename unpacket_traits<PacketType>::type zero(0);
return pset1<PacketType>(zero);
}
/* For products the default is 1 */
template<typename PacketType,typename Scalar>
EIGEN_DEVICE_FUNC
PacketType packetwise_redux_empty_value(const scalar_product_op<Scalar,Scalar>& ) { return pset1<PacketType>(1); }
PacketType packetwise_redux_empty_value(const scalar_product_op<Scalar,Scalar>& ) {
return pset1<PacketType>(Scalar(1));
}
/* Perform the actual reduction */
template<typename Func, typename Evaluator,