MOAB  4.9.3pre
SparseSelfAdjointView.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) 2009-2014 Gael Guennebaud <[email protected]>
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_SELFADJOINTVIEW_H
00011 #define EIGEN_SPARSE_SELFADJOINTVIEW_H
00012 
00013 namespace Eigen { 
00014   
00029 namespace internal {
00030   
00031 template<typename MatrixType, unsigned int Mode>
00032 struct traits<SparseSelfAdjointView<MatrixType,Mode> > : traits<MatrixType> {
00033 };
00034 
00035 template<int SrcMode,int DstMode,typename MatrixType,int DestOrder>
00036 void permute_symm_to_symm(const MatrixType& mat, SparseMatrix<typename MatrixType::Scalar,DestOrder,typename MatrixType::StorageIndex>& _dest, const typename MatrixType::StorageIndex* perm = 0);
00037 
00038 template<int Mode,typename MatrixType,int DestOrder>
00039 void permute_symm_to_fullsymm(const MatrixType& mat, SparseMatrix<typename MatrixType::Scalar,DestOrder,typename MatrixType::StorageIndex>& _dest, const typename MatrixType::StorageIndex* perm = 0);
00040 
00041 }
00042 
00043 template<typename MatrixType, unsigned int _Mode> class SparseSelfAdjointView
00044   : public EigenBase<SparseSelfAdjointView<MatrixType,_Mode> >
00045 {
00046   public:
00047     
00048     enum {
00049       Mode = _Mode,
00050       RowsAtCompileTime = internal::traits<SparseSelfAdjointView>::RowsAtCompileTime,
00051       ColsAtCompileTime = internal::traits<SparseSelfAdjointView>::ColsAtCompileTime
00052     };
00053 
00054     typedef EigenBase<SparseSelfAdjointView> Base;
00055     typedef typename MatrixType::Scalar Scalar;
00056     typedef typename MatrixType::StorageIndex StorageIndex;
00057     typedef Matrix<StorageIndex,Dynamic,1> VectorI;
00058     typedef typename internal::ref_selector<MatrixType>::non_const_type MatrixTypeNested;
00059     typedef typename internal::remove_all<MatrixTypeNested>::type _MatrixTypeNested;
00060     
00061     explicit inline SparseSelfAdjointView(MatrixType& matrix) : m_matrix(matrix)
00062     {
00063       eigen_assert(rows()==cols() && "SelfAdjointView is only for squared matrices");
00064     }
00065 
00066     inline Index rows() const { return m_matrix.rows(); }
00067     inline Index cols() const { return m_matrix.cols(); }
00068 
00070     const _MatrixTypeNested& matrix() const { return m_matrix; }
00071     typename internal::remove_reference<MatrixTypeNested>::type& matrix() { return m_matrix; }
00072 
00078     template<typename OtherDerived>
00079     Product<SparseSelfAdjointView, OtherDerived>
00080     operator*(const SparseMatrixBase<OtherDerived>& rhs) const
00081     {
00082       return Product<SparseSelfAdjointView, OtherDerived>(*this, rhs.derived());
00083     }
00084 
00090     template<typename OtherDerived> friend
00091     Product<OtherDerived, SparseSelfAdjointView>
00092     operator*(const SparseMatrixBase<OtherDerived>& lhs, const SparseSelfAdjointView& rhs)
00093     {
00094       return Product<OtherDerived, SparseSelfAdjointView>(lhs.derived(), rhs);
00095     }
00096     
00098     template<typename OtherDerived>
00099     Product<SparseSelfAdjointView,OtherDerived>
00100     operator*(const MatrixBase<OtherDerived>& rhs) const
00101     {
00102       return Product<SparseSelfAdjointView,OtherDerived>(*this, rhs.derived());
00103     }
00104 
00106     template<typename OtherDerived> friend
00107     Product<OtherDerived,SparseSelfAdjointView>
00108     operator*(const MatrixBase<OtherDerived>& lhs, const SparseSelfAdjointView& rhs)
00109     {
00110       return Product<OtherDerived,SparseSelfAdjointView>(lhs.derived(), rhs);
00111     }
00112 
00121     template<typename DerivedU>
00122     SparseSelfAdjointView& rankUpdate(const SparseMatrixBase<DerivedU>& u, const Scalar& alpha = Scalar(1));
00123     
00125     // TODO implement twists in a more evaluator friendly fashion
00126     SparseSymmetricPermutationProduct<_MatrixTypeNested,Mode> twistedBy(const PermutationMatrix<Dynamic,Dynamic,StorageIndex>& perm) const
00127     {
00128       return SparseSymmetricPermutationProduct<_MatrixTypeNested,Mode>(m_matrix, perm);
00129     }
00130 
00131     template<typename SrcMatrixType,int SrcMode>
00132     SparseSelfAdjointView& operator=(const SparseSymmetricPermutationProduct<SrcMatrixType,SrcMode>& permutedMatrix)
00133     {
00134       internal::call_assignment_no_alias_no_transpose(*this, permutedMatrix);
00135       return *this;
00136     }
00137 
00138     SparseSelfAdjointView& operator=(const SparseSelfAdjointView& src)
00139     {
00140       PermutationMatrix<Dynamic,Dynamic,StorageIndex> pnull;
00141       return *this = src.twistedBy(pnull);
00142     }
00143 
00144     template<typename SrcMatrixType,unsigned int SrcMode>
00145     SparseSelfAdjointView& operator=(const SparseSelfAdjointView<SrcMatrixType,SrcMode>& src)
00146     {
00147       PermutationMatrix<Dynamic,Dynamic,StorageIndex> pnull;
00148       return *this = src.twistedBy(pnull);
00149     }
00150     
00151     void resize(Index rows, Index cols)
00152     {
00153       EIGEN_ONLY_USED_FOR_DEBUG(rows);
00154       EIGEN_ONLY_USED_FOR_DEBUG(cols);
00155       eigen_assert(rows == this->rows() && cols == this->cols()
00156                 && "SparseSelfadjointView::resize() does not actually allow to resize.");
00157     }
00158     
00159   protected:
00160 
00161     MatrixTypeNested m_matrix;
00162     //mutable VectorI m_countPerRow;
00163     //mutable VectorI m_countPerCol;
00164   private:
00165     template<typename Dest> void evalTo(Dest &) const;
00166 };
00167 
00168 /***************************************************************************
00169 * Implementation of SparseMatrixBase methods
00170 ***************************************************************************/
00171 
00172 template<typename Derived>
00173 template<unsigned int UpLo>
00174 typename SparseMatrixBase<Derived>::template ConstSelfAdjointViewReturnType<UpLo>::Type SparseMatrixBase<Derived>::selfadjointView() const
00175 {
00176   return SparseSelfAdjointView<const Derived, UpLo>(derived());
00177 }
00178 
00179 template<typename Derived>
00180 template<unsigned int UpLo>
00181 typename SparseMatrixBase<Derived>::template SelfAdjointViewReturnType<UpLo>::Type SparseMatrixBase<Derived>::selfadjointView()
00182 {
00183   return SparseSelfAdjointView<Derived, UpLo>(derived());
00184 }
00185 
00186 /***************************************************************************
00187 * Implementation of SparseSelfAdjointView methods
00188 ***************************************************************************/
00189 
00190 template<typename MatrixType, unsigned int Mode>
00191 template<typename DerivedU>
00192 SparseSelfAdjointView<MatrixType,Mode>&
00193 SparseSelfAdjointView<MatrixType,Mode>::rankUpdate(const SparseMatrixBase<DerivedU>& u, const Scalar& alpha)
00194 {
00195   SparseMatrix<Scalar,(MatrixType::Flags&RowMajorBit)?RowMajor:ColMajor> tmp = u * u.adjoint();
00196   if(alpha==Scalar(0))
00197     m_matrix = tmp.template triangularView<Mode>();
00198   else
00199     m_matrix += alpha * tmp.template triangularView<Mode>();
00200 
00201   return *this;
00202 }
00203 
00204 namespace internal {
00205   
00206 // TODO currently a selfadjoint expression has the form SelfAdjointView<.,.>
00207 //      in the future selfadjoint-ness should be defined by the expression traits
00208 //      such that Transpose<SelfAdjointView<.,.> > is valid. (currently TriangularBase::transpose() is overloaded to make it work)
00209 template<typename MatrixType, unsigned int Mode>
00210 struct evaluator_traits<SparseSelfAdjointView<MatrixType,Mode> >
00211 {
00212   typedef typename storage_kind_to_evaluator_kind<typename MatrixType::StorageKind>::Kind Kind;
00213   typedef SparseSelfAdjointShape Shape;
00214 };
00215 
00216 struct SparseSelfAdjoint2Sparse {};
00217 
00218 template<> struct AssignmentKind<SparseShape,SparseSelfAdjointShape> { typedef SparseSelfAdjoint2Sparse Kind; };
00219 template<> struct AssignmentKind<SparseSelfAdjointShape,SparseShape> { typedef Sparse2Sparse Kind; };
00220 
00221 template< typename DstXprType, typename SrcXprType, typename Functor, typename Scalar>
00222 struct Assignment<DstXprType, SrcXprType, Functor, SparseSelfAdjoint2Sparse, Scalar>
00223 {
00224   typedef typename DstXprType::StorageIndex StorageIndex;
00225   template<typename DestScalar,int StorageOrder>
00226   static void run(SparseMatrix<DestScalar,StorageOrder,StorageIndex> &dst, const SrcXprType &src, const internal::assign_op<typename DstXprType::Scalar> &/*func*/)
00227   {
00228     internal::permute_symm_to_fullsymm<SrcXprType::Mode>(src.matrix(), dst);
00229   }
00230   
00231   template<typename DestScalar>
00232   static void run(DynamicSparseMatrix<DestScalar,ColMajor,StorageIndex>& dst, const SrcXprType &src, const internal::assign_op<typename DstXprType::Scalar> &/*func*/)
00233   {
00234     // TODO directly evaluate into dst;
00235     SparseMatrix<DestScalar,ColMajor,StorageIndex> tmp(dst.rows(),dst.cols());
00236     internal::permute_symm_to_fullsymm<SrcXprType::Mode>(src.matrix(), tmp);
00237     dst = tmp;
00238   }
00239 };
00240 
00241 } // end namespace internal
00242 
00243 /***************************************************************************
00244 * Implementation of sparse self-adjoint time dense matrix
00245 ***************************************************************************/
00246 
00247 namespace internal {
00248 
00249 template<int Mode, typename SparseLhsType, typename DenseRhsType, typename DenseResType, typename AlphaType>
00250 inline void sparse_selfadjoint_time_dense_product(const SparseLhsType& lhs, const DenseRhsType& rhs, DenseResType& res, const AlphaType& alpha)
00251 {
00252   EIGEN_ONLY_USED_FOR_DEBUG(alpha);
00253   // TODO use alpha
00254   eigen_assert(alpha==AlphaType(1) && "alpha != 1 is not implemented yet, sorry");
00255   
00256   typedef evaluator<SparseLhsType> LhsEval;
00257   typedef typename evaluator<SparseLhsType>::InnerIterator LhsIterator;
00258   typedef typename SparseLhsType::Scalar LhsScalar;
00259   
00260   enum {
00261     LhsIsRowMajor = (LhsEval::Flags&RowMajorBit)==RowMajorBit,
00262     ProcessFirstHalf =
00263               ((Mode&(Upper|Lower))==(Upper|Lower))
00264           || ( (Mode&Upper) && !LhsIsRowMajor)
00265           || ( (Mode&Lower) && LhsIsRowMajor),
00266     ProcessSecondHalf = !ProcessFirstHalf
00267   };
00268   
00269   LhsEval lhsEval(lhs);
00270   
00271   for (Index j=0; j<lhs.outerSize(); ++j)
00272   {
00273     LhsIterator i(lhsEval,j);
00274     if (ProcessSecondHalf)
00275     {
00276       while (i && i.index()<j) ++i;
00277       if(i && i.index()==j)
00278       {
00279         res.row(j) += i.value() * rhs.row(j);
00280         ++i;
00281       }
00282     }
00283     for(; (ProcessFirstHalf ? i && i.index() < j : i) ; ++i)
00284     {
00285       Index a = LhsIsRowMajor ? j : i.index();
00286       Index b = LhsIsRowMajor ? i.index() : j;
00287       LhsScalar v = i.value();
00288       res.row(a) += (v) * rhs.row(b);
00289       res.row(b) += numext::conj(v) * rhs.row(a);
00290     }
00291     if (ProcessFirstHalf && i && (i.index()==j))
00292       res.row(j) += i.value() * rhs.row(j);
00293   }
00294 }
00295 
00296 
00297 template<typename LhsView, typename Rhs, int ProductType>
00298 struct generic_product_impl<LhsView, Rhs, SparseSelfAdjointShape, DenseShape, ProductType>
00299 {
00300   template<typename Dest>
00301   static void evalTo(Dest& dst, const LhsView& lhsView, const Rhs& rhs)
00302   {
00303     typedef typename LhsView::_MatrixTypeNested Lhs;
00304     typedef typename nested_eval<Lhs,Dynamic>::type LhsNested;
00305     typedef typename nested_eval<Rhs,Dynamic>::type RhsNested;
00306     LhsNested lhsNested(lhsView.matrix());
00307     RhsNested rhsNested(rhs);
00308     
00309     dst.setZero();
00310     internal::sparse_selfadjoint_time_dense_product<LhsView::Mode>(lhsNested, rhsNested, dst, typename Dest::Scalar(1));
00311   }
00312 };
00313 
00314 template<typename Lhs, typename RhsView, int ProductType>
00315 struct generic_product_impl<Lhs, RhsView, DenseShape, SparseSelfAdjointShape, ProductType>
00316 {
00317   template<typename Dest>
00318   static void evalTo(Dest& dst, const Lhs& lhs, const RhsView& rhsView)
00319   {
00320     typedef typename RhsView::_MatrixTypeNested Rhs;
00321     typedef typename nested_eval<Lhs,Dynamic>::type LhsNested;
00322     typedef typename nested_eval<Rhs,Dynamic>::type RhsNested;
00323     LhsNested lhsNested(lhs);
00324     RhsNested rhsNested(rhsView.matrix());
00325     
00326     dst.setZero();
00327     // transpoe everything
00328     Transpose<Dest> dstT(dst);
00329     internal::sparse_selfadjoint_time_dense_product<RhsView::Mode>(rhsNested.transpose(), lhsNested.transpose(), dstT, typename Dest::Scalar(1));
00330   }
00331 };
00332 
00333 // NOTE: these two overloads are needed to evaluate the sparse selfadjoint view into a full sparse matrix
00334 // TODO: maybe the copy could be handled by generic_product_impl so that these overloads would not be needed anymore
00335 
00336 template<typename LhsView, typename Rhs, int ProductTag>
00337 struct product_evaluator<Product<LhsView, Rhs, DefaultProduct>, ProductTag, SparseSelfAdjointShape, SparseShape>
00338   : public evaluator<typename Product<typename Rhs::PlainObject, Rhs, DefaultProduct>::PlainObject>
00339 {
00340   typedef Product<LhsView, Rhs, DefaultProduct> XprType;
00341   typedef typename XprType::PlainObject PlainObject;
00342   typedef evaluator<PlainObject> Base;
00343 
00344   product_evaluator(const XprType& xpr)
00345     : m_lhs(xpr.lhs()), m_result(xpr.rows(), xpr.cols())
00346   {
00347     ::new (static_cast<Base*>(this)) Base(m_result);
00348     generic_product_impl<typename Rhs::PlainObject, Rhs, SparseShape, SparseShape, ProductTag>::evalTo(m_result, m_lhs, xpr.rhs());
00349   }
00350   
00351 protected:
00352   typename Rhs::PlainObject m_lhs;
00353   PlainObject m_result;
00354 };
00355 
00356 template<typename Lhs, typename RhsView, int ProductTag>
00357 struct product_evaluator<Product<Lhs, RhsView, DefaultProduct>, ProductTag, SparseShape, SparseSelfAdjointShape>
00358   : public evaluator<typename Product<Lhs, typename Lhs::PlainObject, DefaultProduct>::PlainObject>
00359 {
00360   typedef Product<Lhs, RhsView, DefaultProduct> XprType;
00361   typedef typename XprType::PlainObject PlainObject;
00362   typedef evaluator<PlainObject> Base;
00363 
00364   product_evaluator(const XprType& xpr)
00365     : m_rhs(xpr.rhs()), m_result(xpr.rows(), xpr.cols())
00366   {
00367     ::new (static_cast<Base*>(this)) Base(m_result);
00368     generic_product_impl<Lhs, typename Lhs::PlainObject, SparseShape, SparseShape, ProductTag>::evalTo(m_result, xpr.lhs(), m_rhs);
00369   }
00370   
00371 protected:
00372   typename Lhs::PlainObject m_rhs;
00373   PlainObject m_result;
00374 };
00375 
00376 } // namespace internal
00377 
00378 /***************************************************************************
00379 * Implementation of symmetric copies and permutations
00380 ***************************************************************************/
00381 namespace internal {
00382 
00383 template<int Mode,typename MatrixType,int DestOrder>
00384 void permute_symm_to_fullsymm(const MatrixType& mat, SparseMatrix<typename MatrixType::Scalar,DestOrder,typename MatrixType::StorageIndex>& _dest, const typename MatrixType::StorageIndex* perm)
00385 {
00386   typedef typename MatrixType::StorageIndex StorageIndex;
00387   typedef typename MatrixType::Scalar Scalar;
00388   typedef SparseMatrix<Scalar,DestOrder,StorageIndex> Dest;
00389   typedef Matrix<StorageIndex,Dynamic,1> VectorI;
00390   typedef evaluator<MatrixType> MatEval;
00391   typedef typename evaluator<MatrixType>::InnerIterator MatIterator;
00392   
00393   MatEval matEval(mat);
00394   Dest& dest(_dest.derived());
00395   enum {
00396     StorageOrderMatch = int(Dest::IsRowMajor) == int(MatrixType::IsRowMajor)
00397   };
00398   
00399   Index size = mat.rows();
00400   VectorI count;
00401   count.resize(size);
00402   count.setZero();
00403   dest.resize(size,size);
00404   for(Index j = 0; j<size; ++j)
00405   {
00406     Index jp = perm ? perm[j] : j;
00407     for(MatIterator it(matEval,j); it; ++it)
00408     {
00409       Index i = it.index();
00410       Index r = it.row();
00411       Index c = it.col();
00412       Index ip = perm ? perm[i] : i;
00413       if(Mode==(Upper|Lower))
00414         count[StorageOrderMatch ? jp : ip]++;
00415       else if(r==c)
00416         count[ip]++;
00417       else if(( Mode==Lower && r>c) || ( Mode==Upper && r<c))
00418       {
00419         count[ip]++;
00420         count[jp]++;
00421       }
00422     }
00423   }
00424   Index nnz = count.sum();
00425   
00426   // reserve space
00427   dest.resizeNonZeros(nnz);
00428   dest.outerIndexPtr()[0] = 0;
00429   for(Index j=0; j<size; ++j)
00430     dest.outerIndexPtr()[j+1] = dest.outerIndexPtr()[j] + count[j];
00431   for(Index j=0; j<size; ++j)
00432     count[j] = dest.outerIndexPtr()[j];
00433   
00434   // copy data
00435   for(StorageIndex j = 0; j<size; ++j)
00436   {
00437     for(MatIterator it(matEval,j); it; ++it)
00438     {
00439       StorageIndex i = internal::convert_index<StorageIndex>(it.index());
00440       Index r = it.row();
00441       Index c = it.col();
00442       
00443       StorageIndex jp = perm ? perm[j] : j;
00444       StorageIndex ip = perm ? perm[i] : i;
00445       
00446       if(Mode==(Upper|Lower))
00447       {
00448         Index k = count[StorageOrderMatch ? jp : ip]++;
00449         dest.innerIndexPtr()[k] = StorageOrderMatch ? ip : jp;
00450         dest.valuePtr()[k] = it.value();
00451       }
00452       else if(r==c)
00453       {
00454         Index k = count[ip]++;
00455         dest.innerIndexPtr()[k] = ip;
00456         dest.valuePtr()[k] = it.value();
00457       }
00458       else if(( (Mode&Lower)==Lower && r>c) || ( (Mode&Upper)==Upper && r<c))
00459       {
00460         if(!StorageOrderMatch)
00461           std::swap(ip,jp);
00462         Index k = count[jp]++;
00463         dest.innerIndexPtr()[k] = ip;
00464         dest.valuePtr()[k] = it.value();
00465         k = count[ip]++;
00466         dest.innerIndexPtr()[k] = jp;
00467         dest.valuePtr()[k] = numext::conj(it.value());
00468       }
00469     }
00470   }
00471 }
00472 
00473 template<int _SrcMode,int _DstMode,typename MatrixType,int DstOrder>
00474 void permute_symm_to_symm(const MatrixType& mat, SparseMatrix<typename MatrixType::Scalar,DstOrder,typename MatrixType::StorageIndex>& _dest, const typename MatrixType::StorageIndex* perm)
00475 {
00476   typedef typename MatrixType::StorageIndex StorageIndex;
00477   typedef typename MatrixType::Scalar Scalar;
00478   SparseMatrix<Scalar,DstOrder,StorageIndex>& dest(_dest.derived());
00479   typedef Matrix<StorageIndex,Dynamic,1> VectorI;
00480   typedef evaluator<MatrixType> MatEval;
00481   typedef typename evaluator<MatrixType>::InnerIterator MatIterator;
00482 
00483   enum {
00484     SrcOrder = MatrixType::IsRowMajor ? RowMajor : ColMajor,
00485     StorageOrderMatch = int(SrcOrder) == int(DstOrder),
00486     DstMode = DstOrder==RowMajor ? (_DstMode==Upper ? Lower : Upper) : _DstMode,
00487     SrcMode = SrcOrder==RowMajor ? (_SrcMode==Upper ? Lower : Upper) : _SrcMode
00488   };
00489 
00490   MatEval matEval(mat);
00491   
00492   Index size = mat.rows();
00493   VectorI count(size);
00494   count.setZero();
00495   dest.resize(size,size);
00496   for(StorageIndex j = 0; j<size; ++j)
00497   {
00498     StorageIndex jp = perm ? perm[j] : j;
00499     for(MatIterator it(matEval,j); it; ++it)
00500     {
00501       StorageIndex i = it.index();
00502       if((int(SrcMode)==int(Lower) && i<j) || (int(SrcMode)==int(Upper) && i>j))
00503         continue;
00504                   
00505       StorageIndex ip = perm ? perm[i] : i;
00506       count[int(DstMode)==int(Lower) ? (std::min)(ip,jp) : (std::max)(ip,jp)]++;
00507     }
00508   }
00509   dest.outerIndexPtr()[0] = 0;
00510   for(Index j=0; j<size; ++j)
00511     dest.outerIndexPtr()[j+1] = dest.outerIndexPtr()[j] + count[j];
00512   dest.resizeNonZeros(dest.outerIndexPtr()[size]);
00513   for(Index j=0; j<size; ++j)
00514     count[j] = dest.outerIndexPtr()[j];
00515   
00516   for(StorageIndex j = 0; j<size; ++j)
00517   {
00518     
00519     for(MatIterator it(matEval,j); it; ++it)
00520     {
00521       StorageIndex i = it.index();
00522       if((int(SrcMode)==int(Lower) && i<j) || (int(SrcMode)==int(Upper) && i>j))
00523         continue;
00524                   
00525       StorageIndex jp = perm ? perm[j] : j;
00526       StorageIndex ip = perm? perm[i] : i;
00527       
00528       Index k = count[int(DstMode)==int(Lower) ? (std::min)(ip,jp) : (std::max)(ip,jp)]++;
00529       dest.innerIndexPtr()[k] = int(DstMode)==int(Lower) ? (std::max)(ip,jp) : (std::min)(ip,jp);
00530       
00531       if(!StorageOrderMatch) std::swap(ip,jp);
00532       if( ((int(DstMode)==int(Lower) && ip<jp) || (int(DstMode)==int(Upper) && ip>jp)))
00533         dest.valuePtr()[k] = numext::conj(it.value());
00534       else
00535         dest.valuePtr()[k] = it.value();
00536     }
00537   }
00538 }
00539 
00540 }
00541 
00542 // TODO implement twists in a more evaluator friendly fashion
00543 
00544 namespace internal {
00545 
00546 template<typename MatrixType, int Mode>
00547 struct traits<SparseSymmetricPermutationProduct<MatrixType,Mode> > : traits<MatrixType> {
00548 };
00549 
00550 }
00551 
00552 template<typename MatrixType,int Mode>
00553 class SparseSymmetricPermutationProduct
00554   : public EigenBase<SparseSymmetricPermutationProduct<MatrixType,Mode> >
00555 {
00556   public:
00557     typedef typename MatrixType::Scalar Scalar;
00558     typedef typename MatrixType::StorageIndex StorageIndex;
00559     enum {
00560       RowsAtCompileTime = internal::traits<SparseSymmetricPermutationProduct>::RowsAtCompileTime,
00561       ColsAtCompileTime = internal::traits<SparseSymmetricPermutationProduct>::ColsAtCompileTime
00562     };
00563   protected:
00564     typedef PermutationMatrix<Dynamic,Dynamic,StorageIndex> Perm;
00565   public:
00566     typedef Matrix<StorageIndex,Dynamic,1> VectorI;
00567     typedef typename MatrixType::Nested MatrixTypeNested;
00568     typedef typename internal::remove_all<MatrixTypeNested>::type NestedExpression;
00569     
00570     SparseSymmetricPermutationProduct(const MatrixType& mat, const Perm& perm)
00571       : m_matrix(mat), m_perm(perm)
00572     {}
00573     
00574     inline Index rows() const { return m_matrix.rows(); }
00575     inline Index cols() const { return m_matrix.cols(); }
00576         
00577     const NestedExpression& matrix() const { return m_matrix; }
00578     const Perm& perm() const { return m_perm; }
00579     
00580   protected:
00581     MatrixTypeNested m_matrix;
00582     const Perm& m_perm;
00583 
00584 };
00585 
00586 namespace internal {
00587   
00588 template<typename DstXprType, typename MatrixType, int Mode, typename Scalar>
00589 struct Assignment<DstXprType, SparseSymmetricPermutationProduct<MatrixType,Mode>, internal::assign_op<Scalar>, Sparse2Sparse>
00590 {
00591   typedef SparseSymmetricPermutationProduct<MatrixType,Mode> SrcXprType;
00592   typedef typename DstXprType::StorageIndex DstIndex;
00593   template<int Options>
00594   static void run(SparseMatrix<Scalar,Options,DstIndex> &dst, const SrcXprType &src, const internal::assign_op<Scalar> &)
00595   {
00596     // internal::permute_symm_to_fullsymm<Mode>(m_matrix,_dest,m_perm.indices().data());
00597     SparseMatrix<Scalar,(Options&RowMajor)==RowMajor ? ColMajor : RowMajor, DstIndex> tmp;
00598     internal::permute_symm_to_fullsymm<Mode>(src.matrix(),tmp,src.perm().indices().data());
00599     dst = tmp;
00600   }
00601   
00602   template<typename DestType,unsigned int DestMode>
00603   static void run(SparseSelfAdjointView<DestType,DestMode>& dst, const SrcXprType &src, const internal::assign_op<Scalar> &)
00604   {
00605     internal::permute_symm_to_symm<Mode,DestMode>(src.matrix(),dst.matrix(),src.perm().indices().data());
00606   }
00607 };
00608 
00609 } // end namespace internal
00610 
00611 } // end namespace Eigen
00612 
00613 #endif // EIGEN_SPARSE_SELFADJOINTVIEW_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines