SparseView.h
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2011 Gael Guennebaud <gael.guennebaud@inria.fr>
00005 // Copyright (C) 2010 Daniel Lowengrub <lowdanie@gmail.com>
00006 //
00007 // This Source Code Form is subject to the terms of the Mozilla
00008 // Public License v. 2.0. If a copy of the MPL was not distributed
00009 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
00010 
00011 #ifndef EIGEN_SPARSEVIEW_H
00012 #define EIGEN_SPARSEVIEW_H
00013 
00014 namespace Eigen { 
00015 
00016 namespace internal {
00017 
00018 template<typename MatrixType>
00019 struct traits<SparseView<MatrixType> > : traits<MatrixType>
00020 {
00021   typedef int Index;
00022   typedef Sparse StorageKind;
00023   enum {
00024     Flags = int(traits<MatrixType>::Flags) & (RowMajorBit)
00025   };
00026 };
00027 
00028 } // end namespace internal
00029 
00030 template<typename MatrixType>
00031 class SparseView : public SparseMatrixBase<SparseView<MatrixType> >
00032 {
00033   typedef typename MatrixType::Nested MatrixTypeNested;
00034   typedef typename internal::remove_all<MatrixTypeNested>::type _MatrixTypeNested;
00035 public:
00036   EIGEN_SPARSE_PUBLIC_INTERFACE(SparseView)
00037 
00038   SparseView(const MatrixType& mat, const Scalar& m_reference = Scalar(0),
00039              typename NumTraits<Scalar>::Real m_epsilon = NumTraits<Scalar>::dummy_precision()) : 
00040     m_matrix(mat), m_reference(m_reference), m_epsilon(m_epsilon) {}
00041 
00042   class InnerIterator;
00043 
00044   inline Index rows() const { return m_matrix.rows(); }
00045   inline Index cols() const { return m_matrix.cols(); }
00046 
00047   inline Index innerSize() const { return m_matrix.innerSize(); }
00048   inline Index outerSize() const { return m_matrix.outerSize(); }
00049 
00050 protected:
00051   MatrixTypeNested m_matrix;
00052   Scalar m_reference;
00053   typename NumTraits<Scalar>::Real m_epsilon;
00054 };
00055 
00056 template<typename MatrixType>
00057 class SparseView<MatrixType>::InnerIterator : public _MatrixTypeNested::InnerIterator
00058 {
00059 public:
00060   typedef typename _MatrixTypeNested::InnerIterator IterBase;
00061   InnerIterator(const SparseView& view, Index outer) :
00062   IterBase(view.m_matrix, outer), m_view(view)
00063   {
00064     incrementToNonZero();
00065   }
00066 
00067   EIGEN_STRONG_INLINE InnerIterator& operator++()
00068   {
00069     IterBase::operator++();
00070     incrementToNonZero();
00071     return *this;
00072   }
00073 
00074   using IterBase::value;
00075 
00076 protected:
00077   const SparseView& m_view;
00078 
00079 private:
00080   void incrementToNonZero()
00081   {
00082     while((bool(*this)) && internal::isMuchSmallerThan(value(), m_view.m_reference, m_view.m_epsilon))
00083     {
00084       IterBase::operator++();
00085     }
00086   }
00087 };
00088 
00089 template<typename Derived>
00090 const SparseView<Derived> MatrixBase<Derived>::sparseView(const Scalar& m_reference,
00091                                                           typename NumTraits<Scalar>::Real m_epsilon) const
00092 {
00093   return SparseView<Derived>(derived(), m_reference, m_epsilon);
00094 }
00095 
00096 } // end namespace Eigen
00097 
00098 #endif


win_eigen
Author(s): Daniel Stonier
autogenerated on Wed Sep 16 2015 07:12:14