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