diff --git a/Eigen/src/Core/DenseBase.h b/Eigen/src/Core/DenseBase.h index 3a8487b9b..bcda5f094 100644 --- a/Eigen/src/Core/DenseBase.h +++ b/Eigen/src/Core/DenseBase.h @@ -105,8 +105,7 @@ template class DenseBase * \sa MatrixBase::rows(), MatrixBase::cols(), RowsAtCompileTime, SizeAtCompileTime */ - SizeAtCompileTime = (internal::size_at_compile_time::RowsAtCompileTime, - internal::traits::ColsAtCompileTime>::ret), + SizeAtCompileTime = (internal::size_of_xpr_at_compile_time::ret), /**< This is equal to the number of coefficients, i.e. the number of * rows times the number of columns, or to \a Dynamic if this is not * known at compile-time. \sa RowsAtCompileTime, ColsAtCompileTime */ @@ -133,8 +132,7 @@ template class DenseBase * \sa ColsAtCompileTime, MaxRowsAtCompileTime, MaxSizeAtCompileTime */ - MaxSizeAtCompileTime = (internal::size_at_compile_time::MaxRowsAtCompileTime, - internal::traits::MaxColsAtCompileTime>::ret), + MaxSizeAtCompileTime = (internal::size_of_xpr_at_compile_time::ret), /**< This value is equal to the maximum possible number of coefficients that this expression * might have. If this expression might have an arbitrarily high number of coefficients, * this value is set to \a Dynamic. diff --git a/Eigen/src/Core/Matrix.h b/Eigen/src/Core/Matrix.h index 51455744f..23acd8ae7 100644 --- a/Eigen/src/Core/Matrix.h +++ b/Eigen/src/Core/Matrix.h @@ -20,7 +20,7 @@ template > { private: - enum { size = internal::size_at_compile_time::ret }; + constexpr static int size = internal::size_at_compile_time(Rows_,Cols_); typedef typename find_best_packet::type PacketScalar; enum { row_major_bit = Options_&RowMajor ? RowMajorBit : 0, @@ -42,7 +42,7 @@ public: ColsAtCompileTime = Cols_, MaxRowsAtCompileTime = MaxRows_, MaxColsAtCompileTime = MaxCols_, - Flags = compute_matrix_flags::ret, + Flags = compute_matrix_flags(Options_), Options = Options_, InnerStrideAtCompileTime = 1, OuterStrideAtCompileTime = (Options&RowMajor) ? ColsAtCompileTime : RowsAtCompileTime, diff --git a/Eigen/src/Core/SolverBase.h b/Eigen/src/Core/SolverBase.h index a8e91180d..fda618620 100644 --- a/Eigen/src/Core/SolverBase.h +++ b/Eigen/src/Core/SolverBase.h @@ -81,12 +81,10 @@ class SolverBase : public EigenBase enum { RowsAtCompileTime = internal::traits::RowsAtCompileTime, ColsAtCompileTime = internal::traits::ColsAtCompileTime, - SizeAtCompileTime = (internal::size_at_compile_time::RowsAtCompileTime, - internal::traits::ColsAtCompileTime>::ret), + SizeAtCompileTime = (internal::size_of_xpr_at_compile_time::ret), MaxRowsAtCompileTime = internal::traits::MaxRowsAtCompileTime, MaxColsAtCompileTime = internal::traits::MaxColsAtCompileTime, - MaxSizeAtCompileTime = (internal::size_at_compile_time::MaxRowsAtCompileTime, - internal::traits::MaxColsAtCompileTime>::ret), + MaxSizeAtCompileTime = (internal::size_of_xpr_at_compile_time::ret), IsVectorAtCompileTime = internal::traits::MaxRowsAtCompileTime == 1 || internal::traits::MaxColsAtCompileTime == 1, NumDimensions = int(MaxSizeAtCompileTime) == 1 ? 0 : bool(IsVectorAtCompileTime) ? 1 : 2 diff --git a/Eigen/src/Core/TriangularMatrix.h b/Eigen/src/Core/TriangularMatrix.h index a583f248d..7ecaf7ddd 100644 --- a/Eigen/src/Core/TriangularMatrix.h +++ b/Eigen/src/Core/TriangularMatrix.h @@ -37,14 +37,12 @@ template class TriangularBase : public EigenBase MaxRowsAtCompileTime = internal::traits::MaxRowsAtCompileTime, MaxColsAtCompileTime = internal::traits::MaxColsAtCompileTime, - SizeAtCompileTime = (internal::size_at_compile_time::RowsAtCompileTime, - internal::traits::ColsAtCompileTime>::ret), + SizeAtCompileTime = (internal::size_of_xpr_at_compile_time::ret), /**< This is equal to the number of coefficients, i.e. the number of * rows times the number of columns, or to \a Dynamic if this is not * known at compile-time. \sa RowsAtCompileTime, ColsAtCompileTime */ - MaxSizeAtCompileTime = (internal::size_at_compile_time::MaxRowsAtCompileTime, - internal::traits::MaxColsAtCompileTime>::ret) + MaxSizeAtCompileTime = (internal::size_of_xpr_at_compile_time::ret) }; typedef typename internal::traits::Scalar Scalar; diff --git a/Eigen/src/Core/util/Macros.h b/Eigen/src/Core/util/Macros.h index dea247d2a..60dcb4866 100644 --- a/Eigen/src/Core/util/Macros.h +++ b/Eigen/src/Core/util/Macros.h @@ -913,7 +913,7 @@ // Suppresses 'unused variable' warnings. namespace Eigen { namespace internal { - template EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ignore_unused_variable(const T&) {} + template EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void ignore_unused_variable(const T&) {} } } #define EIGEN_UNUSED_VARIABLE(var) Eigen::internal::ignore_unused_variable(var); diff --git a/Eigen/src/Core/util/XprHelper.h b/Eigen/src/Core/util/XprHelper.h index 137ff2139..5823f029f 100644 --- a/Eigen/src/Core/util/XprHelper.h +++ b/Eigen/src/Core/util/XprHelper.h @@ -203,38 +203,27 @@ struct find_best_packet }; #if EIGEN_MAX_STATIC_ALIGN_BYTES>0 -template -struct compute_default_alignment_helper -{ - enum { value = 0 }; -}; - -template -struct compute_default_alignment_helper // Match -{ - enum { value = AlignmentBytes }; -}; - -template -struct compute_default_alignment_helper // Try-half -{ - // current packet too large, try with an half-packet - enum { value = compute_default_alignment_helper::value }; -}; +constexpr inline int compute_default_alignment_helper(int ArrayBytes, int AlignmentBytes) { + if((ArrayBytes % AlignmentBytes) == 0) { + return AlignmentBytes; + } else if (EIGEN_MIN_ALIGN_BYTES -struct compute_default_alignment_helper -{ - enum { value = 0 }; -}; +// This also avoids a division by zero +constexpr inline int compute_default_alignment_helper(int ArrayBytes, int AlignmentBytes) { + EIGEN_UNUSED_VARIABLE(ArrayBytes); + EIGEN_UNUSED_VARIABLE(AlignmentBytes); + return 0; +} #endif template struct compute_default_alignment { - enum { value = compute_default_alignment_helper::value }; + enum { value = compute_default_alignment_helper(Size*sizeof(T), EIGEN_MAX_STATIC_ALIGN_BYTES) }; }; template struct compute_default_alignment { @@ -261,25 +250,21 @@ template type; }; -template -class compute_matrix_flags -{ - enum { row_major_bit = Options&RowMajor ? RowMajorBit : 0 }; - public: - // FIXME currently we still have to handle DirectAccessBit at the expression level to handle DenseCoeffsBase<> - // and then propagate this information to the evaluator's flags. - // However, I (Gael) think that DirectAccessBit should only matter at the evaluation stage. - enum { ret = DirectAccessBit | LvalueBit | NestByRefBit | row_major_bit }; -}; +constexpr inline unsigned compute_matrix_flags(int Options) { + unsigned row_major_bit = Options&RowMajor ? RowMajorBit : 0; + // FIXME currently we still have to handle DirectAccessBit at the expression level to handle DenseCoeffsBase<> + // and then propagate this information to the evaluator's flags. + // However, I (Gael) think that DirectAccessBit should only matter at the evaluation stage. + return DirectAccessBit | LvalueBit | NestByRefBit | row_major_bit; +} -template struct size_at_compile_time -{ - enum { ret = (Rows_==Dynamic || Cols_==Dynamic) ? Dynamic : Rows_ * Cols_ }; -}; +constexpr inline int size_at_compile_time(int rows, int cols) { + return (rows==Dynamic || cols==Dynamic) ? Dynamic : rows * cols; +} template struct size_of_xpr_at_compile_time { - enum { ret = size_at_compile_time::RowsAtCompileTime,traits::ColsAtCompileTime>::ret }; + enum { ret = size_at_compile_time(traits::RowsAtCompileTime, traits::ColsAtCompileTime) }; }; /* plain_matrix_type : the difference from eval is that plain_matrix_type is always a plain matrix type, diff --git a/Eigen/src/SparseCore/SparseMatrixBase.h b/Eigen/src/SparseCore/SparseMatrixBase.h index 8222d263f..32986e492 100644 --- a/Eigen/src/SparseCore/SparseMatrixBase.h +++ b/Eigen/src/SparseCore/SparseMatrixBase.h @@ -71,8 +71,7 @@ template class SparseMatrixBase * \sa MatrixBase::rows(), MatrixBase::cols(), RowsAtCompileTime, SizeAtCompileTime */ - SizeAtCompileTime = (internal::size_at_compile_time::RowsAtCompileTime, - internal::traits::ColsAtCompileTime>::ret), + SizeAtCompileTime = (internal::size_of_xpr_at_compile_time::ret), /**< This is equal to the number of coefficients, i.e. the number of * rows times the number of columns, or to \a Dynamic if this is not * known at compile-time. \sa RowsAtCompileTime, ColsAtCompileTime */ @@ -80,8 +79,7 @@ template class SparseMatrixBase MaxRowsAtCompileTime = RowsAtCompileTime, MaxColsAtCompileTime = ColsAtCompileTime, - MaxSizeAtCompileTime = (internal::size_at_compile_time::ret), + MaxSizeAtCompileTime = internal::size_at_compile_time(MaxRowsAtCompileTime, MaxColsAtCompileTime), IsVectorAtCompileTime = RowsAtCompileTime == 1 || ColsAtCompileTime == 1, /**< This is set to true if either the number of rows or the number of diff --git a/unsupported/Eigen/src/KroneckerProduct/KroneckerTensorProduct.h b/unsupported/Eigen/src/KroneckerProduct/KroneckerTensorProduct.h index 3aecf9e66..01a75ef23 100644 --- a/unsupported/Eigen/src/KroneckerProduct/KroneckerTensorProduct.h +++ b/unsupported/Eigen/src/KroneckerProduct/KroneckerTensorProduct.h @@ -209,10 +209,10 @@ struct traits > typedef typename promote_index_type::type StorageIndex; enum { - Rows = size_at_compile_time::RowsAtCompileTime, traits::RowsAtCompileTime>::ret, - Cols = size_at_compile_time::ColsAtCompileTime, traits::ColsAtCompileTime>::ret, - MaxRows = size_at_compile_time::MaxRowsAtCompileTime, traits::MaxRowsAtCompileTime>::ret, - MaxCols = size_at_compile_time::MaxColsAtCompileTime, traits::MaxColsAtCompileTime>::ret + Rows = size_at_compile_time(traits::RowsAtCompileTime, traits::RowsAtCompileTime), + Cols = size_at_compile_time(traits::ColsAtCompileTime, traits::ColsAtCompileTime), + MaxRows = size_at_compile_time(traits::MaxRowsAtCompileTime, traits::MaxRowsAtCompileTime), + MaxCols = size_at_compile_time(traits::MaxColsAtCompileTime, traits::MaxColsAtCompileTime) }; typedef Matrix ReturnType; @@ -232,10 +232,10 @@ struct traits > LhsFlags = Lhs::Flags, RhsFlags = Rhs::Flags, - RowsAtCompileTime = size_at_compile_time::RowsAtCompileTime, traits::RowsAtCompileTime>::ret, - ColsAtCompileTime = size_at_compile_time::ColsAtCompileTime, traits::ColsAtCompileTime>::ret, - MaxRowsAtCompileTime = size_at_compile_time::MaxRowsAtCompileTime, traits::MaxRowsAtCompileTime>::ret, - MaxColsAtCompileTime = size_at_compile_time::MaxColsAtCompileTime, traits::MaxColsAtCompileTime>::ret, + RowsAtCompileTime = size_at_compile_time(traits::RowsAtCompileTime, traits::RowsAtCompileTime), + ColsAtCompileTime = size_at_compile_time(traits::ColsAtCompileTime, traits::ColsAtCompileTime), + MaxRowsAtCompileTime = size_at_compile_time(traits::MaxRowsAtCompileTime, traits::MaxRowsAtCompileTime), + MaxColsAtCompileTime = size_at_compile_time(traits::MaxColsAtCompileTime, traits::MaxColsAtCompileTime), EvalToRowMajor = (int(LhsFlags) & int(RhsFlags) & RowMajorBit), RemovedBits = ~(EvalToRowMajor ? 0 : RowMajorBit), diff --git a/unsupported/Eigen/src/Skyline/SkylineMatrixBase.h b/unsupported/Eigen/src/Skyline/SkylineMatrixBase.h index e68d8335e..86fd10d23 100644 --- a/unsupported/Eigen/src/Skyline/SkylineMatrixBase.h +++ b/unsupported/Eigen/src/Skyline/SkylineMatrixBase.h @@ -46,8 +46,7 @@ public: * \sa MatrixBase::rows(), MatrixBase::cols(), RowsAtCompileTime, SizeAtCompileTime */ - SizeAtCompileTime = (internal::size_at_compile_time::RowsAtCompileTime, - internal::traits::ColsAtCompileTime>::ret), + SizeAtCompileTime = (internal::size_of_xpr_at_compile_time::ret), /**< This is equal to the number of coefficients, i.e. the number of * rows times the number of columns, or to \a Dynamic if this is not * known at compile-time. \sa RowsAtCompileTime, ColsAtCompileTime */ @@ -55,8 +54,8 @@ public: MaxRowsAtCompileTime = RowsAtCompileTime, MaxColsAtCompileTime = ColsAtCompileTime, - MaxSizeAtCompileTime = (internal::size_at_compile_time::ret), + MaxSizeAtCompileTime = (internal::size_at_compile_time(MaxRowsAtCompileTime, + MaxColsAtCompileTime)), IsVectorAtCompileTime = RowsAtCompileTime == 1 || ColsAtCompileTime == 1, /**< This is set to true if either the number of rows or the number of