source: trunk/yat/utility/MatrixWeighted.h @ 1469

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

stray trac.thep

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.8 KB
Line 
1#ifndef _theplu_yat_utility_matrix_weighted_
2#define _theplu_yat_utility_matrix_weighted_
3
4// $Id: MatrixWeighted.h 1469 2008-09-02 17:21:00Z peter $
5
6/*
7  Copyright (C) 2003 Daniel Dalevi, Peter Johansson
8  Copyright (C) 2004 Jari Häkkinen, Peter Johansson
9  Copyright (C) 2005, 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér
10  Copyright (C) 2007, 2008 Jari Häkkinen, 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 "DataWeight.h"
31#include "StrideIterator.h"
32
33#include <vector>
34
35namespace theplu {
36namespace yat {
37namespace utility {
38
39  class Matrix;
40
41  ///
42  /// @brief Weighted Matrix
43  ///
44  class MatrixWeighted
45  {
46  public:
47    /**
48       Mutable iterator that iterates over all elements
49     */
50    typedef StrideIterator<std::vector<DataWeight>::iterator> iterator;
51
52    /**
53       Read-only iterator that iterates over all elements
54     */
55    typedef StrideIterator<std::vector<DataWeight>::const_iterator> 
56    const_iterator;
57
58    /**
59       Mutable iterator that iterates over one column
60     */
61    typedef StrideIterator<std::vector<DataWeight>::iterator> column_iterator;
62
63    /**
64       Read-only iterator that iterates over one column
65     */
66    typedef StrideIterator<std::vector<DataWeight>::const_iterator> 
67    const_column_iterator;
68
69    /**
70       Mutable iterator that iterates over one row
71     */
72    typedef StrideIterator<std::vector<DataWeight>::iterator> row_iterator;
73
74    /**
75       Read-only iterator that iterates over one row
76     */
77    typedef StrideIterator<std::vector<DataWeight>::const_iterator> 
78    const_row_iterator;
79
80    /**
81       @brief The default constructor.
82   
83       This contructor does not initialize underlying (essential)
84       structures.
85    */
86    MatrixWeighted(void);
87
88    /**
89       \brief Constructor allocating memory space for \a r times \a c
90       elements, and sets all elements to
91       DataWeight(\a init_value, \a init_weight)
92    */
93    MatrixWeighted(size_t r, size_t c, double init_value=0,
94                   double init_weight=1.0);
95
96    /**
97       \brief The copy constructor.
98    */
99    MatrixWeighted(const MatrixWeighted&);
100
101   
102    /**
103       \brief The istream constructor.
104
105       Data is copied from \a other and weights are calculated using
106       the nan function.
107    */
108    explicit MatrixWeighted(const Matrix& other);
109
110    /**
111       \brief The istream constructor.
112
113       This constructor first creates a Matrix using the istream
114       constructor, and then constructs MatrixWeighted using
115       MatrixWeighted(const Matrix&).
116    */
117    explicit MatrixWeighted(std::istream &, char sep='\0'); 
118
119    /**
120       Iterator iterates along a row. When end of row is reached it
121       jumps to beginning of next row.
122
123       \return iterator pointing to upper-left element.
124     */
125    iterator begin(void);
126
127    /**
128       Iterator iterates along a row. When end of row is reached it
129       jumps to beginning of next row.
130
131       \return const_iterator pointing to upper-left element.
132     */
133    const_iterator begin(void) const;
134
135    /**
136       Iterator iterates along a column.
137
138       \return iterator pointing to first element of column \a i.
139     */
140    iterator begin_column(size_t i);
141
142    /**
143       Iterator iterates along a column.
144
145       \return const_iterator pointing to first element of column \a i.
146     */
147    const_iterator begin_column(size_t i) const;
148
149    /**
150       Iterator iterates along a row.
151
152       \return iterator pointing to first element of row \a i.
153     */
154    iterator begin_row(size_t i);
155
156    /**
157       Iterator iterates along a row.
158
159       \return const_iterator pointing to first element of row \a i.
160     */
161    const_iterator begin_row(size_t i) const;
162
163    /**
164       \return The number of columns in the matrix.
165    */
166    size_t columns(void) const;
167
168    /**
169       \return iterator pointing to end of matrix
170     */
171    iterator end(void);
172
173    /**
174       \return const_iterator pointing to end of matrix
175     */
176    const_iterator end(void) const;
177
178    /**
179       \return iterator pointing to end of column \a i
180     */
181    iterator end_column(size_t i);
182
183    /**
184       \return const_iterator pointing to end of column \a i
185     */
186    const_iterator end_column(size_t i) const;
187
188    /**
189       \return iterator pointing to end of row \a i
190     */
191    iterator end_row(size_t i);
192
193    /**
194       \return const_iterator pointing to end of row \a i
195     */
196    const_iterator end_row(size_t i) const;
197
198    /**
199       \brief Resize Matrix
200
201       \note this function may invalidate iterators.
202    */
203    void resize(size_t, size_t);
204
205    /**
206       \return The number of rows in the matrix.
207    */
208    size_t rows(void) const;
209
210    /**
211       \brief Element access operator.
212
213       \return Reference to the element position (\a row, \a column).
214    */
215    DataWeight& operator()(size_t row,size_t column);
216
217    /**
218       \brief Element access operator.
219
220       \return Const reference to the element position (\a row, \a
221       column).
222    */
223    const DataWeight& operator()(size_t row,size_t column) const;
224
225
226    /**
227       \brief The assignment operator.
228
229       \return A const reference to the resulting Matrix.
230    */
231    const MatrixWeighted& operator=(const MatrixWeighted& other);
232
233  private:
234    void copy(const Matrix&);
235    void copy(const Matrix& data, const Matrix& weight);
236
237    std::vector<DataWeight> vec_;
238    size_t columns_;
239
240  };
241
242  /**
243     \brief Exchange all elements.
244
245     Takes constant time.
246
247     \throw std::runtime_error if the two matrices disagree in size.
248  */
249  void swap(MatrixWeighted&, MatrixWeighted&);
250
251}}} // of namespace utility, yat, and theplu
252
253#endif
Note: See TracBrowser for help on using the repository browser.