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

@@ -7,8 +7,8 @@
// Public License v. 2.0. If a copy of the MPL was not distributed
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include <valarray>
#include <vector>
#include "main.h"
using Eigen::placeholders::all;
@@ -17,11 +17,13 @@ using Eigen::placeholders::lastN;
using Eigen::placeholders::lastp1;
#include <array>
namespace test {
typedef std::pair<Index, Index> IndexPair;
}
int encode(Index i, Index j) { return int(i * 100 + j); }
IndexPair decode(Index ij) { return IndexPair(ij / 100, ij % 100); }
test::IndexPair decode(Index ij) { return test::IndexPair(ij / 100, ij % 100); }
template <typename T>
bool match(const T& xpr, std::string ref, std::string str_xpr = "") {
@@ -69,12 +71,10 @@ void check_indexed_view() {
ArrayXXi A = ArrayXXi::NullaryExpr(n, n, std::ref(encode));
for (Index i = 0; i < n; ++i)
for (Index j = 0; j < n; ++j) VERIFY(decode(A(i, j)) == IndexPair(i, j));
for (Index j = 0; j < n; ++j) VERIFY(decode(A(i, j)) == test::IndexPair(i, j));
Array4i eii(4);
eii << 3, 1, 6, 5;
std::valarray<int> vali(4);
Map<ArrayXi>(&vali[0], 4) = eii;
std::vector<int> veci(4);
Map<ArrayXi>(veci.data(), 4) = eii;

View File

@@ -538,7 +538,7 @@ void packetmath() {
CHECK_CWISE2_IF(PacketTraits::HasMul, REF_MUL, internal::pmul);
CHECK_CWISE2_IF(PacketTraits::HasDiv, REF_DIV, internal::pdiv);
CHECK_CWISE1_IF(PacketTraits::HasNegate, internal::negate, internal::pnegate);
CHECK_CWISE1_IF(PacketTraits::HasNegate, test::negate, internal::pnegate);
CHECK_CWISE1_IF(PacketTraits::HasReciprocal, REF_RECIPROCAL, internal::preciprocal);
CHECK_CWISE1(numext::conj, internal::pconj);
CHECK_CWISE1_IF(PacketTraits::HasSign, numext::sign, internal::psign);
@@ -1141,7 +1141,7 @@ void packetmath_real() {
data1[0] = -Scalar(0.);
h.store(data2, internal::psin(h.load(data1)));
VERIFY(internal::biteq(data2[0], data1[0]));
VERIFY(test::biteq(data2[0], data1[0]));
h.store(data2, internal::pcos(h.load(data1)));
VERIFY_IS_EQUAL(data2[0], Scalar(1));
}

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) {