MatrixBase.h 22.7 KB
Newer Older
xuebingbing's avatar
xuebingbing committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// Copyright (C) 2006-2009 Benoit Jacob <jacob.benoit.1@gmail.com>
// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
//
// 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/.

#ifndef EIGEN_MATRIXBASE_H
#define EIGEN_MATRIXBASE_H

namespace Eigen {

/** \class MatrixBase
  * \ingroup Core_Module
  *
  * \brief Base class for all dense matrices, vectors, and expressions
  *
  * This class is the base that is inherited by all matrix, vector, and related expression
  * types. Most of the Eigen API is contained in this class, and its base classes. Other important
  * classes for the Eigen API are Matrix, and VectorwiseOp.
  *
  * Note that some methods are defined in other modules such as the \ref LU_Module LU module
  * for all functions related to matrix inversions.
  *
  * \tparam Derived is the derived type, e.g. a matrix type, or an expression, etc.
  *
  * When writing a function taking Eigen objects as argument, if you want your function
  * to take as argument any matrix, vector, or expression, just let it take a
  * MatrixBase argument. As an example, here is a function printFirstRow which, given
  * a matrix, vector, or expression \a x, prints the first row of \a x.
  *
  * \code
    template<typename Derived>
    void printFirstRow(const Eigen::MatrixBase<Derived>& x)
    {
      cout << x.row(0) << endl;
    }
  * \endcode
  *
  * This class can be extended with the help of the plugin mechanism described on the page
xuebingbing's avatar
xuebingbing committed
44
  * \ref TopicCustomizing_Plugins by defining the preprocessor symbol \c EIGEN_MATRIXBASE_PLUGIN.
xuebingbing's avatar
xuebingbing committed
45
  *
xuebingbing's avatar
xuebingbing committed
46
  * \sa \blank \ref TopicClassHierarchy
xuebingbing's avatar
xuebingbing committed
47 48 49 50 51 52 53 54
  */
template<typename Derived> class MatrixBase
  : public DenseBase<Derived>
{
  public:
#ifndef EIGEN_PARSED_BY_DOXYGEN
    typedef MatrixBase StorageBaseType;
    typedef typename internal::traits<Derived>::StorageKind StorageKind;
xuebingbing's avatar
xuebingbing committed
55
    typedef typename internal::traits<Derived>::StorageIndex StorageIndex;
xuebingbing's avatar
xuebingbing committed
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
    typedef typename internal::traits<Derived>::Scalar Scalar;
    typedef typename internal::packet_traits<Scalar>::type PacketScalar;
    typedef typename NumTraits<Scalar>::Real RealScalar;

    typedef DenseBase<Derived> Base;
    using Base::RowsAtCompileTime;
    using Base::ColsAtCompileTime;
    using Base::SizeAtCompileTime;
    using Base::MaxRowsAtCompileTime;
    using Base::MaxColsAtCompileTime;
    using Base::MaxSizeAtCompileTime;
    using Base::IsVectorAtCompileTime;
    using Base::Flags;

    using Base::derived;
    using Base::const_cast_derived;
    using Base::rows;
    using Base::cols;
    using Base::size;
    using Base::coeff;
    using Base::coeffRef;
    using Base::lazyAssign;
    using Base::eval;
    using Base::operator+=;
    using Base::operator-=;
    using Base::operator*=;
    using Base::operator/=;

    typedef typename Base::CoeffReturnType CoeffReturnType;
    typedef typename Base::ConstTransposeReturnType ConstTransposeReturnType;
    typedef typename Base::RowXpr RowXpr;
    typedef typename Base::ColXpr ColXpr;
#endif // not EIGEN_PARSED_BY_DOXYGEN



#ifndef EIGEN_PARSED_BY_DOXYGEN
    /** type of the equivalent square matrix */
    typedef Matrix<Scalar,EIGEN_SIZE_MAX(RowsAtCompileTime,ColsAtCompileTime),
                          EIGEN_SIZE_MAX(RowsAtCompileTime,ColsAtCompileTime)> SquareMatrixType;
#endif // not EIGEN_PARSED_BY_DOXYGEN

    /** \returns the size of the main diagonal, which is min(rows(),cols()).
      * \sa rows(), cols(), SizeAtCompileTime. */
xuebingbing's avatar
xuebingbing committed
100 101
    EIGEN_DEVICE_FUNC
    inline Index diagonalSize() const { return (numext::mini)(rows(),cols()); }
xuebingbing's avatar
xuebingbing committed
102

xuebingbing's avatar
xuebingbing committed
103
    typedef typename Base::PlainObject PlainObject;
xuebingbing's avatar
xuebingbing committed
104 105 106

#ifndef EIGEN_PARSED_BY_DOXYGEN
    /** \internal Represents a matrix with all coefficients equal to one another*/
xuebingbing's avatar
xuebingbing committed
107
    typedef CwiseNullaryOp<internal::scalar_constant_op<Scalar>,PlainObject> ConstantReturnType;
xuebingbing's avatar
xuebingbing committed
108 109 110 111 112 113 114 115
    /** \internal the return type of MatrixBase::adjoint() */
    typedef typename internal::conditional<NumTraits<Scalar>::IsComplex,
                        CwiseUnaryOp<internal::scalar_conjugate_op<Scalar>, ConstTransposeReturnType>,
                        ConstTransposeReturnType
                     >::type AdjointReturnType;
    /** \internal Return type of eigenvalues() */
    typedef Matrix<std::complex<RealScalar>, internal::traits<Derived>::ColsAtCompileTime, 1, ColMajor> EigenvaluesReturnType;
    /** \internal the return type of identity */
xuebingbing's avatar
xuebingbing committed
116
    typedef CwiseNullaryOp<internal::scalar_identity_op<Scalar>,PlainObject> IdentityReturnType;
xuebingbing's avatar
xuebingbing committed
117 118 119 120 121 122 123
    /** \internal the return type of unit vectors */
    typedef Block<const CwiseNullaryOp<internal::scalar_identity_op<Scalar>, SquareMatrixType>,
                  internal::traits<Derived>::RowsAtCompileTime,
                  internal::traits<Derived>::ColsAtCompileTime> BasisReturnType;
#endif // not EIGEN_PARSED_BY_DOXYGEN

#define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::MatrixBase
xuebingbing's avatar
xuebingbing committed
124
#define EIGEN_DOC_UNARY_ADDONS(X,Y)
xuebingbing's avatar
xuebingbing committed
125 126 127 128 129 130 131 132
#   include "../plugins/CommonCwiseUnaryOps.h"
#   include "../plugins/CommonCwiseBinaryOps.h"
#   include "../plugins/MatrixCwiseUnaryOps.h"
#   include "../plugins/MatrixCwiseBinaryOps.h"
#   ifdef EIGEN_MATRIXBASE_PLUGIN
#     include EIGEN_MATRIXBASE_PLUGIN
#   endif
#undef EIGEN_CURRENT_STORAGE_BASE_CLASS
xuebingbing's avatar
xuebingbing committed
133
#undef EIGEN_DOC_UNARY_ADDONS
xuebingbing's avatar
xuebingbing committed
134 135 136 137

    /** Special case of the template operator=, in order to prevent the compiler
      * from generating a default operator= (issue hit with g++ 4.1)
      */
xuebingbing's avatar
xuebingbing committed
138
    EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
xuebingbing's avatar
xuebingbing committed
139 140 141 142 143 144
    Derived& operator=(const MatrixBase& other);

    // We cannot inherit here via Base::operator= since it is causing
    // trouble with MSVC.

    template <typename OtherDerived>
xuebingbing's avatar
xuebingbing committed
145
    EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
xuebingbing's avatar
xuebingbing committed
146 147 148
    Derived& operator=(const DenseBase<OtherDerived>& other);

    template <typename OtherDerived>
xuebingbing's avatar
xuebingbing committed
149
    EIGEN_DEVICE_FUNC
xuebingbing's avatar
xuebingbing committed
150 151 152
    Derived& operator=(const EigenBase<OtherDerived>& other);

    template<typename OtherDerived>
xuebingbing's avatar
xuebingbing committed
153
    EIGEN_DEVICE_FUNC
xuebingbing's avatar
xuebingbing committed
154 155 156
    Derived& operator=(const ReturnByValue<OtherDerived>& other);

    template<typename OtherDerived>
xuebingbing's avatar
xuebingbing committed
157
    EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
xuebingbing's avatar
xuebingbing committed
158 159
    Derived& operator+=(const MatrixBase<OtherDerived>& other);
    template<typename OtherDerived>
xuebingbing's avatar
xuebingbing committed
160
    EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
xuebingbing's avatar
xuebingbing committed
161 162 163
    Derived& operator-=(const MatrixBase<OtherDerived>& other);

    template<typename OtherDerived>
xuebingbing's avatar
xuebingbing committed
164 165
    EIGEN_DEVICE_FUNC
    const Product<Derived,OtherDerived>
xuebingbing's avatar
xuebingbing committed
166 167 168
    operator*(const MatrixBase<OtherDerived> &other) const;

    template<typename OtherDerived>
xuebingbing's avatar
xuebingbing committed
169 170
    EIGEN_DEVICE_FUNC
    const Product<Derived,OtherDerived,LazyProduct>
xuebingbing's avatar
xuebingbing committed
171 172 173 174 175 176 177 178 179 180 181 182
    lazyProduct(const MatrixBase<OtherDerived> &other) const;

    template<typename OtherDerived>
    Derived& operator*=(const EigenBase<OtherDerived>& other);

    template<typename OtherDerived>
    void applyOnTheLeft(const EigenBase<OtherDerived>& other);

    template<typename OtherDerived>
    void applyOnTheRight(const EigenBase<OtherDerived>& other);

    template<typename DiagonalDerived>
xuebingbing's avatar
xuebingbing committed
183 184
    EIGEN_DEVICE_FUNC
    const Product<Derived, DiagonalDerived, LazyProduct>
xuebingbing's avatar
xuebingbing committed
185 186 187
    operator*(const DiagonalBase<DiagonalDerived> &diagonal) const;

    template<typename OtherDerived>
xuebingbing's avatar
xuebingbing committed
188 189
    EIGEN_DEVICE_FUNC
    typename ScalarBinaryOpTraits<typename internal::traits<Derived>::Scalar,typename internal::traits<OtherDerived>::Scalar>::ReturnType
xuebingbing's avatar
xuebingbing committed
190 191
    dot(const MatrixBase<OtherDerived>& other) const;

xuebingbing's avatar
xuebingbing committed
192 193
    EIGEN_DEVICE_FUNC RealScalar squaredNorm() const;
    EIGEN_DEVICE_FUNC RealScalar norm() const;
xuebingbing's avatar
xuebingbing committed
194 195 196
    RealScalar stableNorm() const;
    RealScalar blueNorm() const;
    RealScalar hypotNorm() const;
xuebingbing's avatar
xuebingbing committed
197 198 199 200
    EIGEN_DEVICE_FUNC const PlainObject normalized() const;
    EIGEN_DEVICE_FUNC const PlainObject stableNormalized() const;
    EIGEN_DEVICE_FUNC void normalize();
    EIGEN_DEVICE_FUNC void stableNormalize();
xuebingbing's avatar
xuebingbing committed
201

xuebingbing's avatar
xuebingbing committed
202 203
    EIGEN_DEVICE_FUNC const AdjointReturnType adjoint() const;
    EIGEN_DEVICE_FUNC void adjointInPlace();
xuebingbing's avatar
xuebingbing committed
204 205

    typedef Diagonal<Derived> DiagonalReturnType;
xuebingbing's avatar
xuebingbing committed
206
    EIGEN_DEVICE_FUNC
xuebingbing's avatar
xuebingbing committed
207
    DiagonalReturnType diagonal();
xuebingbing's avatar
xuebingbing committed
208 209 210

    typedef typename internal::add_const<Diagonal<const Derived> >::type ConstDiagonalReturnType;
    EIGEN_DEVICE_FUNC
xuebingbing's avatar
xuebingbing committed
211 212 213 214 215
    ConstDiagonalReturnType diagonal() const;

    template<int Index> struct DiagonalIndexReturnType { typedef Diagonal<Derived,Index> Type; };
    template<int Index> struct ConstDiagonalIndexReturnType { typedef const Diagonal<const Derived,Index> Type; };

xuebingbing's avatar
xuebingbing committed
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
    template<int Index>
    EIGEN_DEVICE_FUNC
    typename DiagonalIndexReturnType<Index>::Type diagonal();

    template<int Index>
    EIGEN_DEVICE_FUNC
    typename ConstDiagonalIndexReturnType<Index>::Type diagonal() const;

    typedef Diagonal<Derived,DynamicIndex> DiagonalDynamicIndexReturnType;
    typedef typename internal::add_const<Diagonal<const Derived,DynamicIndex> >::type ConstDiagonalDynamicIndexReturnType;

    EIGEN_DEVICE_FUNC
    DiagonalDynamicIndexReturnType diagonal(Index index);
    EIGEN_DEVICE_FUNC
    ConstDiagonalDynamicIndexReturnType diagonal(Index index) const;
xuebingbing's avatar
xuebingbing committed
231 232 233 234

    template<unsigned int Mode> struct TriangularViewReturnType { typedef TriangularView<Derived, Mode> Type; };
    template<unsigned int Mode> struct ConstTriangularViewReturnType { typedef const TriangularView<const Derived, Mode> Type; };

xuebingbing's avatar
xuebingbing committed
235 236 237 238 239 240
    template<unsigned int Mode>
    EIGEN_DEVICE_FUNC
    typename TriangularViewReturnType<Mode>::Type triangularView();
    template<unsigned int Mode>
    EIGEN_DEVICE_FUNC
    typename ConstTriangularViewReturnType<Mode>::Type triangularView() const;
xuebingbing's avatar
xuebingbing committed
241 242 243 244

    template<unsigned int UpLo> struct SelfAdjointViewReturnType { typedef SelfAdjointView<Derived, UpLo> Type; };
    template<unsigned int UpLo> struct ConstSelfAdjointViewReturnType { typedef const SelfAdjointView<const Derived, UpLo> Type; };

xuebingbing's avatar
xuebingbing committed
245 246 247 248 249 250
    template<unsigned int UpLo>
    EIGEN_DEVICE_FUNC
    typename SelfAdjointViewReturnType<UpLo>::Type selfadjointView();
    template<unsigned int UpLo>
    EIGEN_DEVICE_FUNC
    typename ConstSelfAdjointViewReturnType<UpLo>::Type selfadjointView() const;
xuebingbing's avatar
xuebingbing committed
251 252 253

    const SparseView<Derived> sparseView(const Scalar& m_reference = Scalar(0),
                                         const typename NumTraits<Scalar>::Real& m_epsilon = NumTraits<Scalar>::dummy_precision()) const;
xuebingbing's avatar
xuebingbing committed
254 255 256 257 258 259 260 261 262 263
    EIGEN_DEVICE_FUNC static const IdentityReturnType Identity();
    EIGEN_DEVICE_FUNC static const IdentityReturnType Identity(Index rows, Index cols);
    EIGEN_DEVICE_FUNC static const BasisReturnType Unit(Index size, Index i);
    EIGEN_DEVICE_FUNC static const BasisReturnType Unit(Index i);
    EIGEN_DEVICE_FUNC static const BasisReturnType UnitX();
    EIGEN_DEVICE_FUNC static const BasisReturnType UnitY();
    EIGEN_DEVICE_FUNC static const BasisReturnType UnitZ();
    EIGEN_DEVICE_FUNC static const BasisReturnType UnitW();

    EIGEN_DEVICE_FUNC
xuebingbing's avatar
xuebingbing committed
264 265 266
    const DiagonalWrapper<const Derived> asDiagonal() const;
    const PermutationWrapper<const Derived> asPermutation() const;

xuebingbing's avatar
xuebingbing committed
267
    EIGEN_DEVICE_FUNC
xuebingbing's avatar
xuebingbing committed
268
    Derived& setIdentity();
xuebingbing's avatar
xuebingbing committed
269
    EIGEN_DEVICE_FUNC
xuebingbing's avatar
xuebingbing committed
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
    Derived& setIdentity(Index rows, Index cols);

    bool isIdentity(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
    bool isDiagonal(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;

    bool isUpperTriangular(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
    bool isLowerTriangular(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;

    template<typename OtherDerived>
    bool isOrthogonal(const MatrixBase<OtherDerived>& other,
                      const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
    bool isUnitary(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;

    /** \returns true if each coefficients of \c *this and \a other are all exactly equal.
      * \warning When using floating point scalar values you probably should rather use a
      *          fuzzy comparison such as isApprox()
      * \sa isApprox(), operator!= */
    template<typename OtherDerived>
xuebingbing's avatar
xuebingbing committed
288
    EIGEN_DEVICE_FUNC inline bool operator==(const MatrixBase<OtherDerived>& other) const
xuebingbing's avatar
xuebingbing committed
289 290 291 292 293 294 295
    { return cwiseEqual(other).all(); }

    /** \returns true if at least one pair of coefficients of \c *this and \a other are not exactly equal to each other.
      * \warning When using floating point scalar values you probably should rather use a
      *          fuzzy comparison such as isApprox()
      * \sa isApprox(), operator== */
    template<typename OtherDerived>
xuebingbing's avatar
xuebingbing committed
296
    EIGEN_DEVICE_FUNC inline bool operator!=(const MatrixBase<OtherDerived>& other) const
xuebingbing's avatar
xuebingbing committed
297 298 299 300
    { return cwiseNotEqual(other).any(); }

    NoAlias<Derived,Eigen::MatrixBase > noalias();

xuebingbing's avatar
xuebingbing committed
301 302 303 304 305 306
    // TODO forceAlignedAccess is temporarily disabled
    // Need to find a nicer workaround.
    inline const Derived& forceAlignedAccess() const { return derived(); }
    inline Derived& forceAlignedAccess() { return derived(); }
    template<bool Enable> inline const Derived& forceAlignedAccessIf() const { return derived(); }
    template<bool Enable> inline Derived& forceAlignedAccessIf() { return derived(); }
xuebingbing's avatar
xuebingbing committed
307

xuebingbing's avatar
xuebingbing committed
308
    EIGEN_DEVICE_FUNC Scalar trace() const;
xuebingbing's avatar
xuebingbing committed
309

xuebingbing's avatar
xuebingbing committed
310
    template<int p> EIGEN_DEVICE_FUNC RealScalar lpNorm() const;
xuebingbing's avatar
xuebingbing committed
311

xuebingbing's avatar
xuebingbing committed
312 313
    EIGEN_DEVICE_FUNC MatrixBase<Derived>& matrix() { return *this; }
    EIGEN_DEVICE_FUNC const MatrixBase<Derived>& matrix() const { return *this; }
xuebingbing's avatar
xuebingbing committed
314 315 316

    /** \returns an \link Eigen::ArrayBase Array \endlink expression of this matrix
      * \sa ArrayBase::matrix() */
xuebingbing's avatar
xuebingbing committed
317 318 319 320
    EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ArrayWrapper<Derived> array() { return ArrayWrapper<Derived>(derived()); }
    /** \returns a const \link Eigen::ArrayBase Array \endlink expression of this matrix
      * \sa ArrayBase::matrix() */
    EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const ArrayWrapper<const Derived> array() const { return ArrayWrapper<const Derived>(derived()); }
xuebingbing's avatar
xuebingbing committed
321 322 323

/////////// LU module ///////////

xuebingbing's avatar
xuebingbing committed
324 325
    inline const FullPivLU<PlainObject> fullPivLu() const;
    inline const PartialPivLU<PlainObject> partialPivLu() const;
xuebingbing's avatar
xuebingbing committed
326

xuebingbing's avatar
xuebingbing committed
327
    inline const PartialPivLU<PlainObject> lu() const;
xuebingbing's avatar
xuebingbing committed
328

xuebingbing's avatar
xuebingbing committed
329
    inline const Inverse<Derived> inverse() const;
xuebingbing's avatar
xuebingbing committed
330 331

    template<typename ResultType>
xuebingbing's avatar
xuebingbing committed
332
    inline void computeInverseAndDetWithCheck(
xuebingbing's avatar
xuebingbing committed
333 334 335 336 337 338
      ResultType& inverse,
      typename ResultType::Scalar& determinant,
      bool& invertible,
      const RealScalar& absDeterminantThreshold = NumTraits<Scalar>::dummy_precision()
    ) const;
    template<typename ResultType>
xuebingbing's avatar
xuebingbing committed
339
    inline void computeInverseWithCheck(
xuebingbing's avatar
xuebingbing committed
340 341 342 343 344 345 346 347
      ResultType& inverse,
      bool& invertible,
      const RealScalar& absDeterminantThreshold = NumTraits<Scalar>::dummy_precision()
    ) const;
    Scalar determinant() const;

/////////// Cholesky module ///////////

xuebingbing's avatar
xuebingbing committed
348 349
    inline const LLT<PlainObject>  llt() const;
    inline const LDLT<PlainObject> ldlt() const;
xuebingbing's avatar
xuebingbing committed
350 351 352

/////////// QR module ///////////

xuebingbing's avatar
xuebingbing committed
353 354 355 356
    inline const HouseholderQR<PlainObject> householderQr() const;
    inline const ColPivHouseholderQR<PlainObject> colPivHouseholderQr() const;
    inline const FullPivHouseholderQR<PlainObject> fullPivHouseholderQr() const;
    inline const CompleteOrthogonalDecomposition<PlainObject> completeOrthogonalDecomposition() const;
xuebingbing's avatar
xuebingbing committed
357

xuebingbing's avatar
xuebingbing committed
358
/////////// Eigenvalues module ///////////
xuebingbing's avatar
xuebingbing committed
359

xuebingbing's avatar
xuebingbing committed
360 361
    inline EigenvaluesReturnType eigenvalues() const;
    inline RealScalar operatorNorm() const;
xuebingbing's avatar
xuebingbing committed
362

xuebingbing's avatar
xuebingbing committed
363
/////////// SVD module ///////////
xuebingbing's avatar
xuebingbing committed
364

xuebingbing's avatar
xuebingbing committed
365 366
    inline JacobiSVD<PlainObject> jacobiSvd(unsigned int computationOptions = 0) const;
    inline BDCSVD<PlainObject>    bdcSvd(unsigned int computationOptions = 0) const;
xuebingbing's avatar
xuebingbing committed
367 368 369 370 371 372

/////////// Geometry module ///////////

    #ifndef EIGEN_PARSED_BY_DOXYGEN
    /// \internal helper struct to form the return type of the cross product
    template<typename OtherDerived> struct cross_product_return_type {
xuebingbing's avatar
xuebingbing committed
373
      typedef typename ScalarBinaryOpTraits<typename internal::traits<Derived>::Scalar,typename internal::traits<OtherDerived>::Scalar>::ReturnType Scalar;
xuebingbing's avatar
xuebingbing committed
374 375 376 377
      typedef Matrix<Scalar,MatrixBase::RowsAtCompileTime,MatrixBase::ColsAtCompileTime> type;
    };
    #endif // EIGEN_PARSED_BY_DOXYGEN
    template<typename OtherDerived>
xuebingbing's avatar
xuebingbing committed
378 379 380 381 382 383
    EIGEN_DEVICE_FUNC
#ifndef EIGEN_PARSED_BY_DOXYGEN
    inline typename cross_product_return_type<OtherDerived>::type
#else
    inline PlainObject
#endif
xuebingbing's avatar
xuebingbing committed
384
    cross(const MatrixBase<OtherDerived>& other) const;
xuebingbing's avatar
xuebingbing committed
385

xuebingbing's avatar
xuebingbing committed
386
    template<typename OtherDerived>
xuebingbing's avatar
xuebingbing committed
387 388 389 390 391 392 393 394 395
    EIGEN_DEVICE_FUNC
    inline PlainObject cross3(const MatrixBase<OtherDerived>& other) const;

    EIGEN_DEVICE_FUNC
    inline PlainObject unitOrthogonal(void) const;

    EIGEN_DEVICE_FUNC
    inline Matrix<Scalar,3,1> eulerAngles(Index a0, Index a1, Index a2) const;

xuebingbing's avatar
xuebingbing committed
396
    // put this as separate enum value to work around possible GCC 4.3 bug (?)
xuebingbing's avatar
xuebingbing committed
397 398
    enum { HomogeneousReturnTypeDirection = ColsAtCompileTime==1&&RowsAtCompileTime==1 ? ((internal::traits<Derived>::Flags&RowMajorBit)==RowMajorBit ? Horizontal : Vertical)
                                          : ColsAtCompileTime==1 ? Vertical : Horizontal };
xuebingbing's avatar
xuebingbing committed
399
    typedef Homogeneous<Derived, HomogeneousReturnTypeDirection> HomogeneousReturnType;
xuebingbing's avatar
xuebingbing committed
400 401 402
    EIGEN_DEVICE_FUNC
    inline HomogeneousReturnType homogeneous() const;

xuebingbing's avatar
xuebingbing committed
403 404 405 406 407 408
    enum {
      SizeMinusOne = SizeAtCompileTime==Dynamic ? Dynamic : SizeAtCompileTime-1
    };
    typedef Block<const Derived,
                  internal::traits<Derived>::ColsAtCompileTime==1 ? SizeMinusOne : 1,
                  internal::traits<Derived>::ColsAtCompileTime==1 ? 1 : SizeMinusOne> ConstStartMinusOne;
xuebingbing's avatar
xuebingbing committed
409 410 411
    typedef EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(ConstStartMinusOne,Scalar,quotient) HNormalizedReturnType;
    EIGEN_DEVICE_FUNC
    inline const HNormalizedReturnType hnormalized() const;
xuebingbing's avatar
xuebingbing committed
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434

////////// Householder module ///////////

    void makeHouseholderInPlace(Scalar& tau, RealScalar& beta);
    template<typename EssentialPart>
    void makeHouseholder(EssentialPart& essential,
                         Scalar& tau, RealScalar& beta) const;
    template<typename EssentialPart>
    void applyHouseholderOnTheLeft(const EssentialPart& essential,
                                   const Scalar& tau,
                                   Scalar* workspace);
    template<typename EssentialPart>
    void applyHouseholderOnTheRight(const EssentialPart& essential,
                                    const Scalar& tau,
                                    Scalar* workspace);

///////// Jacobi module /////////

    template<typename OtherScalar>
    void applyOnTheLeft(Index p, Index q, const JacobiRotation<OtherScalar>& j);
    template<typename OtherScalar>
    void applyOnTheRight(Index p, Index q, const JacobiRotation<OtherScalar>& j);

xuebingbing's avatar
xuebingbing committed
435 436 437 438 439 440 441 442 443
///////// SparseCore module /////////

    template<typename OtherDerived>
    EIGEN_STRONG_INLINE const typename SparseMatrixBase<OtherDerived>::template CwiseProductDenseReturnType<Derived>::Type
    cwiseProduct(const SparseMatrixBase<OtherDerived> &other) const
    {
      return other.cwiseProduct(derived());
    }

xuebingbing's avatar
xuebingbing committed
444 445 446
///////// MatrixFunctions module /////////

    typedef typename internal::stem_function<Scalar>::type StemFunction;
xuebingbing's avatar
xuebingbing committed
447 448 449 450 451 452 453 454 455
#define EIGEN_MATRIX_FUNCTION(ReturnType, Name, Description) \
    /** \returns an expression of the matrix Description of \c *this. \brief This function requires the <a href="unsupported/group__MatrixFunctions__Module.html"> unsupported MatrixFunctions module</a>. To compute the coefficient-wise Description use ArrayBase::##Name . */ \
    const ReturnType<Derived> Name() const;
#define EIGEN_MATRIX_FUNCTION_1(ReturnType, Name, Description, Argument) \
    /** \returns an expression of the matrix Description of \c *this. \brief This function requires the <a href="unsupported/group__MatrixFunctions__Module.html"> unsupported MatrixFunctions module</a>. To compute the coefficient-wise Description use ArrayBase::##Name . */ \
    const ReturnType<Derived> Name(Argument) const;

    EIGEN_MATRIX_FUNCTION(MatrixExponentialReturnValue, exp, exponential)
    /** \brief Helper function for the <a href="unsupported/group__MatrixFunctions__Module.html"> unsupported MatrixFunctions module</a>.*/
xuebingbing's avatar
xuebingbing committed
456
    const MatrixFunctionReturnValue<Derived> matrixFunction(StemFunction f) const;
xuebingbing's avatar
xuebingbing committed
457 458 459 460 461 462 463 464
    EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, cosh, hyperbolic cosine)
    EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, sinh, hyperbolic sine)
    EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, cos, cosine)
    EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, sin, sine)
    EIGEN_MATRIX_FUNCTION(MatrixSquareRootReturnValue, sqrt, square root)
    EIGEN_MATRIX_FUNCTION(MatrixLogarithmReturnValue, log, logarithm)
    EIGEN_MATRIX_FUNCTION_1(MatrixPowerReturnValue,        pow, power to \c p, const RealScalar& p)
    EIGEN_MATRIX_FUNCTION_1(MatrixComplexPowerReturnValue, pow, power to \c p, const std::complex<RealScalar>& p)
xuebingbing's avatar
xuebingbing committed
465 466

  protected:
xuebingbing's avatar
xuebingbing committed
467 468
    EIGEN_DEFAULT_COPY_CONSTRUCTOR(MatrixBase)
    EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(MatrixBase)
xuebingbing's avatar
xuebingbing committed
469 470

  private:
xuebingbing's avatar
xuebingbing committed
471 472 473
    EIGEN_DEVICE_FUNC explicit MatrixBase(int);
    EIGEN_DEVICE_FUNC MatrixBase(int,int);
    template<typename OtherDerived> EIGEN_DEVICE_FUNC explicit MatrixBase(const MatrixBase<OtherDerived>&);
xuebingbing's avatar
xuebingbing committed
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530
  protected:
    // mixing arrays and matrices is not legal
    template<typename OtherDerived> Derived& operator+=(const ArrayBase<OtherDerived>& )
    {EIGEN_STATIC_ASSERT(std::ptrdiff_t(sizeof(typename OtherDerived::Scalar))==-1,YOU_CANNOT_MIX_ARRAYS_AND_MATRICES); return *this;}
    // mixing arrays and matrices is not legal
    template<typename OtherDerived> Derived& operator-=(const ArrayBase<OtherDerived>& )
    {EIGEN_STATIC_ASSERT(std::ptrdiff_t(sizeof(typename OtherDerived::Scalar))==-1,YOU_CANNOT_MIX_ARRAYS_AND_MATRICES); return *this;}
};


/***************************************************************************
* Implementation of matrix base methods
***************************************************************************/

/** replaces \c *this by \c *this * \a other.
  *
  * \returns a reference to \c *this
  *
  * Example: \include MatrixBase_applyOnTheRight.cpp
  * Output: \verbinclude MatrixBase_applyOnTheRight.out
  */
template<typename Derived>
template<typename OtherDerived>
inline Derived&
MatrixBase<Derived>::operator*=(const EigenBase<OtherDerived> &other)
{
  other.derived().applyThisOnTheRight(derived());
  return derived();
}

/** replaces \c *this by \c *this * \a other. It is equivalent to MatrixBase::operator*=().
  *
  * Example: \include MatrixBase_applyOnTheRight.cpp
  * Output: \verbinclude MatrixBase_applyOnTheRight.out
  */
template<typename Derived>
template<typename OtherDerived>
inline void MatrixBase<Derived>::applyOnTheRight(const EigenBase<OtherDerived> &other)
{
  other.derived().applyThisOnTheRight(derived());
}

/** replaces \c *this by \a other * \c *this.
  *
  * Example: \include MatrixBase_applyOnTheLeft.cpp
  * Output: \verbinclude MatrixBase_applyOnTheLeft.out
  */
template<typename Derived>
template<typename OtherDerived>
inline void MatrixBase<Derived>::applyOnTheLeft(const EigenBase<OtherDerived> &other)
{
  other.derived().applyThisOnTheLeft(derived());
}

} // end namespace Eigen

#endif // EIGEN_MATRIXBASE_H