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, Markus Ringnér, Peter Johansson |
---|
9 | Copyright (C) 2007 Jari Häkkinen, Peter Johansson |
---|
10 | |
---|
11 | This file is part of the yat library, http://trac.thep.lu.se/yat |
---|
12 | |
---|
13 | The yat library is free software; you can redistribute it and/or |
---|
14 | modify it under the terms of the GNU General Public License as |
---|
15 | published by the Free Software Foundation; either version 2 of the |
---|
16 | License, or (at your option) any later version. |
---|
17 | |
---|
18 | The yat library is distributed in the hope that it will be useful, |
---|
19 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
21 | General Public License for more details. |
---|
22 | |
---|
23 | You should have received a copy of the GNU General Public License |
---|
24 | along with this program; if not, write to the Free Software |
---|
25 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
---|
26 | 02111-1307, USA. |
---|
27 | */ |
---|
28 | |
---|
29 | #include "DataLookup2D.h" |
---|
30 | #include "yat/utility/Iterator.h" |
---|
31 | #include "yat/utility/iterator_traits.h" |
---|
32 | #include "yat/utility/StrideIterator.h" |
---|
33 | |
---|
34 | #include <iostream> |
---|
35 | #include <vector> |
---|
36 | |
---|
37 | namespace theplu { |
---|
38 | namespace yat { |
---|
39 | namespace utility { |
---|
40 | class VectorBase; |
---|
41 | } |
---|
42 | namespace classifier { |
---|
43 | |
---|
44 | /// |
---|
45 | /// @brief Class for general vector view. |
---|
46 | /// |
---|
47 | class DataLookup1D |
---|
48 | { |
---|
49 | |
---|
50 | public: |
---|
51 | /// 'Read Only' iterator |
---|
52 | typedef utility::StrideIterator< |
---|
53 | utility::Iterator<const DataLookup2D, const double, void, const double> > |
---|
54 | const_iterator; |
---|
55 | |
---|
56 | /// |
---|
57 | /// Constructor. |
---|
58 | /// |
---|
59 | /// @param row_vector if true DataLookup1D is looking into a |
---|
60 | /// row of DataLookup2D, otherwise looking into a |
---|
61 | /// column. @param index which row/column to look into. |
---|
62 | /// |
---|
63 | DataLookup1D(const DataLookup2D&, 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 DataLookup2D 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 | /// @brief access operator |
---|
123 | /// |
---|
124 | double operator[](const size_t i) const; |
---|
125 | |
---|
126 | /// |
---|
127 | /// scalar product |
---|
128 | /// |
---|
129 | double operator*(const DataLookup1D&) const; |
---|
130 | |
---|
131 | private: |
---|
132 | const DataLookup1D& operator=(const DataLookup1D&); |
---|
133 | |
---|
134 | const bool column_vector_; |
---|
135 | const size_t index_; |
---|
136 | const DataLookup2D* matrix_; |
---|
137 | const bool owner_; |
---|
138 | |
---|
139 | }; |
---|
140 | |
---|
141 | /// |
---|
142 | /// @brief The output operator for DataLookup1D. |
---|
143 | /// |
---|
144 | /** |
---|
145 | * Elements are separated by the character from the omanip fill. |
---|
146 | * The following example will write the elements separated by tab. |
---|
147 | * |
---|
148 | @verbatim |
---|
149 | char prev=s.fill('\t'); |
---|
150 | s << v; |
---|
151 | s.fill(prev); |
---|
152 | @endverbatim |
---|
153 | */ |
---|
154 | std::ostream& operator<<(std::ostream& s, const DataLookup1D& v); |
---|
155 | |
---|
156 | }}} // of namespace classifier, yat, and theplu |
---|
157 | |
---|
158 | #endif |
---|