Eigen  3.2.8
SparseBlock.h
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr>
00005 //
00006 // This Source Code Form is subject to the terms of the Mozilla
00007 // Public License v. 2.0. If a copy of the MPL was not distributed
00008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
00009 
00010 #ifndef EIGEN_SPARSE_BLOCK_H
00011 #define EIGEN_SPARSE_BLOCK_H
00012 
00013 namespace Eigen { 
00014 
00015 template<typename XprType, int BlockRows, int BlockCols>
00016 class BlockImpl<XprType,BlockRows,BlockCols,true,Sparse>
00017   : public SparseMatrixBase<Block<XprType,BlockRows,BlockCols,true> >
00018 {
00019     typedef typename internal::remove_all<typename XprType::Nested>::type _MatrixTypeNested;
00020     typedef Block<XprType, BlockRows, BlockCols, true> BlockType;
00021 public:
00022     enum { IsRowMajor = internal::traits<BlockType>::IsRowMajor };
00023 protected:
00024     enum { OuterSize = IsRowMajor ? BlockRows : BlockCols };
00025 public:
00026     EIGEN_SPARSE_PUBLIC_INTERFACE(BlockType)
00027     
00028     class InnerIterator: public XprType::InnerIterator
00029     {
00030         typedef typename BlockImpl::Index Index;
00031       public:
00032         inline InnerIterator(const BlockType& xpr, Index outer)
00033           : XprType::InnerIterator(xpr.m_matrix, xpr.m_outerStart + outer), m_outer(outer)
00034         {}
00035         inline Index row() const { return IsRowMajor ? m_outer : this->index(); }
00036         inline Index col() const { return IsRowMajor ? this->index() : m_outer; }
00037       protected:
00038         Index m_outer;
00039     };
00040     class ReverseInnerIterator: public XprType::ReverseInnerIterator
00041     {
00042         typedef typename BlockImpl::Index Index;
00043       public:
00044         inline ReverseInnerIterator(const BlockType& xpr, Index outer)
00045           : XprType::ReverseInnerIterator(xpr.m_matrix, xpr.m_outerStart + outer), m_outer(outer)
00046         {}
00047         inline Index row() const { return IsRowMajor ? m_outer : this->index(); }
00048         inline Index col() const { return IsRowMajor ? this->index() : m_outer; }
00049       protected:
00050         Index m_outer;
00051     };
00052 
00053     inline BlockImpl(const XprType& xpr, int i)
00054       : m_matrix(xpr), m_outerStart(i), m_outerSize(OuterSize)
00055     {}
00056 
00057     inline BlockImpl(const XprType& xpr, int startRow, int startCol, int blockRows, int blockCols)
00058       : m_matrix(xpr), m_outerStart(IsRowMajor ? startRow : startCol), m_outerSize(IsRowMajor ? blockRows : blockCols)
00059     {}
00060     
00061     inline const Scalar coeff(int row, int col) const
00062     {
00063       return m_matrix.coeff(row + IsRowMajor ? m_outerStart : 0, col +IsRowMajor ? 0 :  m_outerStart);
00064     }
00065     
00066     inline const Scalar coeff(int index) const
00067     {
00068       return m_matrix.coeff(IsRowMajor ? m_outerStart : index, IsRowMajor ? index :  m_outerStart);
00069     }
00070 
00071     EIGEN_STRONG_INLINE Index rows() const { return IsRowMajor ? m_outerSize.value() : m_matrix.rows(); }
00072     EIGEN_STRONG_INLINE Index cols() const { return IsRowMajor ? m_matrix.cols() : m_outerSize.value(); }
00073 
00074   protected:
00075 
00076     typename XprType::Nested m_matrix;
00077     Index m_outerStart;
00078     const internal::variable_if_dynamic<Index, OuterSize> m_outerSize;
00079 
00080     EIGEN_INHERIT_ASSIGNMENT_OPERATORS(BlockImpl)
00081   private:
00082     Index nonZeros() const;
00083 };
00084 
00085 
00086 /***************************************************************************
00087 * specialisation for SparseMatrix
00088 ***************************************************************************/
00089 
00090 template<typename _Scalar, int _Options, typename _Index, int BlockRows, int BlockCols>
00091 class BlockImpl<SparseMatrix<_Scalar, _Options, _Index>,BlockRows,BlockCols,true,Sparse>
00092   : public SparseMatrixBase<Block<SparseMatrix<_Scalar, _Options, _Index>,BlockRows,BlockCols,true> >
00093 {
00094     typedef SparseMatrix<_Scalar, _Options, _Index> SparseMatrixType;
00095     typedef typename internal::remove_all<typename SparseMatrixType::Nested>::type _MatrixTypeNested;
00096     typedef Block<SparseMatrixType, BlockRows, BlockCols, true> BlockType;
00097     typedef Block<const SparseMatrixType, BlockRows, BlockCols, true> ConstBlockType;
00098 public:
00099     enum { IsRowMajor = internal::traits<BlockType>::IsRowMajor };
00100     EIGEN_SPARSE_PUBLIC_INTERFACE(BlockType)
00101 protected:
00102     enum { OuterSize = IsRowMajor ? BlockRows : BlockCols };
00103 public:
00104     
00105     class InnerIterator: public SparseMatrixType::InnerIterator
00106     {
00107       public:
00108         inline InnerIterator(const BlockType& xpr, Index outer)
00109           : SparseMatrixType::InnerIterator(xpr.m_matrix, xpr.m_outerStart + outer), m_outer(outer)
00110         {}
00111         inline Index row() const { return IsRowMajor ? m_outer : this->index(); }
00112         inline Index col() const { return IsRowMajor ? this->index() : m_outer; }
00113       protected:
00114         Index m_outer;
00115     };
00116     class ReverseInnerIterator: public SparseMatrixType::ReverseInnerIterator
00117     {
00118       public:
00119         inline ReverseInnerIterator(const BlockType& xpr, Index outer)
00120           : SparseMatrixType::ReverseInnerIterator(xpr.m_matrix, xpr.m_outerStart + outer), m_outer(outer)
00121         {}
00122         inline Index row() const { return IsRowMajor ? m_outer : this->index(); }
00123         inline Index col() const { return IsRowMajor ? this->index() : m_outer; }
00124       protected:
00125         Index m_outer;
00126     };
00127 
00128     inline BlockImpl(const SparseMatrixType& xpr, int i)
00129       : m_matrix(xpr), m_outerStart(i), m_outerSize(OuterSize)
00130     {}
00131 
00132     inline BlockImpl(const SparseMatrixType& xpr, int startRow, int startCol, int blockRows, int blockCols)
00133       : m_matrix(xpr), m_outerStart(IsRowMajor ? startRow : startCol), m_outerSize(IsRowMajor ? blockRows : blockCols)
00134     {}
00135 
00136     template<typename OtherDerived>
00137     inline BlockType& operator=(const SparseMatrixBase<OtherDerived>& other)
00138     {
00139       typedef typename internal::remove_all<typename SparseMatrixType::Nested>::type _NestedMatrixType;
00140       _NestedMatrixType& matrix = const_cast<_NestedMatrixType&>(m_matrix);;
00141       // This assignement is slow if this vector set is not empty
00142       // and/or it is not at the end of the nonzeros of the underlying matrix.
00143 
00144       // 1 - eval to a temporary to avoid transposition and/or aliasing issues
00145       SparseMatrix<Scalar, IsRowMajor ? RowMajor : ColMajor, Index> tmp(other);
00146 
00147       // 2 - let's check whether there is enough allocated memory
00148       Index nnz           = tmp.nonZeros();
00149       Index start         = m_outerStart==0 ? 0 : matrix.outerIndexPtr()[m_outerStart]; // starting position of the current block
00150       Index end           = m_matrix.outerIndexPtr()[m_outerStart+m_outerSize.value()]; // ending posiiton of the current block
00151       Index block_size    = end - start;                                                // available room in the current block
00152       Index tail_size     = m_matrix.outerIndexPtr()[m_matrix.outerSize()] - end;
00153       
00154       Index free_size     = m_matrix.isCompressed()
00155                           ? Index(matrix.data().allocatedSize()) + block_size
00156                           : block_size;
00157 
00158       if(nnz>free_size) 
00159       {
00160         // realloc manually to reduce copies
00161         typename SparseMatrixType::Storage newdata(m_matrix.data().allocatedSize() - block_size + nnz);
00162 
00163         std::memcpy(&newdata.value(0), &m_matrix.data().value(0), start*sizeof(Scalar));
00164         std::memcpy(&newdata.index(0), &m_matrix.data().index(0), start*sizeof(Index));
00165 
00166         std::memcpy(&newdata.value(start), &tmp.data().value(0), nnz*sizeof(Scalar));
00167         std::memcpy(&newdata.index(start), &tmp.data().index(0), nnz*sizeof(Index));
00168 
00169         std::memcpy(&newdata.value(start+nnz), &matrix.data().value(end), tail_size*sizeof(Scalar));
00170         std::memcpy(&newdata.index(start+nnz), &matrix.data().index(end), tail_size*sizeof(Index));
00171         
00172         newdata.resize(m_matrix.outerIndexPtr()[m_matrix.outerSize()] - block_size + nnz);
00173 
00174         matrix.data().swap(newdata);
00175       }
00176       else
00177       {
00178         // no need to realloc, simply copy the tail at its respective position and insert tmp
00179         matrix.data().resize(start + nnz + tail_size);
00180 
00181         std::memmove(&matrix.data().value(start+nnz), &matrix.data().value(end), tail_size*sizeof(Scalar));
00182         std::memmove(&matrix.data().index(start+nnz), &matrix.data().index(end), tail_size*sizeof(Index));
00183 
00184         std::memcpy(&matrix.data().value(start), &tmp.data().value(0), nnz*sizeof(Scalar));
00185         std::memcpy(&matrix.data().index(start), &tmp.data().index(0), nnz*sizeof(Index));
00186       }
00187       
00188       // update innerNonZeros
00189       if(!m_matrix.isCompressed())
00190         for(Index j=0; j<m_outerSize.value(); ++j)
00191           matrix.innerNonZeroPtr()[m_outerStart+j] = tmp.innerVector(j).nonZeros();
00192 
00193       // update outer index pointers
00194       Index p = start;
00195       for(Index k=0; k<m_outerSize.value(); ++k)
00196       {
00197         matrix.outerIndexPtr()[m_outerStart+k] = p;
00198         p += tmp.innerVector(k).nonZeros();
00199       }
00200       std::ptrdiff_t offset = nnz - block_size;
00201       for(Index k = m_outerStart + m_outerSize.value(); k<=matrix.outerSize(); ++k)
00202       {
00203         matrix.outerIndexPtr()[k] += offset;
00204       }
00205 
00206       return derived();
00207     }
00208 
00209     inline BlockType& operator=(const BlockType& other)
00210     {
00211       return operator=<BlockType>(other);
00212     }
00213 
00214     inline const Scalar* valuePtr() const
00215     { return m_matrix.valuePtr() + m_matrix.outerIndexPtr()[m_outerStart]; }
00216     inline Scalar* valuePtr()
00217     { return m_matrix.const_cast_derived().valuePtr() + m_matrix.outerIndexPtr()[m_outerStart]; }
00218 
00219     inline const Index* innerIndexPtr() const
00220     { return m_matrix.innerIndexPtr() + m_matrix.outerIndexPtr()[m_outerStart]; }
00221     inline Index* innerIndexPtr()
00222     { return m_matrix.const_cast_derived().innerIndexPtr() + m_matrix.outerIndexPtr()[m_outerStart]; }
00223 
00224     inline const Index* outerIndexPtr() const
00225     { return m_matrix.outerIndexPtr() + m_outerStart; }
00226     inline Index* outerIndexPtr()
00227     { return m_matrix.const_cast_derived().outerIndexPtr() + m_outerStart; }
00228 
00229     Index nonZeros() const
00230     {
00231       if(m_matrix.isCompressed())
00232         return  std::size_t(m_matrix.outerIndexPtr()[m_outerStart+m_outerSize.value()])
00233               - std::size_t(m_matrix.outerIndexPtr()[m_outerStart]);
00234       else if(m_outerSize.value()==0)
00235         return 0;
00236       else
00237         return Map<const Matrix<Index,OuterSize,1> >(m_matrix.innerNonZeroPtr()+m_outerStart, m_outerSize.value()).sum();
00238     }
00239     
00240     inline Scalar& coeffRef(int row, int col)
00241     {
00242       return m_matrix.const_cast_derived().coeffRef(row + (IsRowMajor ? m_outerStart : 0), col + (IsRowMajor ? 0 :  m_outerStart));
00243     }
00244     
00245     inline const Scalar coeff(int row, int col) const
00246     {
00247       return m_matrix.coeff(row + (IsRowMajor ? m_outerStart : 0), col + (IsRowMajor ? 0 :  m_outerStart));
00248     }
00249     
00250     inline const Scalar coeff(int index) const
00251     {
00252       return m_matrix.coeff(IsRowMajor ? m_outerStart : index, IsRowMajor ? index :  m_outerStart);
00253     }
00254 
00255     const Scalar& lastCoeff() const
00256     {
00257       EIGEN_STATIC_ASSERT_VECTOR_ONLY(BlockImpl);
00258       eigen_assert(nonZeros()>0);
00259       if(m_matrix.isCompressed())
00260         return m_matrix.valuePtr()[m_matrix.outerIndexPtr()[m_outerStart+1]-1];
00261       else
00262         return m_matrix.valuePtr()[m_matrix.outerIndexPtr()[m_outerStart]+m_matrix.innerNonZeroPtr()[m_outerStart]-1];
00263     }
00264 
00265     EIGEN_STRONG_INLINE Index rows() const { return IsRowMajor ? m_outerSize.value() : m_matrix.rows(); }
00266     EIGEN_STRONG_INLINE Index cols() const { return IsRowMajor ? m_matrix.cols() : m_outerSize.value(); }
00267 
00268   protected:
00269 
00270     typename SparseMatrixType::Nested m_matrix;
00271     Index m_outerStart;
00272     const internal::variable_if_dynamic<Index, OuterSize> m_outerSize;
00273 
00274 };
00275 
00276 
00277 template<typename _Scalar, int _Options, typename _Index, int BlockRows, int BlockCols>
00278 class BlockImpl<const SparseMatrix<_Scalar, _Options, _Index>,BlockRows,BlockCols,true,Sparse>
00279   : public SparseMatrixBase<Block<const SparseMatrix<_Scalar, _Options, _Index>,BlockRows,BlockCols,true> >
00280 {
00281     typedef SparseMatrix<_Scalar, _Options, _Index> SparseMatrixType;
00282     typedef typename internal::remove_all<typename SparseMatrixType::Nested>::type _MatrixTypeNested;
00283     typedef Block<const SparseMatrixType, BlockRows, BlockCols, true> BlockType;
00284 public:
00285     enum { IsRowMajor = internal::traits<BlockType>::IsRowMajor };
00286     EIGEN_SPARSE_PUBLIC_INTERFACE(BlockType)
00287 protected:
00288     enum { OuterSize = IsRowMajor ? BlockRows : BlockCols };
00289 public:
00290     
00291     class InnerIterator: public SparseMatrixType::InnerIterator
00292     {
00293       public:
00294         inline InnerIterator(const BlockType& xpr, Index outer)
00295           : SparseMatrixType::InnerIterator(xpr.m_matrix, xpr.m_outerStart + outer), m_outer(outer)
00296         {}
00297         inline Index row() const { return IsRowMajor ? m_outer : this->index(); }
00298         inline Index col() const { return IsRowMajor ? this->index() : m_outer; }
00299       protected:
00300         Index m_outer;
00301     };
00302     class ReverseInnerIterator: public SparseMatrixType::ReverseInnerIterator
00303     {
00304       public:
00305         inline ReverseInnerIterator(const BlockType& xpr, Index outer)
00306           : SparseMatrixType::ReverseInnerIterator(xpr.m_matrix, xpr.m_outerStart + outer), m_outer(outer)
00307         {}
00308         inline Index row() const { return IsRowMajor ? m_outer : this->index(); }
00309         inline Index col() const { return IsRowMajor ? this->index() : m_outer; }
00310       protected:
00311         Index m_outer;
00312     };
00313 
00314     inline BlockImpl(const SparseMatrixType& xpr, int i)
00315       : m_matrix(xpr), m_outerStart(i), m_outerSize(OuterSize)
00316     {}
00317 
00318     inline BlockImpl(const SparseMatrixType& xpr, int startRow, int startCol, int blockRows, int blockCols)
00319       : m_matrix(xpr), m_outerStart(IsRowMajor ? startRow : startCol), m_outerSize(IsRowMajor ? blockRows : blockCols)
00320     {}
00321 
00322     inline const Scalar* valuePtr() const
00323     { return m_matrix.valuePtr() + m_matrix.outerIndexPtr()[m_outerStart]; }
00324 
00325     inline const Index* innerIndexPtr() const
00326     { return m_matrix.innerIndexPtr() + m_matrix.outerIndexPtr()[m_outerStart]; }
00327 
00328     inline const Index* outerIndexPtr() const
00329     { return m_matrix.outerIndexPtr() + m_outerStart; }
00330 
00331     Index nonZeros() const
00332     {
00333       if(m_matrix.isCompressed())
00334         return  std::size_t(m_matrix.outerIndexPtr()[m_outerStart+m_outerSize.value()])
00335               - std::size_t(m_matrix.outerIndexPtr()[m_outerStart]);
00336       else if(m_outerSize.value()==0)
00337         return 0;
00338       else
00339         return Map<const Matrix<Index,OuterSize,1> >(m_matrix.innerNonZeroPtr()+m_outerStart, m_outerSize.value()).sum();
00340     }
00341     
00342     inline const Scalar coeff(int row, int col) const
00343     {
00344       return m_matrix.coeff(row + (IsRowMajor ? m_outerStart : 0), col + (IsRowMajor ? 0 :  m_outerStart));
00345     }
00346     
00347     inline const Scalar coeff(int index) const
00348     {
00349       return m_matrix.coeff(IsRowMajor ? m_outerStart : index, IsRowMajor ? index :  m_outerStart);
00350     }
00351 
00352     const Scalar& lastCoeff() const
00353     {
00354       EIGEN_STATIC_ASSERT_VECTOR_ONLY(BlockImpl);
00355       eigen_assert(nonZeros()>0);
00356       if(m_matrix.isCompressed())
00357         return m_matrix.valuePtr()[m_matrix.outerIndexPtr()[m_outerStart+1]-1];
00358       else
00359         return m_matrix.valuePtr()[m_matrix.outerIndexPtr()[m_outerStart]+m_matrix.innerNonZeroPtr()[m_outerStart]-1];
00360     }
00361 
00362     EIGEN_STRONG_INLINE Index rows() const { return IsRowMajor ? m_outerSize.value() : m_matrix.rows(); }
00363     EIGEN_STRONG_INLINE Index cols() const { return IsRowMajor ? m_matrix.cols() : m_outerSize.value(); }
00364 
00365   protected:
00366 
00367     EIGEN_INHERIT_ASSIGNMENT_OPERATORS(BlockImpl)
00368 
00369     typename SparseMatrixType::Nested m_matrix;
00370     Index m_outerStart;
00371     const internal::variable_if_dynamic<Index, OuterSize> m_outerSize;
00372 };
00373 
00374 //----------
00375 
00379 template<typename Derived>
00380 typename SparseMatrixBase<Derived>::InnerVectorReturnType SparseMatrixBase<Derived>::innerVector(Index outer)
00381 { return InnerVectorReturnType(derived(), outer); }
00382 
00386 template<typename Derived>
00387 const typename SparseMatrixBase<Derived>::ConstInnerVectorReturnType SparseMatrixBase<Derived>::innerVector(Index outer) const
00388 { return ConstInnerVectorReturnType(derived(), outer); }
00389 
00393 template<typename Derived>
00394 typename SparseMatrixBase<Derived>::InnerVectorsReturnType
00395 SparseMatrixBase<Derived>::innerVectors(Index outerStart, Index outerSize)
00396 {
00397   return Block<Derived,Dynamic,Dynamic,true>(derived(),
00398                                              IsRowMajor ? outerStart : 0, IsRowMajor ? 0 : outerStart,
00399                                              IsRowMajor ? outerSize : rows(), IsRowMajor ? cols() : outerSize);
00400   
00401 }
00402 
00406 template<typename Derived>
00407 const typename SparseMatrixBase<Derived>::ConstInnerVectorsReturnType
00408 SparseMatrixBase<Derived>::innerVectors(Index outerStart, Index outerSize) const
00409 {
00410   return Block<const Derived,Dynamic,Dynamic,true>(derived(),
00411                                                   IsRowMajor ? outerStart : 0, IsRowMajor ? 0 : outerStart,
00412                                                   IsRowMajor ? outerSize : rows(), IsRowMajor ? cols() : outerSize);
00413   
00414 }
00415 
00419 template<typename XprType, int BlockRows, int BlockCols, bool InnerPanel>
00420 class BlockImpl<XprType,BlockRows,BlockCols,InnerPanel,Sparse>
00421   : public SparseMatrixBase<Block<XprType,BlockRows,BlockCols,InnerPanel> >, internal::no_assignment_operator
00422 {
00423   typedef typename internal::remove_all<typename XprType::Nested>::type _MatrixTypeNested;
00424   typedef Block<XprType, BlockRows, BlockCols, InnerPanel> BlockType;
00425 public:
00426     enum { IsRowMajor = internal::traits<BlockType>::IsRowMajor };
00427     EIGEN_SPARSE_PUBLIC_INTERFACE(BlockType)
00428 
00429     
00431     inline BlockImpl(const XprType& xpr, int i)
00432       : m_matrix(xpr),
00433         m_startRow( (BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) ? i : 0),
00434         m_startCol( (BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) ? i : 0),
00435         m_blockRows(BlockRows==1 ? 1 : xpr.rows()),
00436         m_blockCols(BlockCols==1 ? 1 : xpr.cols())
00437     {}
00438 
00441     inline BlockImpl(const XprType& xpr, int startRow, int startCol, int blockRows, int blockCols)
00442       : m_matrix(xpr), m_startRow(startRow), m_startCol(startCol), m_blockRows(blockRows), m_blockCols(blockCols)
00443     {}
00444 
00445     inline int rows() const { return m_blockRows.value(); }
00446     inline int cols() const { return m_blockCols.value(); }
00447 
00448     inline Scalar& coeffRef(int row, int col)
00449     {
00450       return m_matrix.const_cast_derived()
00451                .coeffRef(row + m_startRow.value(), col + m_startCol.value());
00452     }
00453 
00454     inline const Scalar coeff(int row, int col) const
00455     {
00456       return m_matrix.coeff(row + m_startRow.value(), col + m_startCol.value());
00457     }
00458 
00459     inline Scalar& coeffRef(int index)
00460     {
00461       return m_matrix.const_cast_derived()
00462              .coeffRef(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
00463                        m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0));
00464     }
00465 
00466     inline const Scalar coeff(int index) const
00467     {
00468       return m_matrix
00469              .coeff(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
00470                     m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0));
00471     }
00472     
00473     inline const _MatrixTypeNested& nestedExpression() const { return m_matrix; }
00474     
00475     class InnerIterator : public _MatrixTypeNested::InnerIterator
00476     {
00477       typedef typename _MatrixTypeNested::InnerIterator Base;
00478       const BlockType& m_block;
00479       Index m_end;
00480     public:
00481 
00482       EIGEN_STRONG_INLINE InnerIterator(const BlockType& block, Index outer)
00483         : Base(block.derived().nestedExpression(), outer + (IsRowMajor ? block.m_startRow.value() : block.m_startCol.value())),
00484           m_block(block),
00485           m_end(IsRowMajor ? block.m_startCol.value()+block.m_blockCols.value() : block.m_startRow.value()+block.m_blockRows.value())
00486       {
00487         while( (Base::operator bool()) && (Base::index() < (IsRowMajor ? m_block.m_startCol.value() : m_block.m_startRow.value())) )
00488           Base::operator++();
00489       }
00490 
00491       inline Index index()  const { return Base::index() - (IsRowMajor ? m_block.m_startCol.value() : m_block.m_startRow.value()); }
00492       inline Index outer()  const { return Base::outer() - (IsRowMajor ? m_block.m_startRow.value() : m_block.m_startCol.value()); }
00493       inline Index row()    const { return Base::row()   - m_block.m_startRow.value(); }
00494       inline Index col()    const { return Base::col()   - m_block.m_startCol.value(); }
00495       
00496       inline operator bool() const { return Base::operator bool() && Base::index() < m_end; }
00497     };
00498     class ReverseInnerIterator : public _MatrixTypeNested::ReverseInnerIterator
00499     {
00500       typedef typename _MatrixTypeNested::ReverseInnerIterator Base;
00501       const BlockType& m_block;
00502       Index m_begin;
00503     public:
00504 
00505       EIGEN_STRONG_INLINE ReverseInnerIterator(const BlockType& block, Index outer)
00506         : Base(block.derived().nestedExpression(), outer + (IsRowMajor ? block.m_startRow.value() : block.m_startCol.value())),
00507           m_block(block),
00508           m_begin(IsRowMajor ? block.m_startCol.value() : block.m_startRow.value())
00509       {
00510         while( (Base::operator bool()) && (Base::index() >= (IsRowMajor ? m_block.m_startCol.value()+block.m_blockCols.value() : m_block.m_startRow.value()+block.m_blockRows.value())) )
00511           Base::operator--();
00512       }
00513 
00514       inline Index index()  const { return Base::index() - (IsRowMajor ? m_block.m_startCol.value() : m_block.m_startRow.value()); }
00515       inline Index outer()  const { return Base::outer() - (IsRowMajor ? m_block.m_startRow.value() : m_block.m_startCol.value()); }
00516       inline Index row()    const { return Base::row()   - m_block.m_startRow.value(); }
00517       inline Index col()    const { return Base::col()   - m_block.m_startCol.value(); }
00518       
00519       inline operator bool() const { return Base::operator bool() && Base::index() >= m_begin; }
00520     };
00521   protected:
00522     friend class InnerIterator;
00523     friend class ReverseInnerIterator;
00524     
00525     EIGEN_INHERIT_ASSIGNMENT_OPERATORS(BlockImpl)
00526 
00527     typename XprType::Nested m_matrix;
00528     const internal::variable_if_dynamic<Index, XprType::RowsAtCompileTime == 1 ? 0 : Dynamic> m_startRow;
00529     const internal::variable_if_dynamic<Index, XprType::ColsAtCompileTime == 1 ? 0 : Dynamic> m_startCol;
00530     const internal::variable_if_dynamic<Index, RowsAtCompileTime> m_blockRows;
00531     const internal::variable_if_dynamic<Index, ColsAtCompileTime> m_blockCols;
00532   private:
00533     Index nonZeros() const;
00534 };
00535 
00536 } // end namespace Eigen
00537 
00538 #endif // EIGEN_SPARSE_BLOCK_H
00539 
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends