mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-14 12:46:00 +08:00
More constexpr helpers
This commit is contained in:
parent
64909b82bd
commit
e1df3636b2
@ -105,8 +105,7 @@ template<typename Derived> class DenseBase
|
||||
* \sa MatrixBase::rows(), MatrixBase::cols(), RowsAtCompileTime, SizeAtCompileTime */
|
||||
|
||||
|
||||
SizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::RowsAtCompileTime,
|
||||
internal::traits<Derived>::ColsAtCompileTime>::ret),
|
||||
SizeAtCompileTime = (internal::size_of_xpr_at_compile_time<Derived>::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<typename Derived> class DenseBase
|
||||
* \sa ColsAtCompileTime, MaxRowsAtCompileTime, MaxSizeAtCompileTime
|
||||
*/
|
||||
|
||||
MaxSizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::MaxRowsAtCompileTime,
|
||||
internal::traits<Derived>::MaxColsAtCompileTime>::ret),
|
||||
MaxSizeAtCompileTime = (internal::size_of_xpr_at_compile_time<Derived>::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.
|
||||
|
@ -20,7 +20,7 @@ template<typename Scalar_, int Rows_, int Cols_, int Options_, int MaxRows_, int
|
||||
struct traits<Matrix<Scalar_, Rows_, Cols_, Options_, MaxRows_, MaxCols_> >
|
||||
{
|
||||
private:
|
||||
enum { size = internal::size_at_compile_time<Rows_,Cols_>::ret };
|
||||
constexpr static int size = internal::size_at_compile_time(Rows_,Cols_);
|
||||
typedef typename find_best_packet<Scalar_,size>::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<Scalar_, Rows_, Cols_, Options_, MaxRows_, MaxCols_>::ret,
|
||||
Flags = compute_matrix_flags(Options_),
|
||||
Options = Options_,
|
||||
InnerStrideAtCompileTime = 1,
|
||||
OuterStrideAtCompileTime = (Options&RowMajor) ? ColsAtCompileTime : RowsAtCompileTime,
|
||||
|
@ -81,12 +81,10 @@ class SolverBase : public EigenBase<Derived>
|
||||
enum {
|
||||
RowsAtCompileTime = internal::traits<Derived>::RowsAtCompileTime,
|
||||
ColsAtCompileTime = internal::traits<Derived>::ColsAtCompileTime,
|
||||
SizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::RowsAtCompileTime,
|
||||
internal::traits<Derived>::ColsAtCompileTime>::ret),
|
||||
SizeAtCompileTime = (internal::size_of_xpr_at_compile_time<Derived>::ret),
|
||||
MaxRowsAtCompileTime = internal::traits<Derived>::MaxRowsAtCompileTime,
|
||||
MaxColsAtCompileTime = internal::traits<Derived>::MaxColsAtCompileTime,
|
||||
MaxSizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::MaxRowsAtCompileTime,
|
||||
internal::traits<Derived>::MaxColsAtCompileTime>::ret),
|
||||
MaxSizeAtCompileTime = (internal::size_of_xpr_at_compile_time<Derived>::ret),
|
||||
IsVectorAtCompileTime = internal::traits<Derived>::MaxRowsAtCompileTime == 1
|
||||
|| internal::traits<Derived>::MaxColsAtCompileTime == 1,
|
||||
NumDimensions = int(MaxSizeAtCompileTime) == 1 ? 0 : bool(IsVectorAtCompileTime) ? 1 : 2
|
||||
|
@ -37,14 +37,12 @@ template<typename Derived> class TriangularBase : public EigenBase<Derived>
|
||||
MaxRowsAtCompileTime = internal::traits<Derived>::MaxRowsAtCompileTime,
|
||||
MaxColsAtCompileTime = internal::traits<Derived>::MaxColsAtCompileTime,
|
||||
|
||||
SizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::RowsAtCompileTime,
|
||||
internal::traits<Derived>::ColsAtCompileTime>::ret),
|
||||
SizeAtCompileTime = (internal::size_of_xpr_at_compile_time<Derived>::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<internal::traits<Derived>::MaxRowsAtCompileTime,
|
||||
internal::traits<Derived>::MaxColsAtCompileTime>::ret)
|
||||
MaxSizeAtCompileTime = (internal::size_of_xpr_at_compile_time<Derived>::ret)
|
||||
|
||||
};
|
||||
typedef typename internal::traits<Derived>::Scalar Scalar;
|
||||
|
@ -913,7 +913,7 @@
|
||||
// Suppresses 'unused variable' warnings.
|
||||
namespace Eigen {
|
||||
namespace internal {
|
||||
template<typename T> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ignore_unused_variable(const T&) {}
|
||||
template<typename T> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void ignore_unused_variable(const T&) {}
|
||||
}
|
||||
}
|
||||
#define EIGEN_UNUSED_VARIABLE(var) Eigen::internal::ignore_unused_variable(var);
|
||||
|
@ -203,38 +203,27 @@ struct find_best_packet
|
||||
};
|
||||
|
||||
#if EIGEN_MAX_STATIC_ALIGN_BYTES>0
|
||||
template<int ArrayBytes, int AlignmentBytes,
|
||||
bool Match = bool((ArrayBytes%AlignmentBytes)==0),
|
||||
bool TryHalf = bool(EIGEN_MIN_ALIGN_BYTES<AlignmentBytes) >
|
||||
struct compute_default_alignment_helper
|
||||
{
|
||||
enum { value = 0 };
|
||||
};
|
||||
|
||||
template<int ArrayBytes, int AlignmentBytes, bool TryHalf>
|
||||
struct compute_default_alignment_helper<ArrayBytes, AlignmentBytes, true, TryHalf> // Match
|
||||
{
|
||||
enum { value = AlignmentBytes };
|
||||
};
|
||||
|
||||
template<int ArrayBytes, int AlignmentBytes>
|
||||
struct compute_default_alignment_helper<ArrayBytes, AlignmentBytes, false, true> // Try-half
|
||||
{
|
||||
// current packet too large, try with an half-packet
|
||||
enum { value = compute_default_alignment_helper<ArrayBytes, AlignmentBytes/2>::value };
|
||||
};
|
||||
constexpr inline int compute_default_alignment_helper(int ArrayBytes, int AlignmentBytes) {
|
||||
if((ArrayBytes % AlignmentBytes) == 0) {
|
||||
return AlignmentBytes;
|
||||
} else if (EIGEN_MIN_ALIGN_BYTES<AlignmentBytes) {
|
||||
return compute_default_alignment_helper(ArrayBytes, AlignmentBytes/2);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#else
|
||||
// If static alignment is disabled, no need to bother.
|
||||
// This also avoids a division by zero in "bool Match = bool((ArrayBytes%AlignmentBytes)==0)"
|
||||
template<int ArrayBytes, int AlignmentBytes>
|
||||
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<typename T, int Size> struct compute_default_alignment {
|
||||
enum { value = compute_default_alignment_helper<Size*sizeof(T),EIGEN_MAX_STATIC_ALIGN_BYTES>::value };
|
||||
enum { value = compute_default_alignment_helper(Size*sizeof(T), EIGEN_MAX_STATIC_ALIGN_BYTES) };
|
||||
};
|
||||
|
||||
template<typename T> struct compute_default_alignment<T,Dynamic> {
|
||||
@ -261,25 +250,21 @@ template<typename Scalar_, int Rows_, int Cols_,
|
||||
typedef Matrix<Scalar_, Rows_, Cols_, Options, MaxRows_, MaxCols_> type;
|
||||
};
|
||||
|
||||
template<typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols>
|
||||
class compute_matrix_flags
|
||||
{
|
||||
enum { row_major_bit = Options&RowMajor ? RowMajorBit : 0 };
|
||||
public:
|
||||
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.
|
||||
enum { ret = DirectAccessBit | LvalueBit | NestByRefBit | row_major_bit };
|
||||
};
|
||||
return DirectAccessBit | LvalueBit | NestByRefBit | row_major_bit;
|
||||
}
|
||||
|
||||
template<int Rows_, int Cols_> 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<typename XprType> struct size_of_xpr_at_compile_time
|
||||
{
|
||||
enum { ret = size_at_compile_time<traits<XprType>::RowsAtCompileTime,traits<XprType>::ColsAtCompileTime>::ret };
|
||||
enum { ret = size_at_compile_time(traits<XprType>::RowsAtCompileTime, traits<XprType>::ColsAtCompileTime) };
|
||||
};
|
||||
|
||||
/* plain_matrix_type : the difference from eval is that plain_matrix_type is always a plain matrix type,
|
||||
|
@ -71,8 +71,7 @@ template<typename Derived> class SparseMatrixBase
|
||||
* \sa MatrixBase::rows(), MatrixBase::cols(), RowsAtCompileTime, SizeAtCompileTime */
|
||||
|
||||
|
||||
SizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::RowsAtCompileTime,
|
||||
internal::traits<Derived>::ColsAtCompileTime>::ret),
|
||||
SizeAtCompileTime = (internal::size_of_xpr_at_compile_time<Derived>::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<typename Derived> class SparseMatrixBase
|
||||
MaxRowsAtCompileTime = RowsAtCompileTime,
|
||||
MaxColsAtCompileTime = ColsAtCompileTime,
|
||||
|
||||
MaxSizeAtCompileTime = (internal::size_at_compile_time<MaxRowsAtCompileTime,
|
||||
MaxColsAtCompileTime>::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
|
||||
|
@ -209,10 +209,10 @@ struct traits<KroneckerProduct<Lhs_,Rhs_> >
|
||||
typedef typename promote_index_type<typename Lhs::StorageIndex, typename Rhs::StorageIndex>::type StorageIndex;
|
||||
|
||||
enum {
|
||||
Rows = size_at_compile_time<traits<Lhs>::RowsAtCompileTime, traits<Rhs>::RowsAtCompileTime>::ret,
|
||||
Cols = size_at_compile_time<traits<Lhs>::ColsAtCompileTime, traits<Rhs>::ColsAtCompileTime>::ret,
|
||||
MaxRows = size_at_compile_time<traits<Lhs>::MaxRowsAtCompileTime, traits<Rhs>::MaxRowsAtCompileTime>::ret,
|
||||
MaxCols = size_at_compile_time<traits<Lhs>::MaxColsAtCompileTime, traits<Rhs>::MaxColsAtCompileTime>::ret
|
||||
Rows = size_at_compile_time(traits<Lhs>::RowsAtCompileTime, traits<Rhs>::RowsAtCompileTime),
|
||||
Cols = size_at_compile_time(traits<Lhs>::ColsAtCompileTime, traits<Rhs>::ColsAtCompileTime),
|
||||
MaxRows = size_at_compile_time(traits<Lhs>::MaxRowsAtCompileTime, traits<Rhs>::MaxRowsAtCompileTime),
|
||||
MaxCols = size_at_compile_time(traits<Lhs>::MaxColsAtCompileTime, traits<Rhs>::MaxColsAtCompileTime)
|
||||
};
|
||||
|
||||
typedef Matrix<Scalar,Rows,Cols> ReturnType;
|
||||
@ -232,10 +232,10 @@ struct traits<KroneckerProductSparse<Lhs_,Rhs_> >
|
||||
LhsFlags = Lhs::Flags,
|
||||
RhsFlags = Rhs::Flags,
|
||||
|
||||
RowsAtCompileTime = size_at_compile_time<traits<Lhs>::RowsAtCompileTime, traits<Rhs>::RowsAtCompileTime>::ret,
|
||||
ColsAtCompileTime = size_at_compile_time<traits<Lhs>::ColsAtCompileTime, traits<Rhs>::ColsAtCompileTime>::ret,
|
||||
MaxRowsAtCompileTime = size_at_compile_time<traits<Lhs>::MaxRowsAtCompileTime, traits<Rhs>::MaxRowsAtCompileTime>::ret,
|
||||
MaxColsAtCompileTime = size_at_compile_time<traits<Lhs>::MaxColsAtCompileTime, traits<Rhs>::MaxColsAtCompileTime>::ret,
|
||||
RowsAtCompileTime = size_at_compile_time(traits<Lhs>::RowsAtCompileTime, traits<Rhs>::RowsAtCompileTime),
|
||||
ColsAtCompileTime = size_at_compile_time(traits<Lhs>::ColsAtCompileTime, traits<Rhs>::ColsAtCompileTime),
|
||||
MaxRowsAtCompileTime = size_at_compile_time(traits<Lhs>::MaxRowsAtCompileTime, traits<Rhs>::MaxRowsAtCompileTime),
|
||||
MaxColsAtCompileTime = size_at_compile_time(traits<Lhs>::MaxColsAtCompileTime, traits<Rhs>::MaxColsAtCompileTime),
|
||||
|
||||
EvalToRowMajor = (int(LhsFlags) & int(RhsFlags) & RowMajorBit),
|
||||
RemovedBits = ~(EvalToRowMajor ? 0 : RowMajorBit),
|
||||
|
@ -46,8 +46,7 @@ public:
|
||||
* \sa MatrixBase::rows(), MatrixBase::cols(), RowsAtCompileTime, SizeAtCompileTime */
|
||||
|
||||
|
||||
SizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::RowsAtCompileTime,
|
||||
internal::traits<Derived>::ColsAtCompileTime>::ret),
|
||||
SizeAtCompileTime = (internal::size_of_xpr_at_compile_time<Derived>::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<MaxRowsAtCompileTime,
|
||||
MaxColsAtCompileTime>::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
|
||||
|
Loading…
x
Reference in New Issue
Block a user