1380 |
16 Jul 08 |
peter |
1 |
#ifndef _theplu_yat_utility_matrix_weighted_ |
1380 |
16 Jul 08 |
peter |
2 |
#define _theplu_yat_utility_matrix_weighted_ |
616 |
31 Aug 06 |
jari |
3 |
|
42 |
26 Feb 04 |
jari |
// $Id$ |
12 |
19 Jun 03 |
daniel |
5 |
|
570 |
05 Apr 06 |
jari |
6 |
/* |
570 |
05 Apr 06 |
jari |
Copyright (C) 2003 Daniel Dalevi, Peter Johansson |
2119 |
12 Dec 09 |
peter |
Copyright (C) 2004 Jari Häkkinen, Peter Johansson |
2119 |
12 Dec 09 |
peter |
Copyright (C) 2005, 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér |
2119 |
12 Dec 09 |
peter |
Copyright (C) 2007, 2008, 2009 Jari Häkkinen, Peter Johansson |
4207 |
26 Aug 22 |
peter |
Copyright (C) 2017, 2022 Peter Johansson |
570 |
05 Apr 06 |
jari |
12 |
|
1469 |
02 Sep 08 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
570 |
05 Apr 06 |
jari |
14 |
|
675 |
10 Oct 06 |
jari |
The yat library is free software; you can redistribute it and/or |
675 |
10 Oct 06 |
jari |
modify it under the terms of the GNU General Public License as |
1486 |
09 Sep 08 |
jari |
published by the Free Software Foundation; either version 3 of the |
675 |
10 Oct 06 |
jari |
License, or (at your option) any later version. |
570 |
05 Apr 06 |
jari |
19 |
|
675 |
10 Oct 06 |
jari |
The yat library is distributed in the hope that it will be useful, |
675 |
10 Oct 06 |
jari |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
675 |
10 Oct 06 |
jari |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
570 |
05 Apr 06 |
jari |
General Public License for more details. |
570 |
05 Apr 06 |
jari |
24 |
|
570 |
05 Apr 06 |
jari |
You should have received a copy of the GNU General Public License |
1487 |
10 Sep 08 |
jari |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
570 |
05 Apr 06 |
jari |
27 |
*/ |
570 |
05 Apr 06 |
jari |
28 |
|
3596 |
21 Jan 17 |
peter |
29 |
#include "config_public.h" |
3596 |
21 Jan 17 |
peter |
30 |
|
1380 |
16 Jul 08 |
peter |
31 |
#include "DataWeight.h" |
1064 |
10 Feb 08 |
peter |
32 |
#include "StrideIterator.h" |
12 |
19 Jun 03 |
daniel |
33 |
|
1380 |
16 Jul 08 |
peter |
34 |
#include <vector> |
12 |
19 Jun 03 |
daniel |
35 |
|
42 |
26 Feb 04 |
jari |
36 |
namespace theplu { |
680 |
11 Oct 06 |
jari |
37 |
namespace yat { |
616 |
31 Aug 06 |
jari |
38 |
namespace utility { |
12 |
19 Jun 03 |
daniel |
39 |
|
4125 |
14 Jan 22 |
peter |
40 |
class MatrixBase; |
1384 |
17 Jul 08 |
peter |
41 |
|
1789 |
10 Feb 09 |
peter |
42 |
/** |
1789 |
10 Feb 09 |
peter |
\brief Weighted Matrix |
1816 |
21 Feb 09 |
peter |
44 |
|
1789 |
10 Feb 09 |
peter |
\since New in yat 0.5 |
1789 |
10 Feb 09 |
peter |
46 |
*/ |
1380 |
16 Jul 08 |
peter |
47 |
class MatrixWeighted |
420 |
02 Dec 05 |
jari |
48 |
{ |
420 |
02 Dec 05 |
jari |
49 |
public: |
1064 |
10 Feb 08 |
peter |
50 |
/** |
1549 |
06 Oct 08 |
peter |
value_type is DataWeight |
1549 |
06 Oct 08 |
peter |
52 |
*/ |
1549 |
06 Oct 08 |
peter |
53 |
typedef DataWeight value_type; |
1549 |
06 Oct 08 |
peter |
54 |
|
1549 |
06 Oct 08 |
peter |
55 |
/** |
1547 |
03 Oct 08 |
peter |
reference type is DataWeight& |
1547 |
03 Oct 08 |
peter |
57 |
*/ |
1547 |
03 Oct 08 |
peter |
58 |
typedef DataWeight& reference; |
1547 |
03 Oct 08 |
peter |
59 |
|
1547 |
03 Oct 08 |
peter |
60 |
/** |
1547 |
03 Oct 08 |
peter |
const_reference type is const DataWeight& |
1547 |
03 Oct 08 |
peter |
62 |
*/ |
1547 |
03 Oct 08 |
peter |
63 |
typedef const DataWeight& const_reference; |
1547 |
03 Oct 08 |
peter |
64 |
|
1547 |
03 Oct 08 |
peter |
65 |
/** |
1125 |
22 Feb 08 |
peter |
Mutable iterator that iterates over all elements |
1064 |
10 Feb 08 |
peter |
67 |
*/ |
1583 |
15 Oct 08 |
peter |
68 |
typedef std::vector<DataWeight>::iterator iterator; |
12 |
19 Jun 03 |
daniel |
69 |
|
614 |
31 Aug 06 |
jari |
70 |
/** |
1125 |
22 Feb 08 |
peter |
Read-only iterator that iterates over all elements |
1064 |
10 Feb 08 |
peter |
72 |
*/ |
1583 |
15 Oct 08 |
peter |
73 |
typedef std::vector<DataWeight>::const_iterator const_iterator; |
1064 |
10 Feb 08 |
peter |
74 |
|
1064 |
10 Feb 08 |
peter |
75 |
/** |
1125 |
22 Feb 08 |
peter |
Mutable iterator that iterates over one column |
1103 |
18 Feb 08 |
peter |
77 |
*/ |
1380 |
16 Jul 08 |
peter |
78 |
typedef StrideIterator<std::vector<DataWeight>::iterator> column_iterator; |
1103 |
18 Feb 08 |
peter |
79 |
|
1103 |
18 Feb 08 |
peter |
80 |
/** |
1125 |
22 Feb 08 |
peter |
Read-only iterator that iterates over one column |
1103 |
18 Feb 08 |
peter |
82 |
*/ |
4200 |
19 Aug 22 |
peter |
83 |
typedef StrideIterator<std::vector<DataWeight>::const_iterator> |
1380 |
16 Jul 08 |
peter |
84 |
const_column_iterator; |
1103 |
18 Feb 08 |
peter |
85 |
|
1103 |
18 Feb 08 |
peter |
86 |
/** |
1125 |
22 Feb 08 |
peter |
Mutable iterator that iterates over one row |
1103 |
18 Feb 08 |
peter |
88 |
*/ |
1589 |
17 Oct 08 |
peter |
89 |
typedef column_iterator row_iterator; |
1103 |
18 Feb 08 |
peter |
90 |
|
1103 |
18 Feb 08 |
peter |
91 |
/** |
1125 |
22 Feb 08 |
peter |
Read-only iterator that iterates over one row |
1103 |
18 Feb 08 |
peter |
93 |
*/ |
1589 |
17 Oct 08 |
peter |
94 |
typedef const_column_iterator const_row_iterator; |
1103 |
18 Feb 08 |
peter |
95 |
|
1103 |
18 Feb 08 |
peter |
96 |
/** |
614 |
31 Aug 06 |
jari |
@brief The default constructor. |
3596 |
21 Jan 17 |
peter |
98 |
|
1816 |
21 Feb 09 |
peter |
Creates a zero size MatrixWeighted |
614 |
31 Aug 06 |
jari |
100 |
*/ |
1380 |
16 Jul 08 |
peter |
101 |
MatrixWeighted(void); |
12 |
19 Jun 03 |
daniel |
102 |
|
754 |
17 Feb 07 |
jari |
103 |
/** |
1816 |
21 Feb 09 |
peter |
\brief Create a \a r times \a c MatrixWeighted |
1816 |
21 Feb 09 |
peter |
105 |
|
1890 |
02 Apr 09 |
peter |
If \a r is zero \a c must be zero and vice versa. |
1890 |
02 Apr 09 |
peter |
107 |
|
1816 |
21 Feb 09 |
peter |
Constructor allocating memory space for \a r times \a c |
4200 |
19 Aug 22 |
peter |
elements, and sets all elements to |
1380 |
16 Jul 08 |
peter |
DataWeight(\a init_value, \a init_weight) |
754 |
17 Feb 07 |
jari |
111 |
*/ |
1381 |
16 Jul 08 |
peter |
112 |
MatrixWeighted(size_t r, size_t c, double init_value=0, |
1381 |
16 Jul 08 |
peter |
113 |
double init_weight=1.0); |
420 |
02 Dec 05 |
jari |
114 |
|
754 |
17 Feb 07 |
jari |
115 |
/** |
754 |
17 Feb 07 |
jari |
\brief The copy constructor. |
754 |
17 Feb 07 |
jari |
117 |
*/ |
1380 |
16 Jul 08 |
peter |
118 |
MatrixWeighted(const MatrixWeighted&); |
12 |
19 Jun 03 |
daniel |
119 |
|
3596 |
21 Jan 17 |
peter |
120 |
|
754 |
17 Feb 07 |
jari |
121 |
/** |
3596 |
21 Jan 17 |
peter |
\brief The move copy constructor. |
3596 |
21 Jan 17 |
peter |
123 |
|
3596 |
21 Jan 17 |
peter |
\since new in yat 0.15 |
3596 |
21 Jan 17 |
peter |
125 |
*/ |
3596 |
21 Jan 17 |
peter |
126 |
MatrixWeighted(MatrixWeighted&&); |
3596 |
21 Jan 17 |
peter |
127 |
|
3596 |
21 Jan 17 |
peter |
128 |
|
3596 |
21 Jan 17 |
peter |
129 |
/** |
1816 |
21 Feb 09 |
peter |
\brief Constructor. |
754 |
17 Feb 07 |
jari |
131 |
|
1384 |
17 Jul 08 |
peter |
Data is copied from \a other and weights are calculated using |
1954 |
07 May 09 |
jari |
the binary_weight function, i.e., a NaN gets a zero weight |
1954 |
07 May 09 |
jari |
(0.0) and other data values results in a unity weight (1.0). |
754 |
17 Feb 07 |
jari |
135 |
*/ |
4125 |
14 Jan 22 |
peter |
136 |
explicit MatrixWeighted(const MatrixBase& other); |
1384 |
17 Jul 08 |
peter |
137 |
|
1384 |
17 Jul 08 |
peter |
138 |
/** |
1384 |
17 Jul 08 |
peter |
\brief The istream constructor. |
1384 |
17 Jul 08 |
peter |
140 |
|
1954 |
07 May 09 |
jari |
This constructor first creates a Matrix using the Matrix |
1954 |
07 May 09 |
jari |
istream constructor, and then constructs MatrixWeighted using |
4125 |
14 Jan 22 |
peter |
MatrixWeighted(const MatrixBase&). |
1816 |
21 Feb 09 |
peter |
144 |
|
1954 |
07 May 09 |
jari |
\note Weights cannot be set from the streams. Weights are set |
4125 |
14 Jan 22 |
peter |
as outlined in the MatrixWeighted(const MatrixBase&) documentation. |
1954 |
07 May 09 |
jari |
147 |
|
4125 |
14 Jan 22 |
peter |
\see Matrix(std::istream &, char) and MatrixWeighted(const |
4125 |
14 Jan 22 |
peter |
MatrixBase&) |
1384 |
17 Jul 08 |
peter |
150 |
*/ |
4125 |
14 Jan 22 |
peter |
151 |
explicit MatrixWeighted(std::istream &, char sep='\0'); |
12 |
19 Jun 03 |
daniel |
152 |
|
754 |
17 Feb 07 |
jari |
153 |
/** |
1065 |
10 Feb 08 |
peter |
Iterator iterates along a row. When end of row is reached it |
1065 |
10 Feb 08 |
peter |
jumps to beginning of next row. |
1065 |
10 Feb 08 |
peter |
156 |
|
1065 |
10 Feb 08 |
peter |
\return iterator pointing to upper-left element. |
1064 |
10 Feb 08 |
peter |
158 |
*/ |
1064 |
10 Feb 08 |
peter |
159 |
iterator begin(void); |
1064 |
10 Feb 08 |
peter |
160 |
|
1064 |
10 Feb 08 |
peter |
161 |
/** |
1065 |
10 Feb 08 |
peter |
Iterator iterates along a row. When end of row is reached it |
1065 |
10 Feb 08 |
peter |
jumps to beginning of next row. |
1065 |
10 Feb 08 |
peter |
164 |
|
1065 |
10 Feb 08 |
peter |
\return const_iterator pointing to upper-left element. |
1064 |
10 Feb 08 |
peter |
166 |
*/ |
1064 |
10 Feb 08 |
peter |
167 |
const_iterator begin(void) const; |
1064 |
10 Feb 08 |
peter |
168 |
|
1064 |
10 Feb 08 |
peter |
169 |
/** |
1065 |
10 Feb 08 |
peter |
Iterator iterates along a column. |
1065 |
10 Feb 08 |
peter |
171 |
|
1065 |
10 Feb 08 |
peter |
\return iterator pointing to first element of column \a i. |
1064 |
10 Feb 08 |
peter |
173 |
*/ |
1583 |
15 Oct 08 |
peter |
174 |
column_iterator begin_column(size_t i); |
1064 |
10 Feb 08 |
peter |
175 |
|
1064 |
10 Feb 08 |
peter |
176 |
/** |
1065 |
10 Feb 08 |
peter |
Iterator iterates along a column. |
1065 |
10 Feb 08 |
peter |
178 |
|
1065 |
10 Feb 08 |
peter |
\return const_iterator pointing to first element of column \a i. |
1064 |
10 Feb 08 |
peter |
180 |
*/ |
1583 |
15 Oct 08 |
peter |
181 |
const_column_iterator begin_column(size_t i) const; |
1064 |
10 Feb 08 |
peter |
182 |
|
1064 |
10 Feb 08 |
peter |
183 |
/** |
1065 |
10 Feb 08 |
peter |
Iterator iterates along a row. |
1065 |
10 Feb 08 |
peter |
185 |
|
1065 |
10 Feb 08 |
peter |
\return iterator pointing to first element of row \a i. |
1064 |
10 Feb 08 |
peter |
187 |
*/ |
1583 |
15 Oct 08 |
peter |
188 |
row_iterator begin_row(size_t i); |
1064 |
10 Feb 08 |
peter |
189 |
|
1064 |
10 Feb 08 |
peter |
190 |
/** |
1065 |
10 Feb 08 |
peter |
Iterator iterates along a row. |
1065 |
10 Feb 08 |
peter |
192 |
|
1065 |
10 Feb 08 |
peter |
\return const_iterator pointing to first element of row \a i. |
1064 |
10 Feb 08 |
peter |
194 |
*/ |
1583 |
15 Oct 08 |
peter |
195 |
const_row_iterator begin_row(size_t i) const; |
1064 |
10 Feb 08 |
peter |
196 |
|
1064 |
10 Feb 08 |
peter |
197 |
/** |
1380 |
16 Jul 08 |
peter |
\return The number of columns in the matrix. |
1380 |
16 Jul 08 |
peter |
199 |
*/ |
716 |
25 Dec 06 |
jari |
200 |
size_t columns(void) const; |
272 |
14 Apr 05 |
peter |
201 |
|
755 |
18 Feb 07 |
jari |
202 |
/** |
1065 |
10 Feb 08 |
peter |
\return iterator pointing to end of matrix |
1064 |
10 Feb 08 |
peter |
204 |
*/ |
1064 |
10 Feb 08 |
peter |
205 |
iterator end(void); |
1064 |
10 Feb 08 |
peter |
206 |
|
1064 |
10 Feb 08 |
peter |
207 |
/** |
1066 |
10 Feb 08 |
peter |
\return const_iterator pointing to end of matrix |
1064 |
10 Feb 08 |
peter |
209 |
*/ |
1064 |
10 Feb 08 |
peter |
210 |
const_iterator end(void) const; |
1064 |
10 Feb 08 |
peter |
211 |
|
1064 |
10 Feb 08 |
peter |
212 |
/** |
1065 |
10 Feb 08 |
peter |
\return iterator pointing to end of column \a i |
1064 |
10 Feb 08 |
peter |
214 |
*/ |
1583 |
15 Oct 08 |
peter |
215 |
column_iterator end_column(size_t i); |
1064 |
10 Feb 08 |
peter |
216 |
|
1064 |
10 Feb 08 |
peter |
217 |
/** |
1065 |
10 Feb 08 |
peter |
\return const_iterator pointing to end of column \a i |
1064 |
10 Feb 08 |
peter |
219 |
*/ |
1583 |
15 Oct 08 |
peter |
220 |
const_column_iterator end_column(size_t i) const; |
1064 |
10 Feb 08 |
peter |
221 |
|
1064 |
10 Feb 08 |
peter |
222 |
/** |
1065 |
10 Feb 08 |
peter |
\return iterator pointing to end of row \a i |
1064 |
10 Feb 08 |
peter |
224 |
*/ |
1583 |
15 Oct 08 |
peter |
225 |
row_iterator end_row(size_t i); |
1064 |
10 Feb 08 |
peter |
226 |
|
1064 |
10 Feb 08 |
peter |
227 |
/** |
1065 |
10 Feb 08 |
peter |
\return const_iterator pointing to end of row \a i |
1064 |
10 Feb 08 |
peter |
229 |
*/ |
1583 |
15 Oct 08 |
peter |
230 |
const_row_iterator end_row(size_t i) const; |
1064 |
10 Feb 08 |
peter |
231 |
|
1064 |
10 Feb 08 |
peter |
232 |
/** |
1816 |
21 Feb 09 |
peter |
\brief Resize MatrixWeighted |
788 |
10 Mar 07 |
jari |
234 |
|
1816 |
21 Feb 09 |
peter |
Elements in MatrixWeighted are undefined after a resize. |
1816 |
21 Feb 09 |
peter |
236 |
|
1890 |
02 Apr 09 |
peter |
If \a rows is zero \a columns must be zero and vice versa. |
1890 |
02 Apr 09 |
peter |
238 |
|
1380 |
16 Jul 08 |
peter |
\note this function may invalidate iterators. |
788 |
10 Mar 07 |
jari |
240 |
*/ |
1789 |
10 Feb 09 |
peter |
241 |
void resize(size_t rows, size_t columns); |
12 |
19 Jun 03 |
daniel |
242 |
|
755 |
18 Feb 07 |
jari |
243 |
/** |
1380 |
16 Jul 08 |
peter |
\return The number of rows in the matrix. |
755 |
18 Feb 07 |
jari |
245 |
*/ |
716 |
25 Dec 06 |
jari |
246 |
size_t rows(void) const; |
12 |
19 Jun 03 |
daniel |
247 |
|
754 |
17 Feb 07 |
jari |
248 |
/** |
1789 |
10 Feb 09 |
peter |
\brief swap objects |
1789 |
10 Feb 09 |
peter |
250 |
|
1789 |
10 Feb 09 |
peter |
Takes constant time. Invalidates iterators. |
1789 |
10 Feb 09 |
peter |
There is no requirement on the size of \a other. |
1789 |
10 Feb 09 |
peter |
253 |
*/ |
1789 |
10 Feb 09 |
peter |
254 |
void swap(MatrixWeighted& other); |
1789 |
10 Feb 09 |
peter |
255 |
|
1789 |
10 Feb 09 |
peter |
256 |
/** |
755 |
18 Feb 07 |
jari |
\brief Element access operator. |
755 |
18 Feb 07 |
jari |
258 |
|
755 |
18 Feb 07 |
jari |
\return Reference to the element position (\a row, \a column). |
755 |
18 Feb 07 |
jari |
260 |
*/ |
1380 |
16 Jul 08 |
peter |
261 |
DataWeight& operator()(size_t row,size_t column); |
390 |
13 Sep 05 |
peter |
262 |
|
755 |
18 Feb 07 |
jari |
263 |
/** |
755 |
18 Feb 07 |
jari |
\brief Element access operator. |
755 |
18 Feb 07 |
jari |
265 |
|
755 |
18 Feb 07 |
jari |
\return Const reference to the element position (\a row, \a |
755 |
18 Feb 07 |
jari |
column). |
755 |
18 Feb 07 |
jari |
268 |
*/ |
1380 |
16 Jul 08 |
peter |
269 |
const DataWeight& operator()(size_t row,size_t column) const; |
12 |
19 Jun 03 |
daniel |
270 |
|
788 |
10 Mar 07 |
jari |
271 |
|
788 |
10 Mar 07 |
jari |
272 |
/** |
3596 |
21 Jan 17 |
peter |
\brief The move assignment operator. |
754 |
17 Feb 07 |
jari |
274 |
|
3596 |
21 Jan 17 |
peter |
\return A reference to the resulting Matrix. |
3596 |
21 Jan 17 |
peter |
276 |
|
3596 |
21 Jan 17 |
peter |
\since new in yat 0.15 |
754 |
17 Feb 07 |
jari |
278 |
*/ |
3596 |
21 Jan 17 |
peter |
279 |
MatrixWeighted& operator=(MatrixWeighted&& other); |
12 |
19 Jun 03 |
daniel |
280 |
|
420 |
02 Dec 05 |
jari |
281 |
private: |
4125 |
14 Jan 22 |
peter |
282 |
void copy(const MatrixBase&); |
1384 |
17 Jul 08 |
peter |
283 |
|
1380 |
16 Jul 08 |
peter |
284 |
std::vector<DataWeight> vec_; |
1380 |
16 Jul 08 |
peter |
285 |
size_t columns_; |
12 |
19 Jun 03 |
daniel |
286 |
|
42 |
26 Feb 04 |
jari |
287 |
}; |
12 |
19 Jun 03 |
daniel |
288 |
|
774 |
01 Mar 07 |
jari |
289 |
/** |
1380 |
16 Jul 08 |
peter |
\brief Exchange all elements. |
774 |
01 Mar 07 |
jari |
291 |
|
1380 |
16 Jul 08 |
peter |
Takes constant time. |
774 |
01 Mar 07 |
jari |
293 |
|
1706 |
08 Jan 09 |
peter |
\see MatrixWeighted::swap(MatrixWeighted&) |
1887 |
31 Mar 09 |
peter |
295 |
|
1887 |
31 Mar 09 |
peter |
\relates MatrixWeighted |
774 |
01 Mar 07 |
jari |
297 |
*/ |
1380 |
16 Jul 08 |
peter |
298 |
void swap(MatrixWeighted&, MatrixWeighted&); |
774 |
01 Mar 07 |
jari |
299 |
|
687 |
16 Oct 06 |
jari |
300 |
}}} // of namespace utility, yat, and theplu |
12 |
19 Jun 03 |
daniel |
301 |
|
420 |
02 Dec 05 |
jari |
302 |
#endif |