SparseRedux.h
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
00005 //
00006 // This Source Code Form is subject to the terms of the Mozilla
00007 // Public License v. 2.0. If a copy of the MPL was not distributed
00008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
00009 
00010 #ifndef EIGEN_SPARSEREDUX_H
00011 #define EIGEN_SPARSEREDUX_H
00012 
00013 namespace Eigen { 
00014 
00015 template<typename Derived>
00016 typename internal::traits<Derived>::Scalar
00017 SparseMatrixBase<Derived>::sum() const
00018 {
00019   eigen_assert(rows()>0 && cols()>0 && "you are using a non initialized matrix");
00020   Scalar res(0);
00021   for (Index j=0; j<outerSize(); ++j)
00022     for (typename Derived::InnerIterator iter(derived(),j); iter; ++iter)
00023       res += iter.value();
00024   return res;
00025 }
00026 
00027 template<typename _Scalar, int _Options, typename _Index>
00028 typename internal::traits<SparseMatrix<_Scalar,_Options,_Index> >::Scalar
00029 SparseMatrix<_Scalar,_Options,_Index>::sum() const
00030 {
00031   eigen_assert(rows()>0 && cols()>0 && "you are using a non initialized matrix");
00032   return Matrix<Scalar,1,Dynamic>::Map(&m_data.value(0), m_data.size()).sum();
00033 }
00034 
00035 template<typename _Scalar, int _Options, typename _Index>
00036 typename internal::traits<SparseVector<_Scalar,_Options, _Index> >::Scalar
00037 SparseVector<_Scalar,_Options,_Index>::sum() const
00038 {
00039   eigen_assert(rows()>0 && cols()>0 && "you are using a non initialized matrix");
00040   return Matrix<Scalar,1,Dynamic>::Map(&m_data.value(0), m_data.size()).sum();
00041 }
00042 
00043 } // end namespace Eigen
00044 
00045 #endif // EIGEN_SPARSEREDUX_H


win_eigen
Author(s): Daniel Stonier
autogenerated on Wed Sep 16 2015 07:12:05