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

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

using DataWeight? rather than std::pair<double, double>

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