#ifndef _utl_SparseMatrixVectorOp_h_ #define _utl_SparseMatrixVectorOp_h_ /** \file Sparse Matrix-Vector operations \author Darko Veberic \version $Id$ \date 8 Jun 2008 */ #include #include #include #include namespace boost { namespace lambda { /// specialization for SMatrix<> * SVector<> template class plain_return_type_2< arithmetic_action, utl::SparseMatrix, utl::SparseVector > { private: // delegate to the type of T * U typedef typename return_type_2< arithmetic_action, T, U >::type res_type; public: typedef utl::SparseVector type; }; } } namespace utl { template typename boost::lambda::return_type_2< boost::lambda::arithmetic_action, SparseMatrix, SparseVector >::type operator*(const SparseMatrix& m, const SparseVector& v) { typedef typename boost::lambda::return_type_2< boost::lambda::arithmetic_action, SparseMatrix, SparseVector >::type ResultType; ResultType result; for (typename SparseMatrix::ConstIterator mIt = m.SparseBegin(); mIt != m.SparseEnd(); ++mIt) { const unsigned int j = mIt.GetColumn(); typename SparseVector::ConstIterator aj = v.Find(j); if (aj != v.SparseEnd()) result(mIt.GetRow()) += mIt() * aj(); } return result; } } #endif