From 1a2bfca8f000286a13877f493a87fee543e13755 Mon Sep 17 00:00:00 2001 From: Charles Schlosser Date: Fri, 7 Jul 2023 20:19:58 +0000 Subject: [PATCH] Fix annoying warnings --- Eigen/src/Core/Dot.h | 5 +- Eigen/src/Core/GenericPacketMath.h | 3 +- Eigen/src/Core/PlainObjectBase.h | 8 +- Eigen/src/Core/Ref.h | 14 +-- Eigen/src/Core/util/Meta.h | 30 +++++- Eigen/src/Core/util/XprHelper.h | 52 +++++++-- Eigen/src/SVD/SVDBase.h | 4 +- Eigen/src/ThreadPool/EventCount.h | 2 +- test/array_cwise.cpp | 100 ++++++++---------- test/basicstuff.cpp | 6 +- test/random_without_cast_overflow.h | 50 ++++++++- test/stdvector.cpp | 2 +- .../Eigen/CXX11/src/Tensor/TensorBlock.h | 2 +- unsupported/Eigen/FFT | 17 +-- unsupported/test/EulerAngles.cpp | 2 + unsupported/test/NNLS.cpp | 11 +- unsupported/test/cxx11_tensor_casts.cpp | 2 +- unsupported/test/cxx11_tensor_reduction.cpp | 2 +- 18 files changed, 207 insertions(+), 105 deletions(-) diff --git a/Eigen/src/Core/Dot.h b/Eigen/src/Core/Dot.h index 0c1319259..139e2ca98 100644 --- a/Eigen/src/Core/Dot.h +++ b/Eigen/src/Core/Dot.h @@ -72,8 +72,9 @@ MatrixBase::dot(const MatrixBase& other) const EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived) EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(Derived,OtherDerived) #if !(defined(EIGEN_NO_STATIC_ASSERT) && defined(EIGEN_NO_DEBUG)) - typedef internal::scalar_conj_product_op func; - EIGEN_CHECK_BINARY_COMPATIBILIY(func,Scalar,typename OtherDerived::Scalar); + EIGEN_CHECK_BINARY_COMPATIBILIY( + Eigen::internal::scalar_conj_product_op, + Scalar, typename OtherDerived::Scalar); #endif eigen_assert(size() == other.size()); diff --git a/Eigen/src/Core/GenericPacketMath.h b/Eigen/src/Core/GenericPacketMath.h index 3d2f144d7..ceb7a0ad7 100644 --- a/Eigen/src/Core/GenericPacketMath.h +++ b/Eigen/src/Core/GenericPacketMath.h @@ -1366,8 +1366,7 @@ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Packet pcarg(const Packet& a) { /** \internal \returns the argument of \a a as a complex number */ template ::value, int> = 0> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Packet pcarg(const Packet& a) { - using Scalar = typename unpacket_traits::type; - EIGEN_STATIC_ASSERT(NumTraits::IsComplex, THIS METHOD IS FOR COMPLEX TYPES ONLY) + EIGEN_STATIC_ASSERT(NumTraits::type>::IsComplex, THIS METHOD IS FOR COMPLEX TYPES ONLY) using RealPacket = typename unpacket_traits::as_real; // a // r i r i ... RealPacket aflip = pcplxflip(a).v; // i r i r ... diff --git a/Eigen/src/Core/PlainObjectBase.h b/Eigen/src/Core/PlainObjectBase.h index fc2e94178..1b8630460 100644 --- a/Eigen/src/Core/PlainObjectBase.h +++ b/Eigen/src/Core/PlainObjectBase.h @@ -775,11 +775,9 @@ class PlainObjectBase : public internal::dense_xpr_base::type EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void _init2(Index rows, Index cols, std::enable_if_t* = 0) { - const bool t0_is_integer_alike = internal::is_valid_index_type::value; - const bool t1_is_integer_alike = internal::is_valid_index_type::value; - EIGEN_STATIC_ASSERT(t0_is_integer_alike && - t1_is_integer_alike, - FLOATING_POINT_ARGUMENT_PASSED__INTEGER_WAS_EXPECTED) + EIGEN_STATIC_ASSERT(internal::is_valid_index_type::value && + internal::is_valid_index_type::value, + T0 AND T1 MUST BE INTEGER TYPES) resize(rows,cols); } diff --git a/Eigen/src/Core/Ref.h b/Eigen/src/Core/Ref.h index e347a0fde..32d51d236 100644 --- a/Eigen/src/Core/Ref.h +++ b/Eigen/src/Core/Ref.h @@ -334,14 +334,14 @@ template class Ref< typedef internal::traits Traits; static constexpr bool may_map_m_object_successfully = - (StrideType::InnerStrideAtCompileTime == 0 || - StrideType::InnerStrideAtCompileTime == 1 || - StrideType::InnerStrideAtCompileTime == Dynamic) && + (static_cast(StrideType::InnerStrideAtCompileTime) == 0 || + static_cast(StrideType::InnerStrideAtCompileTime) == 1 || + static_cast(StrideType::InnerStrideAtCompileTime) == Dynamic) && (TPlainObjectType::IsVectorAtCompileTime || - StrideType::OuterStrideAtCompileTime == 0 || - StrideType::OuterStrideAtCompileTime == Dynamic || - StrideType::OuterStrideAtCompileTime == TPlainObjectType::InnerSizeAtCompileTime || - TPlainObjectType::InnerSizeAtCompileTime == Dynamic); + static_cast(StrideType::OuterStrideAtCompileTime) == 0 || + static_cast(StrideType::OuterStrideAtCompileTime) == Dynamic || + static_cast(StrideType::OuterStrideAtCompileTime) == static_cast(TPlainObjectType::InnerSizeAtCompileTime) || + static_cast(TPlainObjectType::InnerSizeAtCompileTime) == Dynamic); public: typedef RefBase Base; diff --git a/Eigen/src/Core/util/Meta.h b/Eigen/src/Core/util/Meta.h index a192aac87..ba5a56385 100644 --- a/Eigen/src/Core/util/Meta.h +++ b/Eigen/src/Core/util/Meta.h @@ -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 ::IsInteger, bool XIsSigned = NumTraits::IsSigned, + bool YIsInteger = NumTraits::IsInteger, bool YIsSigned = NumTraits::IsSigned> +struct equal_strict_impl { + static EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool run(const X& x, const Y& y) { return x == y; } +}; +template +struct equal_strict_impl { + // 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::type; + static EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool run(const X& x, const Y& y) { + return y < Y(0) ? false : (x == static_cast(y)); + } +}; +template +struct equal_strict_impl { + // 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::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 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC -bool equal_strict(const X& x,const Y& y) { return x == y; } +template EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool equal_strict(const X& x, const Y& y) { return equal_strict_impl::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 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool is_exactly_one(const X& x) { return equal_strict(x, typename NumTraits::Literal{1}); } template 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::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 diff --git a/Eigen/src/Core/util/XprHelper.h b/Eigen/src/Core/util/XprHelper.h index 49fa37c0c..ccc6d4313 100644 --- a/Eigen/src/Core/util/XprHelper.h +++ b/Eigen/src/Core/util/XprHelper.h @@ -17,12 +17,52 @@ namespace Eigen { namespace internal { -template -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::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 +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename make_unsigned::type returnUnsignedIndexValue( + const IndexType& idx) { + EIGEN_STATIC_ASSERT((NumTraits::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::type; + return static_cast(idx); +} + +template ::IsInteger, + bool IndexDestIsSigned = NumTraits::IsSigned, + bool IndexSrcIsInteger = NumTraits::IsInteger, + bool IndexSrcIsSigned = NumTraits::IsSigned> +struct convert_index_impl { + static inline EIGEN_DEVICE_FUNC IndexDest run(const IndexSrc& idx) { + eigen_internal_assert(idx <= NumTraits::highest() && "Index value is too big for target type"); + return static_cast(idx); + } +}; +template +struct convert_index_impl { + // 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::highest()) && + "Index value is too big for target type"); + return static_cast(idx); + } +}; +template +struct convert_index_impl { + // 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::highest() && + "Index value is too big for target type"); + return static_cast(idx); + } +}; + +template +EIGEN_DEVICE_FUNC inline IndexDest convert_index(const IndexSrc& idx) { + return convert_index_impl::run(idx); } // true if T can be considered as an integral index (i.e., and integral type or enum) diff --git a/Eigen/src/SVD/SVDBase.h b/Eigen/src/SVD/SVDBase.h index 10a6d30ff..c4a390cb9 100644 --- a/Eigen/src/SVD/SVDBase.h +++ b/Eigen/src/SVD/SVDBase.h @@ -368,9 +368,11 @@ protected: m_computeFullV(false), m_computeThinV(false), m_computationOptions(0), + m_nonzeroSingularValues(0), m_rows(-1), m_cols(-1), - m_diagSize(0) {} + m_diagSize(0), + m_prescribedThreshold(0) {} }; #ifndef EIGEN_PARSED_BY_DOXYGEN diff --git a/Eigen/src/ThreadPool/EventCount.h b/Eigen/src/ThreadPool/EventCount.h index 034637cc9..3b57d27e7 100644 --- a/Eigen/src/ThreadPool/EventCount.h +++ b/Eigen/src/ThreadPool/EventCount.h @@ -230,7 +230,7 @@ class EventCount { void Unpark(Waiter* w) { for (Waiter* next; w; w = next) { uint64_t wnext = w->next.load(std::memory_order_relaxed) & kStackMask; - next = wnext == kStackMask ? nullptr : &waiters_[wnext]; + next = wnext == kStackMask ? nullptr : &waiters_[internal::convert_index(wnext)]; unsigned state; { EIGEN_MUTEX_LOCK lock(w->mu); diff --git a/test/array_cwise.cpp b/test/array_cwise.cpp index 1648c7cb4..1df9e1d5b 100644 --- a/test/array_cwise.cpp +++ b/test/array_cwise.cpp @@ -267,8 +267,15 @@ void float_pow_test_impl() { #ifdef EIGEN_COMP_MSVC // Work around MSVC return value on underflow. // if std::pow returns 0 and Eigen returns a denormalized value, then skip the test - int fpclass = std::fpclassify(a); - if (e == Base(0) && fpclass == FP_SUBNORMAL) continue; + int eigen_fpclass = std::fpclassify(a); + if (e == Base(0) && eigen_fpclass == FP_SUBNORMAL) continue; + #endif + + #ifdef EIGEN_VECTORIZE_NEON + // Work around NEON flush-to-zero mode + // if std::pow returns denormalized value and Eigen returns 0, then skip the test + int ref_fpclass = std::fpclassify(e); + if (a == Base(0) && ref_fpclass == FP_SUBNORMAL) continue; #endif bool both_nan = (numext::isnan)(a) && (numext::isnan)(e); @@ -330,10 +337,6 @@ void test_exponent(Exponent exponent) { for (Base a : y) { Base e = ref_pow::run(base, exponent); bool pass = (a == e); - //if (!NumTraits::IsInteger) { - // pass = pass || (((numext::isfinite)(e) && internal::isApprox(a, e)) || - // ((numext::isnan)(a) && (numext::isnan)(e))); - //} all_pass &= pass; if (!pass) { std::cout << "pow(" << base << "," << exponent << ") = " << a << " != " << e << std::endl; @@ -442,12 +445,6 @@ void signbit_tests() { signbit_test(); signbit_test(); signbit_test(); - - signbit_test(); - signbit_test(); - signbit_test(); - signbit_test(); - signbit_test(); signbit_test(); signbit_test(); @@ -1324,67 +1321,62 @@ EIGEN_DECLARE_TEST(array_cwise) CALL_SUBTEST_2( array_generic(Array22f()) ); CALL_SUBTEST_3( array_generic(Array44d()) ); CALL_SUBTEST_4( array_generic(ArrayXXcf(internal::random(1,EIGEN_TEST_MAX_SIZE), internal::random(1,EIGEN_TEST_MAX_SIZE))) ); - CALL_SUBTEST_5( array_generic(ArrayXXf(internal::random(1,EIGEN_TEST_MAX_SIZE), internal::random(1,EIGEN_TEST_MAX_SIZE))) ); - CALL_SUBTEST_6( array_generic(ArrayXXi(internal::random(1,EIGEN_TEST_MAX_SIZE), internal::random(1,EIGEN_TEST_MAX_SIZE))) ); - CALL_SUBTEST_6( array_generic(Array(internal::random(1,EIGEN_TEST_MAX_SIZE), internal::random(1,EIGEN_TEST_MAX_SIZE))) ); - CALL_SUBTEST_7( signed_shift_test(ArrayXXi(internal::random(1, EIGEN_TEST_MAX_SIZE), internal::random(1, EIGEN_TEST_MAX_SIZE)))); - CALL_SUBTEST_7( signed_shift_test(Array(internal::random(1, EIGEN_TEST_MAX_SIZE), internal::random(1, EIGEN_TEST_MAX_SIZE)))); - CALL_SUBTEST_8( array_generic(Array(internal::random(1, EIGEN_TEST_MAX_SIZE), internal::random(1, EIGEN_TEST_MAX_SIZE)))); - CALL_SUBTEST_8( array_generic(Array(internal::random(1, EIGEN_TEST_MAX_SIZE), internal::random(1, EIGEN_TEST_MAX_SIZE)))); + CALL_SUBTEST_7( array_generic(ArrayXXf(internal::random(1,EIGEN_TEST_MAX_SIZE), internal::random(1,EIGEN_TEST_MAX_SIZE))) ); + CALL_SUBTEST_8( array_generic(ArrayXXi(internal::random(1,EIGEN_TEST_MAX_SIZE), internal::random(1,EIGEN_TEST_MAX_SIZE))) ); + CALL_SUBTEST_7( array_generic(Array(internal::random(1,EIGEN_TEST_MAX_SIZE), internal::random(1,EIGEN_TEST_MAX_SIZE))) ); + CALL_SUBTEST_8( signed_shift_test(ArrayXXi(internal::random(1, EIGEN_TEST_MAX_SIZE), internal::random(1, EIGEN_TEST_MAX_SIZE)))); + CALL_SUBTEST_9( signed_shift_test(Array(internal::random(1, EIGEN_TEST_MAX_SIZE), internal::random(1, EIGEN_TEST_MAX_SIZE)))); + CALL_SUBTEST_10( array_generic(Array(internal::random(1, EIGEN_TEST_MAX_SIZE), internal::random(1, EIGEN_TEST_MAX_SIZE)))); + CALL_SUBTEST_11( array_generic(Array(internal::random(1, EIGEN_TEST_MAX_SIZE), internal::random(1, EIGEN_TEST_MAX_SIZE)))); } for(int i = 0; i < g_repeat; i++) { CALL_SUBTEST_1( comparisons(Array()) ); CALL_SUBTEST_2( comparisons(Array22f()) ); CALL_SUBTEST_3( comparisons(Array44d()) ); - CALL_SUBTEST_5( comparisons(ArrayXXf(internal::random(1,EIGEN_TEST_MAX_SIZE), internal::random(1,EIGEN_TEST_MAX_SIZE))) ); - CALL_SUBTEST_6( comparisons(ArrayXXi(internal::random(1,EIGEN_TEST_MAX_SIZE), internal::random(1,EIGEN_TEST_MAX_SIZE))) ); + CALL_SUBTEST_7( comparisons(ArrayXXf(internal::random(1,EIGEN_TEST_MAX_SIZE), internal::random(1,EIGEN_TEST_MAX_SIZE))) ); + CALL_SUBTEST_8( comparisons(ArrayXXi(internal::random(1,EIGEN_TEST_MAX_SIZE), internal::random(1,EIGEN_TEST_MAX_SIZE))) ); } for(int i = 0; i < g_repeat; i++) { - CALL_SUBTEST_1( min_max(Array()) ); - CALL_SUBTEST_2( min_max(Array22f()) ); - CALL_SUBTEST_3( min_max(Array44d()) ); - CALL_SUBTEST_5( min_max(ArrayXXf(internal::random(1,EIGEN_TEST_MAX_SIZE), internal::random(1,EIGEN_TEST_MAX_SIZE))) ); - CALL_SUBTEST_6( min_max(ArrayXXi(internal::random(1,EIGEN_TEST_MAX_SIZE), internal::random(1,EIGEN_TEST_MAX_SIZE))) ); + CALL_SUBTEST_6( min_max(Array()) ); + CALL_SUBTEST_7( min_max(Array22f()) ); + CALL_SUBTEST_8( min_max(Array44d()) ); + CALL_SUBTEST_9( min_max(ArrayXXf(internal::random(1,EIGEN_TEST_MAX_SIZE), internal::random(1,EIGEN_TEST_MAX_SIZE))) ); + CALL_SUBTEST_10( min_max(ArrayXXi(internal::random(1,EIGEN_TEST_MAX_SIZE), internal::random(1,EIGEN_TEST_MAX_SIZE))) ); } for(int i = 0; i < g_repeat; i++) { - CALL_SUBTEST_1( array_real(Array()) ); - CALL_SUBTEST_2( array_real(Array22f()) ); - CALL_SUBTEST_3( array_real(Array44d()) ); - CALL_SUBTEST_5( array_real(ArrayXXf(internal::random(1,EIGEN_TEST_MAX_SIZE), internal::random(1,EIGEN_TEST_MAX_SIZE))) ); - CALL_SUBTEST_7( array_real(Array()) ); - CALL_SUBTEST_8( array_real(Array()) ); + CALL_SUBTEST_11( array_real(Array()) ); + CALL_SUBTEST_12( array_real(Array22f()) ); + CALL_SUBTEST_13( array_real(Array44d()) ); + CALL_SUBTEST_14( array_real(ArrayXXf(internal::random(1,EIGEN_TEST_MAX_SIZE), internal::random(1,EIGEN_TEST_MAX_SIZE))) ); + CALL_SUBTEST_15( array_real(Array()) ); + CALL_SUBTEST_16( array_real(Array()) ); } for(int i = 0; i < g_repeat; i++) { - CALL_SUBTEST_4( array_complex(ArrayXXcf(internal::random(1,EIGEN_TEST_MAX_SIZE), internal::random(1,EIGEN_TEST_MAX_SIZE))) ); - CALL_SUBTEST_5( array_complex(ArrayXXcd(internal::random(1,EIGEN_TEST_MAX_SIZE), internal::random(1,EIGEN_TEST_MAX_SIZE)))); + CALL_SUBTEST_17( array_complex(ArrayXXcf(internal::random(1,EIGEN_TEST_MAX_SIZE), internal::random(1,EIGEN_TEST_MAX_SIZE))) ); + CALL_SUBTEST_18( array_complex(ArrayXXcd(internal::random(1,EIGEN_TEST_MAX_SIZE), internal::random(1,EIGEN_TEST_MAX_SIZE)))); } for(int i = 0; i < g_repeat; i++) { - CALL_SUBTEST_5( float_pow_test() ); - CALL_SUBTEST_6( int_pow_test() ); - CALL_SUBTEST_7( mixed_pow_test() ); - CALL_SUBTEST_8( signbit_tests() ); + CALL_SUBTEST_19( float_pow_test() ); + CALL_SUBTEST_20( int_pow_test() ); + CALL_SUBTEST_21( mixed_pow_test() ); + CALL_SUBTEST_22( signbit_tests() ); } for (int i = 0; i < g_repeat; i++) { - CALL_SUBTEST_2( typed_logicals_test(ArrayX(internal::random(1, EIGEN_TEST_MAX_SIZE))) ); - CALL_SUBTEST_2( typed_logicals_test(ArrayX(internal::random(1, EIGEN_TEST_MAX_SIZE))) ); - CALL_SUBTEST_3( typed_logicals_test(ArrayX(internal::random(1, EIGEN_TEST_MAX_SIZE)))); - CALL_SUBTEST_3( typed_logicals_test(ArrayX>(internal::random(1, EIGEN_TEST_MAX_SIZE)))); - CALL_SUBTEST_3( typed_logicals_test(ArrayX>(internal::random(1, EIGEN_TEST_MAX_SIZE)))); + CALL_SUBTEST_23( typed_logicals_test(ArrayX(internal::random(1, EIGEN_TEST_MAX_SIZE))) ); + CALL_SUBTEST_24( typed_logicals_test(ArrayX(internal::random(1, EIGEN_TEST_MAX_SIZE))) ); + CALL_SUBTEST_25( typed_logicals_test(ArrayX(internal::random(1, EIGEN_TEST_MAX_SIZE))) ); + CALL_SUBTEST_26( typed_logicals_test(ArrayX>(internal::random(1, EIGEN_TEST_MAX_SIZE)))); + CALL_SUBTEST_27( typed_logicals_test(ArrayX>(internal::random(1, EIGEN_TEST_MAX_SIZE)))); } for (int i = 0; i < g_repeat; i++) { - CALL_SUBTEST_1((cast_test<1, 1>())); - CALL_SUBTEST_2((cast_test<3, 1>())); - CALL_SUBTEST_2((cast_test<3, 3>())); - CALL_SUBTEST_3((cast_test<5, 1>())); - CALL_SUBTEST_3((cast_test<5, 5>())); - CALL_SUBTEST_4((cast_test<9, 1>())); - CALL_SUBTEST_4((cast_test<9, 9>())); - CALL_SUBTEST_5((cast_test<17, 1>())); - CALL_SUBTEST_5((cast_test<17, 17>())); - CALL_SUBTEST_6((cast_test())); - CALL_SUBTEST_6((cast_test())); + CALL_SUBTEST_28( (cast_test<1, 1>()) ); + CALL_SUBTEST_29( (cast_test<3, 1>()) ); + CALL_SUBTEST_30( (cast_test<5, 1>()) ); + CALL_SUBTEST_31( (cast_test<9, 1>()) ); + CALL_SUBTEST_32( (cast_test<17, 1>()) ); + CALL_SUBTEST_33( (cast_test()) ); } VERIFY((internal::is_same< internal::global_math_functions_filtering_base::type, int >::value)); diff --git a/test/basicstuff.cpp b/test/basicstuff.cpp index 47dfc0469..05cd6ad31 100644 --- a/test/basicstuff.cpp +++ b/test/basicstuff.cpp @@ -69,8 +69,10 @@ template void basicStuff(const MatrixType& m) x = v1(static_cast(r1)); x = v1(static_cast(r1)); x = v1(static_cast(r1)); - x = v1(static_cast(r1)); - x = v1(static_cast(r1)); + if(sizeof(Index) >= sizeof(long long int)) + x = v1(static_cast(r1)); + if(sizeof(Index) >= sizeof(unsigned long long int)) + x = v1(static_cast(r1)); VERIFY_IS_APPROX( v1, v1); VERIFY_IS_NOT_APPROX( v1, 2*v1); diff --git a/test/random_without_cast_overflow.h b/test/random_without_cast_overflow.h index 7f1ea5ff3..715bb8e9e 100644 --- a/test/random_without_cast_overflow.h +++ b/test/random_without_cast_overflow.h @@ -23,7 +23,7 @@ struct random_without_cast_overflow { template struct random_without_cast_overflow< SrcScalar, TgtScalar, - std::enable_if_t::IsInteger && NumTraits::IsInteger && + std::enable_if_t::IsInteger && NumTraits::IsSigned && NumTraits::IsInteger && !NumTraits::IsSigned && (std::numeric_limits::digits < std::numeric_limits::digits || (std::numeric_limits::digits == std::numeric_limits::digits && @@ -34,12 +34,27 @@ struct random_without_cast_overflow< } }; +// Signed to unsigned integer widening cast. +template +struct random_without_cast_overflow< + SrcScalar, TgtScalar, + std::enable_if_t::IsInteger && !NumTraits::IsSigned && NumTraits::IsInteger && + !NumTraits::IsSigned && + (std::numeric_limits::digits < std::numeric_limits::digits || + (std::numeric_limits::digits == std::numeric_limits::digits && + NumTraits::IsSigned))>> { + static SrcScalar value() { + SrcScalar a = internal::random(); + return a; + } +}; + // Integer to unsigned narrowing cast. template struct random_without_cast_overflow< SrcScalar, TgtScalar, std::enable_if_t< - NumTraits::IsInteger && NumTraits::IsInteger && !NumTraits::IsSigned && + NumTraits::IsInteger && NumTraits::IsInteger && NumTraits::IsSigned && !NumTraits::IsSigned && (std::numeric_limits::digits > std::numeric_limits::digits)>> { static SrcScalar value() { TgtScalar b = internal::random(); @@ -47,6 +62,19 @@ struct random_without_cast_overflow< } }; +// Integer to unsigned narrowing cast. +template +struct random_without_cast_overflow< + SrcScalar, TgtScalar, + std::enable_if_t< + NumTraits::IsInteger && NumTraits::IsInteger && !NumTraits::IsSigned && !NumTraits::IsSigned && + (std::numeric_limits::digits > std::numeric_limits::digits)>> { + static SrcScalar value() { + TgtScalar b = internal::random(); + return static_cast(b); + } +}; + // Integer to signed narrowing cast. template struct random_without_cast_overflow< @@ -83,7 +111,7 @@ template struct random_without_cast_overflow< SrcScalar, TgtScalar, std::enable_if_t< - !NumTraits::IsInteger && !NumTraits::IsComplex && NumTraits::IsInteger && + !NumTraits::IsInteger && !NumTraits::IsComplex && NumTraits::IsInteger && NumTraits::IsSigned && (std::numeric_limits::digits > std::numeric_limits::digits)>> { static SrcScalar value() { // NOTE: internal::random() is limited by RAND_MAX, so random is always within that range. @@ -95,6 +123,22 @@ struct random_without_cast_overflow< } }; +template +struct random_without_cast_overflow< + SrcScalar, TgtScalar, + std::enable_if_t< + !NumTraits::IsInteger && !NumTraits::IsComplex && NumTraits::IsInteger && !NumTraits::IsSigned && + (std::numeric_limits::digits > std::numeric_limits::digits)>> { + static SrcScalar value() { + // NOTE: internal::random() is limited by RAND_MAX, so random is always within that range. + // This prevents us from simply shifting bits, which would result in only 0 or -1. + // Instead, keep least-significant K bits and sign. + static const TgtScalar KeepMask = (static_cast(1) << std::numeric_limits::digits) - 1; + const TgtScalar a = internal::random(); + return static_cast(a & KeepMask); + } +}; + // Integer to floating-point, re-use above logic. template struct random_without_cast_overflow< diff --git a/test/stdvector.cpp b/test/stdvector.cpp index 2ca584b9d..1d44e42d1 100644 --- a/test/stdvector.cpp +++ b/test/stdvector.cpp @@ -124,7 +124,7 @@ void std_vector_gcc_warning() { typedef Eigen::Vector3f T; std::vector > v; - v.push_back(T()); + v.push_back(T(1.0f,2.0f,3.0f)); } EIGEN_DECLARE_TEST(stdvector) diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorBlock.h b/unsupported/Eigen/CXX11/src/Tensor/TensorBlock.h index ee01d9932..7e9248796 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorBlock.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorBlock.h @@ -998,8 +998,8 @@ class StridedLinearBufferCopy { enum { Vectorizable = packet_traits::Vectorizable, PacketSize = packet_traits::size, - HasHalfPacket = unpacket_traits::size < PacketSize, HalfPacketSize = unpacket_traits::size, + HasHalfPacket = static_cast(HalfPacketSize) < static_cast(PacketSize) }; public: diff --git a/unsupported/Eigen/FFT b/unsupported/Eigen/FFT index 137b96295..0b4ce1a86 100644 --- a/unsupported/Eigen/FFT +++ b/unsupported/Eigen/FFT @@ -181,15 +181,16 @@ class FFT typedef typename impl_type::Scalar Scalar; typedef typename impl_type::Complex Complex; - enum Flag { - Default=0, // goof proof - Unscaled=1, - HalfSpectrum=2, - // SomeOtherSpeedOptimization=4 - Speedy=32767 - }; + using Flag = int; + static constexpr Flag Default = 0; + static constexpr Flag Unscaled = 1; + static constexpr Flag HalfSpectrum = 2; + static constexpr Flag Speedy = 32767; - FFT( const impl_type & impl=impl_type() , Flag flags=Default ) :m_impl(impl),m_flag(flags) { } + FFT( const impl_type & impl=impl_type() , Flag flags=Default ) :m_impl(impl),m_flag(flags) + { + eigen_assert((flags == Default || flags == Unscaled || flags == HalfSpectrum || flags == Speedy) && "invalid flags argument"); + } inline bool HasFlag(Flag f) const { return (m_flag & (int)f) == f;} diff --git a/unsupported/test/EulerAngles.cpp b/unsupported/test/EulerAngles.cpp index 0955795b6..8452577e8 100644 --- a/unsupported/test/EulerAngles.cpp +++ b/unsupported/test/EulerAngles.cpp @@ -9,6 +9,8 @@ #include "main.h" +EIGEN_DISABLE_DEPRECATED_WARNING + #include using namespace Eigen; diff --git a/unsupported/test/NNLS.cpp b/unsupported/test/NNLS.cpp index b347c06fe..58092efcd 100644 --- a/unsupported/test/NNLS.cpp +++ b/unsupported/test/NNLS.cpp @@ -54,7 +54,7 @@ void test_nnls_known_solution(const MatrixType &A, const VectorB &b, const Vecto } template -void test_nnls_random_problem() { +void test_nnls_random_problem(const MatrixType&) { // // SETUP // @@ -448,12 +448,9 @@ EIGEN_DECLARE_TEST(NNLS) { for (int i = 0; i < g_repeat; i++) { // Essential NNLS properties, across different types. - CALL_SUBTEST_2(test_nnls_random_problem()); - CALL_SUBTEST_3(test_nnls_random_problem()); - { - using MatFixed = Matrix; - CALL_SUBTEST_4(test_nnls_random_problem()); - } + CALL_SUBTEST_2(test_nnls_random_problem(MatrixXf())); + CALL_SUBTEST_3(test_nnls_random_problem(MatrixXd())); + CALL_SUBTEST_4(test_nnls_random_problem(Matrix())); CALL_SUBTEST_5(test_nnls_with_half_precision()); // Robustness tests: diff --git a/unsupported/test/cxx11_tensor_casts.cpp b/unsupported/test/cxx11_tensor_casts.cpp index 81d81efdd..7976dcb01 100644 --- a/unsupported/test/cxx11_tensor_casts.cpp +++ b/unsupported/test/cxx11_tensor_casts.cpp @@ -30,7 +30,7 @@ static void test_type_cast() { for (int i = 0; i < 101; ++i) { for (int j = 0; j < 201; ++j) { - const ToType ref = static_cast(ftensor(i, j)); + const ToType ref = internal::cast(ftensor(i, j)); VERIFY_IS_EQUAL(ttensor(i, j), ref); } } diff --git a/unsupported/test/cxx11_tensor_reduction.cpp b/unsupported/test/cxx11_tensor_reduction.cpp index ce4e53860..071046a32 100644 --- a/unsupported/test/cxx11_tensor_reduction.cpp +++ b/unsupported/test/cxx11_tensor_reduction.cpp @@ -485,7 +485,7 @@ void test_sum_accuracy() { // Test against probabilistic forward error bound. In reality, the error is much smaller // when we use tree summation. double err = Eigen::numext::abs(static_cast(sum()) - expected_sum); - double tol = numext::sqrt(static_cast(num_elements)) * NumTraits::epsilon() * static_cast(abs_sum); + double tol = numext::sqrt(static_cast(num_elements)) * static_cast(NumTraits::epsilon()) * abs_sum; VERIFY_LE(err, tol); } }