source: branches/0.4-stable/yat/classifier/DataLookup1D.h @ 1392

Last change on this file since 1392 was 1392, checked in by Peter, 15 years ago

trac has moved

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