Improve test coverage for inner product, fill, reductions, and IO

libeigen/eigen!2286

Co-authored-by: Rasmus Munk Larsen <rmlarsen@gmail.com>
This commit is contained in:
Rasmus Munk Larsen
2026-03-12 12:48:45 -07:00
parent 5e478d3285
commit c93116b43d
5 changed files with 209 additions and 1 deletions

View File

@@ -207,6 +207,48 @@ void adjoint_extra() {
a = a.transpose();
}
template <typename Scalar>
void inner_product_boundary_sizes() {
const Index PS = internal::packet_traits<Scalar>::size;
// Sizes that exercise every branch in the 4-way unrolled vectorized inner product:
// scalar fallback (< PS), 1-3 packets, quad loop entry/exit, remainder packets, scalar cleanup
const Index sizes[] = {0,
1,
PS - 1,
PS,
PS + 1,
2 * PS - 1,
2 * PS,
2 * PS + 1,
3 * PS - 1,
3 * PS,
3 * PS + 1,
4 * PS - 1,
4 * PS,
4 * PS + 1,
8 * PS,
8 * PS + 1,
8 * PS + PS,
8 * PS + 2 * PS,
8 * PS + 3 * PS,
8 * PS + 3 * PS + 1};
for (int si = 0; si < 20; ++si) {
const Index n = sizes[si];
if (n <= 0) continue;
typedef Matrix<Scalar, Dynamic, 1> Vec;
Vec v1 = Vec::Random(n);
Vec v2 = Vec::Random(n);
// Reference: scalar loop
Scalar expected(0);
for (Index k = 0; k < n; ++k) expected += numext::conj(v1(k)) * v2(k);
VERIFY_IS_APPROX(v1.dot(v2), expected);
// Also test squaredNorm
Scalar sq_expected(0);
for (Index k = 0; k < n; ++k) sq_expected += numext::conj(v1(k)) * v1(k);
VERIFY_IS_APPROX(v1.squaredNorm(), numext::real(sq_expected));
}
}
EIGEN_DECLARE_TEST(adjoint) {
for (int i = 0; i < g_repeat; i++) {
CALL_SUBTEST_1(adjoint(Matrix<float, 1, 1>()));
@@ -233,4 +275,10 @@ EIGEN_DECLARE_TEST(adjoint) {
CALL_SUBTEST_7(adjoint(Matrix<float, 100, 100>()));
CALL_SUBTEST_13(adjoint_extra<0>());
// Inner product vectorization boundary tests (deterministic, outside g_repeat)
CALL_SUBTEST_14(inner_product_boundary_sizes<float>());
CALL_SUBTEST_15(inner_product_boundary_sizes<double>());
CALL_SUBTEST_16(inner_product_boundary_sizes<std::complex<float>>());
CALL_SUBTEST_17(inner_product_boundary_sizes<std::complex<double>>());
}