summaryrefslogtreecommitdiffhomepage
path: root/eigen/Eigen/src/SparseCore/SparseRedux.h
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2016-09-18 12:42:15 +0200
committerStanislaw Halik <sthalik@misaki.pl>2016-11-02 15:12:04 +0100
commit44861dcbfeee041223c4aac1ee075e92fa4daa01 (patch)
tree6dfdfd9637846a7aedd71ace97d7d2ad366496d7 /eigen/Eigen/src/SparseCore/SparseRedux.h
parentf3fe458b9e0a29a99a39d47d9a76dc18964b6fec (diff)
update
Diffstat (limited to 'eigen/Eigen/src/SparseCore/SparseRedux.h')
-rw-r--r--eigen/Eigen/src/SparseCore/SparseRedux.h48
1 files changed, 48 insertions, 0 deletions
diff --git a/eigen/Eigen/src/SparseCore/SparseRedux.h b/eigen/Eigen/src/SparseCore/SparseRedux.h
new file mode 100644
index 0000000..51ed9ae
--- /dev/null
+++ b/eigen/Eigen/src/SparseCore/SparseRedux.h
@@ -0,0 +1,48 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_SPARSEREDUX_H
+#define EIGEN_SPARSEREDUX_H
+
+namespace Eigen {
+
+template<typename Derived>
+typename internal::traits<Derived>::Scalar
+SparseMatrixBase<Derived>::sum() const
+{
+ eigen_assert(rows()>0 && cols()>0 && "you are using a non initialized matrix");
+ Scalar res(0);
+ for (Index j=0; j<outerSize(); ++j)
+ for (typename Derived::InnerIterator iter(derived(),j); iter; ++iter)
+ res += iter.value();
+ return res;
+}
+
+template<typename _Scalar, int _Options, typename _Index>
+typename internal::traits<SparseMatrix<_Scalar,_Options,_Index> >::Scalar
+SparseMatrix<_Scalar,_Options,_Index>::sum() const
+{
+ eigen_assert(rows()>0 && cols()>0 && "you are using a non initialized matrix");
+ if(this->isCompressed())
+ return Matrix<Scalar,1,Dynamic>::Map(m_data.valuePtr(), m_data.size()).sum();
+ else
+ return Base::sum();
+}
+
+template<typename _Scalar, int _Options, typename _Index>
+typename internal::traits<SparseVector<_Scalar,_Options, _Index> >::Scalar
+SparseVector<_Scalar,_Options,_Index>::sum() const
+{
+ eigen_assert(rows()>0 && cols()>0 && "you are using a non initialized matrix");
+ return Matrix<Scalar,1,Dynamic>::Map(m_data.valuePtr(), m_data.size()).sum();
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_SPARSEREDUX_H