From a9ddab3e06e91418633954ebbd32a7d00981c39f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20S=C3=A1nchez?= Date: Tue, 30 Jan 2024 22:38:43 +0000 Subject: [PATCH] Fix a bunch of ODR violations. --- test/indexed_view.cpp | 10 ++--- test/packetmath.cpp | 4 +- test/packetmath_test_shared.h | 42 +------------------ .../Eigen/CXX11/src/Tensor/TensorBase.h | 14 ++++--- .../CXX11/src/Tensor/TensorGlobalFunctions.h | 7 +++- 5 files changed, 22 insertions(+), 55 deletions(-) diff --git a/test/indexed_view.cpp b/test/indexed_view.cpp index 494e0d67d..4040448aa 100644 --- a/test/indexed_view.cpp +++ b/test/indexed_view.cpp @@ -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 #include + #include "main.h" using Eigen::placeholders::all; @@ -17,11 +17,13 @@ using Eigen::placeholders::lastN; using Eigen::placeholders::lastp1; #include +namespace test { typedef std::pair 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 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 vali(4); - Map(&vali[0], 4) = eii; std::vector veci(4); Map(veci.data(), 4) = eii; diff --git a/test/packetmath.cpp b/test/packetmath.cpp index b2cca731e..f68d51391 100644 --- a/test/packetmath.cpp +++ b/test/packetmath.cpp @@ -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)); } diff --git a/test/packetmath_test_shared.h b/test/packetmath_test_shared.h index a4bb34766..86a01fb99 100644 --- a/test/packetmath_test_shared.h +++ b/test/packetmath_test_shared.h @@ -19,7 +19,8 @@ bool g_first_pass = true; namespace Eigen { -namespace internal { + +namespace test { template T negate(const T& x) { @@ -31,50 +32,11 @@ Map > bits(const T& x) { return Map >(reinterpret_cast(&x)); } -// The following implement bitwise operations on floating point types -template -T apply_bit_op(Bits a, Bits b, Func f) { - Array 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(&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(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) \ - EIGEN_TEST_MAKE_BITWISE2(OP, FUNC, std::complex) - -EIGEN_TEST_MAKE_BITWISE(xor, std::bit_xor()) -EIGEN_TEST_MAKE_BITWISE(and, std::bit_and()) -EIGEN_TEST_MAKE_BITWISE(or, std::bit_or()) -struct bit_andnot { - template - T operator()(T a, T b) const { - return a & (~b); - } -}; -EIGEN_TEST_MAKE_BITWISE(andnot, bit_andnot()) template 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 EIGEN_DONT_INLINE bool isApproxAbs(const Scalar& a, const Scalar& b, const typename NumTraits::Real& refvalue) { diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorBase.h b/unsupported/Eigen/CXX11/src/Tensor/TensorBase.h index 93753985f..f9f07d41e 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorBase.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorBase.h @@ -1007,13 +1007,14 @@ class TensorBase #include EIGEN_READONLY_TENSORBASE_PLUGIN #endif + EIGEN_DEVICE_FUNC + EIGEN_STRONG_INLINE const Derived& derived() const { return *static_cast(this); } + protected: template friend class Tensor; template friend class TensorFixedSize; // the Eigen:: prefix is required to workaround a compilation issue with nvcc 9.0 template friend class Eigen::TensorBase; - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const Derived& derived() const { return *static_cast(this); } }; template::value> @@ -1199,6 +1200,11 @@ class TensorBase : public TensorBase { return TensorAsyncDevice(dev, derived(), std::move(done)); } + EIGEN_DEVICE_FUNC + EIGEN_STRONG_INLINE Derived& derived() { return *static_cast(this); } + EIGEN_DEVICE_FUNC + EIGEN_STRONG_INLINE const Derived& derived() const { return *static_cast(this); } + #ifdef EIGEN_TENSORBASE_PLUGIN #include EIGEN_TENSORBASE_PLUGIN #endif @@ -1215,10 +1221,6 @@ class TensorBase : public TensorBase { internal::TensorExecutor::run(assign, DefaultDevice()); return derived(); } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Derived& derived() { return *static_cast(this); } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const Derived& derived() const { return *static_cast(this); } }; #endif // EIGEN_PARSED_BY_DOXYGEN } // end namespace Eigen diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorGlobalFunctions.h b/unsupported/Eigen/CXX11/src/Tensor/TensorGlobalFunctions.h index 8d330b5fa..6a1240cfa 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorGlobalFunctions.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorGlobalFunctions.h @@ -23,9 +23,12 @@ namespace Eigen { template EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const TensorCwiseTernaryOp, const ADerived, const BDerived, const XDerived> -betainc(const ADerived& a, const BDerived& b, const XDerived& x) { +betainc(const Eigen::TensorBase& a, + const Eigen::TensorBase& b, + const Eigen::TensorBase& x) { return TensorCwiseTernaryOp, const ADerived, const BDerived, - const XDerived>(a, b, x, internal::scalar_betainc_op()); + const XDerived>(a.derived(), b.derived(), x.derived(), + internal::scalar_betainc_op()); } } // end namespace Eigen