Eigen  3.2.92
SparseRedux.h
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2008-2014 Gael Guennebaud <gael.guennebaud@inria.fr>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #ifndef EIGEN_SPARSEREDUX_H
11 #define EIGEN_SPARSEREDUX_H
12 
13 namespace Eigen {
14 
15 template<typename Derived>
16 typename internal::traits<Derived>::Scalar
17 SparseMatrixBase<Derived>::sum() const
18 {
19  eigen_assert(rows()>0 && cols()>0 && "you are using a non initialized matrix");
20  Scalar res(0);
21  internal::evaluator<Derived> thisEval(derived());
22  for (Index j=0; j<outerSize(); ++j)
23  for (typename internal::evaluator<Derived>::InnerIterator iter(thisEval,j); iter; ++iter)
24  res += iter.value();
25  return res;
26 }
27 
28 template<typename _Scalar, int _Options, typename _Index>
29 typename internal::traits<SparseMatrix<_Scalar,_Options,_Index> >::Scalar
31 {
32  eigen_assert(rows()>0 && cols()>0 && "you are using a non initialized matrix");
33  return Matrix<Scalar,1,Dynamic>::Map(&m_data.value(0), m_data.size()).sum();
34 }
35 
36 template<typename _Scalar, int _Options, typename _Index>
37 typename internal::traits<SparseVector<_Scalar,_Options, _Index> >::Scalar
39 {
40  eigen_assert(rows()>0 && cols()>0 && "you are using a non initialized matrix");
41  return Matrix<Scalar,1,Dynamic>::Map(&m_data.value(0), m_data.size()).sum();
42 }
43 
44 } // end namespace Eigen
45 
46 #endif // EIGEN_SPARSEREDUX_H
Definition: LDLT.h:16
Scalar sum() const
Definition: SparseRedux.h:38
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:178
Scalar sum() const
Definition: SparseRedux.h:30