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 namespace Eigen {
00041
00042 typedef EIGEN_DEFAULT_DENSE_INDEX_TYPE DenseIndex;
00043
00044 namespace internal {
00045
00046
00047 class no_assignment_operator
00048 {
00049 private:
00050 no_assignment_operator& operator=(const no_assignment_operator&);
00051 };
00052
00054 template<typename I1, typename I2>
00055 struct promote_index_type
00056 {
00057 typedef typename conditional<(sizeof(I1)<sizeof(I2)), I2, I1>::type type;
00058 };
00059
00064 template<typename T, int Value> class variable_if_dynamic
00065 {
00066 public:
00067 EIGEN_EMPTY_STRUCT_CTOR(variable_if_dynamic)
00068 explicit variable_if_dynamic(T v) { EIGEN_ONLY_USED_FOR_DEBUG(v); assert(v == T(Value)); }
00069 static T value() { return T(Value); }
00070 void setValue(T) {}
00071 };
00072
00073 template<typename T> class variable_if_dynamic<T, Dynamic>
00074 {
00075 T m_value;
00076 variable_if_dynamic() { assert(false); }
00077 public:
00078 explicit variable_if_dynamic(T value) : m_value(value) {}
00079 T value() const { return m_value; }
00080 void setValue(T value) { m_value = value; }
00081 };
00082
00083 template<typename T> struct functor_traits
00084 {
00085 enum
00086 {
00087 Cost = 10,
00088 PacketAccess = false
00089 };
00090 };
00091
00092 template<typename T> struct packet_traits;
00093
00094 template<typename T> struct unpacket_traits
00095 {
00096 typedef T type;
00097 enum {size=1};
00098 };
00099
00100 template<typename _Scalar, int _Rows, int _Cols,
00101 int _Options = AutoAlign |
00102 ( (_Rows==1 && _Cols!=1) ? RowMajor
00103 : (_Cols==1 && _Rows!=1) ? ColMajor
00104 : EIGEN_DEFAULT_MATRIX_STORAGE_ORDER_OPTION ),
00105 int _MaxRows = _Rows,
00106 int _MaxCols = _Cols
00107 > class make_proper_matrix_type
00108 {
00109 enum {
00110 IsColVector = _Cols==1 && _Rows!=1,
00111 IsRowVector = _Rows==1 && _Cols!=1,
00112 Options = IsColVector ? (_Options | ColMajor) & ~RowMajor
00113 : IsRowVector ? (_Options | RowMajor) & ~ColMajor
00114 : _Options
00115 };
00116 public:
00117 typedef Matrix<_Scalar, _Rows, _Cols, Options, _MaxRows, _MaxCols> type;
00118 };
00119
00120 template<typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols>
00121 class compute_matrix_flags
00122 {
00123 enum {
00124 row_major_bit = Options&RowMajor ? RowMajorBit : 0,
00125 is_dynamic_size_storage = MaxRows==Dynamic || MaxCols==Dynamic,
00126
00127 aligned_bit =
00128 (
00129 ((Options&DontAlign)==0)
00130 && (
00131 #if EIGEN_ALIGN_STATICALLY
00132 ((!is_dynamic_size_storage) && (((MaxCols*MaxRows*int(sizeof(Scalar))) % 16) == 0))
00133 #else
00134 0
00135 #endif
00136
00137 ||
00138
00139 #if EIGEN_ALIGN
00140 is_dynamic_size_storage
00141 #else
00142 0
00143 #endif
00144
00145 )
00146 ) ? AlignedBit : 0,
00147 packet_access_bit = packet_traits<Scalar>::Vectorizable && aligned_bit ? PacketAccessBit : 0
00148 };
00149
00150 public:
00151 enum { ret = LinearAccessBit | LvalueBit | DirectAccessBit | NestByRefBit | packet_access_bit | row_major_bit | aligned_bit };
00152 };
00153
00154 template<int _Rows, int _Cols> struct size_at_compile_time
00155 {
00156 enum { ret = (_Rows==Dynamic || _Cols==Dynamic) ? Dynamic : _Rows * _Cols };
00157 };
00158
00159
00160
00161
00162
00163 template<typename T, typename StorageKind = typename traits<T>::StorageKind> struct plain_matrix_type;
00164 template<typename T, typename BaseClassType> struct plain_matrix_type_dense;
00165 template<typename T> struct plain_matrix_type<T,Dense>
00166 {
00167 typedef typename plain_matrix_type_dense<T,typename traits<T>::XprKind>::type type;
00168 };
00169
00170 template<typename T> struct plain_matrix_type_dense<T,MatrixXpr>
00171 {
00172 typedef Matrix<typename traits<T>::Scalar,
00173 traits<T>::RowsAtCompileTime,
00174 traits<T>::ColsAtCompileTime,
00175 AutoAlign | (traits<T>::Flags&RowMajorBit ? RowMajor : ColMajor),
00176 traits<T>::MaxRowsAtCompileTime,
00177 traits<T>::MaxColsAtCompileTime
00178 > type;
00179 };
00180
00181 template<typename T> struct plain_matrix_type_dense<T,ArrayXpr>
00182 {
00183 typedef Array<typename traits<T>::Scalar,
00184 traits<T>::RowsAtCompileTime,
00185 traits<T>::ColsAtCompileTime,
00186 AutoAlign | (traits<T>::Flags&RowMajorBit ? RowMajor : ColMajor),
00187 traits<T>::MaxRowsAtCompileTime,
00188 traits<T>::MaxColsAtCompileTime
00189 > type;
00190 };
00191
00192
00193
00194
00195
00196 template<typename T, typename StorageKind = typename traits<T>::StorageKind> struct eval;
00197
00198 template<typename T> struct eval<T,Dense>
00199 {
00200 typedef typename plain_matrix_type<T>::type type;
00201
00202
00203
00204
00205
00206
00207
00208
00209 };
00210
00211
00212 template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
00213 struct eval<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>, Dense>
00214 {
00215 typedef const Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& type;
00216 };
00217
00218 template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
00219 struct eval<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>, Dense>
00220 {
00221 typedef const Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& type;
00222 };
00223
00224
00225
00226
00227
00228 template<typename T> struct plain_matrix_type_column_major
00229 {
00230 enum { Rows = traits<T>::RowsAtCompileTime,
00231 Cols = traits<T>::ColsAtCompileTime,
00232 MaxRows = traits<T>::MaxRowsAtCompileTime,
00233 MaxCols = traits<T>::MaxColsAtCompileTime
00234 };
00235 typedef Matrix<typename traits<T>::Scalar,
00236 Rows,
00237 Cols,
00238 (MaxRows==1&&MaxCols!=1) ? RowMajor : ColMajor,
00239 MaxRows,
00240 MaxCols
00241 > type;
00242 };
00243
00244
00245
00246 template<typename T> struct plain_matrix_type_row_major
00247 {
00248 enum { Rows = traits<T>::RowsAtCompileTime,
00249 Cols = traits<T>::ColsAtCompileTime,
00250 MaxRows = traits<T>::MaxRowsAtCompileTime,
00251 MaxCols = traits<T>::MaxColsAtCompileTime
00252 };
00253 typedef Matrix<typename traits<T>::Scalar,
00254 Rows,
00255 Cols,
00256 (MaxCols==1&&MaxRows!=1) ? RowMajor : ColMajor,
00257 MaxRows,
00258 MaxCols
00259 > type;
00260 };
00261
00262
00263 template<typename T> struct must_nest_by_value { enum { ret = false }; };
00264
00268 template <typename T>
00269 struct ref_selector
00270 {
00271 typedef typename conditional<
00272 bool(traits<T>::Flags & NestByRefBit),
00273 T const&,
00274 const T
00275 >::type type;
00276 };
00277
00279 template<typename T1, typename T2>
00280 struct transfer_constness
00281 {
00282 typedef typename conditional<
00283 bool(internal::is_const<T1>::value),
00284 typename internal::add_const_on_value_type<T2>::type,
00285 T2
00286 >::type type;
00287 };
00288
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 T>
00337 T* const_cast_ptr(const T* ptr)
00338 {
00339 return const_cast<T*>(ptr);
00340 }
00341
00342 template<typename Derived, typename XprKind = typename traits<Derived>::XprKind>
00343 struct dense_xpr_base
00344 {
00345
00346 };
00347
00348 template<typename Derived>
00349 struct dense_xpr_base<Derived, MatrixXpr>
00350 {
00351 typedef MatrixBase<Derived> type;
00352 };
00353
00354 template<typename Derived>
00355 struct dense_xpr_base<Derived, ArrayXpr>
00356 {
00357 typedef ArrayBase<Derived> type;
00358 };
00359
00362 template<typename Derived,typename Scalar,typename OtherScalar,
00363 bool EnableIt = !is_same<Scalar,OtherScalar>::value >
00364 struct special_scalar_op_base : public DenseCoeffsBase<Derived>
00365 {
00366
00367
00368 void operator*() const;
00369 };
00370
00371 template<typename Derived,typename Scalar,typename OtherScalar>
00372 struct special_scalar_op_base<Derived,Scalar,OtherScalar,true> : public DenseCoeffsBase<Derived>
00373 {
00374 const CwiseUnaryOp<scalar_multiple2_op<Scalar,OtherScalar>, Derived>
00375 operator*(const OtherScalar& scalar) const
00376 {
00377 return CwiseUnaryOp<scalar_multiple2_op<Scalar,OtherScalar>, Derived>
00378 (*static_cast<const Derived*>(this), scalar_multiple2_op<Scalar,OtherScalar>(scalar));
00379 }
00380
00381 inline friend const CwiseUnaryOp<scalar_multiple2_op<Scalar,OtherScalar>, Derived>
00382 operator*(const OtherScalar& scalar, const Derived& matrix)
00383 { return static_cast<const special_scalar_op_base&>(matrix).operator*(scalar); }
00384 };
00385
00386 template<typename XprType, typename CastType> struct cast_return_type
00387 {
00388 typedef typename XprType::Scalar CurrentScalarType;
00389 typedef typename remove_all<CastType>::type _CastType;
00390 typedef typename _CastType::Scalar NewScalarType;
00391 typedef typename conditional<is_same<CurrentScalarType,NewScalarType>::value,
00392 const XprType&,CastType>::type type;
00393 };
00394
00395 template <typename A, typename B> struct promote_storage_type;
00396
00397 template <typename A> struct promote_storage_type<A,A>
00398 {
00399 typedef A ret;
00400 };
00401
00405 template<typename ExpressionType, typename Scalar = typename ExpressionType::Scalar>
00406 struct plain_row_type
00407 {
00408 typedef Matrix<Scalar, 1, ExpressionType::ColsAtCompileTime,
00409 ExpressionType::PlainObject::Options | RowMajor, 1, ExpressionType::MaxColsAtCompileTime> MatrixRowType;
00410 typedef Array<Scalar, 1, ExpressionType::ColsAtCompileTime,
00411 ExpressionType::PlainObject::Options | RowMajor, 1, ExpressionType::MaxColsAtCompileTime> ArrayRowType;
00412
00413 typedef typename conditional<
00414 is_same< typename traits<ExpressionType>::XprKind, MatrixXpr >::value,
00415 MatrixRowType,
00416 ArrayRowType
00417 >::type type;
00418 };
00419
00420 template<typename ExpressionType, typename Scalar = typename ExpressionType::Scalar>
00421 struct plain_col_type
00422 {
00423 typedef Matrix<Scalar, ExpressionType::RowsAtCompileTime, 1,
00424 ExpressionType::PlainObject::Options & ~RowMajor, ExpressionType::MaxRowsAtCompileTime, 1> MatrixColType;
00425 typedef Array<Scalar, ExpressionType::RowsAtCompileTime, 1,
00426 ExpressionType::PlainObject::Options & ~RowMajor, ExpressionType::MaxRowsAtCompileTime, 1> ArrayColType;
00427
00428 typedef typename conditional<
00429 is_same< typename traits<ExpressionType>::XprKind, MatrixXpr >::value,
00430 MatrixColType,
00431 ArrayColType
00432 >::type type;
00433 };
00434
00435 template<typename ExpressionType, typename Scalar = typename ExpressionType::Scalar>
00436 struct plain_diag_type
00437 {
00438 enum { diag_size = EIGEN_SIZE_MIN_PREFER_DYNAMIC(ExpressionType::RowsAtCompileTime, ExpressionType::ColsAtCompileTime),
00439 max_diag_size = EIGEN_SIZE_MIN_PREFER_FIXED(ExpressionType::MaxRowsAtCompileTime, ExpressionType::MaxColsAtCompileTime)
00440 };
00441 typedef Matrix<Scalar, diag_size, 1, ExpressionType::PlainObject::Options & ~RowMajor, max_diag_size, 1> MatrixDiagType;
00442 typedef Array<Scalar, diag_size, 1, ExpressionType::PlainObject::Options & ~RowMajor, max_diag_size, 1> ArrayDiagType;
00443
00444 typedef typename conditional<
00445 is_same< typename traits<ExpressionType>::XprKind, MatrixXpr >::value,
00446 MatrixDiagType,
00447 ArrayDiagType
00448 >::type type;
00449 };
00450
00451 template<typename ExpressionType>
00452 struct is_lvalue
00453 {
00454 enum { value = !bool(is_const<ExpressionType>::value) &&
00455 bool(traits<ExpressionType>::Flags & LvalueBit) };
00456 };
00457
00458 }
00459
00460 }
00461
00462 #endif // EIGEN_XPRHELPER_H