00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef EIGEN_XPRHELPER_H
00027 #define EIGEN_XPRHELPER_H
00028
00029
00030
00031
00032 #if (defined __GNUG__) && !((__GNUC__==4) && (__GNUC_MINOR__==3))
00033 #define EIGEN_EMPTY_STRUCT_CTOR(X) \
00034 EIGEN_STRONG_INLINE X() {} \
00035 EIGEN_STRONG_INLINE X(const X& ) {}
00036 #else
00037 #define EIGEN_EMPTY_STRUCT_CTOR(X)
00038 #endif
00039
00040 typedef EIGEN_DEFAULT_DENSE_INDEX_TYPE DenseIndex;
00041
00042 namespace internal {
00043
00044
00045 class no_assignment_operator
00046 {
00047 private:
00048 no_assignment_operator& operator=(const no_assignment_operator&);
00049 };
00050
00051
00052 template<typename I1, typename I2>
00053 struct promote_index_type
00054 {
00055 typedef typename conditional<(sizeof(I1)<sizeof(I2)), I2, I1>::type type;
00056 };
00057
00058
00059
00060
00061
00062 template<typename T, int Value> class variable_if_dynamic
00063 {
00064 public:
00065 EIGEN_EMPTY_STRUCT_CTOR(variable_if_dynamic)
00066 explicit variable_if_dynamic(T v) { EIGEN_ONLY_USED_FOR_DEBUG(v); assert(v == T(Value)); }
00067 static T value() { return T(Value); }
00068 void setValue(T) {}
00069 };
00070
00071 template<typename T> class variable_if_dynamic<T, Dynamic>
00072 {
00073 T m_value;
00074 variable_if_dynamic() { assert(false); }
00075 public:
00076 explicit variable_if_dynamic(T value) : m_value(value) {}
00077 T value() const { return m_value; }
00078 void setValue(T value) { m_value = value; }
00079 };
00080
00081 template<typename T> struct functor_traits
00082 {
00083 enum
00084 {
00085 Cost = 10,
00086 PacketAccess = false
00087 };
00088 };
00089
00090 template<typename T> struct packet_traits;
00091
00092 template<typename T> struct unpacket_traits
00093 {
00094 typedef T type;
00095 enum {size=1};
00096 };
00097
00098 template<typename _Scalar, int _Rows, int _Cols,
00099 int _Options = AutoAlign |
00100 ( (_Rows==1 && _Cols!=1) ? RowMajor
00101 : (_Cols==1 && _Rows!=1) ? ColMajor
00102 : EIGEN_DEFAULT_MATRIX_STORAGE_ORDER_OPTION ),
00103 int _MaxRows = _Rows,
00104 int _MaxCols = _Cols
00105 > class make_proper_matrix_type
00106 {
00107 enum {
00108 IsColVector = _Cols==1 && _Rows!=1,
00109 IsRowVector = _Rows==1 && _Cols!=1,
00110 Options = IsColVector ? (_Options | ColMajor) & ~RowMajor
00111 : IsRowVector ? (_Options | RowMajor) & ~ColMajor
00112 : _Options
00113 };
00114 public:
00115 typedef Matrix<_Scalar, _Rows, _Cols, Options, _MaxRows, _MaxCols> type;
00116 };
00117
00118 template<typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols>
00119 class compute_matrix_flags
00120 {
00121 enum {
00122 row_major_bit = Options&RowMajor ? RowMajorBit : 0,
00123 is_dynamic_size_storage = MaxRows==Dynamic || MaxCols==Dynamic,
00124
00125 aligned_bit =
00126 (
00127 ((Options&DontAlign)==0)
00128 && packet_traits<Scalar>::Vectorizable
00129 && (
00130 #if EIGEN_ALIGN_STATICALLY
00131 ((!is_dynamic_size_storage) && (((MaxCols*MaxRows) % packet_traits<Scalar>::size) == 0))
00132 #else
00133 0
00134 #endif
00135
00136 ||
00137
00138 #if EIGEN_ALIGN
00139 is_dynamic_size_storage
00140 #else
00141 0
00142 #endif
00143
00144 )
00145 ) ? AlignedBit : 0,
00146 packet_access_bit = packet_traits<Scalar>::Vectorizable && aligned_bit ? PacketAccessBit : 0
00147 };
00148
00149 public:
00150 enum { ret = LinearAccessBit | LvalueBit | DirectAccessBit | NestByRefBit | packet_access_bit | row_major_bit | aligned_bit };
00151 };
00152
00153 template<int _Rows, int _Cols> struct size_at_compile_time
00154 {
00155 enum { ret = (_Rows==Dynamic || _Cols==Dynamic) ? Dynamic : _Rows * _Cols };
00156 };
00157
00158
00159
00160
00161
00162 template<typename T, typename StorageKind = typename traits<T>::StorageKind> struct plain_matrix_type;
00163 template<typename T, typename BaseClassType> struct plain_matrix_type_dense;
00164 template<typename T> struct plain_matrix_type<T,Dense>
00165 {
00166 typedef typename plain_matrix_type_dense<T,typename traits<T>::XprKind>::type type;
00167 };
00168
00169 template<typename T> struct plain_matrix_type_dense<T,MatrixXpr>
00170 {
00171 typedef Matrix<typename traits<T>::Scalar,
00172 traits<T>::RowsAtCompileTime,
00173 traits<T>::ColsAtCompileTime,
00174 AutoAlign | (traits<T>::Flags&RowMajorBit ? RowMajor : ColMajor),
00175 traits<T>::MaxRowsAtCompileTime,
00176 traits<T>::MaxColsAtCompileTime
00177 > type;
00178 };
00179
00180 template<typename T> struct plain_matrix_type_dense<T,ArrayXpr>
00181 {
00182 typedef Array<typename traits<T>::Scalar,
00183 traits<T>::RowsAtCompileTime,
00184 traits<T>::ColsAtCompileTime,
00185 AutoAlign | (traits<T>::Flags&RowMajorBit ? RowMajor : ColMajor),
00186 traits<T>::MaxRowsAtCompileTime,
00187 traits<T>::MaxColsAtCompileTime
00188 > type;
00189 };
00190
00191
00192
00193
00194
00195 template<typename T, typename StorageKind = typename traits<T>::StorageKind> struct eval;
00196
00197 template<typename T> struct eval<T,Dense>
00198 {
00199 typedef typename plain_matrix_type<T>::type type;
00200
00201
00202
00203
00204
00205
00206
00207
00208 };
00209
00210
00211 template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
00212 struct eval<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>, Dense>
00213 {
00214 typedef const Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& type;
00215 };
00216
00217 template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
00218 struct eval<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>, Dense>
00219 {
00220 typedef const Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& type;
00221 };
00222
00223
00224
00225
00226
00227 template<typename T> struct plain_matrix_type_column_major
00228 {
00229 enum { Rows = traits<T>::RowsAtCompileTime,
00230 Cols = traits<T>::ColsAtCompileTime,
00231 MaxRows = traits<T>::MaxRowsAtCompileTime,
00232 MaxCols = traits<T>::MaxColsAtCompileTime
00233 };
00234 typedef Matrix<typename traits<T>::Scalar,
00235 Rows,
00236 Cols,
00237 (MaxRows==1&&MaxCols!=1) ? RowMajor : ColMajor,
00238 MaxRows,
00239 MaxCols
00240 > type;
00241 };
00242
00243
00244
00245 template<typename T> struct plain_matrix_type_row_major
00246 {
00247 enum { Rows = traits<T>::RowsAtCompileTime,
00248 Cols = traits<T>::ColsAtCompileTime,
00249 MaxRows = traits<T>::MaxRowsAtCompileTime,
00250 MaxCols = traits<T>::MaxColsAtCompileTime
00251 };
00252 typedef Matrix<typename traits<T>::Scalar,
00253 Rows,
00254 Cols,
00255 (MaxCols==1&&MaxRows!=1) ? RowMajor : ColMajor,
00256 MaxRows,
00257 MaxCols
00258 > type;
00259 };
00260
00261
00262 template<typename T> struct must_nest_by_value { enum { ret = false }; };
00263
00264 template<class T>
00265 struct is_reference
00266 {
00267 enum { ret = false };
00268 };
00269
00270 template<class T>
00271 struct is_reference<T&>
00272 {
00273 enum { ret = true };
00274 };
00275
00276
00277
00278
00279
00280
00281 template <typename T>
00282 struct ref_selector
00283 {
00284 typedef typename conditional<
00285 bool(traits<T>::Flags & NestByRefBit),
00286 T const&,
00287 T
00288 >::type type;
00289 };
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309 template<typename T, int n=1, typename PlainObject = typename eval<T>::type> struct nested
00310 {
00311 enum {
00312
00313
00314
00315
00316
00317 DynamicAsInteger = 10000,
00318 ScalarReadCost = NumTraits<typename traits<T>::Scalar>::ReadCost,
00319 ScalarReadCostAsInteger = ScalarReadCost == Dynamic ? DynamicAsInteger : ScalarReadCost,
00320 CoeffReadCost = traits<T>::CoeffReadCost,
00321 CoeffReadCostAsInteger = CoeffReadCost == Dynamic ? DynamicAsInteger : CoeffReadCost,
00322 NAsInteger = n == Dynamic ? int(DynamicAsInteger) : n,
00323 CostEvalAsInteger = (NAsInteger+1) * ScalarReadCostAsInteger + CoeffReadCostAsInteger,
00324 CostNoEvalAsInteger = NAsInteger * CoeffReadCostAsInteger
00325 };
00326
00327 typedef typename conditional<
00328 ( (int(traits<T>::Flags) & EvalBeforeNestingBit) ||
00329 int(CostEvalAsInteger) < int(CostNoEvalAsInteger)
00330 ),
00331 PlainObject,
00332 typename ref_selector<T>::type
00333 >::type type;
00334 };
00335
00336 template<typename Derived, typename XprKind = typename traits<Derived>::XprKind>
00337 struct dense_xpr_base
00338 {
00339
00340 };
00341
00342 template<typename Derived>
00343 struct dense_xpr_base<Derived, MatrixXpr>
00344 {
00345 typedef MatrixBase<Derived> type;
00346 };
00347
00348 template<typename Derived>
00349 struct dense_xpr_base<Derived, ArrayXpr>
00350 {
00351 typedef ArrayBase<Derived> type;
00352 };
00353
00354
00355
00356 template<typename Derived,typename Scalar,typename OtherScalar,
00357 bool EnableIt = !is_same<Scalar,OtherScalar>::value >
00358 struct special_scalar_op_base : public DenseCoeffsBase<Derived>
00359 {
00360
00361
00362 void operator*() const;
00363 };
00364
00365 template<typename Derived,typename Scalar,typename OtherScalar>
00366 struct special_scalar_op_base<Derived,Scalar,OtherScalar,true> : public DenseCoeffsBase<Derived>
00367 {
00368 const CwiseUnaryOp<scalar_multiple2_op<Scalar,OtherScalar>, Derived>
00369 operator*(const OtherScalar& scalar) const
00370 {
00371 return CwiseUnaryOp<scalar_multiple2_op<Scalar,OtherScalar>, Derived>
00372 (*static_cast<const Derived*>(this), scalar_multiple2_op<Scalar,OtherScalar>(scalar));
00373 }
00374
00375 inline friend const CwiseUnaryOp<scalar_multiple2_op<Scalar,OtherScalar>, Derived>
00376 operator*(const OtherScalar& scalar, const Derived& matrix)
00377 { return static_cast<const special_scalar_op_base&>(matrix).operator*(scalar); }
00378 };
00379
00380 template<typename XprType, typename CastType> struct cast_return_type
00381 {
00382 typedef typename XprType::Scalar CurrentScalarType;
00383 typedef typename remove_all<CastType>::type _CastType;
00384 typedef typename _CastType::Scalar NewScalarType;
00385 typedef typename conditional<is_same<CurrentScalarType,NewScalarType>::value,
00386 const XprType&,CastType>::type type;
00387 };
00388
00389 template <typename A, typename B> struct promote_storage_type;
00390
00391 template <typename A> struct promote_storage_type<A,A>
00392 {
00393 typedef A ret;
00394 };
00395
00396
00397
00398
00399 template<typename ExpressionType, typename Scalar = typename ExpressionType::Scalar>
00400 struct plain_row_type
00401 {
00402 typedef Matrix<Scalar, 1, ExpressionType::ColsAtCompileTime,
00403 ExpressionType::PlainObject::Options | RowMajor, 1, ExpressionType::MaxColsAtCompileTime> MatrixRowType;
00404 typedef Array<Scalar, 1, ExpressionType::ColsAtCompileTime,
00405 ExpressionType::PlainObject::Options | RowMajor, 1, ExpressionType::MaxColsAtCompileTime> ArrayRowType;
00406
00407 typedef typename conditional<
00408 is_same< typename traits<ExpressionType>::XprKind, MatrixXpr >::value,
00409 MatrixRowType,
00410 ArrayRowType
00411 >::type type;
00412 };
00413
00414 template<typename ExpressionType, typename Scalar = typename ExpressionType::Scalar>
00415 struct plain_col_type
00416 {
00417 typedef Matrix<Scalar, ExpressionType::RowsAtCompileTime, 1,
00418 ExpressionType::PlainObject::Options & ~RowMajor, ExpressionType::MaxRowsAtCompileTime, 1> MatrixColType;
00419 typedef Array<Scalar, ExpressionType::RowsAtCompileTime, 1,
00420 ExpressionType::PlainObject::Options & ~RowMajor, ExpressionType::MaxRowsAtCompileTime, 1> ArrayColType;
00421
00422 typedef typename conditional<
00423 is_same< typename traits<ExpressionType>::XprKind, MatrixXpr >::value,
00424 MatrixColType,
00425 ArrayColType
00426 >::type type;
00427 };
00428
00429 template<typename ExpressionType, typename Scalar = typename ExpressionType::Scalar>
00430 struct plain_diag_type
00431 {
00432 enum { diag_size = EIGEN_SIZE_MIN_PREFER_DYNAMIC(ExpressionType::RowsAtCompileTime, ExpressionType::ColsAtCompileTime),
00433 max_diag_size = EIGEN_SIZE_MIN_PREFER_FIXED(ExpressionType::MaxRowsAtCompileTime, ExpressionType::MaxColsAtCompileTime)
00434 };
00435 typedef Matrix<Scalar, diag_size, 1, ExpressionType::PlainObject::Options & ~RowMajor, max_diag_size, 1> MatrixDiagType;
00436 typedef Array<Scalar, diag_size, 1, ExpressionType::PlainObject::Options & ~RowMajor, max_diag_size, 1> ArrayDiagType;
00437
00438 typedef typename conditional<
00439 is_same< typename traits<ExpressionType>::XprKind, MatrixXpr >::value,
00440 MatrixDiagType,
00441 ArrayDiagType
00442 >::type type;
00443 };
00444
00445 template<typename ExpressionType>
00446 struct is_lvalue
00447 {
00448 enum { value = !bool(is_const<ExpressionType>::value) &&
00449 bool(traits<ExpressionType>::Flags & LvalueBit) };
00450 };
00451
00452 }
00453
00454 #endif // EIGEN_XPRHELPER_H