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

Last change on this file since 1486 was 1486, checked in by Jari Häkkinen, 13 years ago

Addresses #436.

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