source: trunk/yat/utility/MatrixWeighted.cc @ 1381

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

working on #363

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.9 KB
Line 
1// $Id: MatrixWeighted.cc 1381 2008-07-16 23:14:42Z peter $
2
3/*
4  Copyright (C) 2003 Daniel Dalevi, Peter Johansson
5  Copyright (C) 2004 Jari Häkkinen, Peter Johansson
6  Copyright (C) 2005, 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér
7  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
8
9  This file is part of the yat library, http://trac.thep.lu.se/yat
10
11  The yat library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU General Public License as
13  published by the Free Software Foundation; either version 2 of the
14  License, or (at your option) any later version.
15
16  The yat library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20
21  You should have received a copy of the GNU General Public License
22  along with this program; if not, write to the Free Software
23  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24  02111-1307, USA.
25*/
26
27#include "MatrixWeighted.h"
28
29#include "DataIterator.h"
30#include "Matrix.h"
31#include "WeightIterator.h"
32
33#include <cassert>
34#include <vector>
35
36namespace theplu {
37namespace yat {
38namespace utility {
39
40
41  MatrixWeighted::MatrixWeighted(void)
42    : columns_(0)
43  {
44  }
45
46
47  MatrixWeighted::MatrixWeighted(size_t r, size_t c, double x, double w)
48    : vec_(std::vector<DataWeight>(r*c, DataWeight(x,w))), columns_(c)
49  {}
50
51 
52  MatrixWeighted::MatrixWeighted(const MatrixWeighted& other)
53    : vec_(other.vec_), columns_(other.columns_)
54  {}
55
56
57  MatrixWeighted::MatrixWeighted(std::istream& is, char sep)
58  {
59    Matrix data(is, sep);
60    Matrix weight;
61    nan(data, weight);
62    columns_ = data.columns();
63    resize(data.columns(), data.rows());
64    // FIXME
65    //std::copy(data.begin(), data.end(), make_data_iterator(vec_.begin()));
66    //std::copy(weight.begin(), weight.end(), make_weight_iterator(vec_.begin()));
67  }
68
69 
70  MatrixWeighted::iterator MatrixWeighted::begin(void)
71  {
72    return iterator(vec_.begin());
73  }
74
75
76  MatrixWeighted::const_iterator MatrixWeighted::begin(void) const
77  {
78    return const_iterator(vec_.begin());
79  }
80
81
82  MatrixWeighted::iterator MatrixWeighted::begin_column(size_t i)
83  {
84    return iterator(vec_.begin()+i, columns_);
85  }
86
87
88  MatrixWeighted::const_iterator MatrixWeighted::begin_column(size_t i) const
89  {
90    return const_iterator(vec_.begin()+i, columns_);
91  }
92
93
94  MatrixWeighted::iterator MatrixWeighted::begin_row(size_t i)
95  {
96    return iterator(vec_.begin()+columns_*i);
97  }
98
99
100  MatrixWeighted::const_iterator MatrixWeighted::begin_row(size_t i) const
101  {
102    return const_iterator(vec_.begin()+columns_*i);
103  }
104
105
106  size_t MatrixWeighted::columns(void) const
107  {
108    return columns_;
109  }
110
111
112  MatrixWeighted::iterator MatrixWeighted::end(void)
113  {
114    return iterator(vec_.end());
115  }
116
117
118  MatrixWeighted::const_iterator MatrixWeighted::end(void) const
119  {
120    return const_iterator(vec_.end());
121  }
122
123
124  MatrixWeighted::iterator MatrixWeighted::end_column(size_t i)
125  {
126    return iterator(vec_.begin()+i+vec_.size(), columns_);
127  }
128
129
130  MatrixWeighted::const_iterator MatrixWeighted::end_column(size_t i) const
131  {
132    return const_iterator(vec_.begin()+i+vec_.size(), columns_);
133  }
134
135
136  MatrixWeighted::iterator MatrixWeighted::end_row(size_t i)
137  {
138    return iterator(vec_.begin()+columns_*(i+1));
139  }
140
141
142  MatrixWeighted::const_iterator MatrixWeighted::end_row(size_t i) const
143  {
144    return const_iterator(vec_.begin()+columns_*(i+1));
145  }
146
147
148  void MatrixWeighted::resize(size_t rows, size_t columns)
149  {
150    columns_ = columns;
151    vec_.resize(rows*columns);
152  }
153
154 
155  size_t MatrixWeighted::rows(void) const
156  {
157    if (vec_.size())
158      return vec_.size()/columns_;
159    return 0;
160  }
161
162
163  DataWeight& MatrixWeighted::operator()(size_t row, size_t column)
164  {
165    assert(column<columns_);
166    assert(row*column < vec_.size());
167    return vec_[row*columns_ + column];
168  }
169
170
171  const DataWeight& MatrixWeighted::operator()(size_t row, size_t column) const
172  {
173    assert(column<columns_);
174    assert(row*column < vec_.size());
175    return vec_[row*columns_ + column];
176  }
177
178}}} // of namespace utility, yat and thep
Note: See TracBrowser for help on using the repository browser.