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 typename MatrixType::Index 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   typedef typename SparseView::Index Index;
00060 public:
00061   typedef typename _MatrixTypeNested::InnerIterator IterBase;
00062   InnerIterator(const SparseView& view, Index outer) :
00063   IterBase(view.m_matrix, outer), m_view(view)
00064   {
00065     incrementToNonZero();
00066   }
00067 
00068   EIGEN_STRONG_INLINE InnerIterator& operator++()
00069   {
00070     IterBase::operator++();
00071     incrementToNonZero();
00072     return *this;
00073   }
00074 
00075   using IterBase::value;
00076 
00077 protected:
00078   const SparseView& m_view;
00079 
00080 private:
00081   void incrementToNonZero()
00082   {
00083     while((bool(*this)) && internal::isMuchSmallerThan(value(), m_view.m_reference, m_view.m_epsilon))
00084     {
00085       IterBase::operator++();
00086     }
00087   }
00088 };
00089 
00090 template<typename Derived>
00091 const SparseView<Derived> MatrixBase<Derived>::sparseView(const Scalar& m_reference,
00092                                                           const typename NumTraits<Scalar>::Real& m_epsilon) const
00093 {
00094   return SparseView<Derived>(derived(), m_reference, m_epsilon);
00095 }
00096 
00097 } // end namespace Eigen
00098 
00099 #endif


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Sat Jun 8 2019 19:39:43