Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/eigen3/Eigen/src/Core/util/StaticAssert.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // This file is part of Eigen, a lightweight C++ template library
0002 // for linear algebra.
0003 //
0004 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
0005 // Copyright (C) 2008 Benoit Jacob <jacob.benoit.1@gmail.com>
0006 //
0007 // This Source Code Form is subject to the terms of the Mozilla
0008 // Public License v. 2.0. If a copy of the MPL was not distributed
0009 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
0010 
0011 #ifndef EIGEN_STATIC_ASSERT_H
0012 #define EIGEN_STATIC_ASSERT_H
0013 
0014 /* Some notes on Eigen's static assertion mechanism:
0015  *
0016  *  - in EIGEN_STATIC_ASSERT(CONDITION,MSG) the parameter CONDITION must be a compile time boolean
0017  *    expression, and MSG an enum listed in struct internal::static_assertion<true>
0018  *
0019  *  - define EIGEN_NO_STATIC_ASSERT to disable them (and save compilation time)
0020  *    in that case, the static assertion is converted to the following runtime assert:
0021  *      eigen_assert(CONDITION && "MSG")
0022  *
0023  *  - currently EIGEN_STATIC_ASSERT can only be used in function scope
0024  *
0025  */
0026 
0027 #ifndef EIGEN_STATIC_ASSERT
0028 #ifndef EIGEN_NO_STATIC_ASSERT
0029 
0030   #if EIGEN_MAX_CPP_VER>=11 && (__has_feature(cxx_static_assert) || (EIGEN_COMP_CXXVER >= 11) || (EIGEN_COMP_MSVC >= 1600))
0031 
0032     // if native static_assert is enabled, let's use it
0033     #define EIGEN_STATIC_ASSERT(X,MSG) static_assert(X,#MSG);
0034 
0035   #else // not CXX0X
0036 
0037     namespace Eigen {
0038 
0039     namespace internal {
0040 
0041     template<bool condition>
0042     struct static_assertion {};
0043 
0044     template<>
0045     struct static_assertion<true>
0046     {
0047       enum {
0048         YOU_TRIED_CALLING_A_VECTOR_METHOD_ON_A_MATRIX=1,
0049         YOU_MIXED_VECTORS_OF_DIFFERENT_SIZES=1,
0050         YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES=1,
0051         THIS_METHOD_IS_ONLY_FOR_VECTORS_OF_A_SPECIFIC_SIZE=1,
0052         THIS_METHOD_IS_ONLY_FOR_MATRICES_OF_A_SPECIFIC_SIZE=1,
0053         THIS_METHOD_IS_ONLY_FOR_OBJECTS_OF_A_SPECIFIC_SIZE=1,
0054         OUT_OF_RANGE_ACCESS=1,
0055         YOU_MADE_A_PROGRAMMING_MISTAKE=1,
0056         EIGEN_INTERNAL_ERROR_PLEASE_FILE_A_BUG_REPORT=1,
0057         EIGEN_INTERNAL_COMPILATION_ERROR_OR_YOU_MADE_A_PROGRAMMING_MISTAKE=1,
0058         YOU_CALLED_A_FIXED_SIZE_METHOD_ON_A_DYNAMIC_SIZE_MATRIX_OR_VECTOR=1,
0059         YOU_CALLED_A_DYNAMIC_SIZE_METHOD_ON_A_FIXED_SIZE_MATRIX_OR_VECTOR=1,
0060         UNALIGNED_LOAD_AND_STORE_OPERATIONS_UNIMPLEMENTED_ON_ALTIVEC=1,
0061         THIS_FUNCTION_IS_NOT_FOR_INTEGER_NUMERIC_TYPES=1,
0062         FLOATING_POINT_ARGUMENT_PASSED__INTEGER_WAS_EXPECTED=1,
0063         NUMERIC_TYPE_MUST_BE_REAL=1,
0064         COEFFICIENT_WRITE_ACCESS_TO_SELFADJOINT_NOT_SUPPORTED=1,
0065         WRITING_TO_TRIANGULAR_PART_WITH_UNIT_DIAGONAL_IS_NOT_SUPPORTED=1,
0066         THIS_METHOD_IS_ONLY_FOR_FIXED_SIZE=1,
0067         INVALID_MATRIX_PRODUCT=1,
0068         INVALID_VECTOR_VECTOR_PRODUCT__IF_YOU_WANTED_A_DOT_OR_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTIONS=1,
0069         INVALID_MATRIX_PRODUCT__IF_YOU_WANTED_A_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTION=1,
0070         YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY=1,
0071         THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES=1,
0072         THIS_METHOD_IS_ONLY_FOR_ROW_MAJOR_MATRICES=1,
0073         INVALID_MATRIX_TEMPLATE_PARAMETERS=1,
0074         INVALID_MATRIXBASE_TEMPLATE_PARAMETERS=1,
0075         BOTH_MATRICES_MUST_HAVE_THE_SAME_STORAGE_ORDER=1,
0076         THIS_METHOD_IS_ONLY_FOR_DIAGONAL_MATRIX=1,
0077         THE_MATRIX_OR_EXPRESSION_THAT_YOU_PASSED_DOES_NOT_HAVE_THE_EXPECTED_TYPE=1,
0078         THIS_METHOD_IS_ONLY_FOR_EXPRESSIONS_WITH_DIRECT_MEMORY_ACCESS_SUCH_AS_MAP_OR_PLAIN_MATRICES=1,
0079         YOU_ALREADY_SPECIFIED_THIS_STRIDE=1,
0080         INVALID_STORAGE_ORDER_FOR_THIS_VECTOR_EXPRESSION=1,
0081         THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD=1,
0082         PACKET_ACCESS_REQUIRES_TO_HAVE_INNER_STRIDE_FIXED_TO_1=1,
0083         THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS=1,
0084         YOU_CANNOT_MIX_ARRAYS_AND_MATRICES=1,
0085         YOU_PERFORMED_AN_INVALID_TRANSFORMATION_CONVERSION=1,
0086         THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY=1,
0087         YOU_ARE_TRYING_TO_USE_AN_INDEX_BASED_ACCESSOR_ON_AN_EXPRESSION_THAT_DOES_NOT_SUPPORT_THAT=1,
0088         THIS_METHOD_IS_ONLY_FOR_1x1_EXPRESSIONS=1,
0089         THIS_METHOD_IS_ONLY_FOR_INNER_OR_LAZY_PRODUCTS=1,
0090         THIS_METHOD_IS_ONLY_FOR_EXPRESSIONS_OF_BOOL=1,
0091         THIS_METHOD_IS_ONLY_FOR_ARRAYS_NOT_MATRICES=1,
0092         YOU_PASSED_A_ROW_VECTOR_BUT_A_COLUMN_VECTOR_WAS_EXPECTED=1,
0093         YOU_PASSED_A_COLUMN_VECTOR_BUT_A_ROW_VECTOR_WAS_EXPECTED=1,
0094         THE_INDEX_TYPE_MUST_BE_A_SIGNED_TYPE=1,
0095         THE_STORAGE_ORDER_OF_BOTH_SIDES_MUST_MATCH=1,
0096         OBJECT_ALLOCATED_ON_STACK_IS_TOO_BIG=1,
0097         IMPLICIT_CONVERSION_TO_SCALAR_IS_FOR_INNER_PRODUCT_ONLY=1,
0098         STORAGE_LAYOUT_DOES_NOT_MATCH=1,
0099         EIGEN_INTERNAL_ERROR_PLEASE_FILE_A_BUG_REPORT__INVALID_COST_VALUE=1,
0100         THIS_COEFFICIENT_ACCESSOR_TAKING_ONE_ACCESS_IS_ONLY_FOR_EXPRESSIONS_ALLOWING_LINEAR_ACCESS=1,
0101         MATRIX_FREE_CONJUGATE_GRADIENT_IS_COMPATIBLE_WITH_UPPER_UNION_LOWER_MODE_ONLY=1,
0102         THIS_TYPE_IS_NOT_SUPPORTED=1,
0103         STORAGE_KIND_MUST_MATCH=1,
0104         STORAGE_INDEX_MUST_MATCH=1,
0105         CHOLMOD_SUPPORTS_DOUBLE_PRECISION_ONLY=1,
0106         SELFADJOINTVIEW_ACCEPTS_UPPER_AND_LOWER_MODE_ONLY=1,
0107         INVALID_TEMPLATE_PARAMETER=1,
0108         GPU_TENSOR_CONTRACTION_DOES_NOT_SUPPORT_OUTPUT_KERNELS=1,
0109         THE_ARRAY_SIZE_SHOULD_EQUAL_WITH_PACKET_SIZE=1
0110       };
0111     };
0112 
0113     } // end namespace internal
0114 
0115     } // end namespace Eigen
0116 
0117     // Specialized implementation for MSVC to avoid "conditional
0118     // expression is constant" warnings.  This implementation doesn't
0119     // appear to work under GCC, hence the multiple implementations.
0120     #if EIGEN_COMP_MSVC
0121 
0122       #define EIGEN_STATIC_ASSERT(CONDITION,MSG) \
0123         {Eigen::internal::static_assertion<bool(CONDITION)>::MSG;}
0124 
0125     #else
0126       // In some cases clang interprets bool(CONDITION) as function declaration
0127       #define EIGEN_STATIC_ASSERT(CONDITION,MSG) \
0128         if (Eigen::internal::static_assertion<static_cast<bool>(CONDITION)>::MSG) {}
0129 
0130     #endif
0131 
0132   #endif // not CXX0X
0133 
0134 #else // EIGEN_NO_STATIC_ASSERT
0135 
0136   #define EIGEN_STATIC_ASSERT(CONDITION,MSG) eigen_assert((CONDITION) && #MSG);
0137 
0138 #endif // EIGEN_NO_STATIC_ASSERT
0139 #endif // EIGEN_STATIC_ASSERT
0140 
0141 // static assertion failing if the type \a TYPE is not a vector type
0142 #define EIGEN_STATIC_ASSERT_VECTOR_ONLY(TYPE) \
0143   EIGEN_STATIC_ASSERT(TYPE::IsVectorAtCompileTime, \
0144                       YOU_TRIED_CALLING_A_VECTOR_METHOD_ON_A_MATRIX)
0145 
0146 // static assertion failing if the type \a TYPE is not fixed-size
0147 #define EIGEN_STATIC_ASSERT_FIXED_SIZE(TYPE) \
0148   EIGEN_STATIC_ASSERT(TYPE::SizeAtCompileTime!=Eigen::Dynamic, \
0149                       YOU_CALLED_A_FIXED_SIZE_METHOD_ON_A_DYNAMIC_SIZE_MATRIX_OR_VECTOR)
0150 
0151 // static assertion failing if the type \a TYPE is not dynamic-size
0152 #define EIGEN_STATIC_ASSERT_DYNAMIC_SIZE(TYPE) \
0153   EIGEN_STATIC_ASSERT(TYPE::SizeAtCompileTime==Eigen::Dynamic, \
0154                       YOU_CALLED_A_DYNAMIC_SIZE_METHOD_ON_A_FIXED_SIZE_MATRIX_OR_VECTOR)
0155 
0156 // static assertion failing if the type \a TYPE is not a vector type of the given size
0157 #define EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(TYPE, SIZE) \
0158   EIGEN_STATIC_ASSERT(TYPE::IsVectorAtCompileTime && TYPE::SizeAtCompileTime==SIZE, \
0159                       THIS_METHOD_IS_ONLY_FOR_VECTORS_OF_A_SPECIFIC_SIZE)
0160 
0161 // static assertion failing if the type \a TYPE is not a vector type of the given size
0162 #define EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(TYPE, ROWS, COLS) \
0163   EIGEN_STATIC_ASSERT(TYPE::RowsAtCompileTime==ROWS && TYPE::ColsAtCompileTime==COLS, \
0164                       THIS_METHOD_IS_ONLY_FOR_MATRICES_OF_A_SPECIFIC_SIZE)
0165 
0166 // static assertion failing if the two vector expression types are not compatible (same fixed-size or dynamic size)
0167 #define EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(TYPE0,TYPE1) \
0168   EIGEN_STATIC_ASSERT( \
0169       (int(TYPE0::SizeAtCompileTime)==Eigen::Dynamic \
0170     || int(TYPE1::SizeAtCompileTime)==Eigen::Dynamic \
0171     || int(TYPE0::SizeAtCompileTime)==int(TYPE1::SizeAtCompileTime)),\
0172     YOU_MIXED_VECTORS_OF_DIFFERENT_SIZES)
0173 
0174 #define EIGEN_PREDICATE_SAME_MATRIX_SIZE(TYPE0,TYPE1) \
0175      ( \
0176         (int(Eigen::internal::size_of_xpr_at_compile_time<TYPE0>::ret)==0 && int(Eigen::internal::size_of_xpr_at_compile_time<TYPE1>::ret)==0) \
0177     || (\
0178           (int(TYPE0::RowsAtCompileTime)==Eigen::Dynamic \
0179         || int(TYPE1::RowsAtCompileTime)==Eigen::Dynamic \
0180         || int(TYPE0::RowsAtCompileTime)==int(TYPE1::RowsAtCompileTime)) \
0181       &&  (int(TYPE0::ColsAtCompileTime)==Eigen::Dynamic \
0182         || int(TYPE1::ColsAtCompileTime)==Eigen::Dynamic \
0183         || int(TYPE0::ColsAtCompileTime)==int(TYPE1::ColsAtCompileTime))\
0184        ) \
0185      )
0186 
0187 #define EIGEN_STATIC_ASSERT_NON_INTEGER(TYPE) \
0188     EIGEN_STATIC_ASSERT(!Eigen::NumTraits<TYPE>::IsInteger, THIS_FUNCTION_IS_NOT_FOR_INTEGER_NUMERIC_TYPES)
0189 
0190 
0191 // static assertion failing if it is guaranteed at compile-time that the two matrix expression types have different sizes
0192 #define EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(TYPE0,TYPE1) \
0193   EIGEN_STATIC_ASSERT( \
0194      EIGEN_PREDICATE_SAME_MATRIX_SIZE(TYPE0,TYPE1),\
0195     YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES)
0196 
0197 #define EIGEN_STATIC_ASSERT_SIZE_1x1(TYPE) \
0198       EIGEN_STATIC_ASSERT((TYPE::RowsAtCompileTime == 1 || TYPE::RowsAtCompileTime == Eigen::Dynamic) && \
0199                           (TYPE::ColsAtCompileTime == 1 || TYPE::ColsAtCompileTime == Eigen::Dynamic), \
0200                           THIS_METHOD_IS_ONLY_FOR_1x1_EXPRESSIONS)
0201 
0202 #define EIGEN_STATIC_ASSERT_LVALUE(Derived) \
0203       EIGEN_STATIC_ASSERT(Eigen::internal::is_lvalue<Derived>::value, \
0204                           THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY)
0205 
0206 #define EIGEN_STATIC_ASSERT_ARRAYXPR(Derived) \
0207       EIGEN_STATIC_ASSERT((Eigen::internal::is_same<typename Eigen::internal::traits<Derived>::XprKind, ArrayXpr>::value), \
0208                           THIS_METHOD_IS_ONLY_FOR_ARRAYS_NOT_MATRICES)
0209 
0210 #define EIGEN_STATIC_ASSERT_SAME_XPR_KIND(Derived1, Derived2) \
0211       EIGEN_STATIC_ASSERT((Eigen::internal::is_same<typename Eigen::internal::traits<Derived1>::XprKind, \
0212                                              typename Eigen::internal::traits<Derived2>::XprKind \
0213                                             >::value), \
0214                           YOU_CANNOT_MIX_ARRAYS_AND_MATRICES)
0215 
0216 // Check that a cost value is positive, and that is stay within a reasonable range
0217 // TODO this check could be enabled for internal debugging only
0218 #define EIGEN_INTERNAL_CHECK_COST_VALUE(C) \
0219       EIGEN_STATIC_ASSERT((C)>=0 && (C)<=HugeCost*HugeCost, EIGEN_INTERNAL_ERROR_PLEASE_FILE_A_BUG_REPORT__INVALID_COST_VALUE);
0220 
0221 #endif // EIGEN_STATIC_ASSERT_H