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 namespace Eigen {
14 
15 template<typename Derived>
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>
31 {
32  eigen_assert(rows()>0 && cols()>0 && "you are using a non initialized matrix");
33  if(this->isCompressed())
34  return Matrix<Scalar,1,Dynamic>::Map(m_data.valuePtr(), m_data.size()).sum();
35  else
36  return Base::sum();
37 }
38 
39 template<typename _Scalar, int _Options, typename _Index>
42 {
43  eigen_assert(rows()>0 && cols()>0 && "you are using a non initialized matrix");
44  return Matrix<Scalar,1,Dynamic>::Map(m_data.valuePtr(), m_data.size()).sum();
45 }
46 
47 } // end namespace Eigen
48 
49 #endif // EIGEN_SPARSEREDUX_H
SCALAR Scalar
Definition: bench_gemm.cpp:33
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
iterator iter(handle obj)
Definition: pytypes.h:1547
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:38
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
Scalar sum() const
Definition: SparseRedux.h:41
internal::traits< Derived >::Scalar Scalar
object value
Definition: pytypes.h:892
#define eigen_assert(x)
Definition: Macros.h:579
const mpreal sum(const mpreal tab[], const unsigned long int n, int &status, mp_rnd_t mode=mpreal::get_default_rnd())
Definition: mpreal.h:2381
Scalar sum() const
Definition: SparseRedux.h:17
std::ptrdiff_t j
Scalar sum() const
Definition: SparseRedux.h:30


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:44:36