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_MATRIXBASE_H
00027 #define EIGEN_MATRIXBASE_H
00028
00055 template<typename Derived> class MatrixBase
00056 {
00057 public:
00058
00059 #ifndef EIGEN_PARSED_BY_DOXYGEN
00060 class InnerIterator;
00061
00062 typedef typename ei_traits<Derived>::Scalar Scalar;
00063 typedef typename ei_packet_traits<Scalar>::type PacketScalar;
00064 #endif // not EIGEN_PARSED_BY_DOXYGEN
00065
00066 enum {
00067
00068 RowsAtCompileTime = ei_traits<Derived>::RowsAtCompileTime,
00074 ColsAtCompileTime = ei_traits<Derived>::ColsAtCompileTime,
00081 SizeAtCompileTime = (ei_size_at_compile_time<ei_traits<Derived>::RowsAtCompileTime,
00082 ei_traits<Derived>::ColsAtCompileTime>::ret),
00087 MaxRowsAtCompileTime = ei_traits<Derived>::MaxRowsAtCompileTime,
00098 MaxColsAtCompileTime = ei_traits<Derived>::MaxColsAtCompileTime,
00109 MaxSizeAtCompileTime = (ei_size_at_compile_time<ei_traits<Derived>::MaxRowsAtCompileTime,
00110 ei_traits<Derived>::MaxColsAtCompileTime>::ret),
00121 IsVectorAtCompileTime = ei_traits<Derived>::RowsAtCompileTime == 1
00122 || ei_traits<Derived>::ColsAtCompileTime == 1,
00128 Flags = ei_traits<Derived>::Flags,
00133 CoeffReadCost = ei_traits<Derived>::CoeffReadCost
00137 };
00138
00139 #ifndef EIGEN_PARSED_BY_DOXYGEN
00140
00146 typedef typename NumTraits<Scalar>::Real RealScalar;
00147
00149 typedef Matrix<Scalar,EIGEN_ENUM_MAX(RowsAtCompileTime,ColsAtCompileTime),
00150 EIGEN_ENUM_MAX(RowsAtCompileTime,ColsAtCompileTime)> SquareMatrixType;
00151 #endif // not EIGEN_PARSED_BY_DOXYGEN
00152
00154 inline int rows() const { return derived().rows(); }
00156 inline int cols() const { return derived().cols(); }
00159 inline int size() const { return rows() * cols(); }
00162 inline int nonZeros() const { return size(); }
00167 inline bool isVector() const { return rows()==1 || cols()==1; }
00170 int outerSize() const { return (int(Flags)&RowMajorBit) ? this->rows() : this->cols(); }
00173 int innerSize() const { return (int(Flags)&RowMajorBit) ? this->cols() : this->rows(); }
00174
00175 #ifndef EIGEN_PARSED_BY_DOXYGEN
00176
00181 typedef typename ei_plain_matrix_type<Derived>::type PlainMatrixType;
00187 typedef typename ei_plain_matrix_type<Derived>::type PlainMatrixType_ColMajor;
00188
00190 typedef CwiseNullaryOp<ei_scalar_constant_op<Scalar>,Derived> ConstantReturnType;
00192 typedef CwiseUnaryOp<ei_scalar_multiple_op<Scalar>, Derived> ScalarMultipleReturnType;
00194 typedef CwiseUnaryOp<ei_scalar_quotient1_op<Scalar>, Derived> ScalarQuotient1ReturnType;
00196 typedef typename ei_meta_if<NumTraits<Scalar>::IsComplex,
00197 const CwiseUnaryOp<ei_scalar_conjugate_op<Scalar>, Derived>,
00198 const Derived&
00199 >::ret ConjugateReturnType;
00201 typedef CwiseUnaryOp<ei_scalar_real_op<Scalar>, Derived> RealReturnType;
00203 typedef CwiseUnaryOp<ei_scalar_imag_op<Scalar>, Derived> ImagReturnType;
00205 typedef Eigen::Transpose<NestByValue<typename ei_cleantype<ConjugateReturnType>::type> >
00206 AdjointReturnType;
00208 typedef Matrix<typename NumTraits<typename ei_traits<Derived>::Scalar>::Real, ei_traits<Derived>::ColsAtCompileTime, 1> EigenvaluesReturnType;
00210 typedef Block<Derived, ei_traits<Derived>::RowsAtCompileTime, 1> ColXpr;
00212 typedef Block<Derived, 1, ei_traits<Derived>::ColsAtCompileTime> RowXpr;
00214 typedef CwiseNullaryOp<ei_scalar_identity_op<Scalar>,Derived> IdentityReturnType;
00216 typedef Block<CwiseNullaryOp<ei_scalar_identity_op<Scalar>, SquareMatrixType>,
00217 ei_traits<Derived>::RowsAtCompileTime,
00218 ei_traits<Derived>::ColsAtCompileTime> BasisReturnType;
00219 #endif // not EIGEN_PARSED_BY_DOXYGEN
00220
00221
00223 template<typename OtherDerived>
00224 Derived& operator=(const MatrixBase<OtherDerived>& other);
00225
00229 inline Derived& operator=(const MatrixBase& other)
00230 {
00231 return this->operator=<Derived>(other);
00232 }
00233
00234 #ifndef EIGEN_PARSED_BY_DOXYGEN
00235
00236 template<typename OtherDerived>
00237 Derived& lazyAssign(const MatrixBase<OtherDerived>& other);
00238
00240 template<typename Lhs, typename Rhs>
00241 Derived& lazyAssign(const Product<Lhs,Rhs,CacheFriendlyProduct>& product);
00242
00244 template<typename OtherDerived>
00245 Derived& lazyAssign(const Flagged<OtherDerived, 0, EvalBeforeNestingBit | EvalBeforeAssigningBit>& other)
00246 { return lazyAssign(other._expression()); }
00247 #endif // not EIGEN_PARSED_BY_DOXYGEN
00248
00249 CommaInitializer<Derived> operator<< (const Scalar& s);
00250
00251 template<typename OtherDerived>
00252 CommaInitializer<Derived> operator<< (const MatrixBase<OtherDerived>& other);
00253
00254 const Scalar coeff(int row, int col) const;
00255 const Scalar operator()(int row, int col) const;
00256
00257 Scalar& coeffRef(int row, int col);
00258 Scalar& operator()(int row, int col);
00259
00260 const Scalar coeff(int index) const;
00261 const Scalar operator[](int index) const;
00262 const Scalar operator()(int index) const;
00263
00264 Scalar& coeffRef(int index);
00265 Scalar& operator[](int index);
00266 Scalar& operator()(int index);
00267
00268 #ifndef EIGEN_PARSED_BY_DOXYGEN
00269 template<typename OtherDerived>
00270 void copyCoeff(int row, int col, const MatrixBase<OtherDerived>& other);
00271 template<typename OtherDerived>
00272 void copyCoeff(int index, const MatrixBase<OtherDerived>& other);
00273 template<typename OtherDerived, int StoreMode, int LoadMode>
00274 void copyPacket(int row, int col, const MatrixBase<OtherDerived>& other);
00275 template<typename OtherDerived, int StoreMode, int LoadMode>
00276 void copyPacket(int index, const MatrixBase<OtherDerived>& other);
00277 #endif // not EIGEN_PARSED_BY_DOXYGEN
00278
00279 template<int LoadMode>
00280 PacketScalar packet(int row, int col) const;
00281 template<int StoreMode>
00282 void writePacket(int row, int col, const PacketScalar& x);
00283
00284 template<int LoadMode>
00285 PacketScalar packet(int index) const;
00286 template<int StoreMode>
00287 void writePacket(int index, const PacketScalar& x);
00288
00289 const Scalar x() const;
00290 const Scalar y() const;
00291 const Scalar z() const;
00292 const Scalar w() const;
00293 Scalar& x();
00294 Scalar& y();
00295 Scalar& z();
00296 Scalar& w();
00297
00298
00299 const CwiseUnaryOp<ei_scalar_opposite_op<typename ei_traits<Derived>::Scalar>,Derived> operator-() const;
00300
00301 template<typename OtherDerived>
00302 const CwiseBinaryOp<ei_scalar_sum_op<typename ei_traits<Derived>::Scalar>, Derived, OtherDerived>
00303 operator+(const MatrixBase<OtherDerived> &other) const;
00304
00305 template<typename OtherDerived>
00306 const CwiseBinaryOp<ei_scalar_difference_op<typename ei_traits<Derived>::Scalar>, Derived, OtherDerived>
00307 operator-(const MatrixBase<OtherDerived> &other) const;
00308
00309 template<typename OtherDerived>
00310 Derived& operator+=(const MatrixBase<OtherDerived>& other);
00311 template<typename OtherDerived>
00312 Derived& operator-=(const MatrixBase<OtherDerived>& other);
00313
00314 template<typename Lhs,typename Rhs>
00315 Derived& operator+=(const Flagged<Product<Lhs,Rhs,CacheFriendlyProduct>, 0, EvalBeforeNestingBit | EvalBeforeAssigningBit>& other);
00316
00317 Derived& operator*=(const Scalar& other);
00318 Derived& operator/=(const Scalar& other);
00319
00320 const ScalarMultipleReturnType operator*(const Scalar& scalar) const;
00321 const CwiseUnaryOp<ei_scalar_quotient1_op<typename ei_traits<Derived>::Scalar>, Derived>
00322 operator/(const Scalar& scalar) const;
00323
00324 inline friend const CwiseUnaryOp<ei_scalar_multiple_op<typename ei_traits<Derived>::Scalar>, Derived>
00325 operator*(const Scalar& scalar, const MatrixBase& matrix)
00326 { return matrix*scalar; }
00327
00328
00329 template<typename OtherDerived>
00330 const typename ProductReturnType<Derived,OtherDerived>::Type
00331 operator*(const MatrixBase<OtherDerived> &other) const;
00332
00333 template<typename OtherDerived>
00334 Derived& operator*=(const MatrixBase<OtherDerived>& other);
00335
00336 template<typename OtherDerived>
00337 typename ei_plain_matrix_type_column_major<OtherDerived>::type
00338 solveTriangular(const MatrixBase<OtherDerived>& other) const;
00339
00340 template<typename OtherDerived>
00341 void solveTriangularInPlace(const MatrixBase<OtherDerived>& other) const;
00342
00343
00344 template<typename OtherDerived>
00345 Scalar dot(const MatrixBase<OtherDerived>& other) const;
00346 RealScalar squaredNorm() const;
00347 RealScalar norm() const;
00348 const PlainMatrixType normalized() const;
00349 void normalize();
00350
00351 Eigen::Transpose<Derived> transpose();
00352 const Eigen::Transpose<Derived> transpose() const;
00353 void transposeInPlace();
00354 const AdjointReturnType adjoint() const;
00355
00356
00357 RowXpr row(int i);
00358 const RowXpr row(int i) const;
00359
00360 ColXpr col(int i);
00361 const ColXpr col(int i) const;
00362
00363 Minor<Derived> minor(int row, int col);
00364 const Minor<Derived> minor(int row, int col) const;
00365
00366 typename BlockReturnType<Derived>::Type block(int startRow, int startCol, int blockRows, int blockCols);
00367 const typename BlockReturnType<Derived>::Type
00368 block(int startRow, int startCol, int blockRows, int blockCols) const;
00369
00370 typename BlockReturnType<Derived>::SubVectorType segment(int start, int size);
00371 const typename BlockReturnType<Derived>::SubVectorType segment(int start, int size) const;
00372
00373 typename BlockReturnType<Derived,Dynamic>::SubVectorType start(int size);
00374 const typename BlockReturnType<Derived,Dynamic>::SubVectorType start(int size) const;
00375
00376 typename BlockReturnType<Derived,Dynamic>::SubVectorType end(int size);
00377 const typename BlockReturnType<Derived,Dynamic>::SubVectorType end(int size) const;
00378
00379 typename BlockReturnType<Derived>::Type corner(CornerType type, int cRows, int cCols);
00380 const typename BlockReturnType<Derived>::Type corner(CornerType type, int cRows, int cCols) const;
00381
00382 template<int BlockRows, int BlockCols>
00383 typename BlockReturnType<Derived, BlockRows, BlockCols>::Type block(int startRow, int startCol);
00384 template<int BlockRows, int BlockCols>
00385 const typename BlockReturnType<Derived, BlockRows, BlockCols>::Type block(int startRow, int startCol) const;
00386
00387 template<int CRows, int CCols>
00388 typename BlockReturnType<Derived, CRows, CCols>::Type corner(CornerType type);
00389 template<int CRows, int CCols>
00390 const typename BlockReturnType<Derived, CRows, CCols>::Type corner(CornerType type) const;
00391
00392 template<int Size> typename BlockReturnType<Derived,Size>::SubVectorType start(void);
00393 template<int Size> const typename BlockReturnType<Derived,Size>::SubVectorType start() const;
00394
00395 template<int Size> typename BlockReturnType<Derived,Size>::SubVectorType end();
00396 template<int Size> const typename BlockReturnType<Derived,Size>::SubVectorType end() const;
00397
00398 template<int Size> typename BlockReturnType<Derived,Size>::SubVectorType segment(int start);
00399 template<int Size> const typename BlockReturnType<Derived,Size>::SubVectorType segment(int start) const;
00400
00401 DiagonalCoeffs<Derived> diagonal();
00402 const DiagonalCoeffs<Derived> diagonal() const;
00403
00404 template<unsigned int Mode> Part<Derived, Mode> part();
00405 template<unsigned int Mode> const Part<Derived, Mode> part() const;
00406
00407
00408 static const ConstantReturnType
00409 Constant(int rows, int cols, const Scalar& value);
00410 static const ConstantReturnType
00411 Constant(int size, const Scalar& value);
00412 static const ConstantReturnType
00413 Constant(const Scalar& value);
00414
00415 template<typename CustomNullaryOp>
00416 static const CwiseNullaryOp<CustomNullaryOp, Derived>
00417 NullaryExpr(int rows, int cols, const CustomNullaryOp& func);
00418 template<typename CustomNullaryOp>
00419 static const CwiseNullaryOp<CustomNullaryOp, Derived>
00420 NullaryExpr(int size, const CustomNullaryOp& func);
00421 template<typename CustomNullaryOp>
00422 static const CwiseNullaryOp<CustomNullaryOp, Derived>
00423 NullaryExpr(const CustomNullaryOp& func);
00424
00425 static const ConstantReturnType Zero(int rows, int cols);
00426 static const ConstantReturnType Zero(int size);
00427 static const ConstantReturnType Zero();
00428 static const ConstantReturnType Ones(int rows, int cols);
00429 static const ConstantReturnType Ones(int size);
00430 static const ConstantReturnType Ones();
00431 static const IdentityReturnType Identity();
00432 static const IdentityReturnType Identity(int rows, int cols);
00433 static const BasisReturnType Unit(int size, int i);
00434 static const BasisReturnType Unit(int i);
00435 static const BasisReturnType UnitX();
00436 static const BasisReturnType UnitY();
00437 static const BasisReturnType UnitZ();
00438 static const BasisReturnType UnitW();
00439
00440 const DiagonalMatrix<Derived> asDiagonal() const;
00441
00442 void fill(const Scalar& value);
00443 Derived& setConstant(const Scalar& value);
00444 Derived& setZero();
00445 Derived& setOnes();
00446 Derived& setRandom();
00447 Derived& setIdentity();
00448
00449
00450 template<typename OtherDerived>
00451 bool isApprox(const MatrixBase<OtherDerived>& other,
00452 RealScalar prec = precision<Scalar>()) const;
00453 bool isMuchSmallerThan(const RealScalar& other,
00454 RealScalar prec = precision<Scalar>()) const;
00455 template<typename OtherDerived>
00456 bool isMuchSmallerThan(const MatrixBase<OtherDerived>& other,
00457 RealScalar prec = precision<Scalar>()) const;
00458
00459 bool isApproxToConstant(const Scalar& value, RealScalar prec = precision<Scalar>()) const;
00460 bool isConstant(const Scalar& value, RealScalar prec = precision<Scalar>()) const;
00461 bool isZero(RealScalar prec = precision<Scalar>()) const;
00462 bool isOnes(RealScalar prec = precision<Scalar>()) const;
00463 bool isIdentity(RealScalar prec = precision<Scalar>()) const;
00464 bool isDiagonal(RealScalar prec = precision<Scalar>()) const;
00465
00466 bool isUpperTriangular(RealScalar prec = precision<Scalar>()) const;
00467 bool isLowerTriangular(RealScalar prec = precision<Scalar>()) const;
00468
00469 template<typename OtherDerived>
00470 bool isOrthogonal(const MatrixBase<OtherDerived>& other,
00471 RealScalar prec = precision<Scalar>()) const;
00472 bool isUnitary(RealScalar prec = precision<Scalar>()) const;
00473
00474 template<typename OtherDerived>
00475 inline bool operator==(const MatrixBase<OtherDerived>& other) const
00476 { return (cwise() == other).all(); }
00477
00478 template<typename OtherDerived>
00479 inline bool operator!=(const MatrixBase<OtherDerived>& other) const
00480 { return (cwise() != other).any(); }
00481
00482
00483 template<typename NewType>
00484 const CwiseUnaryOp<ei_scalar_cast_op<typename ei_traits<Derived>::Scalar, NewType>, Derived> cast() const;
00485
00491 EIGEN_STRONG_INLINE const typename ei_eval<Derived>::type eval() const
00492 { return typename ei_eval<Derived>::type(derived()); }
00493
00494 template<typename OtherDerived>
00495 void swap(const MatrixBase<OtherDerived>& other);
00496
00497 template<unsigned int Added>
00498 const Flagged<Derived, Added, 0> marked() const;
00499 const Flagged<Derived, 0, EvalBeforeNestingBit | EvalBeforeAssigningBit> lazy() const;
00500
00506 inline int stride(void) const { return derived().stride(); }
00507
00508 inline const NestByValue<Derived> nestByValue() const;
00509
00510
00511 ConjugateReturnType conjugate() const;
00512 const RealReturnType real() const;
00513 const ImagReturnType imag() const;
00514
00515 template<typename CustomUnaryOp>
00516 const CwiseUnaryOp<CustomUnaryOp, Derived> unaryExpr(const CustomUnaryOp& func = CustomUnaryOp()) const;
00517
00518 template<typename CustomBinaryOp, typename OtherDerived>
00519 const CwiseBinaryOp<CustomBinaryOp, Derived, OtherDerived>
00520 binaryExpr(const MatrixBase<OtherDerived> &other, const CustomBinaryOp& func = CustomBinaryOp()) const;
00521
00522
00523 Scalar sum() const;
00524 Scalar trace() const;
00525
00526 typename ei_traits<Derived>::Scalar minCoeff() const;
00527 typename ei_traits<Derived>::Scalar maxCoeff() const;
00528
00529 typename ei_traits<Derived>::Scalar minCoeff(int* row, int* col) const;
00530 typename ei_traits<Derived>::Scalar maxCoeff(int* row, int* col) const;
00531
00532 typename ei_traits<Derived>::Scalar minCoeff(int* index) const;
00533 typename ei_traits<Derived>::Scalar maxCoeff(int* index) const;
00534
00535 template<typename BinaryOp>
00536 typename ei_result_of<BinaryOp(typename ei_traits<Derived>::Scalar)>::type
00537 redux(const BinaryOp& func) const;
00538
00539 template<typename Visitor>
00540 void visit(Visitor& func) const;
00541
00542 #ifndef EIGEN_PARSED_BY_DOXYGEN
00543 inline const Derived& derived() const { return *static_cast<const Derived*>(this); }
00544 inline Derived& derived() { return *static_cast<Derived*>(this); }
00545 inline Derived& const_cast_derived() const
00546 { return *static_cast<Derived*>(const_cast<MatrixBase*>(this)); }
00547 #endif // not EIGEN_PARSED_BY_DOXYGEN
00548
00549 const Cwise<Derived> cwise() const;
00550 Cwise<Derived> cwise();
00551
00552 inline const WithFormat<Derived> format(const IOFormat& fmt) const;
00553
00555
00556 bool all(void) const;
00557 bool any(void) const;
00558 int count() const;
00559
00560 const PartialRedux<Derived,Horizontal> rowwise() const;
00561 const PartialRedux<Derived,Vertical> colwise() const;
00562
00563 static const CwiseNullaryOp<ei_scalar_random_op<Scalar>,Derived> Random(int rows, int cols);
00564 static const CwiseNullaryOp<ei_scalar_random_op<Scalar>,Derived> Random(int size);
00565 static const CwiseNullaryOp<ei_scalar_random_op<Scalar>,Derived> Random();
00566
00567 template<typename ThenDerived,typename ElseDerived>
00568 const Select<Derived,ThenDerived,ElseDerived>
00569 select(const MatrixBase<ThenDerived>& thenMatrix,
00570 const MatrixBase<ElseDerived>& elseMatrix) const;
00571
00572 template<typename ThenDerived>
00573 inline const Select<Derived,ThenDerived, NestByValue<typename ThenDerived::ConstantReturnType> >
00574 select(const MatrixBase<ThenDerived>& thenMatrix, typename ThenDerived::Scalar elseScalar) const;
00575
00576 template<typename ElseDerived>
00577 inline const Select<Derived, NestByValue<typename ElseDerived::ConstantReturnType>, ElseDerived >
00578 select(typename ElseDerived::Scalar thenScalar, const MatrixBase<ElseDerived>& elseMatrix) const;
00579
00580 template<int p> RealScalar lpNorm() const;
00581
00583
00584 const LU<PlainMatrixType> lu() const;
00585 const PlainMatrixType inverse() const;
00586 template<typename ResultType>
00587 void computeInverse(MatrixBase<ResultType> *result) const;
00588 Scalar determinant() const;
00589
00591
00592 const LLT<PlainMatrixType> llt() const;
00593 const LDLT<PlainMatrixType> ldlt() const;
00594
00596
00597 const QR<PlainMatrixType> qr() const;
00598
00599 EigenvaluesReturnType eigenvalues() const;
00600 RealScalar operatorNorm() const;
00601
00603
00604 SVD<PlainMatrixType> svd() const;
00605
00607
00608 template<typename OtherDerived>
00609 PlainMatrixType cross(const MatrixBase<OtherDerived>& other) const;
00610 PlainMatrixType unitOrthogonal(void) const;
00611 Matrix<Scalar,3,1> eulerAngles(int a0, int a1, int a2) const;
00612
00614
00615
00616 template<typename Derived1, typename Derived2>
00617 Derived& lazyAssign(const SparseProduct<Derived1,Derived2,SparseTimeDenseProduct>& product);
00618
00619 template<typename Derived1, typename Derived2>
00620 Derived& lazyAssign(const SparseProduct<Derived1,Derived2,DenseTimeSparseProduct>& product);
00621
00622 #ifdef EIGEN_MATRIXBASE_PLUGIN
00623 #include EIGEN_MATRIXBASE_PLUGIN
00624 #endif
00625
00626 protected:
00628 MatrixBase()
00629 {
00630
00631
00632
00633 #ifdef EIGEN_INTERNAL_DEBUGGING
00634 EIGEN_STATIC_ASSERT(ei_are_flags_consistent<Flags>::ret,
00635 INVALID_MATRIXBASE_TEMPLATE_PARAMETERS)
00636 #endif
00637 }
00638
00639 private:
00640 explicit MatrixBase(int);
00641 MatrixBase(int,int);
00642 template<typename OtherDerived> explicit MatrixBase(const MatrixBase<OtherDerived>&);
00643 };
00644
00645 #endif // EIGEN_MATRIXBASE_H