mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-14 04:35:57 +08:00
Fix a bunch of ODR violations.
This commit is contained in:
parent
7fd7a3f946
commit
a9ddab3e06
@ -7,8 +7,8 @@
|
|||||||
// Public License v. 2.0. If a copy of the MPL was not distributed
|
// 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/.
|
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
#include <valarray>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
using Eigen::placeholders::all;
|
using Eigen::placeholders::all;
|
||||||
@ -17,11 +17,13 @@ using Eigen::placeholders::lastN;
|
|||||||
using Eigen::placeholders::lastp1;
|
using Eigen::placeholders::lastp1;
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
|
namespace test {
|
||||||
typedef std::pair<Index, Index> IndexPair;
|
typedef std::pair<Index, Index> IndexPair;
|
||||||
|
}
|
||||||
|
|
||||||
int encode(Index i, Index j) { return int(i * 100 + j); }
|
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>
|
template <typename T>
|
||||||
bool match(const T& xpr, std::string ref, std::string str_xpr = "") {
|
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));
|
ArrayXXi A = ArrayXXi::NullaryExpr(n, n, std::ref(encode));
|
||||||
|
|
||||||
for (Index i = 0; i < n; ++i)
|
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);
|
Array4i eii(4);
|
||||||
eii << 3, 1, 6, 5;
|
eii << 3, 1, 6, 5;
|
||||||
std::valarray<int> vali(4);
|
|
||||||
Map<ArrayXi>(&vali[0], 4) = eii;
|
|
||||||
std::vector<int> veci(4);
|
std::vector<int> veci(4);
|
||||||
Map<ArrayXi>(veci.data(), 4) = eii;
|
Map<ArrayXi>(veci.data(), 4) = eii;
|
||||||
|
|
||||||
|
@ -538,7 +538,7 @@ void packetmath() {
|
|||||||
CHECK_CWISE2_IF(PacketTraits::HasMul, REF_MUL, internal::pmul);
|
CHECK_CWISE2_IF(PacketTraits::HasMul, REF_MUL, internal::pmul);
|
||||||
CHECK_CWISE2_IF(PacketTraits::HasDiv, REF_DIV, internal::pdiv);
|
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_IF(PacketTraits::HasReciprocal, REF_RECIPROCAL, internal::preciprocal);
|
||||||
CHECK_CWISE1(numext::conj, internal::pconj);
|
CHECK_CWISE1(numext::conj, internal::pconj);
|
||||||
CHECK_CWISE1_IF(PacketTraits::HasSign, numext::sign, internal::psign);
|
CHECK_CWISE1_IF(PacketTraits::HasSign, numext::sign, internal::psign);
|
||||||
@ -1141,7 +1141,7 @@ void packetmath_real() {
|
|||||||
|
|
||||||
data1[0] = -Scalar(0.);
|
data1[0] = -Scalar(0.);
|
||||||
h.store(data2, internal::psin(h.load(data1)));
|
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)));
|
h.store(data2, internal::pcos(h.load(data1)));
|
||||||
VERIFY_IS_EQUAL(data2[0], Scalar(1));
|
VERIFY_IS_EQUAL(data2[0], Scalar(1));
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,8 @@
|
|||||||
bool g_first_pass = true;
|
bool g_first_pass = true;
|
||||||
|
|
||||||
namespace Eigen {
|
namespace Eigen {
|
||||||
namespace internal {
|
|
||||||
|
namespace test {
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T negate(const T& x) {
|
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));
|
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>
|
template <typename T>
|
||||||
bool biteq(T a, T b) {
|
bool biteq(T a, T b) {
|
||||||
return (bits(a) == bits(b)).all();
|
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.
|
// NOTE: we disable inlining for this function to workaround a GCC issue when using -O3 and the i387 FPU.
|
||||||
template <typename Scalar>
|
template <typename Scalar>
|
||||||
EIGEN_DONT_INLINE bool isApproxAbs(const Scalar& a, const Scalar& b, const typename NumTraits<Scalar>::Real& refvalue) {
|
EIGEN_DONT_INLINE bool isApproxAbs(const Scalar& a, const Scalar& b, const typename NumTraits<Scalar>::Real& refvalue) {
|
||||||
|
@ -1007,13 +1007,14 @@ class TensorBase<Derived, ReadOnlyAccessors>
|
|||||||
#include EIGEN_READONLY_TENSORBASE_PLUGIN
|
#include EIGEN_READONLY_TENSORBASE_PLUGIN
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
EIGEN_DEVICE_FUNC
|
||||||
|
EIGEN_STRONG_INLINE const Derived& derived() const { return *static_cast<const Derived*>(this); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
template <typename Scalar, int NumIndices, int Options, typename IndexType> friend class Tensor;
|
template <typename Scalar, int NumIndices, int Options, typename IndexType> friend class Tensor;
|
||||||
template <typename Scalar, typename Dimensions, int Option, typename IndexTypes> friend class TensorFixedSize;
|
template <typename Scalar, typename Dimensions, int Option, typename IndexTypes> friend class TensorFixedSize;
|
||||||
// the Eigen:: prefix is required to workaround a compilation issue with nvcc 9.0
|
// the Eigen:: prefix is required to workaround a compilation issue with nvcc 9.0
|
||||||
template <typename OtherDerived, int AccessLevel> friend class Eigen::TensorBase;
|
template <typename OtherDerived, int AccessLevel> friend class Eigen::TensorBase;
|
||||||
EIGEN_DEVICE_FUNC
|
|
||||||
EIGEN_STRONG_INLINE const Derived& derived() const { return *static_cast<const Derived*>(this); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Derived, int AccessLevel = internal::accessors_level<Derived>::value>
|
template<typename Derived, int AccessLevel = internal::accessors_level<Derived>::value>
|
||||||
@ -1199,6 +1200,11 @@ class TensorBase : public TensorBase<Derived, ReadOnlyAccessors> {
|
|||||||
return TensorAsyncDevice<Derived, DeviceType, DoneCallback>(dev, derived(), std::move(done));
|
return TensorAsyncDevice<Derived, DeviceType, DoneCallback>(dev, derived(), std::move(done));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EIGEN_DEVICE_FUNC
|
||||||
|
EIGEN_STRONG_INLINE Derived& derived() { return *static_cast<Derived*>(this); }
|
||||||
|
EIGEN_DEVICE_FUNC
|
||||||
|
EIGEN_STRONG_INLINE const Derived& derived() const { return *static_cast<const Derived*>(this); }
|
||||||
|
|
||||||
#ifdef EIGEN_TENSORBASE_PLUGIN
|
#ifdef EIGEN_TENSORBASE_PLUGIN
|
||||||
#include EIGEN_TENSORBASE_PLUGIN
|
#include EIGEN_TENSORBASE_PLUGIN
|
||||||
#endif
|
#endif
|
||||||
@ -1215,10 +1221,6 @@ class TensorBase : public TensorBase<Derived, ReadOnlyAccessors> {
|
|||||||
internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice());
|
internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice());
|
||||||
return derived();
|
return derived();
|
||||||
}
|
}
|
||||||
EIGEN_DEVICE_FUNC
|
|
||||||
EIGEN_STRONG_INLINE Derived& derived() { return *static_cast<Derived*>(this); }
|
|
||||||
EIGEN_DEVICE_FUNC
|
|
||||||
EIGEN_STRONG_INLINE const Derived& derived() const { return *static_cast<const Derived*>(this); }
|
|
||||||
};
|
};
|
||||||
#endif // EIGEN_PARSED_BY_DOXYGEN
|
#endif // EIGEN_PARSED_BY_DOXYGEN
|
||||||
} // end namespace Eigen
|
} // end namespace Eigen
|
||||||
|
@ -23,9 +23,12 @@ namespace Eigen {
|
|||||||
template <typename ADerived, typename BDerived, typename XDerived>
|
template <typename ADerived, typename BDerived, typename XDerived>
|
||||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const TensorCwiseTernaryOp<internal::scalar_betainc_op<typename XDerived::Scalar>,
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const TensorCwiseTernaryOp<internal::scalar_betainc_op<typename XDerived::Scalar>,
|
||||||
const ADerived, const BDerived, const XDerived>
|
const ADerived, const BDerived, const XDerived>
|
||||||
betainc(const ADerived& a, const BDerived& b, const XDerived& x) {
|
betainc(const Eigen::TensorBase<ADerived, ReadOnlyAccessors>& a,
|
||||||
|
const Eigen::TensorBase<BDerived, ReadOnlyAccessors>& b,
|
||||||
|
const Eigen::TensorBase<XDerived, ReadOnlyAccessors>& x) {
|
||||||
return TensorCwiseTernaryOp<internal::scalar_betainc_op<typename XDerived::Scalar>, const ADerived, const BDerived,
|
return TensorCwiseTernaryOp<internal::scalar_betainc_op<typename XDerived::Scalar>, const ADerived, const BDerived,
|
||||||
const XDerived>(a, b, x, internal::scalar_betainc_op<typename XDerived::Scalar>());
|
const XDerived>(a.derived(), b.derived(), x.derived(),
|
||||||
|
internal::scalar_betainc_op<typename XDerived::Scalar>());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end namespace Eigen
|
} // end namespace Eigen
|
||||||
|
Loading…
x
Reference in New Issue
Block a user