Fix a bunch of ODR violations.

This commit is contained in:
Antonio Sánchez
2024-01-30 22:38:43 +00:00
parent 7fd7a3f946
commit a9ddab3e06
5 changed files with 22 additions and 55 deletions

View File

@@ -19,7 +19,8 @@
bool g_first_pass = true;
namespace Eigen {
namespace internal {
namespace test {
template <typename T>
T negate(const T& x) {
@@ -31,50 +32,11 @@ Map<const Array<unsigned char, sizeof(T), 1> > bits(const T& x) {
return Map<const Array<unsigned char, sizeof(T), 1> >(reinterpret_cast<const unsigned char*>(&x));
}
// The following implement bitwise operations on floating point types
template <typename T, typename Bits, typename Func>
T apply_bit_op(Bits a, Bits b, Func f) {
Array<unsigned char, sizeof(T), 1> data;
T res;
for (Index i = 0; i < data.size(); ++i) data[i] = f(a[i], b[i]);
// Note: The reinterpret_cast works around GCC's class-memaccess warnings:
std::memcpy(reinterpret_cast<unsigned char*>(&res), data.data(), sizeof(T));
return res;
}
#define EIGEN_TEST_MAKE_BITWISE2(OP, FUNC, T) \
template <> \
T EIGEN_CAT(p, OP)(const T& a, const T& b) { \
return apply_bit_op<T>(bits(a), bits(b), FUNC); \
}
#define EIGEN_TEST_MAKE_BITWISE(OP, FUNC) \
EIGEN_TEST_MAKE_BITWISE2(OP, FUNC, float) \
EIGEN_TEST_MAKE_BITWISE2(OP, FUNC, double) \
EIGEN_TEST_MAKE_BITWISE2(OP, FUNC, half) \
EIGEN_TEST_MAKE_BITWISE2(OP, FUNC, bfloat16) \
EIGEN_TEST_MAKE_BITWISE2(OP, FUNC, std::complex<float>) \
EIGEN_TEST_MAKE_BITWISE2(OP, FUNC, std::complex<double>)
EIGEN_TEST_MAKE_BITWISE(xor, std::bit_xor<unsigned char>())
EIGEN_TEST_MAKE_BITWISE(and, std::bit_and<unsigned char>())
EIGEN_TEST_MAKE_BITWISE(or, std::bit_or<unsigned char>())
struct bit_andnot {
template <typename T>
T operator()(T a, T b) const {
return a & (~b);
}
};
EIGEN_TEST_MAKE_BITWISE(andnot, bit_andnot())
template <typename T>
bool biteq(T a, T b) {
return (bits(a) == bits(b)).all();
}
} // namespace internal
namespace test {
// NOTE: we disable inlining for this function to workaround a GCC issue when using -O3 and the i387 FPU.
template <typename Scalar>
EIGEN_DONT_INLINE bool isApproxAbs(const Scalar& a, const Scalar& b, const typename NumTraits<Scalar>::Real& refvalue) {