source: trunk/yat/classifier/DataLookup2D.cc @ 1134

Last change on this file since 1134 was 1134, checked in by Peter, 14 years ago

using Index class instead of std::vector<size_t>

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date ID
File size: 3.2 KB
Line 
1// $Id$
2
3/*
4  Copyright (C) 2005 Markus Ringnér, Peter Johansson
5  Copyright (C) 2006 Jari Häkkinen, Markus Ringnér, Peter Johansson
6
7  This file is part of the yat library, http://trac.thep.lu.se/yat
8
9  The yat library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of the
12  License, or (at your option) any later version.
13
14  The yat library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22  02111-1307, USA.
23*/
24
25#include "DataLookup2D.h"
26
27#include <vector>
28
29#include <cassert>
30#ifndef NDEBUG
31#include <algorithm>
32#endif
33
34namespace theplu {
35namespace yat {
36namespace classifier {
37
38
39  DataLookup2D::DataLookup2D(const bool own)
40    : ref_count_(NULL)
41  {
42    if (own)
43      ref_count_ = new u_int(1);
44  }
45
46
47  DataLookup2D::DataLookup2D(const DataLookup2D& m,
48                             const utility::Index& row, 
49                             const utility::Index& col)
50    : ref_count_(NULL)
51  {
52    row_index_ = utility::Index(m.row_index_, row);
53    column_index_ = utility::Index(m.column_index_, col);
54  }
55   
56
57
58  DataLookup2D::DataLookup2D(const DataLookup2D& m,
59                             const utility::Index& index, 
60                             const bool row)
61    : ref_count_(NULL)
62  {
63    if (row){
64      row_index_ = utility::Index(m.row_index_, index);
65      column_index_= m.column_index_;
66    }
67    else{
68      column_index_ = utility::Index(m.column_index_, index);
69      row_index_= m.row_index_;
70    }
71  }   
72
73
74  DataLookup2D::DataLookup2D(const utility::Index& row, 
75                             const utility::Index& col,
76                             const bool own)
77    : row_index_(row),column_index_(col), ref_count_(NULL)
78  {
79    if (own)
80      ref_count_ = new u_int(1);
81  }
82
83
84
85  DataLookup2D::DataLookup2D(const DataLookup2D& mv)
86    : row_index_(mv.row_index_),column_index_(mv.column_index_), 
87      ref_count_(NULL)
88  {
89  }
90
91
92  DataLookup2D::DataLookup2D(const size_t rows, const size_t columns)
93    : row_index_(std::vector<size_t>(rows,0)), 
94      column_index_(std::vector<size_t>(columns,0)), ref_count_(NULL)
95
96  {
97  } 
98
99
100  size_t DataLookup2D::columns(void) const
101  {
102    return column_index_.size();
103  }
104
105
106  double DataLookup2D::data(size_t i, size_t j) const
107  {
108    return (*this)(i,j);
109  }
110
111
112  size_t DataLookup2D::rows(void) const
113  {
114    return row_index_.size();
115  }
116
117
118  double DataLookup2D::weight(size_t i, size_t j) const
119  {
120    return 1.0;
121  }
122
123
124  const DataLookup2D& DataLookup2D::operator=(const DataLookup2D& other)
125  {
126    // never copy yourself
127    if (this!=&other){
128      row_index_ = other.row_index_;
129      column_index_ = other.column_index_;
130    }
131    return *this;
132  }
133
134  std::ostream& operator<<(std::ostream& s, const DataLookup2D& m)
135  {
136    s.setf(std::ios::dec);
137    s.precision(12);
138    for(size_t i=0, j=0; i<m.rows(); i++)
139      for (j=0; j<m.columns(); j++) {
140        s << m(i,j);
141        if (j<m.columns()-1)
142          s << s.fill();
143        else if (i<m.rows()-1)
144          s << "\n";
145      }
146    return s;
147  }
148
149}}} // of namespace classifier, yat, and theplu
Note: See TracBrowser for help on using the repository browser.