Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-22 10:34:43

0001 // This file is part of Eigen, a lightweight C++ template library
0002 // for linear algebra.
0003 //
0004 // Copyright (C) 2008-2014 Gael Guennebaud <gael.guennebaud@inria.fr>
0005 //
0006 // This Source Code Form is subject to the terms of the Mozilla
0007 // Public License v. 2.0. If a copy of the MPL was not distributed
0008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
0009 
0010 #ifndef EIGEN_SPARSEREDUX_H
0011 #define EIGEN_SPARSEREDUX_H
0012 
0013 namespace Eigen { 
0014 
0015 template<typename Derived>
0016 typename internal::traits<Derived>::Scalar
0017 SparseMatrixBase<Derived>::sum() const
0018 {
0019   eigen_assert(rows()>0 && cols()>0 && "you are using a non initialized matrix");
0020   Scalar res(0);
0021   internal::evaluator<Derived> thisEval(derived());
0022   for (Index j=0; j<outerSize(); ++j)
0023     for (typename internal::evaluator<Derived>::InnerIterator iter(thisEval,j); iter; ++iter)
0024       res += iter.value();
0025   return res;
0026 }
0027 
0028 template<typename _Scalar, int _Options, typename _Index>
0029 typename internal::traits<SparseMatrix<_Scalar,_Options,_Index> >::Scalar
0030 SparseMatrix<_Scalar,_Options,_Index>::sum() const
0031 {
0032   eigen_assert(rows()>0 && cols()>0 && "you are using a non initialized matrix");
0033   if(this->isCompressed())
0034     return Matrix<Scalar,1,Dynamic>::Map(m_data.valuePtr(), m_data.size()).sum();
0035   else
0036     return Base::sum();
0037 }
0038 
0039 template<typename _Scalar, int _Options, typename _Index>
0040 typename internal::traits<SparseVector<_Scalar,_Options, _Index> >::Scalar
0041 SparseVector<_Scalar,_Options,_Index>::sum() const
0042 {
0043   eigen_assert(rows()>0 && cols()>0 && "you are using a non initialized matrix");
0044   return Matrix<Scalar,1,Dynamic>::Map(m_data.valuePtr(), m_data.size()).sum();
0045 }
0046 
0047 } // end namespace Eigen
0048 
0049 #endif // EIGEN_SPARSEREDUX_H