2008-06-04 11:16:11 +00:00
|
|
|
// This file is part of Eigen, a lightweight C++ template library
|
2009-05-22 20:25:33 +02:00
|
|
|
// for linear algebra.
|
2008-06-04 11:16:11 +00:00
|
|
|
//
|
2010-06-24 23:21:58 +02:00
|
|
|
// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
|
2010-02-18 20:42:38 -05:00
|
|
|
// Copyright (C) 2008 Benoit Jacob <jacob.benoit.1@gmail.com>
|
2008-06-04 11:16:11 +00:00
|
|
|
//
|
2012-07-13 14:42:47 -04:00
|
|
|
// This Source Code Form is subject to the terms of the Mozilla
|
|
|
|
|
// Public License v. 2.0. If a copy of the MPL was not distributed
|
|
|
|
|
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2008-06-04 11:16:11 +00:00
|
|
|
|
|
|
|
|
#ifndef EIGEN_STATIC_ASSERT_H
|
|
|
|
|
#define EIGEN_STATIC_ASSERT_H
|
|
|
|
|
|
|
|
|
|
/* Some notes on Eigen's static assertion mechanism:
|
|
|
|
|
*
|
|
|
|
|
* - in EIGEN_STATIC_ASSERT(CONDITION,MSG) the parameter CONDITION must be a compile time boolean
|
2010-10-25 10:15:22 -04:00
|
|
|
* expression, and MSG an enum listed in struct internal::static_assertion<true>
|
2008-06-04 11:16:11 +00:00
|
|
|
*
|
|
|
|
|
* - currently EIGEN_STATIC_ASSERT can only be used in function scope
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2018-03-09 10:00:51 +01:00
|
|
|
#ifndef EIGEN_STATIC_ASSERT
|
2008-06-04 11:16:11 +00:00
|
|
|
#ifndef EIGEN_NO_STATIC_ASSERT
|
|
|
|
|
|
2021-09-16 20:43:54 +00:00
|
|
|
#define EIGEN_STATIC_ASSERT(X,MSG) static_assert(X,#MSG);
|
2008-06-04 11:16:11 +00:00
|
|
|
|
|
|
|
|
#else // EIGEN_NO_STATIC_ASSERT
|
|
|
|
|
|
2021-09-16 20:43:54 +00:00
|
|
|
#define EIGEN_STATIC_ASSERT(CONDITION,MSG)
|
2008-06-04 11:16:11 +00:00
|
|
|
|
|
|
|
|
#endif // EIGEN_NO_STATIC_ASSERT
|
2018-03-09 10:00:51 +01:00
|
|
|
#endif // EIGEN_STATIC_ASSERT
|
2008-06-04 11:16:11 +00:00
|
|
|
|
2008-07-19 00:25:41 +00:00
|
|
|
// static assertion failing if the type \a TYPE is not a vector type
|
2008-06-26 16:06:41 +00:00
|
|
|
#define EIGEN_STATIC_ASSERT_VECTOR_ONLY(TYPE) \
|
|
|
|
|
EIGEN_STATIC_ASSERT(TYPE::IsVectorAtCompileTime, \
|
2008-12-18 21:04:06 +00:00
|
|
|
YOU_TRIED_CALLING_A_VECTOR_METHOD_ON_A_MATRIX)
|
2008-06-04 11:16:11 +00:00
|
|
|
|
2008-07-19 00:25:41 +00:00
|
|
|
// static assertion failing if the type \a TYPE is not fixed-size
|
|
|
|
|
#define EIGEN_STATIC_ASSERT_FIXED_SIZE(TYPE) \
|
|
|
|
|
EIGEN_STATIC_ASSERT(TYPE::SizeAtCompileTime!=Eigen::Dynamic, \
|
2008-12-18 21:04:06 +00:00
|
|
|
YOU_CALLED_A_FIXED_SIZE_METHOD_ON_A_DYNAMIC_SIZE_MATRIX_OR_VECTOR)
|
2008-07-19 00:25:41 +00:00
|
|
|
|
2009-09-03 17:27:51 +02:00
|
|
|
// static assertion failing if the type \a TYPE is not dynamic-size
|
|
|
|
|
#define EIGEN_STATIC_ASSERT_DYNAMIC_SIZE(TYPE) \
|
|
|
|
|
EIGEN_STATIC_ASSERT(TYPE::SizeAtCompileTime==Eigen::Dynamic, \
|
|
|
|
|
YOU_CALLED_A_DYNAMIC_SIZE_METHOD_ON_A_FIXED_SIZE_MATRIX_OR_VECTOR)
|
|
|
|
|
|
2008-07-19 00:25:41 +00:00
|
|
|
// static assertion failing if the type \a TYPE is not a vector type of the given size
|
|
|
|
|
#define EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(TYPE, SIZE) \
|
|
|
|
|
EIGEN_STATIC_ASSERT(TYPE::IsVectorAtCompileTime && TYPE::SizeAtCompileTime==SIZE, \
|
2008-12-18 21:04:06 +00:00
|
|
|
THIS_METHOD_IS_ONLY_FOR_VECTORS_OF_A_SPECIFIC_SIZE)
|
2008-07-19 00:25:41 +00:00
|
|
|
|
2008-08-18 22:17:42 +00:00
|
|
|
// static assertion failing if the type \a TYPE is not a vector type of the given size
|
|
|
|
|
#define EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(TYPE, ROWS, COLS) \
|
|
|
|
|
EIGEN_STATIC_ASSERT(TYPE::RowsAtCompileTime==ROWS && TYPE::ColsAtCompileTime==COLS, \
|
2008-12-18 21:04:06 +00:00
|
|
|
THIS_METHOD_IS_ONLY_FOR_MATRICES_OF_A_SPECIFIC_SIZE)
|
2008-08-18 22:17:42 +00:00
|
|
|
|
2008-07-19 00:25:41 +00:00
|
|
|
// static assertion failing if the two vector expression types are not compatible (same fixed-size or dynamic size)
|
2008-06-04 11:16:11 +00:00
|
|
|
#define EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(TYPE0,TYPE1) \
|
|
|
|
|
EIGEN_STATIC_ASSERT( \
|
|
|
|
|
(int(TYPE0::SizeAtCompileTime)==Eigen::Dynamic \
|
|
|
|
|
|| int(TYPE1::SizeAtCompileTime)==Eigen::Dynamic \
|
|
|
|
|
|| int(TYPE0::SizeAtCompileTime)==int(TYPE1::SizeAtCompileTime)),\
|
2008-12-18 21:04:06 +00:00
|
|
|
YOU_MIXED_VECTORS_OF_DIFFERENT_SIZES)
|
2008-06-04 11:16:11 +00:00
|
|
|
|
2008-10-25 11:52:13 +00:00
|
|
|
#define EIGEN_PREDICATE_SAME_MATRIX_SIZE(TYPE0,TYPE1) \
|
2010-03-21 11:28:03 -04:00
|
|
|
( \
|
2016-06-28 20:09:25 +02:00
|
|
|
(int(Eigen::internal::size_of_xpr_at_compile_time<TYPE0>::ret)==0 && int(Eigen::internal::size_of_xpr_at_compile_time<TYPE1>::ret)==0) \
|
2010-03-21 11:28:03 -04:00
|
|
|
|| (\
|
|
|
|
|
(int(TYPE0::RowsAtCompileTime)==Eigen::Dynamic \
|
|
|
|
|
|| int(TYPE1::RowsAtCompileTime)==Eigen::Dynamic \
|
|
|
|
|
|| int(TYPE0::RowsAtCompileTime)==int(TYPE1::RowsAtCompileTime)) \
|
|
|
|
|
&& (int(TYPE0::ColsAtCompileTime)==Eigen::Dynamic \
|
|
|
|
|
|| int(TYPE1::ColsAtCompileTime)==Eigen::Dynamic \
|
|
|
|
|
|| int(TYPE0::ColsAtCompileTime)==int(TYPE1::ColsAtCompileTime))\
|
|
|
|
|
) \
|
|
|
|
|
)
|
2008-10-25 11:52:13 +00:00
|
|
|
|
2014-07-01 16:58:11 +02:00
|
|
|
#define EIGEN_STATIC_ASSERT_NON_INTEGER(TYPE) \
|
2019-06-05 09:51:59 +02:00
|
|
|
EIGEN_STATIC_ASSERT(!Eigen::NumTraits<TYPE>::IsInteger, THIS_FUNCTION_IS_NOT_FOR_INTEGER_NUMERIC_TYPES)
|
2011-01-20 10:36:32 -05:00
|
|
|
|
2010-04-28 18:51:38 -04:00
|
|
|
|
2008-12-03 21:01:55 +00:00
|
|
|
// static assertion failing if it is guaranteed at compile-time that the two matrix expression types have different sizes
|
2008-10-25 11:52:13 +00:00
|
|
|
#define EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(TYPE0,TYPE1) \
|
|
|
|
|
EIGEN_STATIC_ASSERT( \
|
|
|
|
|
EIGEN_PREDICATE_SAME_MATRIX_SIZE(TYPE0,TYPE1),\
|
2008-12-18 21:04:06 +00:00
|
|
|
YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES)
|
2008-06-04 11:16:11 +00:00
|
|
|
|
2010-12-09 03:47:35 -05:00
|
|
|
#define EIGEN_STATIC_ASSERT_SIZE_1x1(TYPE) \
|
2019-06-05 09:51:59 +02:00
|
|
|
EIGEN_STATIC_ASSERT((TYPE::RowsAtCompileTime == 1 || TYPE::RowsAtCompileTime == Eigen::Dynamic) && \
|
|
|
|
|
(TYPE::ColsAtCompileTime == 1 || TYPE::ColsAtCompileTime == Eigen::Dynamic), \
|
2010-12-09 03:47:35 -05:00
|
|
|
THIS_METHOD_IS_ONLY_FOR_1x1_EXPRESSIONS)
|
|
|
|
|
|
2010-12-10 02:09:58 -05:00
|
|
|
#define EIGEN_STATIC_ASSERT_LVALUE(Derived) \
|
2016-06-28 20:09:25 +02:00
|
|
|
EIGEN_STATIC_ASSERT(Eigen::internal::is_lvalue<Derived>::value, \
|
2010-12-22 17:45:37 -05:00
|
|
|
THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY)
|
2010-12-10 02:09:58 -05:00
|
|
|
|
2011-11-18 11:10:27 -05:00
|
|
|
#define EIGEN_STATIC_ASSERT_ARRAYXPR(Derived) \
|
2016-06-28 20:09:25 +02:00
|
|
|
EIGEN_STATIC_ASSERT((Eigen::internal::is_same<typename Eigen::internal::traits<Derived>::XprKind, ArrayXpr>::value), \
|
2011-11-18 11:10:27 -05:00
|
|
|
THIS_METHOD_IS_ONLY_FOR_ARRAYS_NOT_MATRICES)
|
|
|
|
|
|
|
|
|
|
#define EIGEN_STATIC_ASSERT_SAME_XPR_KIND(Derived1, Derived2) \
|
2016-06-28 20:09:25 +02:00
|
|
|
EIGEN_STATIC_ASSERT((Eigen::internal::is_same<typename Eigen::internal::traits<Derived1>::XprKind, \
|
|
|
|
|
typename Eigen::internal::traits<Derived2>::XprKind \
|
2011-11-18 11:10:27 -05:00
|
|
|
>::value), \
|
|
|
|
|
YOU_CANNOT_MIX_ARRAYS_AND_MATRICES)
|
|
|
|
|
|
2015-10-28 11:42:14 +01:00
|
|
|
// Check that a cost value is positive, and that is stay within a reasonable range
|
|
|
|
|
// TODO this check could be enabled for internal debugging only
|
|
|
|
|
#define EIGEN_INTERNAL_CHECK_COST_VALUE(C) \
|
2015-10-28 13:39:02 +01:00
|
|
|
EIGEN_STATIC_ASSERT((C)>=0 && (C)<=HugeCost*HugeCost, EIGEN_INTERNAL_ERROR_PLEASE_FILE_A_BUG_REPORT__INVALID_COST_VALUE);
|
2011-11-18 11:10:27 -05:00
|
|
|
|
2008-06-04 11:16:11 +00:00
|
|
|
#endif // EIGEN_STATIC_ASSERT_H
|