mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
change the value of Dynamic to -1, since the index type is now configurable.
remove EIGEN_ENUM_MIN/MAX, implement new macros instead
This commit is contained in:
@@ -29,19 +29,9 @@
|
||||
/** This value means that a quantity is not known at compile-time, and that instead the value is
|
||||
* stored in some runtime variable.
|
||||
*
|
||||
* Explanation for the choice of this value:
|
||||
* - It should be positive and larger than the number of entries in any reasonable fixed-size matrix.
|
||||
* This allows to simplify many compile-time conditions throughout Eigen.
|
||||
* - It should be smaller than the sqrt of INT_MAX. Indeed, we often multiply a number of rows with a number
|
||||
* of columns in order to compute a number of coefficients. Even if we guard that with an "if" checking whether
|
||||
* the values are Dynamic, we still get a compiler warning "integer overflow". So the only way to get around
|
||||
* it would be a meta-selector. Doing this everywhere would reduce code readability and lengthen compilation times.
|
||||
* Also, disabling compiler warnings for integer overflow, sounds like a bad idea.
|
||||
* - It should be a prime number, because for example the old value 10000 led to bugs with 100x100 matrices.
|
||||
*
|
||||
* Changing the value of Dynamic breaks the ABI, as Dynamic is often used as a template parameter for Matrix.
|
||||
*/
|
||||
const int Dynamic = sizeof(int) >= 4 ? 33331 : 101;
|
||||
const int Dynamic = -1;
|
||||
|
||||
/** This value means +Infinity; it is currently used only as the p parameter to MatrixBase::lpNorm<int>().
|
||||
* The value Infinity there means the L-infinity norm.
|
||||
|
||||
@@ -306,11 +306,31 @@
|
||||
using Base::const_cast_derived;
|
||||
|
||||
|
||||
#define EIGEN_ENUM_MIN(a,b) (((int)a <= (int)b) ? (int)a : (int)b)
|
||||
#define EIGEN_SIZE_MIN(a,b) (((int)a == 1 || (int)b == 1) ? 1 \
|
||||
#define EIGEN_PLAIN_ENUM_MIN(a,b) (((int)a <= (int)b) ? (int)a : (int)b)
|
||||
#define EIGEN_PLAIN_ENUM_MAX(a,b) (((int)a >= (int)b) ? (int)a : (int)b)
|
||||
|
||||
// EIGEN_SIZE_MIN gives the min between compile-time sizes. 0 has absolute priority, followed by 1,
|
||||
// followed by Dynamic, followed by other finite values. The reason for giving Dynamic the priority over
|
||||
// finite values is that min(3, Dynamic) should be Dynamic, since that could be anything between 0 and 3.
|
||||
#define EIGEN_SIZE_MIN(a,b) (((int)a == 0 || (int)b == 0) ? 0 \
|
||||
: ((int)a == 1 || (int)b == 1) ? 1 \
|
||||
: ((int)a == Dynamic || (int)b == Dynamic) ? Dynamic \
|
||||
: ((int)a <= (int)b) ? (int)a : (int)b)
|
||||
#define EIGEN_ENUM_MAX(a,b) (((int)a >= (int)b) ? (int)a : (int)b)
|
||||
|
||||
// EIGEN_MAXSIZE_MIN is a variant of EIGEN_SIZE_MIN comparing MaxSizes. The difference is that finite values
|
||||
// now have priority over Dynamic, so that min(3, Dynamic) gives 3. Indeed, whatever the actual value is
|
||||
// (between 0 and 3), it is not more than 3.
|
||||
#define EIGEN_MAXSIZE_MIN(a,b) (((int)a == 0 || (int)b == 0) ? 0 \
|
||||
: ((int)a == 1 || (int)b == 1) ? 1 \
|
||||
: ((int)a == Dynamic && (int)b == Dynamic) ? Dynamic \
|
||||
: ((int)a == Dynamic) ? (int)b \
|
||||
: ((int)b == Dynamic) ? (int)a \
|
||||
: ((int)a <= (int)b) ? (int)a : (int)b)
|
||||
|
||||
// see EIGEN_SIZE_MIN. No need for a separate variant for MaxSizes here.
|
||||
#define EIGEN_SIZE_MAX(a,b) (((int)a == Dynamic || (int)b == Dynamic) ? Dynamic \
|
||||
: ((int)a >= (int)b) ? (int)a : (int)b)
|
||||
|
||||
#define EIGEN_LOGICAL_XOR(a,b) (((a) || (b)) && !((a) && (b)))
|
||||
|
||||
#define EIGEN_IMPLIES(a,b) (!(a) || (b))
|
||||
|
||||
@@ -84,7 +84,8 @@
|
||||
THIS_METHOD_IS_ONLY_FOR_EXPRESSIONS_WITH_DIRECT_MEMORY_ACCESS_SUCH_AS_MAP_OR_PLAIN_MATRICES,
|
||||
YOU_ALREADY_SPECIFIED_THIS_STRIDE,
|
||||
INVALID_STORAGE_ORDER_FOR_THIS_VECTOR_EXPRESSION,
|
||||
THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD
|
||||
THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD,
|
||||
PACKET_ACCESS_REQUIRES_TO_HAVE_INNER_STRIDE_FIXED_TO_1
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -293,9 +293,15 @@ struct ei_ref_selector
|
||||
*/
|
||||
template<typename T, int n=1, typename PlainObject = typename ei_eval<T>::type> struct ei_nested
|
||||
{
|
||||
// this is a direct port of the logic used when Dynamic was 33331, to make an atomic commit.
|
||||
enum {
|
||||
CostEval = (n+1) * int(NumTraits<typename ei_traits<T>::Scalar>::ReadCost),
|
||||
CostNoEval = (n-1) * int(ei_traits<T>::CoeffReadCost)
|
||||
_ScalarReadCost = NumTraits<typename ei_traits<T>::Scalar>::ReadCost,
|
||||
ScalarReadCost = _ScalarReadCost == Dynamic ? 33331 : int(_ScalarReadCost),
|
||||
_CoeffReadCost = int(ei_traits<T>::CoeffReadCost),
|
||||
CoeffReadCost = _CoeffReadCost == Dynamic ? 33331 : int(_CoeffReadCost),
|
||||
N = n == Dynamic ? 33331 : n,
|
||||
CostEval = (N+1) * int(ScalarReadCost),
|
||||
CostNoEval = (N-1) * int(CoeffReadCost)
|
||||
};
|
||||
|
||||
typedef typename ei_meta_if<
|
||||
@@ -304,6 +310,24 @@ template<typename T, int n=1, typename PlainObject = typename ei_eval<T>::type>
|
||||
PlainObject,
|
||||
typename ei_ref_selector<T>::type
|
||||
>::ret type;
|
||||
|
||||
/* this is what the above logic should be updated to look like:
|
||||
enum {
|
||||
ScalarReadCost = NumTraits<typename ei_traits<T>::Scalar>::ReadCost,
|
||||
CoeffReadCost = ei_traits<T>::CoeffReadCost,
|
||||
CostEval = n == Dynamic || ScalarReadCost == Dynamic ? int(Dynamic) : (n+1) * int(ScalarReadCost),
|
||||
CostNoEval = n == Dynamic || (CoeffReadCost == Dynamic && n>1) ? int(Dynamic) : (n-1) * int(CoeffReadCost)
|
||||
};
|
||||
|
||||
typedef typename ei_meta_if<
|
||||
( int(ei_traits<T>::Flags) & EvalBeforeNestingBit ) ||
|
||||
( int(CostNoEval) == Dynamic ? true
|
||||
: int(CostEval) == Dynamic ? false
|
||||
: int(CostEval) <= int(CostNoEval) ),
|
||||
PlainObject,
|
||||
typename ei_ref_selector<T>::type
|
||||
>::ret type;
|
||||
*/
|
||||
};
|
||||
|
||||
template<unsigned int Flags> struct ei_are_flags_consistent
|
||||
@@ -405,7 +429,7 @@ template<typename MatrixType, typename Scalar = typename MatrixType::Scalar>
|
||||
struct ei_plain_diag_type
|
||||
{
|
||||
enum { diag_size = EIGEN_SIZE_MIN(MatrixType::RowsAtCompileTime, MatrixType::ColsAtCompileTime),
|
||||
max_diag_size = EIGEN_SIZE_MIN(MatrixType::MaxRowsAtCompileTime, MatrixType::MaxColsAtCompileTime)
|
||||
max_diag_size = EIGEN_MAXSIZE_MIN(MatrixType::MaxRowsAtCompileTime, MatrixType::MaxColsAtCompileTime)
|
||||
};
|
||||
typedef Matrix<Scalar, diag_size, 1, MatrixType::PlainObject::Options & ~RowMajor, max_diag_size, 1> type;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user