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 // Eigen is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 3 of the License, or (at your option) any later version.
00010 //
00011 // Alternatively, you can redistribute it and/or
00012 // modify it under the terms of the GNU General Public License as
00013 // published by the Free Software Foundation; either version 2 of
00014 // the License, or (at your option) any later version.
00015 //
00016 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00017 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00018 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00019 // GNU General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License and a copy of the GNU General Public License along with
00023 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00024 
00025 #ifndef EIGEN_SPARSEREDUX_H
00026 #define EIGEN_SPARSEREDUX_H
00027 
00028 template<typename Derived>
00029 typename internal::traits<Derived>::Scalar
00030 SparseMatrixBase<Derived>::sum() const
00031 {
00032   eigen_assert(rows()>0 && cols()>0 && "you are using a non initialized matrix");
00033   Scalar res = 0;
00034   for (Index j=0; j<outerSize(); ++j)
00035     for (typename Derived::InnerIterator iter(derived(),j); iter; ++iter)
00036       res += iter.value();
00037   return res;
00038 }
00039 
00040 template<typename _Scalar, int _Options, typename _Index>
00041 typename internal::traits<SparseMatrix<_Scalar,_Options,_Index> >::Scalar
00042 SparseMatrix<_Scalar,_Options,_Index>::sum() const
00043 {
00044   eigen_assert(rows()>0 && cols()>0 && "you are using a non initialized matrix");
00045   return Matrix<Scalar,1,Dynamic>::Map(&m_data.value(0), m_data.size()).sum();
00046 }
00047 
00048 template<typename _Scalar, int _Options, typename _Index>
00049 typename internal::traits<SparseVector<_Scalar,_Options, _Index> >::Scalar
00050 SparseVector<_Scalar,_Options,_Index>::sum() const
00051 {
00052   eigen_assert(rows()>0 && cols()>0 && "you are using a non initialized matrix");
00053   return Matrix<Scalar,1,Dynamic>::Map(&m_data.value(0), m_data.size()).sum();
00054 }
00055 
00056 #endif // EIGEN_SPARSEREDUX_H


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:32:54