1 | #ifndef _theplu_yat_classifier_DataLookup2D_ |
---|
2 | #define _theplu_yat_classifier_DataLookup2D_ |
---|
3 | |
---|
4 | // $Id$ |
---|
5 | |
---|
6 | /* |
---|
7 | Copyright (C) 2005 Markus Ringnér, Peter Johansson |
---|
8 | Copyright (C) 2006 Jari Häkkinen, Markus Ringnér, Peter Johansson |
---|
9 | Copyright (C) 2007 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 "yat/utility/Index.h" |
---|
30 | |
---|
31 | #include <vector> |
---|
32 | #include <iostream> |
---|
33 | |
---|
34 | namespace theplu { |
---|
35 | namespace yat { |
---|
36 | namespace classifier { |
---|
37 | |
---|
38 | /// |
---|
39 | /// @brief Interface class for classifier data. |
---|
40 | /// |
---|
41 | /// This is the abstract base class defining a common interface for |
---|
42 | /// MatrixLookup and KernelLookup. The general idea of the Lookup |
---|
43 | /// classes is to: rather than copying the sub-matrix or sub-kernel, |
---|
44 | /// to hold a pointer to the underlying matrix/kernel and a vector |
---|
45 | /// of row indices and a vector of column indices. These indices |
---|
46 | /// then define what element to look into. |
---|
47 | /// |
---|
48 | /// This allow fast construction of sub-matrices/sub-kernels and at |
---|
49 | /// almost no extra memory usage. |
---|
50 | /// |
---|
51 | /// There is a possibility to set DataLookup2D as owner of the |
---|
52 | /// underlying data. This implies that underlying data is deleted in |
---|
53 | /// destructor of DataLookup2D (actually in destructor of inherited |
---|
54 | /// class since underlying data is class specific), but only if |
---|
55 | /// there is no other owner of the underlying data. A reference |
---|
56 | /// counter is used to keep track of number of owners. |
---|
57 | /// |
---|
58 | class DataLookup2D |
---|
59 | { |
---|
60 | |
---|
61 | public: |
---|
62 | |
---|
63 | /// |
---|
64 | /// Default constructor. |
---|
65 | /// |
---|
66 | DataLookup2D(const bool own=false); |
---|
67 | |
---|
68 | |
---|
69 | /// |
---|
70 | /// Constructor taking the @a row index vector and @a column index |
---|
71 | /// vector as input. |
---|
72 | /// |
---|
73 | DataLookup2D(const utility::Index& row, |
---|
74 | const utility::Index& column, |
---|
75 | const bool own=false); |
---|
76 | |
---|
77 | /// |
---|
78 | /// @brief Copy constructor. Indices and pointer to underlying |
---|
79 | /// data is copied, whereas owner is set to false. |
---|
80 | /// |
---|
81 | DataLookup2D(const DataLookup2D&); |
---|
82 | |
---|
83 | /// |
---|
84 | /// Copy the index such that new(i,j) = old(row[i],col[j]) |
---|
85 | /// |
---|
86 | DataLookup2D(const DataLookup2D&, const utility::Index& row, |
---|
87 | const utility::Index& col); |
---|
88 | |
---|
89 | /// |
---|
90 | /// If row is true indices are copied so new(i,j)=old(index[i],j). |
---|
91 | /// Else indices are copied so new(i,j)=old(i,index[j]) |
---|
92 | /// |
---|
93 | DataLookup2D(const DataLookup2D&, const utility::Index& index, |
---|
94 | const bool row); |
---|
95 | |
---|
96 | |
---|
97 | /// |
---|
98 | /// Indices are created all pointing to the zero-zero element |
---|
99 | /// created in daughter classes. |
---|
100 | /// |
---|
101 | DataLookup2D(const size_t, const size_t); |
---|
102 | |
---|
103 | |
---|
104 | /// |
---|
105 | /// @brief Destructor |
---|
106 | /// |
---|
107 | virtual ~DataLookup2D() {}; |
---|
108 | |
---|
109 | /// |
---|
110 | /// @return number of columns |
---|
111 | /// |
---|
112 | size_t columns(void) const; |
---|
113 | |
---|
114 | |
---|
115 | /** |
---|
116 | \return data |
---|
117 | */ |
---|
118 | virtual double data(size_t i, size_t j) const; |
---|
119 | |
---|
120 | /// |
---|
121 | /// @return number of rows |
---|
122 | /// |
---|
123 | size_t rows(void) const; |
---|
124 | |
---|
125 | /// |
---|
126 | /// Is lookup weighted? |
---|
127 | /// |
---|
128 | virtual bool weighted(void) const=0; |
---|
129 | |
---|
130 | /// |
---|
131 | /// @brief access operator |
---|
132 | /// |
---|
133 | /// @return value in that particular element |
---|
134 | /// |
---|
135 | virtual double operator()(const size_t row, const size_t column) const=0; |
---|
136 | |
---|
137 | protected: |
---|
138 | /// |
---|
139 | /// @brief assignment operator |
---|
140 | /// |
---|
141 | const DataLookup2D& operator=(const DataLookup2D&); |
---|
142 | |
---|
143 | /// |
---|
144 | /// @brief which rows to look into |
---|
145 | /// |
---|
146 | utility::Index row_index_; |
---|
147 | |
---|
148 | /// |
---|
149 | /// @brief which columns to look into |
---|
150 | /// |
---|
151 | utility::Index column_index_; |
---|
152 | |
---|
153 | }; |
---|
154 | |
---|
155 | /// |
---|
156 | /// The output operator DataLookup2D |
---|
157 | /// |
---|
158 | std::ostream& operator<< (std::ostream& s, const DataLookup2D&); |
---|
159 | |
---|
160 | }}} // of namespace classifier, yat, and theplu |
---|
161 | |
---|
162 | #endif |
---|