source: pacpussensors/trunk/Vislab/lib3dv/eigen/Eigen/src/SparseCore/SparseRedux.h@ 136

Last change on this file since 136 was 136, checked in by ldecherf, 7 years ago

Doc

File size: 1.6 KB
Line 
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2008 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
13namespace Eigen {
14
15template<typename Derived>
16typename internal::traits<Derived>::Scalar
17SparseMatrixBase<Derived>::sum() const
18{
19 eigen_assert(rows()>0 && cols()>0 && "you are using a non initialized matrix");
20 Scalar res(0);
21 for (Index j=0; j<outerSize(); ++j)
22 for (typename Derived::InnerIterator iter(derived(),j); iter; ++iter)
23 res += iter.value();
24 return res;
25}
26
27template<typename _Scalar, int _Options, typename _Index>
28typename internal::traits<SparseMatrix<_Scalar,_Options,_Index> >::Scalar
29SparseMatrix<_Scalar,_Options,_Index>::sum() const
30{
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
40SparseVector<_Scalar,_Options,_Index>::sum() const
41{
42 eigen_assert(rows()>0 && cols()>0 && "you are using a non initialized matrix");
43 return Matrix<Scalar,1,Dynamic>::Map(m_data.valuePtr(), m_data.size()).sum();
44}
45
46} // end namespace Eigen
47
48#endif // EIGEN_SPARSEREDUX_H
Note: See TracBrowser for help on using the repository browser.