mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-04-22 01:29:35 +08:00
added the SparseView class.
This commit is contained in:
parent
9e00697ccc
commit
dcd39a96e1
@ -111,6 +111,7 @@ struct Sparse {};
|
|||||||
#include "src/Sparse/SparseLLT.h"
|
#include "src/Sparse/SparseLLT.h"
|
||||||
#include "src/Sparse/SparseLDLT.h"
|
#include "src/Sparse/SparseLDLT.h"
|
||||||
#include "src/Sparse/SparseLU.h"
|
#include "src/Sparse/SparseLU.h"
|
||||||
|
#include "src/Sparse/SparseView.h"
|
||||||
|
|
||||||
#ifdef EIGEN_CHOLMOD_SUPPORT
|
#ifdef EIGEN_CHOLMOD_SUPPORT
|
||||||
# include "src/Sparse/CholmodSupport.h"
|
# include "src/Sparse/CholmodSupport.h"
|
||||||
|
@ -215,6 +215,8 @@ template<typename Derived> class MatrixBase
|
|||||||
template<unsigned int UpLo> SelfAdjointView<Derived, UpLo> selfadjointView();
|
template<unsigned int UpLo> SelfAdjointView<Derived, UpLo> selfadjointView();
|
||||||
template<unsigned int UpLo> const SelfAdjointView<Derived, UpLo> selfadjointView() const;
|
template<unsigned int UpLo> const SelfAdjointView<Derived, UpLo> selfadjointView() const;
|
||||||
|
|
||||||
|
const SparseView<Derived> sparseView(const Scalar m_reference = Scalar(0),
|
||||||
|
typename NumTraits<Scalar>::Real m_epsilon = NumTraits<Scalar>::dummy_precision()) const;
|
||||||
static const IdentityReturnType Identity();
|
static const IdentityReturnType Identity();
|
||||||
static const IdentityReturnType Identity(Index rows, Index cols);
|
static const IdentityReturnType Identity(Index rows, Index cols);
|
||||||
static const BasisReturnType Unit(Index size, Index i);
|
static const BasisReturnType Unit(Index size, Index i);
|
||||||
|
@ -86,6 +86,7 @@ template<typename MatrixType, int MapOptions=Unaligned, typename StrideType = St
|
|||||||
template<typename Derived> class TriangularBase;
|
template<typename Derived> class TriangularBase;
|
||||||
template<typename MatrixType, unsigned int Mode> class TriangularView;
|
template<typename MatrixType, unsigned int Mode> class TriangularView;
|
||||||
template<typename MatrixType, unsigned int Mode> class SelfAdjointView;
|
template<typename MatrixType, unsigned int Mode> class SelfAdjointView;
|
||||||
|
template<typename MatrixType> class SparseView;
|
||||||
template<typename ExpressionType> class WithFormat;
|
template<typename ExpressionType> class WithFormat;
|
||||||
template<typename MatrixType> struct CommaInitializer;
|
template<typename MatrixType> struct CommaInitializer;
|
||||||
template<typename Derived> class ReturnByValue;
|
template<typename Derived> class ReturnByValue;
|
||||||
|
@ -114,7 +114,7 @@ template<typename MatrixType, int Size> class SparseInnerVectorSet;
|
|||||||
template<typename MatrixType, int Mode> class SparseTriangularView;
|
template<typename MatrixType, int Mode> class SparseTriangularView;
|
||||||
template<typename MatrixType, unsigned int UpLo> class SparseSelfAdjointView;
|
template<typename MatrixType, unsigned int UpLo> class SparseSelfAdjointView;
|
||||||
template<typename Lhs, typename Rhs> class SparseDiagonalProduct;
|
template<typename Lhs, typename Rhs> class SparseDiagonalProduct;
|
||||||
|
template<typename MatrixType> class SparseView;
|
||||||
|
|
||||||
template<typename Lhs, typename Rhs> class SparseProduct;
|
template<typename Lhs, typename Rhs> class SparseProduct;
|
||||||
template<typename Lhs, typename Rhs> class SparseTimeDenseProduct;
|
template<typename Lhs, typename Rhs> class SparseTimeDenseProduct;
|
||||||
|
95
Eigen/src/Sparse/SparseView.h
Normal file
95
Eigen/src/Sparse/SparseView.h
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
// This file is part of Eigen, a lightweight C++ template library
|
||||||
|
// for linear algebra.
|
||||||
|
//
|
||||||
|
// Copyright (C) 2010 Gael Guennebaud <g.gael@free.fr>
|
||||||
|
// Copyright (C) 2010 Daniel Lowengrub <lowdanie@gmail.com>
|
||||||
|
//
|
||||||
|
// Eigen is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU Lesser General Public
|
||||||
|
// License as published by the Free Software Foundation; either
|
||||||
|
// version 3 of the License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Alternatively, you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU General Public License as
|
||||||
|
// published by the Free Software Foundation; either version 2 of
|
||||||
|
// the License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
|
// License and a copy of the GNU General Public License along with
|
||||||
|
// Eigen. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#ifndef EIGEN_SPARSEVIEW_H
|
||||||
|
#define EIGEN_SPARSEVIEW_H
|
||||||
|
|
||||||
|
template<typename MatrixType>
|
||||||
|
struct ei_traits<SparseView<MatrixType> > : ei_traits<MatrixType> {};
|
||||||
|
|
||||||
|
template<typename MatrixType>
|
||||||
|
class SparseView : public SparseMatrixBase<SparseView<MatrixType> >
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
EIGEN_SPARSE_PUBLIC_INTERFACE(SparseView);
|
||||||
|
|
||||||
|
SparseView(const MatrixType& mat, const Scalar m_reference = Scalar(0),
|
||||||
|
typename NumTraits<Scalar>::Real m_epsilon = NumTraits<Scalar>::dummy_precision()) :
|
||||||
|
m_matrix(mat), m_reference(m_reference), m_epsilon(m_epsilon) {}
|
||||||
|
class InnerIterator;
|
||||||
|
|
||||||
|
inline Index rows() const { return m_matrix.rows(); }
|
||||||
|
inline Index cols() const { return m_matrix.cols(); }
|
||||||
|
|
||||||
|
inline Index innerSize() const { return m_matrix.innerSize(); }
|
||||||
|
inline Index outerSize() const { return m_matrix.outerSize(); }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
const typename MatrixType::Nested m_matrix;
|
||||||
|
Scalar m_reference;
|
||||||
|
typename NumTraits<Scalar>::Real m_epsilon;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename MatrixType>
|
||||||
|
class SparseView<MatrixType>::InnerIterator : public MatrixType::InnerIterator
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef typename MatrixType::InnerIterator IterBase;
|
||||||
|
InnerIterator(const SparseView& view, Index outer) :
|
||||||
|
DenseBase<MatrixType>::InnerIterator(view.m_matrix, outer), m_view(view)
|
||||||
|
{
|
||||||
|
incrementToNonZero();
|
||||||
|
}
|
||||||
|
|
||||||
|
EIGEN_STRONG_INLINE InnerIterator& operator++()
|
||||||
|
{
|
||||||
|
IterBase::operator++();
|
||||||
|
incrementToNonZero();
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
using IterBase::value;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
const SparseView& m_view;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void incrementToNonZero()
|
||||||
|
{
|
||||||
|
while(ei_isMuchSmallerThan(value(), m_view.m_reference, m_view.m_epsilon) && (bool(*this)))
|
||||||
|
{
|
||||||
|
IterBase::operator++();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename Derived>
|
||||||
|
const SparseView<Derived> MatrixBase<Derived>::sparseView(const Scalar m_reference,
|
||||||
|
typename NumTraits<Scalar>::Real m_epsilon) const
|
||||||
|
{
|
||||||
|
return SparseView<Derived>(derived(), m_reference, m_epsilon);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
x
Reference in New Issue
Block a user