diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2016-09-18 12:42:15 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2016-11-02 15:12:04 +0100 |
commit | 44861dcbfeee041223c4aac1ee075e92fa4daa01 (patch) | |
tree | 6dfdfd9637846a7aedd71ace97d7d2ad366496d7 /eigen/Eigen/src/SparseCore/SparseView.h | |
parent | f3fe458b9e0a29a99a39d47d9a76dc18964b6fec (diff) |
update
Diffstat (limited to 'eigen/Eigen/src/SparseCore/SparseView.h')
-rw-r--r-- | eigen/Eigen/src/SparseCore/SparseView.h | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/eigen/Eigen/src/SparseCore/SparseView.h b/eigen/Eigen/src/SparseCore/SparseView.h new file mode 100644 index 0000000..2820b39 --- /dev/null +++ b/eigen/Eigen/src/SparseCore/SparseView.h @@ -0,0 +1,99 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2011 Gael Guennebaud <gael.guennebaud@inria.fr> +// Copyright (C) 2010 Daniel Lowengrub <lowdanie@gmail.com> +// +// 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_SPARSEVIEW_H +#define EIGEN_SPARSEVIEW_H + +namespace Eigen { + +namespace internal { + +template<typename MatrixType> +struct traits<SparseView<MatrixType> > : traits<MatrixType> +{ + typedef typename MatrixType::Index Index; + typedef Sparse StorageKind; + enum { + Flags = int(traits<MatrixType>::Flags) & (RowMajorBit) + }; +}; + +} // end namespace internal + +template<typename MatrixType> +class SparseView : public SparseMatrixBase<SparseView<MatrixType> > +{ + typedef typename MatrixType::Nested MatrixTypeNested; + typedef typename internal::remove_all<MatrixTypeNested>::type _MatrixTypeNested; +public: + EIGEN_SPARSE_PUBLIC_INTERFACE(SparseView) + + explicit SparseView(const MatrixType& mat, const Scalar& reference = Scalar(0), + const RealScalar &epsilon = NumTraits<Scalar>::dummy_precision()) + : m_matrix(mat), m_reference(reference), m_epsilon(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: + MatrixTypeNested m_matrix; + Scalar m_reference; + typename NumTraits<Scalar>::Real m_epsilon; +}; + +template<typename MatrixType> +class SparseView<MatrixType>::InnerIterator : public _MatrixTypeNested::InnerIterator +{ + typedef typename SparseView::Index Index; +public: + typedef typename _MatrixTypeNested::InnerIterator IterBase; + InnerIterator(const SparseView& view, Index outer) : + IterBase(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((bool(*this)) && internal::isMuchSmallerThan(value(), m_view.m_reference, m_view.m_epsilon)) + { + IterBase::operator++(); + } + } +}; + +template<typename Derived> +const SparseView<Derived> MatrixBase<Derived>::sparseView(const Scalar& m_reference, + const typename NumTraits<Scalar>::Real& m_epsilon) const +{ + return SparseView<Derived>(derived(), m_reference, m_epsilon); +} + +} // end namespace Eigen + +#endif |