~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to extern/Eigen3/Eigen/src/Sparse/SparseMatrixBase.h

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// This file is part of Eigen, a lightweight C++ template library
2
 
// for linear algebra.
3
 
//
4
 
// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr>
5
 
//
6
 
// Eigen is free software; you can redistribute it and/or
7
 
// modify it under the terms of the GNU Lesser General Public
8
 
// License as published by the Free Software Foundation; either
9
 
// version 3 of the License, or (at your option) any later version.
10
 
//
11
 
// Alternatively, you can redistribute it and/or
12
 
// modify it under the terms of the GNU General Public License as
13
 
// published by the Free Software Foundation; either version 2 of
14
 
// the License, or (at your option) any later version.
15
 
//
16
 
// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
17
 
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18
 
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
19
 
// GNU General Public License for more details.
20
 
//
21
 
// You should have received a copy of the GNU Lesser General Public
22
 
// License and a copy of the GNU General Public License along with
23
 
// Eigen. If not, see <http://www.gnu.org/licenses/>.
24
 
 
25
 
#ifndef EIGEN_SPARSEMATRIXBASE_H
26
 
#define EIGEN_SPARSEMATRIXBASE_H
27
 
 
28
 
/** \ingroup Sparse_Module
29
 
  *
30
 
  * \class SparseMatrixBase
31
 
  *
32
 
  * \brief Base class of any sparse matrices or sparse expressions
33
 
  *
34
 
  * \tparam Derived
35
 
  *
36
 
  * This class can be extended with the help of the plugin mechanism described on the page
37
 
  * \ref TopicCustomizingEigen by defining the preprocessor symbol \c EIGEN_SPARSEMATRIXBASE_PLUGIN.
38
 
  */
39
 
template<typename Derived> class SparseMatrixBase : public EigenBase<Derived>
40
 
{
41
 
  public:
42
 
 
43
 
    typedef typename internal::traits<Derived>::Scalar Scalar;
44
 
    typedef typename internal::packet_traits<Scalar>::type PacketScalar;
45
 
    typedef typename internal::traits<Derived>::StorageKind StorageKind;
46
 
    typedef typename internal::traits<Derived>::Index Index;
47
 
 
48
 
    typedef SparseMatrixBase StorageBaseType;
49
 
    typedef EigenBase<Derived> Base;
50
 
    
51
 
    template<typename OtherDerived>
52
 
    Derived& operator=(const EigenBase<OtherDerived> &other)
53
 
    {
54
 
      other.derived().evalTo(derived());
55
 
      return derived();
56
 
    }
57
 
    
58
 
//     using Base::operator=;
59
 
 
60
 
    enum {
61
 
 
62
 
      RowsAtCompileTime = internal::traits<Derived>::RowsAtCompileTime,
63
 
        /**< The number of rows at compile-time. This is just a copy of the value provided
64
 
          * by the \a Derived type. If a value is not known at compile-time,
65
 
          * it is set to the \a Dynamic constant.
66
 
          * \sa MatrixBase::rows(), MatrixBase::cols(), ColsAtCompileTime, SizeAtCompileTime */
67
 
 
68
 
      ColsAtCompileTime = internal::traits<Derived>::ColsAtCompileTime,
69
 
        /**< The number of columns at compile-time. This is just a copy of the value provided
70
 
          * by the \a Derived type. If a value is not known at compile-time,
71
 
          * it is set to the \a Dynamic constant.
72
 
          * \sa MatrixBase::rows(), MatrixBase::cols(), RowsAtCompileTime, SizeAtCompileTime */
73
 
 
74
 
 
75
 
      SizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::RowsAtCompileTime,
76
 
                                                   internal::traits<Derived>::ColsAtCompileTime>::ret),
77
 
        /**< This is equal to the number of coefficients, i.e. the number of
78
 
          * rows times the number of columns, or to \a Dynamic if this is not
79
 
          * known at compile-time. \sa RowsAtCompileTime, ColsAtCompileTime */
80
 
 
81
 
      MaxRowsAtCompileTime = RowsAtCompileTime,
82
 
      MaxColsAtCompileTime = ColsAtCompileTime,
83
 
 
84
 
      MaxSizeAtCompileTime = (internal::size_at_compile_time<MaxRowsAtCompileTime,
85
 
                                                      MaxColsAtCompileTime>::ret),
86
 
 
87
 
      IsVectorAtCompileTime = RowsAtCompileTime == 1 || ColsAtCompileTime == 1,
88
 
        /**< This is set to true if either the number of rows or the number of
89
 
          * columns is known at compile-time to be equal to 1. Indeed, in that case,
90
 
          * we are dealing with a column-vector (if there is only one column) or with
91
 
          * a row-vector (if there is only one row). */
92
 
 
93
 
      Flags = internal::traits<Derived>::Flags,
94
 
        /**< This stores expression \ref flags flags which may or may not be inherited by new expressions
95
 
          * constructed from this one. See the \ref flags "list of flags".
96
 
          */
97
 
 
98
 
      CoeffReadCost = internal::traits<Derived>::CoeffReadCost,
99
 
        /**< This is a rough measure of how expensive it is to read one coefficient from
100
 
          * this expression.
101
 
          */
102
 
 
103
 
      IsRowMajor = Flags&RowMajorBit ? 1 : 0,
104
 
 
105
 
      #ifndef EIGEN_PARSED_BY_DOXYGEN
106
 
      _HasDirectAccess = (int(Flags)&DirectAccessBit) ? 1 : 0 // workaround sunCC
107
 
      #endif
108
 
    };
109
 
 
110
 
    /* \internal the return type of MatrixBase::conjugate() */
111
 
//     typedef typename internal::conditional<NumTraits<Scalar>::IsComplex,
112
 
//                         const SparseCwiseUnaryOp<internal::scalar_conjugate_op<Scalar>, Derived>,
113
 
//                         const Derived&
114
 
//                      >::type ConjugateReturnType;
115
 
    /* \internal the return type of MatrixBase::real() */
116
 
//     typedef SparseCwiseUnaryOp<internal::scalar_real_op<Scalar>, Derived> RealReturnType;
117
 
    /* \internal the return type of MatrixBase::imag() */
118
 
//     typedef SparseCwiseUnaryOp<internal::scalar_imag_op<Scalar>, Derived> ImagReturnType;
119
 
    /** \internal the return type of MatrixBase::adjoint() */
120
 
    typedef typename internal::conditional<NumTraits<Scalar>::IsComplex,
121
 
                        CwiseUnaryOp<internal::scalar_conjugate_op<Scalar>, Eigen::Transpose<const Derived> >,
122
 
                        Transpose<const Derived>
123
 
                     >::type AdjointReturnType;
124
 
 
125
 
 
126
 
    typedef SparseMatrix<Scalar, Flags&RowMajorBit ? RowMajor : ColMajor> PlainObject;
127
 
 
128
 
#define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::SparseMatrixBase
129
 
#   include "../plugins/CommonCwiseUnaryOps.h"
130
 
#   include "../plugins/CommonCwiseBinaryOps.h"
131
 
#   include "../plugins/MatrixCwiseUnaryOps.h"
132
 
#   include "../plugins/MatrixCwiseBinaryOps.h"
133
 
#   ifdef EIGEN_SPARSEMATRIXBASE_PLUGIN
134
 
#     include EIGEN_SPARSEMATRIXBASE_PLUGIN
135
 
#   endif
136
 
#   undef EIGEN_CURRENT_STORAGE_BASE_CLASS
137
 
#undef EIGEN_CURRENT_STORAGE_BASE_CLASS
138
 
 
139
 
#ifndef EIGEN_PARSED_BY_DOXYGEN
140
 
    /** This is the "real scalar" type; if the \a Scalar type is already real numbers
141
 
      * (e.g. int, float or double) then \a RealScalar is just the same as \a Scalar. If
142
 
      * \a Scalar is \a std::complex<T> then RealScalar is \a T.
143
 
      *
144
 
      * \sa class NumTraits
145
 
      */
146
 
    typedef typename NumTraits<Scalar>::Real RealScalar;
147
 
 
148
 
    /** \internal the return type of coeff()
149
 
      */
150
 
    typedef typename internal::conditional<_HasDirectAccess, const Scalar&, Scalar>::type CoeffReturnType;
151
 
 
152
 
    /** \internal Represents a matrix with all coefficients equal to one another*/
153
 
    typedef CwiseNullaryOp<internal::scalar_constant_op<Scalar>,Matrix<Scalar,Dynamic,Dynamic> > ConstantReturnType;
154
 
 
155
 
    /** type of the equivalent square matrix */
156
 
    typedef Matrix<Scalar,EIGEN_SIZE_MAX(RowsAtCompileTime,ColsAtCompileTime),
157
 
                          EIGEN_SIZE_MAX(RowsAtCompileTime,ColsAtCompileTime)> SquareMatrixType;
158
 
 
159
 
    inline const Derived& derived() const { return *static_cast<const Derived*>(this); }
160
 
    inline Derived& derived() { return *static_cast<Derived*>(this); }
161
 
    inline Derived& const_cast_derived() const
162
 
    { return *static_cast<Derived*>(const_cast<SparseMatrixBase*>(this)); }
163
 
#endif // not EIGEN_PARSED_BY_DOXYGEN
164
 
 
165
 
    /** \returns the number of rows. \sa cols(), RowsAtCompileTime */
166
 
    inline Index rows() const { return derived().rows(); }
167
 
    /** \returns the number of columns. \sa rows(), ColsAtCompileTime*/
168
 
    inline Index cols() const { return derived().cols(); }
169
 
    /** \returns the number of coefficients, which is \a rows()*cols().
170
 
      * \sa rows(), cols(), SizeAtCompileTime. */
171
 
    inline Index size() const { return rows() * cols(); }
172
 
    /** \returns the number of nonzero coefficients which is in practice the number
173
 
      * of stored coefficients. */
174
 
    inline Index nonZeros() const { return derived().nonZeros(); }
175
 
    /** \returns true if either the number of rows or the number of columns is equal to 1.
176
 
      * In other words, this function returns
177
 
      * \code rows()==1 || cols()==1 \endcode
178
 
      * \sa rows(), cols(), IsVectorAtCompileTime. */
179
 
    inline bool isVector() const { return rows()==1 || cols()==1; }
180
 
    /** \returns the size of the storage major dimension,
181
 
      * i.e., the number of columns for a columns major matrix, and the number of rows otherwise */
182
 
    Index outerSize() const { return (int(Flags)&RowMajorBit) ? this->rows() : this->cols(); }
183
 
    /** \returns the size of the inner dimension according to the storage order,
184
 
      * i.e., the number of rows for a columns major matrix, and the number of cols otherwise */
185
 
    Index innerSize() const { return (int(Flags)&RowMajorBit) ? this->cols() : this->rows(); }
186
 
 
187
 
    bool isRValue() const { return m_isRValue; }
188
 
    Derived& markAsRValue() { m_isRValue = true; return derived(); }
189
 
 
190
 
    SparseMatrixBase() : m_isRValue(false) { /* TODO check flags */ }
191
 
    
192
 
    inline Derived& operator=(const Derived& other)
193
 
    {
194
 
//       std::cout << "Derived& operator=(const Derived& other)\n";
195
 
//       if (other.isRValue())
196
 
//         derived().swap(other.const_cast_derived());
197
 
//       else
198
 
        this->operator=<Derived>(other);
199
 
      return derived();
200
 
    }
201
 
    
202
 
    template<typename OtherDerived>
203
 
    Derived& operator=(const ReturnByValue<OtherDerived>& other)
204
 
    {
205
 
      other.evalTo(derived());
206
 
      return derived();
207
 
    }
208
 
 
209
 
 
210
 
    template<typename OtherDerived>
211
 
    inline void assignGeneric(const OtherDerived& other)
212
 
    {
213
 
//       std::cout << "Derived& operator=(const MatrixBase<OtherDerived>& other)\n";
214
 
      //const bool transpose = (Flags & RowMajorBit) != (OtherDerived::Flags & RowMajorBit);
215
 
      eigen_assert(( ((internal::traits<Derived>::SupportedAccessPatterns&OuterRandomAccessPattern)==OuterRandomAccessPattern) ||
216
 
                  (!((Flags & RowMajorBit) != (OtherDerived::Flags & RowMajorBit)))) &&
217
 
                  "the transpose operation is supposed to be handled in SparseMatrix::operator=");
218
 
 
219
 
      enum { Flip = (Flags & RowMajorBit) != (OtherDerived::Flags & RowMajorBit) };
220
 
 
221
 
      const Index outerSize = other.outerSize();
222
 
      //typedef typename internal::conditional<transpose, LinkedVectorMatrix<Scalar,Flags&RowMajorBit>, Derived>::type TempType;
223
 
      // thanks to shallow copies, we always eval to a tempary
224
 
      Derived temp(other.rows(), other.cols());
225
 
 
226
 
      temp.reserve((std::max)(this->rows(),this->cols())*2);
227
 
      for (Index j=0; j<outerSize; ++j)
228
 
      {
229
 
        temp.startVec(j);
230
 
        for (typename OtherDerived::InnerIterator it(other.derived(), j); it; ++it)
231
 
        {
232
 
          Scalar v = it.value();
233
 
          if (v!=Scalar(0))
234
 
            temp.insertBackByOuterInner(Flip?it.index():j,Flip?j:it.index()) = v;
235
 
        }
236
 
      }
237
 
      temp.finalize();
238
 
 
239
 
      derived() = temp.markAsRValue();
240
 
    }
241
 
 
242
 
 
243
 
    template<typename OtherDerived>
244
 
    inline Derived& operator=(const SparseMatrixBase<OtherDerived>& other)
245
 
    {
246
 
//       std::cout << typeid(OtherDerived).name() << "\n";
247
 
//       std::cout << Flags << " " << OtherDerived::Flags << "\n";
248
 
      const bool transpose = (Flags & RowMajorBit) != (OtherDerived::Flags & RowMajorBit);
249
 
//       std::cout << "eval transpose = " << transpose << "\n";
250
 
      const Index outerSize = (int(OtherDerived::Flags) & RowMajorBit) ? other.rows() : other.cols();
251
 
      if ((!transpose) && other.isRValue())
252
 
      {
253
 
        // eval without temporary
254
 
        derived().resize(other.rows(), other.cols());
255
 
        derived().setZero();
256
 
        derived().reserve((std::max)(this->rows(),this->cols())*2);
257
 
        for (Index j=0; j<outerSize; ++j)
258
 
        {
259
 
          derived().startVec(j);
260
 
          for (typename OtherDerived::InnerIterator it(other.derived(), j); it; ++it)
261
 
          {
262
 
            Scalar v = it.value();
263
 
            if (v!=Scalar(0))
264
 
              derived().insertBackByOuterInner(j,it.index()) = v;
265
 
          }
266
 
        }
267
 
        derived().finalize();
268
 
      }
269
 
      else
270
 
      {
271
 
        assignGeneric(other.derived());
272
 
      }
273
 
      return derived();
274
 
    }
275
 
 
276
 
    template<typename Lhs, typename Rhs>
277
 
    inline Derived& operator=(const SparseSparseProduct<Lhs,Rhs>& product);
278
 
 
279
 
    template<typename Lhs, typename Rhs>
280
 
    inline void _experimentalNewProduct(const Lhs& lhs, const Rhs& rhs);
281
 
 
282
 
    friend std::ostream & operator << (std::ostream & s, const SparseMatrixBase& m)
283
 
    {
284
 
      if (Flags&RowMajorBit)
285
 
      {
286
 
        for (Index row=0; row<m.outerSize(); ++row)
287
 
        {
288
 
          Index col = 0;
289
 
          for (typename Derived::InnerIterator it(m.derived(), row); it; ++it)
290
 
          {
291
 
            for ( ; col<it.index(); ++col)
292
 
              s << "0 ";
293
 
            s << it.value() << " ";
294
 
            ++col;
295
 
          }
296
 
          for ( ; col<m.cols(); ++col)
297
 
            s << "0 ";
298
 
          s << std::endl;
299
 
        }
300
 
      }
301
 
      else
302
 
      {
303
 
        if (m.cols() == 1) {
304
 
          Index row = 0;
305
 
          for (typename Derived::InnerIterator it(m.derived(), 0); it; ++it)
306
 
          {
307
 
            for ( ; row<it.index(); ++row)
308
 
              s << "0" << std::endl;
309
 
            s << it.value() << std::endl;
310
 
            ++row;
311
 
          }
312
 
          for ( ; row<m.rows(); ++row)
313
 
            s << "0" << std::endl;
314
 
        }
315
 
        else
316
 
        {
317
 
          SparseMatrix<Scalar, RowMajorBit> trans = m.derived();
318
 
          s << trans;
319
 
        }
320
 
      }
321
 
      return s;
322
 
    }
323
 
 
324
 
//     const SparseCwiseUnaryOp<internal::scalar_opposite_op<typename internal::traits<Derived>::Scalar>,Derived> operator-() const;
325
 
 
326
 
//     template<typename OtherDerived>
327
 
//     const CwiseBinaryOp<internal::scalar_sum_op<typename internal::traits<Derived>::Scalar>, Derived, OtherDerived>
328
 
//     operator+(const SparseMatrixBase<OtherDerived> &other) const;
329
 
 
330
 
//     template<typename OtherDerived>
331
 
//     const CwiseBinaryOp<internal::scalar_difference_op<typename internal::traits<Derived>::Scalar>, Derived, OtherDerived>
332
 
//     operator-(const SparseMatrixBase<OtherDerived> &other) const;
333
 
 
334
 
    template<typename OtherDerived>
335
 
    Derived& operator+=(const SparseMatrixBase<OtherDerived>& other);
336
 
    template<typename OtherDerived>
337
 
    Derived& operator-=(const SparseMatrixBase<OtherDerived>& other);
338
 
 
339
 
//     template<typename Lhs,typename Rhs>
340
 
//     Derived& operator+=(const Flagged<Product<Lhs,Rhs,CacheFriendlyProduct>, 0, EvalBeforeNestingBit | EvalBeforeAssigningBit>& other);
341
 
 
342
 
    Derived& operator*=(const Scalar& other);
343
 
    Derived& operator/=(const Scalar& other);
344
 
 
345
 
    #define EIGEN_SPARSE_CWISE_PRODUCT_RETURN_TYPE \
346
 
      CwiseBinaryOp< \
347
 
        internal::scalar_product_op< \
348
 
          typename internal::scalar_product_traits< \
349
 
            typename internal::traits<Derived>::Scalar, \
350
 
            typename internal::traits<OtherDerived>::Scalar \
351
 
          >::ReturnType \
352
 
        >, \
353
 
        Derived, \
354
 
        OtherDerived \
355
 
      >
356
 
 
357
 
    template<typename OtherDerived>
358
 
    EIGEN_STRONG_INLINE const EIGEN_SPARSE_CWISE_PRODUCT_RETURN_TYPE
359
 
    cwiseProduct(const MatrixBase<OtherDerived> &other) const;
360
 
 
361
 
//     const SparseCwiseUnaryOp<internal::scalar_multiple_op<typename internal::traits<Derived>::Scalar>, Derived>
362
 
//     operator*(const Scalar& scalar) const;
363
 
//     const SparseCwiseUnaryOp<internal::scalar_quotient1_op<typename internal::traits<Derived>::Scalar>, Derived>
364
 
//     operator/(const Scalar& scalar) const;
365
 
 
366
 
//     inline friend const SparseCwiseUnaryOp<internal::scalar_multiple_op<typename internal::traits<Derived>::Scalar>, Derived>
367
 
//     operator*(const Scalar& scalar, const SparseMatrixBase& matrix)
368
 
//     { return matrix*scalar; }
369
 
 
370
 
 
371
 
    // sparse * sparse
372
 
    template<typename OtherDerived>
373
 
    const typename SparseSparseProductReturnType<Derived,OtherDerived>::Type
374
 
    operator*(const SparseMatrixBase<OtherDerived> &other) const;
375
 
 
376
 
    // sparse * diagonal
377
 
    template<typename OtherDerived>
378
 
    const SparseDiagonalProduct<Derived,OtherDerived>
379
 
    operator*(const DiagonalBase<OtherDerived> &other) const;
380
 
 
381
 
    // diagonal * sparse
382
 
    template<typename OtherDerived> friend
383
 
    const SparseDiagonalProduct<OtherDerived,Derived>
384
 
    operator*(const DiagonalBase<OtherDerived> &lhs, const SparseMatrixBase& rhs)
385
 
    { return SparseDiagonalProduct<OtherDerived,Derived>(lhs.derived(), rhs.derived()); }
386
 
 
387
 
    /** dense * sparse (return a dense object unless it is an outer product) */
388
 
    template<typename OtherDerived> friend
389
 
    const typename DenseSparseProductReturnType<OtherDerived,Derived>::Type
390
 
    operator*(const MatrixBase<OtherDerived>& lhs, const Derived& rhs)
391
 
    { return typename DenseSparseProductReturnType<OtherDerived,Derived>::Type(lhs.derived(),rhs); }
392
 
 
393
 
    /** sparse * dense (returns a dense object unless it is an outer product) */
394
 
    template<typename OtherDerived>
395
 
    const typename SparseDenseProductReturnType<Derived,OtherDerived>::Type
396
 
    operator*(const MatrixBase<OtherDerived> &other) const;
397
 
 
398
 
    template<typename OtherDerived>
399
 
    Derived& operator*=(const SparseMatrixBase<OtherDerived>& other);
400
 
 
401
 
    #ifdef EIGEN2_SUPPORT
402
 
    // deprecated
403
 
    template<typename OtherDerived>
404
 
    typename internal::plain_matrix_type_column_major<OtherDerived>::type
405
 
    solveTriangular(const MatrixBase<OtherDerived>& other) const;
406
 
 
407
 
    // deprecated
408
 
    template<typename OtherDerived>
409
 
    void solveTriangularInPlace(MatrixBase<OtherDerived>& other) const;
410
 
//     template<typename OtherDerived>
411
 
//     void solveTriangularInPlace(SparseMatrixBase<OtherDerived>& other) const;
412
 
    #endif // EIGEN2_SUPPORT
413
 
 
414
 
    template<int Mode>
415
 
    inline const SparseTriangularView<Derived, Mode> triangularView() const;
416
 
 
417
 
    template<unsigned int UpLo> inline const SparseSelfAdjointView<Derived, UpLo> selfadjointView() const;
418
 
    template<unsigned int UpLo> inline SparseSelfAdjointView<Derived, UpLo> selfadjointView();
419
 
 
420
 
    template<typename OtherDerived> Scalar dot(const MatrixBase<OtherDerived>& other) const;
421
 
    template<typename OtherDerived> Scalar dot(const SparseMatrixBase<OtherDerived>& other) const;
422
 
    RealScalar squaredNorm() const;
423
 
    RealScalar norm()  const;
424
 
//     const PlainObject normalized() const;
425
 
//     void normalize();
426
 
 
427
 
    Transpose<Derived> transpose() { return derived(); }
428
 
    const Transpose<const Derived> transpose() const { return derived(); }
429
 
    // void transposeInPlace();
430
 
    const AdjointReturnType adjoint() const { return transpose(); }
431
 
 
432
 
    // sub-vector
433
 
    SparseInnerVectorSet<Derived,1> row(Index i);
434
 
    const SparseInnerVectorSet<Derived,1> row(Index i) const;
435
 
    SparseInnerVectorSet<Derived,1> col(Index j);
436
 
    const SparseInnerVectorSet<Derived,1> col(Index j) const;
437
 
    SparseInnerVectorSet<Derived,1> innerVector(Index outer);
438
 
    const SparseInnerVectorSet<Derived,1> innerVector(Index outer) const;
439
 
 
440
 
    // set of sub-vectors
441
 
    SparseInnerVectorSet<Derived,Dynamic> subrows(Index start, Index size);
442
 
    const SparseInnerVectorSet<Derived,Dynamic> subrows(Index start, Index size) const;
443
 
    SparseInnerVectorSet<Derived,Dynamic> subcols(Index start, Index size);
444
 
    const SparseInnerVectorSet<Derived,Dynamic> subcols(Index start, Index size) const;
445
 
    SparseInnerVectorSet<Derived,Dynamic> innerVectors(Index outerStart, Index outerSize);
446
 
    const SparseInnerVectorSet<Derived,Dynamic> innerVectors(Index outerStart, Index outerSize) const;
447
 
 
448
 
//     typename BlockReturnType<Derived>::Type block(int startRow, int startCol, int blockRows, int blockCols);
449
 
//     const typename BlockReturnType<Derived>::Type
450
 
//     block(int startRow, int startCol, int blockRows, int blockCols) const;
451
 
//
452
 
//     typename BlockReturnType<Derived>::SubVectorType segment(int start, int size);
453
 
//     const typename BlockReturnType<Derived>::SubVectorType segment(int start, int size) const;
454
 
//
455
 
//     typename BlockReturnType<Derived,Dynamic>::SubVectorType start(int size);
456
 
//     const typename BlockReturnType<Derived,Dynamic>::SubVectorType start(int size) const;
457
 
//
458
 
//     typename BlockReturnType<Derived,Dynamic>::SubVectorType end(int size);
459
 
//     const typename BlockReturnType<Derived,Dynamic>::SubVectorType end(int size) const;
460
 
//
461
 
//     template<int BlockRows, int BlockCols>
462
 
//     typename BlockReturnType<Derived, BlockRows, BlockCols>::Type block(int startRow, int startCol);
463
 
//     template<int BlockRows, int BlockCols>
464
 
//     const typename BlockReturnType<Derived, BlockRows, BlockCols>::Type block(int startRow, int startCol) const;
465
 
 
466
 
//     template<int Size> typename BlockReturnType<Derived,Size>::SubVectorType start(void);
467
 
//     template<int Size> const typename BlockReturnType<Derived,Size>::SubVectorType start() const;
468
 
 
469
 
//     template<int Size> typename BlockReturnType<Derived,Size>::SubVectorType end();
470
 
//     template<int Size> const typename BlockReturnType<Derived,Size>::SubVectorType end() const;
471
 
 
472
 
//     template<int Size> typename BlockReturnType<Derived,Size>::SubVectorType segment(int start);
473
 
//     template<int Size> const typename BlockReturnType<Derived,Size>::SubVectorType segment(int start) const;
474
 
 
475
 
//     Diagonal<Derived> diagonal();
476
 
//     const Diagonal<Derived> diagonal() const;
477
 
 
478
 
//     template<unsigned int Mode> Part<Derived, Mode> part();
479
 
//     template<unsigned int Mode> const Part<Derived, Mode> part() const;
480
 
 
481
 
 
482
 
//     static const ConstantReturnType Constant(int rows, int cols, const Scalar& value);
483
 
//     static const ConstantReturnType Constant(int size, const Scalar& value);
484
 
//     static const ConstantReturnType Constant(const Scalar& value);
485
 
 
486
 
//     template<typename CustomNullaryOp>
487
 
//     static const CwiseNullaryOp<CustomNullaryOp, Derived> NullaryExpr(int rows, int cols, const CustomNullaryOp& func);
488
 
//     template<typename CustomNullaryOp>
489
 
//     static const CwiseNullaryOp<CustomNullaryOp, Derived> NullaryExpr(int size, const CustomNullaryOp& func);
490
 
//     template<typename CustomNullaryOp>
491
 
//     static const CwiseNullaryOp<CustomNullaryOp, Derived> NullaryExpr(const CustomNullaryOp& func);
492
 
 
493
 
//     static const ConstantReturnType Zero(int rows, int cols);
494
 
//     static const ConstantReturnType Zero(int size);
495
 
//     static const ConstantReturnType Zero();
496
 
//     static const ConstantReturnType Ones(int rows, int cols);
497
 
//     static const ConstantReturnType Ones(int size);
498
 
//     static const ConstantReturnType Ones();
499
 
//     static const IdentityReturnType Identity();
500
 
//     static const IdentityReturnType Identity(int rows, int cols);
501
 
//     static const BasisReturnType Unit(int size, int i);
502
 
//     static const BasisReturnType Unit(int i);
503
 
//     static const BasisReturnType UnitX();
504
 
//     static const BasisReturnType UnitY();
505
 
//     static const BasisReturnType UnitZ();
506
 
//     static const BasisReturnType UnitW();
507
 
 
508
 
//     const DiagonalMatrix<Derived> asDiagonal() const;
509
 
 
510
 
//     Derived& setConstant(const Scalar& value);
511
 
//     Derived& setZero();
512
 
//     Derived& setOnes();
513
 
//     Derived& setRandom();
514
 
//     Derived& setIdentity();
515
 
 
516
 
      /** \internal use operator= */
517
 
      template<typename DenseDerived>
518
 
      void evalTo(MatrixBase<DenseDerived>& dst) const
519
 
      {
520
 
        dst.setZero();
521
 
        for (Index j=0; j<outerSize(); ++j)
522
 
          for (typename Derived::InnerIterator i(derived(),j); i; ++i)
523
 
            dst.coeffRef(i.row(),i.col()) = i.value();
524
 
      }
525
 
 
526
 
      Matrix<Scalar,RowsAtCompileTime,ColsAtCompileTime> toDense() const
527
 
      {
528
 
        return derived();
529
 
      }
530
 
 
531
 
    template<typename OtherDerived>
532
 
    bool isApprox(const SparseMatrixBase<OtherDerived>& other,
533
 
                  RealScalar prec = NumTraits<Scalar>::dummy_precision()) const
534
 
    { return toDense().isApprox(other.toDense(),prec); }
535
 
 
536
 
    template<typename OtherDerived>
537
 
    bool isApprox(const MatrixBase<OtherDerived>& other,
538
 
                  RealScalar prec = NumTraits<Scalar>::dummy_precision()) const
539
 
    { return toDense().isApprox(other,prec); }
540
 
//     bool isMuchSmallerThan(const RealScalar& other,
541
 
//                            RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
542
 
//     template<typename OtherDerived>
543
 
//     bool isMuchSmallerThan(const MatrixBase<OtherDerived>& other,
544
 
//                            RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
545
 
 
546
 
//     bool isApproxToConstant(const Scalar& value, RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
547
 
//     bool isZero(RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
548
 
//     bool isOnes(RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
549
 
//     bool isIdentity(RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
550
 
//     bool isDiagonal(RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
551
 
 
552
 
//     bool isUpper(RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
553
 
//     bool isLower(RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
554
 
 
555
 
//     template<typename OtherDerived>
556
 
//     bool isOrthogonal(const MatrixBase<OtherDerived>& other,
557
 
//                       RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
558
 
//     bool isUnitary(RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
559
 
 
560
 
//     template<typename OtherDerived>
561
 
//     inline bool operator==(const MatrixBase<OtherDerived>& other) const
562
 
//     { return (cwise() == other).all(); }
563
 
 
564
 
//     template<typename OtherDerived>
565
 
//     inline bool operator!=(const MatrixBase<OtherDerived>& other) const
566
 
//     { return (cwise() != other).any(); }
567
 
 
568
 
 
569
 
//     template<typename NewType>
570
 
//     const SparseCwiseUnaryOp<internal::scalar_cast_op<typename internal::traits<Derived>::Scalar, NewType>, Derived> cast() const;
571
 
 
572
 
    /** \returns the matrix or vector obtained by evaluating this expression.
573
 
      *
574
 
      * Notice that in the case of a plain matrix or vector (not an expression) this function just returns
575
 
      * a const reference, in order to avoid a useless copy.
576
 
      */
577
 
    inline const typename internal::eval<Derived>::type eval() const
578
 
    { return typename internal::eval<Derived>::type(derived()); }
579
 
 
580
 
//     template<typename OtherDerived>
581
 
//     void swap(MatrixBase<OtherDerived> const & other);
582
 
 
583
 
//     template<unsigned int Added>
584
 
//     const SparseFlagged<Derived, Added, 0> marked() const;
585
 
//     const Flagged<Derived, 0, EvalBeforeNestingBit | EvalBeforeAssigningBit> lazy() const;
586
 
 
587
 
    /** \returns number of elements to skip to pass from one row (resp. column) to another
588
 
      * for a row-major (resp. column-major) matrix.
589
 
      * Combined with coeffRef() and the \ref flags flags, it allows a direct access to the data
590
 
      * of the underlying matrix.
591
 
      */
592
 
//     inline int stride(void) const { return derived().stride(); }
593
 
 
594
 
// FIXME
595
 
//     ConjugateReturnType conjugate() const;
596
 
//     const RealReturnType real() const;
597
 
//     const ImagReturnType imag() const;
598
 
 
599
 
//     template<typename CustomUnaryOp>
600
 
//     const SparseCwiseUnaryOp<CustomUnaryOp, Derived> unaryExpr(const CustomUnaryOp& func = CustomUnaryOp()) const;
601
 
 
602
 
//     template<typename CustomBinaryOp, typename OtherDerived>
603
 
//     const CwiseBinaryOp<CustomBinaryOp, Derived, OtherDerived>
604
 
//     binaryExpr(const MatrixBase<OtherDerived> &other, const CustomBinaryOp& func = CustomBinaryOp()) const;
605
 
 
606
 
 
607
 
    Scalar sum() const;
608
 
//     Scalar trace() const;
609
 
 
610
 
//     typename internal::traits<Derived>::Scalar minCoeff() const;
611
 
//     typename internal::traits<Derived>::Scalar maxCoeff() const;
612
 
 
613
 
//     typename internal::traits<Derived>::Scalar minCoeff(int* row, int* col = 0) const;
614
 
//     typename internal::traits<Derived>::Scalar maxCoeff(int* row, int* col = 0) const;
615
 
 
616
 
//     template<typename BinaryOp>
617
 
//     typename internal::result_of<BinaryOp(typename internal::traits<Derived>::Scalar)>::type
618
 
//     redux(const BinaryOp& func) const;
619
 
 
620
 
//     template<typename Visitor>
621
 
//     void visit(Visitor& func) const;
622
 
 
623
 
 
624
 
//     const SparseCwise<Derived> cwise() const;
625
 
//     SparseCwise<Derived> cwise();
626
 
 
627
 
//     inline const WithFormat<Derived> format(const IOFormat& fmt) const;
628
 
 
629
 
/////////// Array module ///////////
630
 
    /*
631
 
    bool all(void) const;
632
 
    bool any(void) const;
633
 
 
634
 
    const VectorwiseOp<Derived,Horizontal> rowwise() const;
635
 
    const VectorwiseOp<Derived,Vertical> colwise() const;
636
 
 
637
 
    static const CwiseNullaryOp<internal::scalar_random_op<Scalar>,Derived> Random(int rows, int cols);
638
 
    static const CwiseNullaryOp<internal::scalar_random_op<Scalar>,Derived> Random(int size);
639
 
    static const CwiseNullaryOp<internal::scalar_random_op<Scalar>,Derived> Random();
640
 
 
641
 
    template<typename ThenDerived,typename ElseDerived>
642
 
    const Select<Derived,ThenDerived,ElseDerived>
643
 
    select(const MatrixBase<ThenDerived>& thenMatrix,
644
 
           const MatrixBase<ElseDerived>& elseMatrix) const;
645
 
 
646
 
    template<typename ThenDerived>
647
 
    inline const Select<Derived,ThenDerived, typename ThenDerived::ConstantReturnType>
648
 
    select(const MatrixBase<ThenDerived>& thenMatrix, typename ThenDerived::Scalar elseScalar) const;
649
 
 
650
 
    template<typename ElseDerived>
651
 
    inline const Select<Derived, typename ElseDerived::ConstantReturnType, ElseDerived >
652
 
    select(typename ElseDerived::Scalar thenScalar, const MatrixBase<ElseDerived>& elseMatrix) const;
653
 
 
654
 
    template<int p> RealScalar lpNorm() const;
655
 
    */
656
 
 
657
 
 
658
 
//     template<typename OtherDerived>
659
 
//     Scalar dot(const MatrixBase<OtherDerived>& other) const
660
 
//     {
661
 
//       EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
662
 
//       EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
663
 
//       EIGEN_STATIC_ASSERT((internal::is_same<Scalar, typename OtherDerived::Scalar>::value),
664
 
//         YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
665
 
//
666
 
//       eigen_assert(derived().size() == other.size());
667
 
//       // short version, but the assembly looks more complicated because
668
 
//       // of the CwiseBinaryOp iterator complexity
669
 
//       // return res = (derived().cwise() * other.derived().conjugate()).sum();
670
 
//
671
 
//       // optimized, generic version
672
 
//       typename Derived::InnerIterator i(derived(),0);
673
 
//       typename OtherDerived::InnerIterator j(other.derived(),0);
674
 
//       Scalar res = 0;
675
 
//       while (i && j)
676
 
//       {
677
 
//         if (i.index()==j.index())
678
 
//         {
679
 
// //           std::cerr << i.value() << " * " << j.value() << "\n";
680
 
//           res += i.value() * internal::conj(j.value());
681
 
//           ++i; ++j;
682
 
//         }
683
 
//         else if (i.index()<j.index())
684
 
//           ++i;
685
 
//         else
686
 
//           ++j;
687
 
//       }
688
 
//       return res;
689
 
//     }
690
 
//
691
 
//     Scalar sum() const
692
 
//     {
693
 
//       Scalar res = 0;
694
 
//       for (typename Derived::InnerIterator iter(*this,0); iter; ++iter)
695
 
//       {
696
 
//         res += iter.value();
697
 
//       }
698
 
//       return res;
699
 
//     }
700
 
 
701
 
  protected:
702
 
 
703
 
    bool m_isRValue;
704
 
};
705
 
 
706
 
#endif // EIGEN_SPARSEMATRIXBASE_H