source: trunk/yat/classifier/DataLookup1D.h @ 1487

Last change on this file since 1487 was 1487, checked in by Jari Häkkinen, 14 years ago

Addresses #436. GPL license copy reference should also be updated.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date ID
File size: 3.9 KB
Line 
1#ifndef _theplu_yat_classifier_dataLookup1D_
2#define _theplu_yat_classifier_dataLookup1D_
3
4// $Id$
5
6/*
7  Copyright (C) 2005 Peter Johansson
8  Copyright (C) 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér
9  Copyright (C) 2007 Jari Häkkinen, Peter Johansson
10  Copyright (C) 2008 Peter Johansson
11
12  This file is part of the yat library, http://dev.thep.lu.se/yat
13
14  The yat library is free software; you can redistribute it and/or
15  modify it under the terms of the GNU General Public License as
16  published by the Free Software Foundation; either version 3 of the
17  License, or (at your option) any later version.
18
19  The yat library is distributed in the hope that it will be useful,
20  but WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  General Public License for more details.
23
24  You should have received a copy of the GNU General Public License
25  along with yat. If not, see <http://www.gnu.org/licenses/>.
26*/
27
28#include "MatrixLookup.h"
29#include "yat/utility/Container2DIterator.h"
30#include "yat/utility/iterator_traits.h"
31#include "yat/utility/StrideIterator.h"
32
33#include <iostream>
34#include <vector>
35
36namespace theplu {
37namespace yat {
38namespace utility {
39  class VectorBase;
40}
41namespace classifier { 
42
43  ///
44  /// @brief Class for general vector view.
45  ///
46  class DataLookup1D
47  {
48  public:
49    /// 'Read Only' iterator
50    typedef utility::StrideIterator<
51    utility::Container2DIterator<const MatrixLookup, const double, void, 
52                                 const double> >
53    const_iterator;
54
55    ///
56    /// Constructor.
57    ///
58    /// \param m MatrixLookup to look into
59    /// @param row_vector if true DataLookup1D is looking into a
60    /// row of MatrixLookup, otherwise looking into a
61    /// column. @param index which row/column to look into.
62    ///
63    DataLookup1D(const MatrixLookup& m, const size_t index, 
64                 const bool row_vector);
65
66    ///
67    /// Copy constructor
68    ///
69    DataLookup1D(const DataLookup1D&);
70
71    ///
72    /// Construct DataLookup1D that owns its underlying matrix. Object
73    /// has size @ size and all its element is equal to @a value.
74    ///
75    DataLookup1D(const size_t size, const double value=0); 
76
77    /**
78       @brief Create general view from utility::VectorBase
79   
80       Constructor creates a proper MatrixLookup that object can view
81       into. Object is owner of this underlying MatrixLookup. Object fulfills
82       \f$ x(i) = vec(index(i)) \f$
83    */
84    DataLookup1D(const utility::VectorBase& vec, 
85                 const std::vector<size_t>& index); 
86
87    /**
88       @brief Create general view from utility::VectorBase
89   
90       Constructor creates a proper MatrixLookup that object can view
91       into. Object is owner of this underlying MatrixLookup. Object fulfills
92       \f$ x(i) = vec(i) \f$
93    */
94    DataLookup1D(const utility::VectorBase& vec); 
95
96    ///
97    /// @brief Destructor deletes underlying MatrixLookup if object is owner
98    ///
99    virtual ~DataLookup1D();
100
101    /**
102       \return 'Read Only' iterator to first element.
103     */
104    const_iterator begin() const;
105
106    /**
107       \return 'Read Only' iterator to end of DataLookup1D.
108     */
109    const_iterator end() const;
110
111    ///
112    /// @return number of elements
113    ///
114    size_t size(void) const;
115
116    ///
117    /// @brief access operator
118    ///
119    double operator()(const size_t i) const;
120
121    ///
122    /// scalar product
123    ///
124    double operator*(const DataLookup1D&) const;
125
126  private:
127    const DataLookup1D& operator=(const DataLookup1D&);
128
129    const bool column_vector_;
130    const size_t index_;
131    const MatrixLookup* matrix_;
132    const bool owner_;
133   
134  };
135
136  ///
137  /// @brief The output operator for DataLookup1D.
138  ///
139  /**
140   * Elements are separated by the character from the omanip fill.
141   * The following example will write the elements separated by tab.
142   *
143   @verbatim
144   char prev=s.fill('\t');
145   s << v;
146   s.fill(prev);
147   @endverbatim
148  */
149  std::ostream& operator<<(std::ostream& s, const DataLookup1D& v);
150 
151}}} // of namespace classifier, yat, and theplu
152
153#endif
Note: See TracBrowser for help on using the repository browser.