mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-03-07 18:27:40 +08:00
Update sparse reduxions and sparse-vectors to evaluators.
This commit is contained in:
parent
b868bfb84a
commit
a7bd4c455a
@ -45,10 +45,10 @@ struct Sparse {};
|
||||
#include "src/SparseCore/SparseCwiseBinaryOp.h"
|
||||
#include "src/SparseCore/SparseTranspose.h"
|
||||
#include "src/SparseCore/SparseBlock.h"
|
||||
#ifndef EIGEN_TEST_EVALUATORS
|
||||
#include "src/SparseCore/SparseDot.h"
|
||||
#include "src/SparseCore/SparsePermutation.h"
|
||||
#include "src/SparseCore/SparseRedux.h"
|
||||
#ifndef EIGEN_TEST_EVALUATORS
|
||||
#include "src/SparseCore/SparsePermutation.h"
|
||||
#include "src/SparseCore/SparseFuzzy.h"
|
||||
#include "src/SparseCore/ConservativeSparseSparseProduct.h"
|
||||
#include "src/SparseCore/SparseSparseProductWithPruning.h"
|
||||
|
@ -26,7 +26,12 @@ SparseMatrixBase<Derived>::dot(const MatrixBase<OtherDerived>& other) const
|
||||
eigen_assert(size() == other.size());
|
||||
eigen_assert(other.size()>0 && "you are using a non initialized vector");
|
||||
|
||||
#ifndef EIGEN_TEST_EVALUATORS
|
||||
typename Derived::InnerIterator i(derived(),0);
|
||||
#else
|
||||
typename internal::evaluator<Derived>::type thisEval(derived());
|
||||
typename internal::evaluator<Derived>::InnerIterator i(thisEval, 0);
|
||||
#endif
|
||||
Scalar res(0);
|
||||
while (i)
|
||||
{
|
||||
@ -49,6 +54,7 @@ SparseMatrixBase<Derived>::dot(const SparseMatrixBase<OtherDerived>& other) cons
|
||||
|
||||
eigen_assert(size() == other.size());
|
||||
|
||||
#ifndef EIGEN_TEST_EVALUATORS
|
||||
typedef typename Derived::Nested Nested;
|
||||
typedef typename OtherDerived::Nested OtherNested;
|
||||
typedef typename internal::remove_all<Nested>::type NestedCleaned;
|
||||
@ -59,6 +65,13 @@ SparseMatrixBase<Derived>::dot(const SparseMatrixBase<OtherDerived>& other) cons
|
||||
|
||||
typename NestedCleaned::InnerIterator i(nthis,0);
|
||||
typename OtherNestedCleaned::InnerIterator j(nother,0);
|
||||
#else
|
||||
typename internal::evaluator<Derived>::type thisEval(derived());
|
||||
typename internal::evaluator<Derived>::InnerIterator i(thisEval, 0);
|
||||
|
||||
typename internal::evaluator<OtherDerived>::type otherEval(other.derived());
|
||||
typename internal::evaluator<OtherDerived>::InnerIterator j(otherEval, 0);
|
||||
#endif
|
||||
Scalar res(0);
|
||||
while (i && j)
|
||||
{
|
||||
|
@ -18,8 +18,14 @@ SparseMatrixBase<Derived>::sum() const
|
||||
{
|
||||
eigen_assert(rows()>0 && cols()>0 && "you are using a non initialized matrix");
|
||||
Scalar res(0);
|
||||
#ifndef EIGEN_TEST_EVALUATORS
|
||||
for (Index j=0; j<outerSize(); ++j)
|
||||
for (typename Derived::InnerIterator iter(derived(),j); iter; ++iter)
|
||||
#else
|
||||
typename internal::evaluator<Derived>::type thisEval(derived());
|
||||
for (Index j=0; j<outerSize(); ++j)
|
||||
for (typename internal::evaluator<Derived>::InnerIterator iter(thisEval,j); iter; ++iter)
|
||||
#endif
|
||||
res += iter.value();
|
||||
return res;
|
||||
}
|
||||
|
@ -433,6 +433,28 @@ struct sparse_vector_assign_selector<Dest,Src,SVA_Outer> {
|
||||
}
|
||||
};
|
||||
#else // EIGEN_TEST_EVALUATORS
|
||||
|
||||
template<typename _Scalar, int _Options, typename _Index>
|
||||
struct evaluator<SparseVector<_Scalar,_Options,_Index> >
|
||||
: evaluator_base<SparseVector<_Scalar,_Options,_Index> >
|
||||
{
|
||||
typedef SparseVector<_Scalar,_Options,_Index> SparseVectorType;
|
||||
typedef typename SparseVectorType::InnerIterator InnerIterator;
|
||||
typedef typename SparseVectorType::ReverseInnerIterator ReverseInnerIterator;
|
||||
|
||||
enum {
|
||||
CoeffReadCost = NumTraits<_Scalar>::ReadCost,
|
||||
Flags = SparseVectorType::Flags
|
||||
};
|
||||
|
||||
evaluator(const SparseVectorType &mat) : m_matrix(mat) {}
|
||||
|
||||
operator SparseVectorType&() { return m_matrix.const_cast_derived(); }
|
||||
operator const SparseVectorType&() const { return m_matrix; }
|
||||
|
||||
const SparseVectorType &m_matrix;
|
||||
};
|
||||
|
||||
template< typename Dest, typename Src>
|
||||
struct sparse_vector_assign_selector<Dest,Src,SVA_Inner> {
|
||||
static void run(Dest& dst, const Src& src) {
|
||||
|
Loading…
Reference in New Issue
Block a user