From 77b48c440ed1de189b5296feb86e24536f645065 Mon Sep 17 00:00:00 2001 From: Rasmus Munk Larsen Date: Fri, 10 Feb 2023 12:38:26 -0800 Subject: [PATCH] Fix compiler warnings. --- Eigen/src/Core/PlainObjectBase.h | 4 +- Eigen/src/Core/functors/BinaryFunctors.h | 2 +- .../Core/products/TriangularMatrixVector.h | 49 +++++++++---------- Eigen/src/Jacobi/Jacobi.h | 19 +++---- test/unalignedcount.cpp | 3 ++ 5 files changed, 36 insertions(+), 41 deletions(-) diff --git a/Eigen/src/Core/PlainObjectBase.h b/Eigen/src/Core/PlainObjectBase.h index 60a75b1d6..fc2e94178 100644 --- a/Eigen/src/Core/PlainObjectBase.h +++ b/Eigen/src/Core/PlainObjectBase.h @@ -538,7 +538,9 @@ class PlainObjectBase : public internal::dense_xpr_base::type if (ColsAtCompileTime == 1 && list.size() == 1) { eigen_assert(list_size == static_cast(RowsAtCompileTime) || RowsAtCompileTime == Dynamic); resize(list_size, ColsAtCompileTime); - std::copy(list.begin()->begin(), list.begin()->end(), m_storage.data()); + if (list.begin()->begin() != nullptr) { + std::copy(list.begin()->begin(), list.begin()->end(), m_storage.data()); + } } else { eigen_assert(list.size() == static_cast(RowsAtCompileTime) || RowsAtCompileTime == Dynamic); eigen_assert(list_size == static_cast(ColsAtCompileTime) || ColsAtCompileTime == Dynamic); diff --git a/Eigen/src/Core/functors/BinaryFunctors.h b/Eigen/src/Core/functors/BinaryFunctors.h index 3c7601963..1cd8c5d87 100644 --- a/Eigen/src/Core/functors/BinaryFunctors.h +++ b/Eigen/src/Core/functors/BinaryFunctors.h @@ -534,7 +534,7 @@ template using Scalar = LhsScalar; enum { PacketAccess = is_same::value && packet_traits::HasATan && packet_traits::HasDiv && !NumTraits::IsInteger && !NumTraits::IsComplex, - Cost = scalar_div_cost::value + functor_traits>::Cost + Cost = int(scalar_div_cost::value) + int(functor_traits>::Cost) }; }; diff --git a/Eigen/src/Core/products/TriangularMatrixVector.h b/Eigen/src/Core/products/TriangularMatrixVector.h index df15e814d..ce7550c36 100644 --- a/Eigen/src/Core/products/TriangularMatrixVector.h +++ b/Eigen/src/Core/products/TriangularMatrixVector.h @@ -23,13 +23,12 @@ template { typedef typename ScalarBinaryOpTraits::ReturnType ResScalar; - enum { - IsLower = ((Mode&Lower)==Lower), - HasUnitDiag = (Mode & UnitDiag)==UnitDiag, - HasZeroDiag = (Mode & ZeroDiag)==ZeroDiag - }; - static EIGEN_DONT_INLINE void run(Index _rows, Index _cols, const LhsScalar* _lhs, Index lhsStride, - const RhsScalar* _rhs, Index rhsIncr, ResScalar* _res, Index resIncr, const RhsScalar& alpha); + static constexpr bool IsLower = ((Mode & Lower) == Lower); + static constexpr bool HasUnitDiag = (Mode & UnitDiag) == UnitDiag; + static constexpr bool HasZeroDiag = (Mode & ZeroDiag) == ZeroDiag; + static EIGEN_DONT_INLINE void run(Index _rows, Index _cols, const LhsScalar* _lhs, Index lhsStride, + const RhsScalar* _rhs, Index rhsIncr, ResScalar* _res, Index resIncr, + const RhsScalar& alpha); }; template @@ -94,13 +93,12 @@ template { typedef typename ScalarBinaryOpTraits::ReturnType ResScalar; - enum { - IsLower = ((Mode&Lower)==Lower), - HasUnitDiag = (Mode & UnitDiag)==UnitDiag, - HasZeroDiag = (Mode & ZeroDiag)==ZeroDiag - }; + static constexpr bool IsLower = ((Mode & Lower) == Lower); + static constexpr bool HasUnitDiag = (Mode & UnitDiag) == UnitDiag; + static constexpr bool HasZeroDiag = (Mode & ZeroDiag) == ZeroDiag; static EIGEN_DONT_INLINE void run(Index _rows, Index _cols, const LhsScalar* _lhs, Index lhsStride, - const RhsScalar* _rhs, Index rhsIncr, ResScalar* _res, Index resIncr, const ResScalar& alpha); + const RhsScalar* _rhs, Index rhsIncr, ResScalar* _res, Index resIncr, + const ResScalar& alpha); }; template @@ -202,7 +200,7 @@ struct triangular_product_impl namespace internal { // TODO: find a way to factorize this piece of code with gemv_selector since the logic is exactly the same. - + template struct trmv_selector { template @@ -211,13 +209,14 @@ template struct trmv_selector typedef typename Lhs::Scalar LhsScalar; typedef typename Rhs::Scalar RhsScalar; typedef typename Dest::Scalar ResScalar; - + typedef internal::blas_traits LhsBlasTraits; typedef typename LhsBlasTraits::DirectLinearAccessType ActualLhsType; typedef internal::blas_traits RhsBlasTraits; typedef typename RhsBlasTraits::DirectLinearAccessType ActualRhsType; - - typedef Map, plain_enum_min(AlignedMax,internal::packet_traits::size)> MappedDest; + constexpr int Alignment = (std::min)(int(AlignedMax), int(internal::packet_traits::size)); + + typedef Map, Alignment> MappedDest; add_const_on_value_type_t actualLhs = LhsBlasTraits::extract(lhs); add_const_on_value_type_t actualRhs = RhsBlasTraits::extract(rhs); @@ -226,13 +225,11 @@ template struct trmv_selector RhsScalar rhs_alpha = RhsBlasTraits::extractScalarFactor(rhs); ResScalar actualAlpha = alpha * lhs_alpha * rhs_alpha; - enum { - // FIXME find a way to allow an inner stride on the result if packet_traits::size==1 - // on, the other hand it is good for the cache to pack the vector anyways... - EvalToDestAtCompileTime = Dest::InnerStrideAtCompileTime==1, - ComplexByReal = (NumTraits::IsComplex) && (!NumTraits::IsComplex), - MightCannotUseDest = (Dest::InnerStrideAtCompileTime!=1) || ComplexByReal - }; + // FIXME find a way to allow an inner stride on the result if packet_traits::size==1 + // on, the other hand it is good for the cache to pack the vector anyways... + constexpr bool EvalToDestAtCompileTime = Dest::InnerStrideAtCompileTime==1; + constexpr bool ComplexByReal = (NumTraits::IsComplex) && (!NumTraits::IsComplex); + constexpr bool MightCannotUseDest = (Dest::InnerStrideAtCompileTime!=1) || ComplexByReal; gemv_static_vector_if static_dest; @@ -307,9 +304,7 @@ template struct trmv_selector RhsScalar rhs_alpha = RhsBlasTraits::extractScalarFactor(rhs); ResScalar actualAlpha = alpha * lhs_alpha * rhs_alpha; - enum { - DirectlyUseRhs = ActualRhsTypeCleaned::InnerStrideAtCompileTime==1 - }; + constexpr bool DirectlyUseRhs = ActualRhsTypeCleaned::InnerStrideAtCompileTime==1; gemv_static_vector_if static_rhs; diff --git a/Eigen/src/Jacobi/Jacobi.h b/Eigen/src/Jacobi/Jacobi.h index 5d9698990..5d0f27637 100644 --- a/Eigen/src/Jacobi/Jacobi.h +++ b/Eigen/src/Jacobi/Jacobi.h @@ -347,18 +347,15 @@ struct apply_rotation_in_the_plane_selector::type Packet; typedef typename packet_traits::type OtherPacket; - enum { - RequiredAlignment = plain_enum_max(unpacket_traits::alignment, - unpacket_traits::alignment), - PacketSize = packet_traits::size, - OtherPacketSize = packet_traits::size - }; + constexpr int RequiredAlignment = + (std::max)(unpacket_traits::alignment, unpacket_traits::alignment); + constexpr Index PacketSize = packet_traits::size; /*** dynamic-size vectorized paths ***/ if(size >= 2 * PacketSize && SizeAtCompileTime == Dynamic && ((incrx == 1 && incry == 1) || PacketSize == 1)) { // both vectors are sequentially stored in memory => vectorization - enum { Peeling = 2 }; + constexpr Index Peeling = 2; Index alignedStart = internal::first_default_aligned(y, size); Index alignedEnd = alignedStart + ((size-alignedStart)/PacketSize)*PacketSize; @@ -474,11 +471,9 @@ void inline apply_rotation_in_the_plane(DenseBase& xpr_x, DenseBase::Alignment, evaluator::Alignment), - Vectorizable>::run(x,incrx,y,incry,size,c,s); + constexpr int Alignment = (std::min)(int(evaluator::Alignment), int(evaluator::Alignment)); + apply_rotation_in_the_plane_selector::run( + x, incrx, y, incry, size, c, s); } } // end namespace internal diff --git a/test/unalignedcount.cpp b/test/unalignedcount.cpp index 52cdd9e1d..40b9ab8ec 100644 --- a/test/unalignedcount.cpp +++ b/test/unalignedcount.cpp @@ -32,6 +32,7 @@ EIGEN_DECLARE_TEST(unalignedcount) { #if defined(EIGEN_VECTORIZE_AVX512) VectorXf a(48), b(48); + a.fill(0); b.fill(1); VERIFY_ALIGNED_UNALIGNED_COUNT(a += b, 6, 0, 3, 0); VERIFY_ALIGNED_UNALIGNED_COUNT(a.segment(0,48) += b.segment(0,48), 3, 3, 3, 0); VERIFY_ALIGNED_UNALIGNED_COUNT(a.segment(0,48) -= b.segment(0,48), 3, 3, 3, 0); @@ -39,6 +40,7 @@ EIGEN_DECLARE_TEST(unalignedcount) VERIFY_ALIGNED_UNALIGNED_COUNT(a.segment(0,48) /= 3.5, 3, 0, 3, 0); #elif defined(EIGEN_VECTORIZE_AVX) VectorXf a(40), b(40); + a.fill(0); b.fill(1); VERIFY_ALIGNED_UNALIGNED_COUNT(a += b, 10, 0, 5, 0); VERIFY_ALIGNED_UNALIGNED_COUNT(a.segment(0,40) += b.segment(0,40), 5, 5, 5, 0); VERIFY_ALIGNED_UNALIGNED_COUNT(a.segment(0,40) -= b.segment(0,40), 5, 5, 5, 0); @@ -46,6 +48,7 @@ EIGEN_DECLARE_TEST(unalignedcount) VERIFY_ALIGNED_UNALIGNED_COUNT(a.segment(0,40) /= 3.5, 5, 0, 5, 0); #elif defined(EIGEN_VECTORIZE_SSE) VectorXf a(40), b(40); + a.fill(0); b.fill(1); VERIFY_ALIGNED_UNALIGNED_COUNT(a += b, 20, 0, 10, 0); VERIFY_ALIGNED_UNALIGNED_COUNT(a.segment(0,40) += b.segment(0,40), 10, 10, 10, 0); VERIFY_ALIGNED_UNALIGNED_COUNT(a.segment(0,40) -= b.segment(0,40), 10, 10, 10, 0);