MOAB
4.9.3pre
|
00001 // This file is part of Eigen, a lightweight C++ template library 00002 // for linear algebra. 00003 // 00004 // Copyright (C) 2008-2014 Gael Guennebaud <[email protected]> 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 internal::evaluator<Derived> thisEval(derived()); 00022 for (Index j=0; j<outerSize(); ++j) 00023 for (typename internal::evaluator<Derived>::InnerIterator iter(thisEval,j); iter; ++iter) 00024 res += iter.value(); 00025 return res; 00026 } 00027 00028 template<typename _Scalar, int _Options, typename _Index> 00029 typename internal::traits<SparseMatrix<_Scalar,_Options,_Index> >::Scalar 00030 SparseMatrix<_Scalar,_Options,_Index>::sum() const 00031 { 00032 eigen_assert(rows()>0 && cols()>0 && "you are using a non initialized matrix"); 00033 return Matrix<Scalar,1,Dynamic>::Map(m_data.valuePtr(), m_data.size()).sum(); 00034 } 00035 00036 template<typename _Scalar, int _Options, typename _Index> 00037 typename internal::traits<SparseVector<_Scalar,_Options, _Index> >::Scalar 00038 SparseVector<_Scalar,_Options,_Index>::sum() const 00039 { 00040 eigen_assert(rows()>0 && cols()>0 && "you are using a non initialized matrix"); 00041 return Matrix<Scalar,1,Dynamic>::Map(m_data.valuePtr(), m_data.size()).sum(); 00042 } 00043 00044 } // end namespace Eigen 00045 00046 #endif // EIGEN_SPARSEREDUX_H