Eigen  3.4.90 (git rev 67eeba6e720c5745abc77ae6c92ce0a44aa7b7ae)
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 #include "./InternalHeaderCheck.h"
14 
15 namespace Eigen {
16 
17 template<typename Derived>
18 typename internal::traits<Derived>::Scalar
19 SparseMatrixBase<Derived>::sum() const
20 {
21  eigen_assert(rows()>0 && cols()>0 && "you are using a non initialized matrix");
22  Scalar res(0);
23  internal::evaluator<Derived> thisEval(derived());
24  for (Index j=0; j<outerSize(); ++j)
25  for (typename internal::evaluator<Derived>::InnerIterator iter(thisEval,j); iter; ++iter)
26  res += iter.value();
27  return res;
28 }
29 
30 template<typename Scalar_, int Options_, typename Index_>
31 typename internal::traits<SparseMatrix<Scalar_,Options_,Index_> >::Scalar
33 {
34  eigen_assert(rows()>0 && cols()>0 && "you are using a non initialized matrix");
35  if(this->isCompressed())
36  return Matrix<Scalar,1,Dynamic>::Map(m_data.valuePtr(), m_data.size()).sum();
37  else
38  return Base::sum();
39 }
40 
41 template<typename Scalar_, int Options_, typename Index_>
42 typename internal::traits<SparseVector<Scalar_,Options_, Index_> >::Scalar
44 {
45  eigen_assert(rows()>0 && cols()>0 && "you are using a non initialized matrix");
46  return Matrix<Scalar,1,Dynamic>::Map(m_data.valuePtr(), m_data.size()).sum();
47 }
48 
49 } // end namespace Eigen
50 
51 #endif // EIGEN_SPARSEREDUX_H
static ConstMapType Map(const Scalar *data)
Definition: PlainObjectBase.h:642
Scalar sum() const
Definition: SparseRedux.h:32
Scalar sum() const
Definition: SparseRedux.h:43
Namespace containing all symbols from the Eigen library.
Definition: Core:139
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:59