DenseBase.h 26.8 KB
Newer Older
LM's avatar
LM committed
1 2 3 4 5 6
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// Copyright (C) 2007-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
// Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
//
Don Gagne's avatar
Don Gagne committed
7 8 9
// 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/.
LM's avatar
LM committed
10 11 12 13

#ifndef EIGEN_DENSEBASE_H
#define EIGEN_DENSEBASE_H

Don Gagne's avatar
Don Gagne committed
14 15 16 17 18 19 20 21 22 23 24 25
namespace Eigen {

namespace internal {
  
// The index type defined by EIGEN_DEFAULT_DENSE_INDEX_TYPE must be a signed type.
// This dummy function simply aims at checking that at compile time.
static inline void check_DenseIndex_is_signed() {
  EIGEN_STATIC_ASSERT(NumTraits<DenseIndex>::IsSigned,THE_INDEX_TYPE_MUST_BE_A_SIGNED_TYPE); 
}

} // end namespace internal
  
LM's avatar
LM committed
26 27 28 29 30 31 32 33 34 35 36
/** \class DenseBase
  * \ingroup Core_Module
  *
  * \brief Base class for all dense matrices, vectors, and arrays
  *
  * This class is the base that is inherited by all dense objects (matrix, vector, arrays,
  * and related expression types). The common Eigen API for dense objects is contained in this class.
  *
  * \tparam Derived is the derived type, e.g., a matrix type or an expression.
  *
  * This class can be extended with the help of the plugin mechanism described on the page
37
  * \ref TopicCustomizing_Plugins by defining the preprocessor symbol \c EIGEN_DENSEBASE_PLUGIN.
LM's avatar
LM committed
38
  *
39
  * \sa \blank \ref TopicClassHierarchy
LM's avatar
LM committed
40 41 42 43
  */
template<typename Derived> class DenseBase
#ifndef EIGEN_PARSED_BY_DOXYGEN
  : public DenseCoeffsBase<Derived>
44 45
#else
  : public DenseCoeffsBase<Derived,DirectWriteAccessors>
LM's avatar
LM committed
46 47 48 49
#endif // not EIGEN_PARSED_BY_DOXYGEN
{
  public:

50 51 52 53
    /** Inner iterator type to iterate over the coefficients of a row or column.
      * \sa class InnerIterator
      */
    typedef Eigen::InnerIterator<Derived> InnerIterator;
LM's avatar
LM committed
54 55 56

    typedef typename internal::traits<Derived>::StorageKind StorageKind;

57 58 59 60 61 62 63
    /**
      * \brief The type used to store indices
      * \details This typedef is relevant for types that store multiple indices such as
      *          PermutationMatrix or Transpositions, otherwise it defaults to Eigen::Index
      * \sa \blank \ref TopicPreprocessorDirectives, Eigen::Index, SparseMatrixBase.
     */
    typedef typename internal::traits<Derived>::StorageIndex StorageIndex;
LM's avatar
LM committed
64

65
    /** The numeric type of the expression' coefficients, e.g. float, double, int or std::complex<float>, etc. */
LM's avatar
LM committed
66
    typedef typename internal::traits<Derived>::Scalar Scalar;
67 68 69 70 71 72
    
    /** The numeric type of the expression' coefficients, e.g. float, double, int or std::complex<float>, etc.
      *
      * It is an alias for the Scalar type */
    typedef Scalar value_type;
    
LM's avatar
LM committed
73
    typedef typename NumTraits<Scalar>::Real RealScalar;
74
    typedef DenseCoeffsBase<Derived> Base;
LM's avatar
LM committed
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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166

    using Base::derived;
    using Base::const_cast_derived;
    using Base::rows;
    using Base::cols;
    using Base::size;
    using Base::rowIndexByOuterInner;
    using Base::colIndexByOuterInner;
    using Base::coeff;
    using Base::coeffByOuterInner;
    using Base::operator();
    using Base::operator[];
    using Base::x;
    using Base::y;
    using Base::z;
    using Base::w;
    using Base::stride;
    using Base::innerStride;
    using Base::outerStride;
    using Base::rowStride;
    using Base::colStride;
    typedef typename Base::CoeffReturnType CoeffReturnType;

    enum {

      RowsAtCompileTime = internal::traits<Derived>::RowsAtCompileTime,
        /**< The number of rows at compile-time. This is just a copy of the value provided
          * by the \a Derived type. If a value is not known at compile-time,
          * it is set to the \a Dynamic constant.
          * \sa MatrixBase::rows(), MatrixBase::cols(), ColsAtCompileTime, SizeAtCompileTime */

      ColsAtCompileTime = internal::traits<Derived>::ColsAtCompileTime,
        /**< The number of columns at compile-time. This is just a copy of the value provided
          * by the \a Derived type. If a value is not known at compile-time,
          * it is set to the \a Dynamic constant.
          * \sa MatrixBase::rows(), MatrixBase::cols(), RowsAtCompileTime, SizeAtCompileTime */


      SizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::RowsAtCompileTime,
                                                   internal::traits<Derived>::ColsAtCompileTime>::ret),
        /**< This is equal to the number of coefficients, i.e. the number of
          * rows times the number of columns, or to \a Dynamic if this is not
          * known at compile-time. \sa RowsAtCompileTime, ColsAtCompileTime */

      MaxRowsAtCompileTime = internal::traits<Derived>::MaxRowsAtCompileTime,
        /**< This value is equal to the maximum possible number of rows that this expression
          * might have. If this expression might have an arbitrarily high number of rows,
          * this value is set to \a Dynamic.
          *
          * This value is useful to know when evaluating an expression, in order to determine
          * whether it is possible to avoid doing a dynamic memory allocation.
          *
          * \sa RowsAtCompileTime, MaxColsAtCompileTime, MaxSizeAtCompileTime
          */

      MaxColsAtCompileTime = internal::traits<Derived>::MaxColsAtCompileTime,
        /**< This value is equal to the maximum possible number of columns that this expression
          * might have. If this expression might have an arbitrarily high number of columns,
          * this value is set to \a Dynamic.
          *
          * This value is useful to know when evaluating an expression, in order to determine
          * whether it is possible to avoid doing a dynamic memory allocation.
          *
          * \sa ColsAtCompileTime, MaxRowsAtCompileTime, MaxSizeAtCompileTime
          */

      MaxSizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::MaxRowsAtCompileTime,
                                                      internal::traits<Derived>::MaxColsAtCompileTime>::ret),
        /**< This value is equal to the maximum possible number of coefficients that this expression
          * might have. If this expression might have an arbitrarily high number of coefficients,
          * this value is set to \a Dynamic.
          *
          * This value is useful to know when evaluating an expression, in order to determine
          * whether it is possible to avoid doing a dynamic memory allocation.
          *
          * \sa SizeAtCompileTime, MaxRowsAtCompileTime, MaxColsAtCompileTime
          */

      IsVectorAtCompileTime = internal::traits<Derived>::MaxRowsAtCompileTime == 1
                           || internal::traits<Derived>::MaxColsAtCompileTime == 1,
        /**< This is set to true if either the number of rows or the number of
          * columns is known at compile-time to be equal to 1. Indeed, in that case,
          * we are dealing with a column-vector (if there is only one column) or with
          * a row-vector (if there is only one row). */

      Flags = internal::traits<Derived>::Flags,
        /**< This stores expression \ref flags flags which may or may not be inherited by new expressions
          * constructed from this one. See the \ref flags "list of flags".
          */

      IsRowMajor = int(Flags) & RowMajorBit, /**< True if this expression has row-major storage order. */

Don Gagne's avatar
Don Gagne committed
167 168
      InnerSizeAtCompileTime = int(IsVectorAtCompileTime) ? int(SizeAtCompileTime)
                             : int(IsRowMajor) ? int(ColsAtCompileTime) : int(RowsAtCompileTime),
LM's avatar
LM committed
169 170 171 172

      InnerStrideAtCompileTime = internal::inner_stride_at_compile_time<Derived>::ret,
      OuterStrideAtCompileTime = internal::outer_stride_at_compile_time<Derived>::ret
    };
173 174
    
    typedef typename internal::find_best_packet<Scalar,SizeAtCompileTime>::type PacketScalar;
LM's avatar
LM committed
175

176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
    enum { IsPlainObjectBase = 0 };
    
    /** The plain matrix type corresponding to this expression.
      * \sa PlainObject */
    typedef Matrix<typename internal::traits<Derived>::Scalar,
                internal::traits<Derived>::RowsAtCompileTime,
                internal::traits<Derived>::ColsAtCompileTime,
                AutoAlign | (internal::traits<Derived>::Flags&RowMajorBit ? RowMajor : ColMajor),
                internal::traits<Derived>::MaxRowsAtCompileTime,
                internal::traits<Derived>::MaxColsAtCompileTime
          > PlainMatrix;
    
    /** The plain array type corresponding to this expression.
      * \sa PlainObject */
    typedef Array<typename internal::traits<Derived>::Scalar,
                internal::traits<Derived>::RowsAtCompileTime,
                internal::traits<Derived>::ColsAtCompileTime,
                AutoAlign | (internal::traits<Derived>::Flags&RowMajorBit ? RowMajor : ColMajor),
                internal::traits<Derived>::MaxRowsAtCompileTime,
                internal::traits<Derived>::MaxColsAtCompileTime
          > PlainArray;

    /** \brief The plain matrix or array type corresponding to this expression.
      *
      * This is not necessarily exactly the return type of eval(). In the case of plain matrices,
      * the return type of eval() is a const reference to a matrix, not a matrix! It is however guaranteed
      * that the return type of eval() is either PlainObject or const PlainObject&.
      */
    typedef typename internal::conditional<internal::is_same<typename internal::traits<Derived>::XprKind,MatrixXpr >::value,
                                 PlainMatrix, PlainArray>::type PlainObject;
LM's avatar
LM committed
206 207 208

    /** \returns the number of nonzero coefficients which is in practice the number
      * of stored coefficients. */
209
    EIGEN_DEVICE_FUNC
LM's avatar
LM committed
210 211 212 213 214 215 216
    inline Index nonZeros() const { return size(); }

    /** \returns the outer size.
      *
      * \note For a vector, this returns just 1. For a matrix (non-vector), this is the major dimension
      * with respect to the \ref TopicStorageOrders "storage order", i.e., the number of columns for a
      * column-major matrix, and the number of rows for a row-major matrix. */
217
    EIGEN_DEVICE_FUNC
LM's avatar
LM committed
218 219 220 221 222 223 224 225 226 227 228
    Index outerSize() const
    {
      return IsVectorAtCompileTime ? 1
           : int(IsRowMajor) ? this->rows() : this->cols();
    }

    /** \returns the inner size.
      *
      * \note For a vector, this is just the size. For a matrix (non-vector), this is the minor dimension
      * with respect to the \ref TopicStorageOrders "storage order", i.e., the number of rows for a 
      * column-major matrix, and the number of columns for a row-major matrix. */
229
    EIGEN_DEVICE_FUNC
LM's avatar
LM committed
230 231 232 233 234 235 236 237 238 239
    Index innerSize() const
    {
      return IsVectorAtCompileTime ? this->size()
           : int(IsRowMajor) ? this->cols() : this->rows();
    }

    /** Only plain matrices/arrays, not expressions, may be resized; therefore the only useful resize methods are
      * Matrix::resize() and Array::resize(). The present method only asserts that the new size equals the old size, and does
      * nothing else.
      */
240
    EIGEN_DEVICE_FUNC
Don Gagne's avatar
Don Gagne committed
241
    void resize(Index newSize)
LM's avatar
LM committed
242
    {
Don Gagne's avatar
Don Gagne committed
243 244
      EIGEN_ONLY_USED_FOR_DEBUG(newSize);
      eigen_assert(newSize == this->size()
LM's avatar
LM committed
245 246 247 248 249 250
                && "DenseBase::resize() does not actually allow to resize.");
    }
    /** Only plain matrices/arrays, not expressions, may be resized; therefore the only useful resize methods are
      * Matrix::resize() and Array::resize(). The present method only asserts that the new size equals the old size, and does
      * nothing else.
      */
251 252
    EIGEN_DEVICE_FUNC
    void resize(Index rows, Index cols)
LM's avatar
LM committed
253
    {
254 255 256
      EIGEN_ONLY_USED_FOR_DEBUG(rows);
      EIGEN_ONLY_USED_FOR_DEBUG(cols);
      eigen_assert(rows == this->rows() && cols == this->cols()
LM's avatar
LM committed
257 258 259 260 261
                && "DenseBase::resize() does not actually allow to resize.");
    }

#ifndef EIGEN_PARSED_BY_DOXYGEN
    /** \internal Represents a matrix with all coefficients equal to one another*/
262 263 264
    typedef CwiseNullaryOp<internal::scalar_constant_op<Scalar>,PlainObject> ConstantReturnType;
    /** \internal \deprecated Represents a vector with linearly spaced coefficients that allows sequential access only. */
    typedef CwiseNullaryOp<internal::linspaced_op<Scalar,PacketScalar>,PlainObject> SequentialLinSpacedReturnType;
LM's avatar
LM committed
265
    /** \internal Represents a vector with linearly spaced coefficients that allows random access. */
266
    typedef CwiseNullaryOp<internal::linspaced_op<Scalar,PacketScalar>,PlainObject> RandomAccessLinSpacedReturnType;
LM's avatar
LM committed
267 268 269 270 271 272 273
    /** \internal the return type of MatrixBase::eigenvalues() */
    typedef Matrix<typename NumTraits<typename internal::traits<Derived>::Scalar>::Real, internal::traits<Derived>::ColsAtCompileTime, 1> EigenvaluesReturnType;

#endif // not EIGEN_PARSED_BY_DOXYGEN

    /** Copies \a other into *this. \returns a reference to *this. */
    template<typename OtherDerived>
274
    EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
LM's avatar
LM committed
275 276 277 278 279
    Derived& operator=(const DenseBase<OtherDerived>& other);

    /** Special case of the template operator=, in order to prevent the compiler
      * from generating a default operator= (issue hit with g++ 4.1)
      */
280
    EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
LM's avatar
LM committed
281 282 283
    Derived& operator=(const DenseBase& other);

    template<typename OtherDerived>
284
    EIGEN_DEVICE_FUNC
LM's avatar
LM committed
285 286 287
    Derived& operator=(const EigenBase<OtherDerived> &other);

    template<typename OtherDerived>
288
    EIGEN_DEVICE_FUNC
LM's avatar
LM committed
289 290 291
    Derived& operator+=(const EigenBase<OtherDerived> &other);

    template<typename OtherDerived>
292
    EIGEN_DEVICE_FUNC
LM's avatar
LM committed
293 294 295
    Derived& operator-=(const EigenBase<OtherDerived> &other);

    template<typename OtherDerived>
296
    EIGEN_DEVICE_FUNC
LM's avatar
LM committed
297 298
    Derived& operator=(const ReturnByValue<OtherDerived>& func);

299 300 301
    /** \internal
      * Copies \a other into *this without evaluating other. \returns a reference to *this.
      * \deprecated */
LM's avatar
LM committed
302
    template<typename OtherDerived>
303
    EIGEN_DEVICE_FUNC
LM's avatar
LM committed
304
    Derived& lazyAssign(const DenseBase<OtherDerived>& other);
305

306
    EIGEN_DEVICE_FUNC
LM's avatar
LM committed
307 308
    CommaInitializer<Derived> operator<< (const Scalar& s);

309
    /** \deprecated it now returns \c *this */
LM's avatar
LM committed
310
    template<unsigned int Added,unsigned int Removed>
311 312 313
    EIGEN_DEPRECATED
    const Derived& flagged() const
    { return derived(); }
LM's avatar
LM committed
314 315

    template<typename OtherDerived>
316
    EIGEN_DEVICE_FUNC
LM's avatar
LM committed
317 318
    CommaInitializer<Derived> operator<< (const DenseBase<OtherDerived>& other);

319 320 321 322 323
    typedef Transpose<Derived> TransposeReturnType;
    EIGEN_DEVICE_FUNC
    TransposeReturnType transpose();
    typedef typename internal::add_const<Transpose<const Derived> >::type ConstTransposeReturnType;
    EIGEN_DEVICE_FUNC
LM's avatar
LM committed
324
    ConstTransposeReturnType transpose() const;
325
    EIGEN_DEVICE_FUNC
LM's avatar
LM committed
326 327
    void transposeInPlace();

328
    EIGEN_DEVICE_FUNC static const ConstantReturnType
LM's avatar
LM committed
329
    Constant(Index rows, Index cols, const Scalar& value);
330
    EIGEN_DEVICE_FUNC static const ConstantReturnType
LM's avatar
LM committed
331
    Constant(Index size, const Scalar& value);
332
    EIGEN_DEVICE_FUNC static const ConstantReturnType
LM's avatar
LM committed
333 334
    Constant(const Scalar& value);

335
    EIGEN_DEVICE_FUNC static const SequentialLinSpacedReturnType
LM's avatar
LM committed
336
    LinSpaced(Sequential_t, Index size, const Scalar& low, const Scalar& high);
337
    EIGEN_DEVICE_FUNC static const RandomAccessLinSpacedReturnType
LM's avatar
LM committed
338
    LinSpaced(Index size, const Scalar& low, const Scalar& high);
339
    EIGEN_DEVICE_FUNC static const SequentialLinSpacedReturnType
LM's avatar
LM committed
340
    LinSpaced(Sequential_t, const Scalar& low, const Scalar& high);
341
    EIGEN_DEVICE_FUNC static const RandomAccessLinSpacedReturnType
LM's avatar
LM committed
342 343
    LinSpaced(const Scalar& low, const Scalar& high);

344 345
    template<typename CustomNullaryOp> EIGEN_DEVICE_FUNC
    static const CwiseNullaryOp<CustomNullaryOp, PlainObject>
LM's avatar
LM committed
346
    NullaryExpr(Index rows, Index cols, const CustomNullaryOp& func);
347 348
    template<typename CustomNullaryOp> EIGEN_DEVICE_FUNC
    static const CwiseNullaryOp<CustomNullaryOp, PlainObject>
LM's avatar
LM committed
349
    NullaryExpr(Index size, const CustomNullaryOp& func);
350 351
    template<typename CustomNullaryOp> EIGEN_DEVICE_FUNC
    static const CwiseNullaryOp<CustomNullaryOp, PlainObject>
LM's avatar
LM committed
352 353
    NullaryExpr(const CustomNullaryOp& func);

354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369
    EIGEN_DEVICE_FUNC static const ConstantReturnType Zero(Index rows, Index cols);
    EIGEN_DEVICE_FUNC static const ConstantReturnType Zero(Index size);
    EIGEN_DEVICE_FUNC static const ConstantReturnType Zero();
    EIGEN_DEVICE_FUNC static const ConstantReturnType Ones(Index rows, Index cols);
    EIGEN_DEVICE_FUNC static const ConstantReturnType Ones(Index size);
    EIGEN_DEVICE_FUNC static const ConstantReturnType Ones();

    EIGEN_DEVICE_FUNC void fill(const Scalar& value);
    EIGEN_DEVICE_FUNC Derived& setConstant(const Scalar& value);
    EIGEN_DEVICE_FUNC Derived& setLinSpaced(Index size, const Scalar& low, const Scalar& high);
    EIGEN_DEVICE_FUNC Derived& setLinSpaced(const Scalar& low, const Scalar& high);
    EIGEN_DEVICE_FUNC Derived& setZero();
    EIGEN_DEVICE_FUNC Derived& setOnes();
    EIGEN_DEVICE_FUNC Derived& setRandom();

    template<typename OtherDerived> EIGEN_DEVICE_FUNC
LM's avatar
LM committed
370
    bool isApprox(const DenseBase<OtherDerived>& other,
Don Gagne's avatar
Don Gagne committed
371
                  const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
372
    EIGEN_DEVICE_FUNC 
LM's avatar
LM committed
373
    bool isMuchSmallerThan(const RealScalar& other,
Don Gagne's avatar
Don Gagne committed
374
                           const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
375
    template<typename OtherDerived> EIGEN_DEVICE_FUNC
LM's avatar
LM committed
376
    bool isMuchSmallerThan(const DenseBase<OtherDerived>& other,
Don Gagne's avatar
Don Gagne committed
377
                           const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
LM's avatar
LM committed
378

379 380 381 382
    EIGEN_DEVICE_FUNC bool isApproxToConstant(const Scalar& value, const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
    EIGEN_DEVICE_FUNC bool isConstant(const Scalar& value, const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
    EIGEN_DEVICE_FUNC bool isZero(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
    EIGEN_DEVICE_FUNC bool isOnes(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
Don Gagne's avatar
Don Gagne committed
383 384 385
    
    inline bool hasNaN() const;
    inline bool allFinite() const;
LM's avatar
LM committed
386

387 388 389 390
    EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
    Derived& operator*=(const Scalar& other);
    EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
    Derived& operator/=(const Scalar& other);
LM's avatar
LM committed
391

Don Gagne's avatar
Don Gagne committed
392
    typedef typename internal::add_const_on_value_type<typename internal::eval<Derived>::type>::type EvalReturnType;
LM's avatar
LM committed
393 394 395 396
    /** \returns the matrix or vector obtained by evaluating this expression.
      *
      * Notice that in the case of a plain matrix or vector (not an expression) this function just returns
      * a const reference, in order to avoid a useless copy.
397 398
      * 
      * \warning Be carefull with eval() and the auto C++ keyword, as detailed in this \link TopicPitfalls_auto_keyword page \endlink.
LM's avatar
LM committed
399
      */
400
    EIGEN_DEVICE_FUNC
Don Gagne's avatar
Don Gagne committed
401
    EIGEN_STRONG_INLINE EvalReturnType eval() const
LM's avatar
LM committed
402 403 404 405 406 407
    {
      // Even though MSVC does not honor strong inlining when the return type
      // is a dynamic matrix, we desperately need strong inlining for fixed
      // size types on MSVC.
      return typename internal::eval<Derived>::type(derived());
    }
408
    
LM's avatar
LM committed
409 410 411 412
    /** swaps *this with the expression \a other.
      *
      */
    template<typename OtherDerived>
413 414
    EIGEN_DEVICE_FUNC
    void swap(const DenseBase<OtherDerived>& other)
LM's avatar
LM committed
415
    {
416 417 418
      EIGEN_STATIC_ASSERT(!OtherDerived::IsPlainObjectBase,THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY);
      eigen_assert(rows()==other.rows() && cols()==other.cols());
      call_assignment(derived(), other.const_cast_derived(), internal::swap_assign_op<Scalar>());
LM's avatar
LM committed
419 420 421 422 423 424
    }

    /** swaps *this with the matrix or array \a other.
      *
      */
    template<typename OtherDerived>
425
    EIGEN_DEVICE_FUNC
LM's avatar
LM committed
426 427
    void swap(PlainObjectBase<OtherDerived>& other)
    {
428 429
      eigen_assert(rows()==other.rows() && cols()==other.cols());
      call_assignment(derived(), other.derived(), internal::swap_assign_op<Scalar>());
LM's avatar
LM committed
430 431
    }

432 433 434 435 436 437 438
    EIGEN_DEVICE_FUNC inline const NestByValue<Derived> nestByValue() const;
    EIGEN_DEVICE_FUNC inline const ForceAlignedAccess<Derived> forceAlignedAccess() const;
    EIGEN_DEVICE_FUNC inline ForceAlignedAccess<Derived> forceAlignedAccess();
    template<bool Enable> EIGEN_DEVICE_FUNC
    inline const typename internal::conditional<Enable,ForceAlignedAccess<Derived>,Derived&>::type forceAlignedAccessIf() const;
    template<bool Enable> EIGEN_DEVICE_FUNC
    inline typename internal::conditional<Enable,ForceAlignedAccess<Derived>,Derived&>::type forceAlignedAccessIf();
LM's avatar
LM committed
439

440 441 442
    EIGEN_DEVICE_FUNC Scalar sum() const;
    EIGEN_DEVICE_FUNC Scalar mean() const;
    EIGEN_DEVICE_FUNC Scalar trace() const;
LM's avatar
LM committed
443

444
    EIGEN_DEVICE_FUNC Scalar prod() const;
LM's avatar
LM committed
445

446 447
    EIGEN_DEVICE_FUNC typename internal::traits<Derived>::Scalar minCoeff() const;
    EIGEN_DEVICE_FUNC typename internal::traits<Derived>::Scalar maxCoeff() const;
LM's avatar
LM committed
448

449
    template<typename IndexType> EIGEN_DEVICE_FUNC
LM's avatar
LM committed
450
    typename internal::traits<Derived>::Scalar minCoeff(IndexType* row, IndexType* col) const;
451
    template<typename IndexType> EIGEN_DEVICE_FUNC
LM's avatar
LM committed
452
    typename internal::traits<Derived>::Scalar maxCoeff(IndexType* row, IndexType* col) const;
453
    template<typename IndexType> EIGEN_DEVICE_FUNC
LM's avatar
LM committed
454
    typename internal::traits<Derived>::Scalar minCoeff(IndexType* index) const;
455
    template<typename IndexType> EIGEN_DEVICE_FUNC
LM's avatar
LM committed
456 457 458
    typename internal::traits<Derived>::Scalar maxCoeff(IndexType* index) const;

    template<typename BinaryOp>
459 460
    EIGEN_DEVICE_FUNC
    Scalar redux(const BinaryOp& func) const;
LM's avatar
LM committed
461 462

    template<typename Visitor>
463
    EIGEN_DEVICE_FUNC
LM's avatar
LM committed
464 465
    void visit(Visitor& func) const;

466 467 468 469 470 471 472 473 474 475 476
    /** \returns a WithFormat proxy object allowing to print a matrix the with given
      * format \a fmt.
      *
      * See class IOFormat for some examples.
      *
      * \sa class IOFormat, class WithFormat
      */
    inline const WithFormat<Derived> format(const IOFormat& fmt) const
    {
      return WithFormat<Derived>(derived(), fmt);
    }
LM's avatar
LM committed
477 478

    /** \returns the unique coefficient of a 1x1 expression */
479
    EIGEN_DEVICE_FUNC
LM's avatar
LM committed
480 481 482 483 484 485 486
    CoeffReturnType value() const
    {
      EIGEN_STATIC_ASSERT_SIZE_1x1(Derived)
      eigen_assert(this->rows() == 1 && this->cols() == 1);
      return derived().coeff(0,0);
    }

487 488 489
    EIGEN_DEVICE_FUNC bool all() const;
    EIGEN_DEVICE_FUNC bool any() const;
    EIGEN_DEVICE_FUNC Index count() const;
LM's avatar
LM committed
490 491 492 493 494 495

    typedef VectorwiseOp<Derived, Horizontal> RowwiseReturnType;
    typedef const VectorwiseOp<const Derived, Horizontal> ConstRowwiseReturnType;
    typedef VectorwiseOp<Derived, Vertical> ColwiseReturnType;
    typedef const VectorwiseOp<const Derived, Vertical> ConstColwiseReturnType;

496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519
    /** \returns a VectorwiseOp wrapper of *this providing additional partial reduction operations
    *
    * Example: \include MatrixBase_rowwise.cpp
    * Output: \verbinclude MatrixBase_rowwise.out
    *
    * \sa colwise(), class VectorwiseOp, \ref TutorialReductionsVisitorsBroadcasting
    */
    //Code moved here due to a CUDA compiler bug
    EIGEN_DEVICE_FUNC inline ConstRowwiseReturnType rowwise() const {
      return ConstRowwiseReturnType(derived());
    }
    EIGEN_DEVICE_FUNC RowwiseReturnType rowwise();

    /** \returns a VectorwiseOp wrapper of *this providing additional partial reduction operations
    *
    * Example: \include MatrixBase_colwise.cpp
    * Output: \verbinclude MatrixBase_colwise.out
    *
    * \sa rowwise(), class VectorwiseOp, \ref TutorialReductionsVisitorsBroadcasting
    */
    EIGEN_DEVICE_FUNC inline ConstColwiseReturnType colwise() const {
      return ConstColwiseReturnType(derived());
    }
    EIGEN_DEVICE_FUNC ColwiseReturnType colwise();
LM's avatar
LM committed
520

521 522 523 524
    typedef CwiseNullaryOp<internal::scalar_random_op<Scalar>,PlainObject> RandomReturnType;
    static const RandomReturnType Random(Index rows, Index cols);
    static const RandomReturnType Random(Index size);
    static const RandomReturnType Random();
LM's avatar
LM committed
525 526 527 528 529 530 531 532

    template<typename ThenDerived,typename ElseDerived>
    const Select<Derived,ThenDerived,ElseDerived>
    select(const DenseBase<ThenDerived>& thenMatrix,
           const DenseBase<ElseDerived>& elseMatrix) const;

    template<typename ThenDerived>
    inline const Select<Derived,ThenDerived, typename ThenDerived::ConstantReturnType>
Don Gagne's avatar
Don Gagne committed
533
    select(const DenseBase<ThenDerived>& thenMatrix, const typename ThenDerived::Scalar& elseScalar) const;
LM's avatar
LM committed
534 535 536

    template<typename ElseDerived>
    inline const Select<Derived, typename ElseDerived::ConstantReturnType, ElseDerived >
Don Gagne's avatar
Don Gagne committed
537
    select(const typename ElseDerived::Scalar& thenScalar, const DenseBase<ElseDerived>& elseMatrix) const;
LM's avatar
LM committed
538 539 540 541

    template<int p> RealScalar lpNorm() const;

    template<int RowFactor, int ColFactor>
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557
    EIGEN_DEVICE_FUNC
    const Replicate<Derived,RowFactor,ColFactor> replicate() const;
    /**
    * \return an expression of the replication of \c *this
    *
    * Example: \include MatrixBase_replicate_int_int.cpp
    * Output: \verbinclude MatrixBase_replicate_int_int.out
    *
    * \sa VectorwiseOp::replicate(), DenseBase::replicate<int,int>(), class Replicate
    */
    //Code moved here due to a CUDA compiler bug
    EIGEN_DEVICE_FUNC
    const Replicate<Derived, Dynamic, Dynamic> replicate(Index rowFactor, Index colFactor) const
    {
      return Replicate<Derived, Dynamic, Dynamic>(derived(), rowFactor, colFactor);
    }
LM's avatar
LM committed
558 559 560

    typedef Reverse<Derived, BothDirections> ReverseReturnType;
    typedef const Reverse<const Derived, BothDirections> ConstReverseReturnType;
561 562 563 564 565 566 567 568
    EIGEN_DEVICE_FUNC ReverseReturnType reverse();
    /** This is the const version of reverse(). */
    //Code moved here due to a CUDA compiler bug
    EIGEN_DEVICE_FUNC ConstReverseReturnType reverse() const
    {
      return ConstReverseReturnType(derived());
    }
    EIGEN_DEVICE_FUNC void reverseInPlace();
LM's avatar
LM committed
569 570

#define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::DenseBase
571 572
#define EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL
#define EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(COND)
LM's avatar
LM committed
573 574 575 576 577
#   include "../plugins/BlockMethods.h"
#   ifdef EIGEN_DENSEBASE_PLUGIN
#     include EIGEN_DENSEBASE_PLUGIN
#   endif
#undef EIGEN_CURRENT_STORAGE_BASE_CLASS
578 579
#undef EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL
#undef EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF
LM's avatar
LM committed
580 581

    // disable the use of evalTo for dense objects with a nice compilation error
582 583 584
    template<typename Dest>
    EIGEN_DEVICE_FUNC
    inline void evalTo(Dest& ) const
LM's avatar
LM committed
585 586 587 588 589 590
    {
      EIGEN_STATIC_ASSERT((internal::is_same<Dest,void>::value),THE_EVAL_EVALTO_FUNCTION_SHOULD_NEVER_BE_CALLED_FOR_DENSE_OBJECTS);
    }

  protected:
    /** Default constructor. Do nothing. */
591
    EIGEN_DEVICE_FUNC DenseBase()
LM's avatar
LM committed
592 593 594 595 596 597 598 599 600 601 602 603
    {
      /* Just checks for self-consistency of the flags.
       * Only do it when debugging Eigen, as this borders on paranoiac and could slow compilation down
       */
#ifdef EIGEN_INTERNAL_DEBUGGING
      EIGEN_STATIC_ASSERT((EIGEN_IMPLIES(MaxRowsAtCompileTime==1 && MaxColsAtCompileTime!=1, int(IsRowMajor))
                        && EIGEN_IMPLIES(MaxColsAtCompileTime==1 && MaxRowsAtCompileTime!=1, int(!IsRowMajor))),
                          INVALID_STORAGE_ORDER_FOR_THIS_VECTOR_EXPRESSION)
#endif
    }

  private:
604 605 606
    EIGEN_DEVICE_FUNC explicit DenseBase(int);
    EIGEN_DEVICE_FUNC DenseBase(int,int);
    template<typename OtherDerived> EIGEN_DEVICE_FUNC explicit DenseBase(const DenseBase<OtherDerived>&);
LM's avatar
LM committed
607 608
};

Don Gagne's avatar
Don Gagne committed
609 610
} // end namespace Eigen

LM's avatar
LM committed
611
#endif // EIGEN_DENSEBASE_H