Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GaussianProcessTuning/HeuristicLab.Eigen/Eigen/src/SparseCore/SparseView.h @ 9562

Last change on this file since 9562 was 9562, checked in by gkronber, 11 years ago

#1967 worked on Gaussian process evolution.

File size: 2.7 KB
Line 
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2011 Gael Guennebaud <gael.guennebaud@inria.fr>
5// Copyright (C) 2010 Daniel Lowengrub <lowdanie@gmail.com>
6//
7// This Source Code Form is subject to the terms of the Mozilla
8// Public License v. 2.0. If a copy of the MPL was not distributed
9// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10
11#ifndef EIGEN_SPARSEVIEW_H
12#define EIGEN_SPARSEVIEW_H
13
14namespace Eigen {
15
16namespace internal {
17
18template<typename MatrixType>
19struct traits<SparseView<MatrixType> > : traits<MatrixType>
20{
21  typedef int Index;
22  typedef Sparse StorageKind;
23  enum {
24    Flags = int(traits<MatrixType>::Flags) & (RowMajorBit)
25  };
26};
27
28} // end namespace internal
29
30template<typename MatrixType>
31class SparseView : public SparseMatrixBase<SparseView<MatrixType> >
32{
33  typedef typename MatrixType::Nested MatrixTypeNested;
34  typedef typename internal::remove_all<MatrixTypeNested>::type _MatrixTypeNested;
35public:
36  EIGEN_SPARSE_PUBLIC_INTERFACE(SparseView)
37
38  SparseView(const MatrixType& mat, const Scalar& m_reference = Scalar(0),
39             typename NumTraits<Scalar>::Real m_epsilon = NumTraits<Scalar>::dummy_precision()) :
40    m_matrix(mat), m_reference(m_reference), m_epsilon(m_epsilon) {}
41
42  class InnerIterator;
43
44  inline Index rows() const { return m_matrix.rows(); }
45  inline Index cols() const { return m_matrix.cols(); }
46
47  inline Index innerSize() const { return m_matrix.innerSize(); }
48  inline Index outerSize() const { return m_matrix.outerSize(); }
49
50protected:
51  MatrixTypeNested m_matrix;
52  Scalar m_reference;
53  typename NumTraits<Scalar>::Real m_epsilon;
54};
55
56template<typename MatrixType>
57class SparseView<MatrixType>::InnerIterator : public _MatrixTypeNested::InnerIterator
58{
59public:
60  typedef typename _MatrixTypeNested::InnerIterator IterBase;
61  InnerIterator(const SparseView& view, Index outer) :
62  IterBase(view.m_matrix, outer), m_view(view)
63  {
64    incrementToNonZero();
65  }
66
67  EIGEN_STRONG_INLINE InnerIterator& operator++()
68  {
69    IterBase::operator++();
70    incrementToNonZero();
71    return *this;
72  }
73
74  using IterBase::value;
75
76protected:
77  const SparseView& m_view;
78
79private:
80  void incrementToNonZero()
81  {
82    while((bool(*this)) && internal::isMuchSmallerThan(value(), m_view.m_reference, m_view.m_epsilon))
83    {
84      IterBase::operator++();
85    }
86  }
87};
88
89template<typename Derived>
90const SparseView<Derived> MatrixBase<Derived>::sparseView(const Scalar& m_reference,
91                                                          typename NumTraits<Scalar>::Real m_epsilon) const
92{
93  return SparseView<Derived>(derived(), m_reference, m_epsilon);
94}
95
96} // end namespace Eigen
97
98#endif
Note: See TracBrowser for help on using the repository browser.