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