Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef EIGEN_SPARSEREDUX_H
00026 #define EIGEN_SPARSEREDUX_H
00027
00028 namespace Eigen {
00029
00030 template<typename Derived>
00031 typename internal::traits<Derived>::Scalar
00032 SparseMatrixBase<Derived>::sum() const
00033 {
00034 eigen_assert(rows()>0 && cols()>0 && "you are using a non initialized matrix");
00035 Scalar res(0);
00036 for (Index j=0; j<outerSize(); ++j)
00037 for (typename Derived::InnerIterator iter(derived(),j); iter; ++iter)
00038 res += iter.value();
00039 return res;
00040 }
00041
00042 template<typename _Scalar, int _Options, typename _Index>
00043 typename internal::traits<SparseMatrix<_Scalar,_Options,_Index> >::Scalar
00044 SparseMatrix<_Scalar,_Options,_Index>::sum() const
00045 {
00046 eigen_assert(rows()>0 && cols()>0 && "you are using a non initialized matrix");
00047 return Matrix<Scalar,1,Dynamic>::Map(&m_data.value(0), m_data.size()).sum();
00048 }
00049
00050 template<typename _Scalar, int _Options, typename _Index>
00051 typename internal::traits<SparseVector<_Scalar,_Options, _Index> >::Scalar
00052 SparseVector<_Scalar,_Options,_Index>::sum() const
00053 {
00054 eigen_assert(rows()>0 && cols()>0 && "you are using a non initialized matrix");
00055 return Matrix<Scalar,1,Dynamic>::Map(&m_data.value(0), m_data.size()).sum();
00056 }
00057
00058 }
00059
00060 #endif // EIGEN_SPARSEREDUX_H