mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Eliminate boolean product warnings by factoring out a
`combine_scalar_factors` helper function.
This commit is contained in:
committed by
Rasmus Munk Larsen
parent
070d303d56
commit
12dda34b15
@@ -618,6 +618,47 @@ template<typename T> const typename T::Scalar* extract_data(const T& m)
|
||||
return extract_data_selector<T>::run(m);
|
||||
}
|
||||
|
||||
/**
|
||||
* \c combine_scalar_factors extracts and multiplies factors from GEMM and GEMV products.
|
||||
* There is a specialization for booleans
|
||||
*/
|
||||
template<typename ResScalar, typename Lhs, typename Rhs>
|
||||
struct combine_scalar_factors_impl
|
||||
{
|
||||
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE static ResScalar run(const Lhs& lhs, const Rhs& rhs)
|
||||
{
|
||||
return blas_traits<Lhs>::extractScalarFactor(lhs) * blas_traits<Rhs>::extractScalarFactor(rhs);
|
||||
}
|
||||
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE static ResScalar run(const ResScalar& alpha, const Lhs& lhs, const Rhs& rhs)
|
||||
{
|
||||
return alpha * blas_traits<Lhs>::extractScalarFactor(lhs) * blas_traits<Rhs>::extractScalarFactor(rhs);
|
||||
}
|
||||
};
|
||||
template<typename Lhs, typename Rhs>
|
||||
struct combine_scalar_factors_impl<bool, Lhs, Rhs>
|
||||
{
|
||||
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE static bool run(const Lhs& lhs, const Rhs& rhs)
|
||||
{
|
||||
return blas_traits<Lhs>::extractScalarFactor(lhs) && blas_traits<Rhs>::extractScalarFactor(rhs);
|
||||
}
|
||||
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE static bool run(const bool& alpha, const Lhs& lhs, const Rhs& rhs)
|
||||
{
|
||||
return alpha && blas_traits<Lhs>::extractScalarFactor(lhs) && blas_traits<Rhs>::extractScalarFactor(rhs);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename ResScalar, typename Lhs, typename Rhs>
|
||||
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE ResScalar combine_scalar_factors(const ResScalar& alpha, const Lhs& lhs, const Rhs& rhs)
|
||||
{
|
||||
return combine_scalar_factors_impl<ResScalar,Lhs,Rhs>::run(alpha, lhs, rhs);
|
||||
}
|
||||
template<typename ResScalar, typename Lhs, typename Rhs>
|
||||
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE ResScalar combine_scalar_factors(const Lhs& lhs, const Rhs& rhs)
|
||||
{
|
||||
return combine_scalar_factors_impl<ResScalar,Lhs,Rhs>::run(lhs, rhs);
|
||||
}
|
||||
|
||||
|
||||
} // end namespace internal
|
||||
|
||||
} // end namespace Eigen
|
||||
|
||||
Reference in New Issue
Block a user