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) 2010 Gael Guennebaud <gael.guennebaud@inria.fr>
00005 // Copyright (C) 2010 Daniel Lowengrub <lowdanie@gmail.com>
00006 //
00007 // Eigen is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU Lesser General Public
00009 // License as published by the Free Software Foundation; either
00010 // version 3 of the License, or (at your option) any later version.
00011 //
00012 // Alternatively, you can redistribute it and/or
00013 // modify it under the terms of the GNU General Public License as
00014 // published by the Free Software Foundation; either version 2 of
00015 // the License, or (at your option) any later version.
00016 //
00017 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00018 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00019 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00020 // GNU General Public License for more details.
00021 //
00022 // You should have received a copy of the GNU Lesser General Public
00023 // License and a copy of the GNU General Public License along with
00024 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00025 
00026 #ifndef EIGEN_SPARSEVIEW_H
00027 #define EIGEN_SPARSEVIEW_H
00028 
00029 namespace internal {
00030 
00031 template<typename MatrixType>
00032 struct traits<SparseView<MatrixType> > : traits<MatrixType>
00033 {
00034   typedef int Index;
00035   typedef Sparse StorageKind;
00036   enum {
00037     Flags = int(traits<MatrixType>::Flags) & (RowMajorBit)
00038   };
00039 };
00040 
00041 } // end namespace internal
00042 
00043 template<typename MatrixType>
00044 class SparseView : public SparseMatrixBase<SparseView<MatrixType> >
00045 {
00046   typedef typename MatrixType::Nested MatrixTypeNested;
00047   typedef typename internal::remove_all<MatrixTypeNested>::type _MatrixTypeNested;
00048 public:
00049   EIGEN_SPARSE_PUBLIC_INTERFACE(SparseView)
00050 
00051   SparseView(const MatrixType& mat, const Scalar& m_reference = Scalar(0),
00052              typename NumTraits<Scalar>::Real m_epsilon = NumTraits<Scalar>::dummy_precision()) : 
00053     m_matrix(mat), m_reference(m_reference), m_epsilon(m_epsilon) {}
00054 
00055   class InnerIterator;
00056 
00057   inline Index rows() const { return m_matrix.rows(); }
00058   inline Index cols() const { return m_matrix.cols(); }
00059 
00060   inline Index innerSize() const { return m_matrix.innerSize(); }
00061   inline Index outerSize() const { return m_matrix.outerSize(); }
00062 
00063 protected:
00064   const MatrixTypeNested m_matrix;
00065   Scalar m_reference;
00066   typename NumTraits<Scalar>::Real m_epsilon;
00067 };
00068 
00069 template<typename MatrixType>
00070 class SparseView<MatrixType>::InnerIterator : public _MatrixTypeNested::InnerIterator
00071 {
00072 public:
00073   typedef typename _MatrixTypeNested::InnerIterator IterBase;
00074   InnerIterator(const SparseView& view, Index outer) :
00075   IterBase(view.m_matrix, outer), m_view(view)
00076   {
00077     incrementToNonZero();
00078   }
00079 
00080   EIGEN_STRONG_INLINE InnerIterator& operator++()
00081   {
00082     IterBase::operator++();
00083     incrementToNonZero();
00084     return *this;
00085   }
00086 
00087   using IterBase::value;
00088 
00089 protected:
00090   const SparseView& m_view;
00091 
00092 private:
00093   void incrementToNonZero()
00094   {
00095     while(internal::isMuchSmallerThan(value(), m_view.m_reference, m_view.m_epsilon) && (bool(*this)))
00096       {
00097         IterBase::operator++();
00098       }
00099   }
00100 };
00101 
00102 template<typename Derived>
00103 const SparseView<Derived> MatrixBase<Derived>::sparseView(const Scalar& m_reference,
00104                                                           typename NumTraits<Scalar>::Real m_epsilon) const
00105 {
00106   return SparseView<Derived>(derived(), m_reference, m_epsilon);
00107 }
00108 
00109 #endif


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:32:59