mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Fix annoying warnings
This commit is contained in:
@@ -430,10 +430,34 @@ T div_ceil(const T &a, const T &b)
|
||||
return (a+b-1) / b;
|
||||
}
|
||||
|
||||
// Handle integer comparisons of different signedness.
|
||||
template <typename X, typename Y, bool XIsInteger = NumTraits<X>::IsInteger, bool XIsSigned = NumTraits<X>::IsSigned,
|
||||
bool YIsInteger = NumTraits<Y>::IsInteger, bool YIsSigned = NumTraits<Y>::IsSigned>
|
||||
struct equal_strict_impl {
|
||||
static EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool run(const X& x, const Y& y) { return x == y; }
|
||||
};
|
||||
template <typename X, typename Y>
|
||||
struct equal_strict_impl<X, Y, true, false, true, true> {
|
||||
// X is an unsigned integer
|
||||
// Y is a signed integer
|
||||
// if Y is non-negative, it may be represented exactly as its unsigned counterpart.
|
||||
using UnsignedY = typename internal::make_unsigned<Y>::type;
|
||||
static EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool run(const X& x, const Y& y) {
|
||||
return y < Y(0) ? false : (x == static_cast<UnsignedY>(y));
|
||||
}
|
||||
};
|
||||
template <typename X, typename Y>
|
||||
struct equal_strict_impl<X, Y, true, true, true, false> {
|
||||
// X is a signed integer
|
||||
// Y is an unsigned integer
|
||||
static EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool run(const X& x, const Y& y) {
|
||||
return equal_strict_impl<Y, X>::run(y, x);
|
||||
}
|
||||
};
|
||||
|
||||
// The aim of the following functions is to bypass -Wfloat-equal warnings
|
||||
// when we really want a strict equality comparison on floating points.
|
||||
template<typename X, typename Y> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
|
||||
bool equal_strict(const X& x,const Y& y) { return x == y; }
|
||||
template<typename X, typename Y> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool equal_strict(const X& x, const Y& y) { return equal_strict_impl<X, Y>::run(x, y); }
|
||||
|
||||
#if !defined(EIGEN_GPU_COMPILE_PHASE) || (!defined(EIGEN_CUDA_ARCH) && defined(EIGEN_CONSTEXPR_ARE_DEVICE_FUNC))
|
||||
template<> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
|
||||
@@ -458,7 +482,7 @@ template<typename X> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
|
||||
bool is_exactly_one(const X& x) { return equal_strict(x, typename NumTraits<X>::Literal{1}); }
|
||||
|
||||
template<typename X, typename Y> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
|
||||
bool not_equal_strict(const X& x,const Y& y) { return x != y; }
|
||||
bool not_equal_strict(const X& x,const Y& y) { return !equal_strict_impl<X, Y>::run(x, y); }
|
||||
|
||||
#if !defined(EIGEN_GPU_COMPILE_PHASE) || (!defined(EIGEN_CUDA_ARCH) && defined(EIGEN_CONSTEXPR_ARE_DEVICE_FUNC))
|
||||
template<> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
|
||||
|
||||
@@ -17,12 +17,52 @@ namespace Eigen {
|
||||
|
||||
namespace internal {
|
||||
|
||||
template<typename IndexDest, typename IndexSrc>
|
||||
EIGEN_DEVICE_FUNC
|
||||
inline IndexDest convert_index(const IndexSrc& idx) {
|
||||
// for sizeof(IndexDest)>=sizeof(IndexSrc) compilers should be able to optimize this away:
|
||||
eigen_internal_assert(idx <= NumTraits<IndexDest>::highest() && "Index value to big for target type");
|
||||
return IndexDest(idx);
|
||||
|
||||
// useful for unsigned / signed integer comparisons when idx is intended to be non-negative
|
||||
template <typename IndexType>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename make_unsigned<IndexType>::type returnUnsignedIndexValue(
|
||||
const IndexType& idx) {
|
||||
EIGEN_STATIC_ASSERT((NumTraits<IndexType>::IsInteger), THIS FUNCTION IS FOR INTEGER TYPES)
|
||||
eigen_internal_assert(idx >= 0 && "Index value is negative and target type is unsigned");
|
||||
using UnsignedType = typename make_unsigned<IndexType>::type;
|
||||
return static_cast<UnsignedType>(idx);
|
||||
}
|
||||
|
||||
template <typename IndexDest, typename IndexSrc,
|
||||
bool IndexDestIsInteger = NumTraits<IndexDest>::IsInteger,
|
||||
bool IndexDestIsSigned = NumTraits<IndexDest>::IsSigned,
|
||||
bool IndexSrcIsInteger = NumTraits<IndexSrc>::IsInteger,
|
||||
bool IndexSrcIsSigned = NumTraits<IndexSrc>::IsSigned>
|
||||
struct convert_index_impl {
|
||||
static inline EIGEN_DEVICE_FUNC IndexDest run(const IndexSrc& idx) {
|
||||
eigen_internal_assert(idx <= NumTraits<IndexDest>::highest() && "Index value is too big for target type");
|
||||
return static_cast<IndexDest>(idx);
|
||||
}
|
||||
};
|
||||
template <typename IndexDest, typename IndexSrc>
|
||||
struct convert_index_impl<IndexDest, IndexSrc, true, true, true, false> {
|
||||
// IndexDest is a signed integer
|
||||
// IndexSrc is an unsigned integer
|
||||
static inline EIGEN_DEVICE_FUNC IndexDest run(const IndexSrc& idx) {
|
||||
eigen_internal_assert(idx <= returnUnsignedIndexValue(NumTraits<IndexDest>::highest()) &&
|
||||
"Index value is too big for target type");
|
||||
return static_cast<IndexDest>(idx);
|
||||
}
|
||||
};
|
||||
template <typename IndexDest, typename IndexSrc>
|
||||
struct convert_index_impl<IndexDest, IndexSrc, true, false, true, true> {
|
||||
// IndexDest is an unsigned integer
|
||||
// IndexSrc is a signed integer
|
||||
static inline EIGEN_DEVICE_FUNC IndexDest run(const IndexSrc& idx) {
|
||||
eigen_internal_assert(returnUnsignedIndexValue(idx) <= NumTraits<IndexDest>::highest() &&
|
||||
"Index value is too big for target type");
|
||||
return static_cast<IndexDest>(idx);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename IndexDest, typename IndexSrc>
|
||||
EIGEN_DEVICE_FUNC inline IndexDest convert_index(const IndexSrc& idx) {
|
||||
return convert_index_impl<IndexDest, IndexSrc>::run(idx);
|
||||
}
|
||||
|
||||
// true if T can be considered as an integral index (i.e., and integral type or enum)
|
||||
|
||||
Reference in New Issue
Block a user