BlockOfDynamicSparseMatrix.h
Go to the documentation of this file.
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_BLOCKFORDYNAMICMATRIX_H
00011 #define EIGEN_SPARSE_BLOCKFORDYNAMICMATRIX_H
00012 
00013 namespace Eigen { 
00014 
00015 /***************************************************************************
00016 * specialisation for DynamicSparseMatrix
00017 ***************************************************************************/
00018 
00019 template<typename _Scalar, int _Options, typename _Index, int Size>
00020 class SparseInnerVectorSet<DynamicSparseMatrix<_Scalar, _Options, _Index>, Size>
00021   : public SparseMatrixBase<SparseInnerVectorSet<DynamicSparseMatrix<_Scalar, _Options, _Index>, Size> >
00022 {
00023     typedef DynamicSparseMatrix<_Scalar, _Options, _Index> MatrixType;
00024   public:
00025 
00026     enum { IsRowMajor = internal::traits<SparseInnerVectorSet>::IsRowMajor };
00027 
00028     EIGEN_SPARSE_PUBLIC_INTERFACE(SparseInnerVectorSet)
00029     class InnerIterator: public MatrixType::InnerIterator
00030     {
00031       public:
00032         inline InnerIterator(const SparseInnerVectorSet& xpr, Index outer)
00033           : MatrixType::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 
00041     inline SparseInnerVectorSet(const MatrixType& matrix, Index outerStart, Index outerSize)
00042       : m_matrix(matrix), m_outerStart(outerStart), m_outerSize(outerSize)
00043     {
00044       eigen_assert( (outerStart>=0) && ((outerStart+outerSize)<=matrix.outerSize()) );
00045     }
00046 
00047     inline SparseInnerVectorSet(const MatrixType& matrix, Index outer)
00048       : m_matrix(matrix), m_outerStart(outer), m_outerSize(Size)
00049     {
00050       eigen_assert(Size!=Dynamic);
00051       eigen_assert( (outer>=0) && (outer<matrix.outerSize()) );
00052     }
00053 
00054     template<typename OtherDerived>
00055     inline SparseInnerVectorSet& operator=(const SparseMatrixBase<OtherDerived>& other)
00056     {
00057       if (IsRowMajor != ((OtherDerived::Flags&RowMajorBit)==RowMajorBit))
00058       {
00059         // need to transpose => perform a block evaluation followed by a big swap
00060         DynamicSparseMatrix<Scalar,IsRowMajor?RowMajorBit:0> aux(other);
00061         *this = aux.markAsRValue();
00062       }
00063       else
00064       {
00065         // evaluate/copy vector per vector
00066         for (Index j=0; j<m_outerSize.value(); ++j)
00067         {
00068           SparseVector<Scalar,IsRowMajor ? RowMajorBit : 0> aux(other.innerVector(j));
00069           m_matrix.const_cast_derived()._data()[m_outerStart+j].swap(aux._data());
00070         }
00071       }
00072       return *this;
00073     }
00074 
00075     inline SparseInnerVectorSet& operator=(const SparseInnerVectorSet& other)
00076     {
00077       return operator=<SparseInnerVectorSet>(other);
00078     }
00079 
00080     Index nonZeros() const
00081     {
00082       Index count = 0;
00083       for (Index j=0; j<m_outerSize.value(); ++j)
00084         count += m_matrix._data()[m_outerStart+j].size();
00085       return count;
00086     }
00087 
00088     const Scalar& lastCoeff() const
00089     {
00090       EIGEN_STATIC_ASSERT_VECTOR_ONLY(SparseInnerVectorSet);
00091       eigen_assert(m_matrix.data()[m_outerStart].size()>0);
00092       return m_matrix.data()[m_outerStart].vale(m_matrix.data()[m_outerStart].size()-1);
00093     }
00094 
00095 //     template<typename Sparse>
00096 //     inline SparseInnerVectorSet& operator=(const SparseMatrixBase<OtherDerived>& other)
00097 //     {
00098 //       return *this;
00099 //     }
00100 
00101     EIGEN_STRONG_INLINE Index rows() const { return IsRowMajor ? m_outerSize.value() : m_matrix.rows(); }
00102     EIGEN_STRONG_INLINE Index cols() const { return IsRowMajor ? m_matrix.cols() : m_outerSize.value(); }
00103 
00104   protected:
00105 
00106     const typename MatrixType::Nested m_matrix;
00107     Index m_outerStart;
00108     const internal::variable_if_dynamic<Index, Size> m_outerSize;
00109 
00110 };
00111 
00112 } // end namespace Eigen
00113 
00114 #endif // EIGEN_SPARSE_BLOCKFORDYNAMICMATRIX_H


win_eigen
Author(s): Daniel Stonier
autogenerated on Wed Sep 16 2015 07:10:21