v1.0
SparseRedux.h
Go to the documentation of this file.
1
// This file is part of Eigen, a lightweight C++ template library
2
// for linear algebra.
3
//
4
// Copyright (C) 2008-2014 Gael Guennebaud <gael.guennebaud@inria.fr>
5
//
6
// This Source Code Form is subject to the terms of the Mozilla
7
// Public License v. 2.0. If a copy of the MPL was not distributed
8
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
10
#ifndef EIGEN_SPARSEREDUX_H
11
#define EIGEN_SPARSEREDUX_H
12
13
// IWYU pragma: private
14
#include "
./InternalHeaderCheck.h
"
15
16
namespace
Eigen
{
17
18
template
<
typename
Derived>
19
typename
internal::traits<Derived>::Scalar
SparseMatrixBase<Derived>::sum
()
const
{
20
eigen_assert
(
rows
() > 0 &&
cols
() > 0 &&
"you are using a non initialized matrix"
);
21
Scalar
res
(0);
22
internal::evaluator<Derived>
thisEval(derived());
23
for
(
Index
j
= 0;
j
< outerSize(); ++
j
)
24
for
(
typename
internal::evaluator<Derived>::InnerIterator
iter(thisEval,
j
); iter; ++iter)
res
+= iter.value();
25
return
res
;
26
}
27
28
template
<
typename
Scalar_,
int
Options_,
typename
Index_>
29
typename
internal::traits<SparseMatrix<Scalar_, Options_, Index_>
>
::Scalar
30
SparseMatrix<Scalar_, Options_, Index_>::sum
()
const
{
31
eigen_assert
(
rows
() > 0 &&
cols
() > 0 &&
"you are using a non initialized matrix"
);
32
if
(this->isCompressed())
33
return
Matrix<Scalar, 1, Dynamic>::Map
(m_data.valuePtr(), m_data.size()).sum();
34
else
35
return
Base::sum();
36
}
37
38
template
<
typename
Scalar_,
int
Options_,
typename
Index_>
39
typename
internal::traits<SparseVector<Scalar_, Options_, Index_>
>
::Scalar
40
SparseVector<Scalar_, Options_, Index_>::sum
()
const
{
41
eigen_assert
(
rows
() > 0 &&
cols
() > 0 &&
"you are using a non initialized matrix"
);
42
return
Matrix<Scalar, 1, Dynamic>::Map
(m_data.valuePtr(), m_data.size()).sum();
43
}
44
45
}
// end namespace Eigen
46
47
#endif
// EIGEN_SPARSEREDUX_H
eigen_assert
#define eigen_assert(x)
Definition:
Macros.h:910
res
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
Definition:
PartialRedux_count.cpp:3
rows
int rows
Definition:
Tutorial_commainit_02.cpp:1
cols
int cols
Definition:
Tutorial_commainit_02.cpp:1
Scalar
SCALAR Scalar
Definition:
bench_gemm.cpp:45
Eigen::PlainObjectBase< Matrix< Scalar_, Rows_, Cols_, Options_, MaxRows_, MaxCols_ > >::Map
static ConstMapType Map(const Scalar *data)
Definition:
PlainObjectBase.h:595
Eigen::SparseMatrixBase::Scalar
internal::traits< Derived >::Scalar Scalar
Definition:
SparseMatrixBase.h:32
Eigen::SparseMatrixBase::sum
Scalar sum() const
Definition:
SparseRedux.h:19
Eigen::SparseMatrix::sum
Scalar sum() const
Definition:
SparseRedux.h:30
Eigen::SparseVector::sum
Scalar sum() const
Definition:
SparseRedux.h:40
Eigen
Namespace containing all symbols from the Eigen library.
Definition:
bench_norm.cpp:70
Eigen::EigenBase::Index
Eigen::Index Index
The interface type of indices.
Definition:
EigenBase.h:43
Eigen::internal::evaluator
Definition:
CoreEvaluators.h:104
Eigen::internal::traits
Definition:
ForwardDeclarations.h:21
j
std::ptrdiff_t j
Definition:
tut_arithmetic_redux_minmax.cpp:2
InternalHeaderCheck.h
Eigen
Eigen
src
SparseCore
SparseRedux.h
Generated on Wed Aug 27 2025 17:03:10 for MercuryDPM by
1.9.1