SparseRedux.h
Go to the documentation of this file.
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
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
#define eigen_assert(x)
Definition: Macros.h:902
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
internal::traits< Derived >::Scalar Scalar
Scalar sum() const
Definition: SparseRedux.h:19
Scalar sum() const
Definition: SparseRedux.h:32
Scalar sum() const
Definition: SparseRedux.h:43
: InteropHeaders
Definition: Core:139
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:41
std::ptrdiff_t j