Reduce flakiness of test for Eigen::half.

This commit is contained in:
Antonio Sanchez
2025-03-23 22:31:25 -07:00
parent d935916ac6
commit 8e32cbf7da
3 changed files with 39 additions and 1 deletions

View File

@@ -38,6 +38,15 @@ template <typename LhsType, typename RhsType>
std::enable_if_t<RhsType::SizeAtCompileTime != Dynamic, void> check_mismatched_product(LhsType& /*unused*/,
const RhsType& /*unused*/) {}
template <typename Scalar, typename V1, typename V2>
Scalar ref_dot_product(const V1& v1, const V2& v2) {
Scalar out = Scalar(0);
for (Index i = 0; i < v1.size(); ++i) {
out = Eigen::numext::fma(v1[i], v2[i], out);
}
return out;
}
template <typename MatrixType>
void product(const MatrixType& m) {
/* this test covers the following files:
@@ -245,7 +254,10 @@ void product(const MatrixType& m) {
// inner product
{
Scalar x = square2.row(c) * square2.col(c2);
VERIFY_IS_APPROX(x, square2.row(c).transpose().cwiseProduct(square2.col(c2)).sum());
// NOTE: FMA is necessary here in the reference to ensure accuracy for
// large vector sizes and float16/bfloat16 types.
Scalar y = ref_dot_product<Scalar>(square2.row(c), square2.col(c2));
VERIFY_IS_APPROX(x, y);
}
// outer product