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

Last change on this file since 1525 was 1525, checked in by Peter, 13 years ago

refs #444 - simplifying code in DataLookupD by calling underlying MatrixLookup? rather than creating iterator yourself.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date ID
File size: 3.7 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
30#include <iostream>
31#include <vector>
32
33namespace theplu {
34namespace yat {
35namespace utility {
36  class VectorBase;
37}
38namespace classifier { 
39
40  ///
41  /// @brief Class for general vector view.
42  ///
43  class DataLookup1D
44  {
45  public:
46    /// 'Read Only' iterator
47    typedef MatrixLookup::const_row_iterator const_iterator;
48
49    ///
50    /// Constructor.
51    ///
52    /// \param m MatrixLookup to look into
53    /// @param row_vector if true DataLookup1D is looking into a
54    /// row of MatrixLookup, otherwise looking into a
55    /// column. @param index which row/column to look into.
56    ///
57    DataLookup1D(const MatrixLookup& m, const size_t index, 
58                 const bool row_vector);
59
60    ///
61    /// Copy constructor
62    ///
63    DataLookup1D(const DataLookup1D&);
64
65    ///
66    /// Construct DataLookup1D that owns its underlying matrix. Object
67    /// has size @ size and all its element is equal to @a value.
68    ///
69    DataLookup1D(const size_t size, const double value=0); 
70
71    /**
72       @brief Create general view from utility::VectorBase
73   
74       Constructor creates a proper MatrixLookup that object can view
75       into. Object is owner of this underlying MatrixLookup. Object fulfills
76       \f$ x(i) = vec(index(i)) \f$
77    */
78    DataLookup1D(const utility::VectorBase& vec, 
79                 const std::vector<size_t>& index); 
80
81    /**
82       @brief Create general view from utility::VectorBase
83   
84       Constructor creates a proper MatrixLookup that object can view
85       into. Object is owner of this underlying MatrixLookup. Object fulfills
86       \f$ x(i) = vec(i) \f$
87    */
88    DataLookup1D(const utility::VectorBase& vec); 
89
90    ///
91    /// @brief Destructor deletes underlying MatrixLookup if object is owner
92    ///
93    virtual ~DataLookup1D();
94
95    /**
96       \return 'Read Only' iterator to first element.
97     */
98    const_iterator begin() const;
99
100    /**
101       \return 'Read Only' iterator to end of DataLookup1D.
102     */
103    const_iterator end() const;
104
105    ///
106    /// @return number of elements
107    ///
108    size_t size(void) const;
109
110    ///
111    /// @brief access operator
112    ///
113    double operator()(const size_t i) const;
114
115    ///
116    /// scalar product
117    ///
118    double operator*(const DataLookup1D&) const;
119
120  private:
121    // assignment no allowed
122    const DataLookup1D& operator=(const DataLookup1D&);
123
124    const bool column_vector_;
125    const size_t index_;
126    const MatrixLookup* matrix_;
127    const bool owner_;
128   
129  };
130
131  ///
132  /// @brief The output operator for DataLookup1D.
133  ///
134  /**
135   * Elements are separated by the character from the omanip fill.
136   * The following example will write the elements separated by tab.
137   *
138   @verbatim
139   char prev=s.fill('\t');
140   s << v;
141   s.fill(prev);
142   @endverbatim
143  */
144  std::ostream& operator<<(std::ostream& s, const DataLookup1D& v);
145 
146}}} // of namespace classifier, yat, and theplu
147
148#endif
Note: See TracBrowser for help on using the repository browser.