blob: ef5dc9ba9739293d5aa0145e5686d89532d134fd [file] [edit]
// SPDX-FileCopyrightText: The Eigen Authors
// SPDX-License-Identifier: MPL-2.0
#ifndef EIGEN_STRUCTURED_TEST_HELPERS_H
#define EIGEN_STRUCTURED_TEST_HELPERS_H
#include <Eigen/Core>
namespace Eigen {
// Vectorized complex products can introduce Inf - Inf across component accumulators.
// Preserve scalar evaluation order for the non-finite reference results.
template <typename Scalar>
Matrix<Scalar, Dynamic, 1> reference_product_ieee(const Matrix<Scalar, Dynamic, Dynamic>& matrix,
const Matrix<Scalar, Dynamic, 1>& vector) {
Matrix<Scalar, Dynamic, 1> result(matrix.rows());
for (Index i = 0; i < matrix.rows(); ++i) {
Scalar accumulator(0);
for (Index j = 0; j < matrix.cols(); ++j) accumulator += matrix(i, j) * vector[j];
result[i] = accumulator;
}
return result;
}
// The FFT-based products mix every input entry into every output entry, so an Inf or NaN may make more entries
// non-finite than the dense product does. \returns whether it makes at least those.
template <typename Actual, typename Reference>
bool nonfinite_covers_reference(const Actual& actual, const Reference& reference) {
for (Index i = 0; i < reference.size(); ++i)
if (!(numext::isfinite)(reference[i]) && (numext::isfinite)(actual[i])) return false;
return true;
}
} // namespace Eigen
#endif // EIGEN_STRUCTURED_TEST_HELPERS_H