source: trunk/yat/classifier/DataLookupWeighted1D.cc @ 720

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

Fixes #170. Almost all inlines removed, some classes have no cc file.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.5 KB
Line 
1// $Id: DataLookupWeighted1D.cc 720 2006-12-26 18:21:36Z jari $
2
3/*
4  Copyright (C) The authors contributing to this file.
5
6  This file is part of the yat library, http://lev.thep.lu.se/trac/yat
7
8  The yat library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2 of the
11  License, or (at your option) any later version.
12
13  The yat library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21  02111-1307, USA.
22*/
23
24#include "DataLookupWeighted1D.h"
25#include "MatrixLookupWeighted.h"
26
27#include <cassert>
28#include <iostream>
29#include <iomanip>
30
31namespace theplu {
32namespace yat {
33namespace classifier {
34
35  DataLookupWeighted1D::DataLookupWeighted1D(const MatrixLookupWeighted& m, 
36                                             const size_t i, 
37                             const bool row_vector)
38    : column_vector_(!row_vector), index_(i), matrix_(&m), owner_(false)
39  {
40    assert( !column_vector_ || i<m.columns());
41    assert( column_vector_ || i<m.rows());
42  }
43 
44
45  DataLookupWeighted1D::DataLookupWeighted1D(const size_t size, 
46                                             const double value,
47                                             const double weight)
48    : column_vector_(false), index_(0), owner_(true)
49  {
50    matrix_ = new MatrixLookupWeighted(1,size,value,weight);
51  }
52
53 
54  DataLookupWeighted1D::DataLookupWeighted1D(const DataLookupWeighted1D& other)
55    : column_vector_(other.column_vector_), index_(other.index_),
56      matrix_(other.matrix_), owner_(false)
57  {
58  }
59
60
61  DataLookupWeighted1D::~DataLookupWeighted1D()
62  {
63    if (owner_)
64      delete matrix_;
65  }
66
67
68  double DataLookupWeighted1D::data(const size_t i) const
69  {
70    return column_vector_? matrix_->data(i,index_) : matrix_->data(index_,i);
71  }
72
73
74  size_t DataLookupWeighted1D::size(void) const
75  {
76    return column_vector_ ? matrix_->rows() : matrix_->columns();
77  }
78
79
80  double DataLookupWeighted1D::weight(const size_t i) const
81  {
82    return column_vector_? matrix_->weight(i,index_) : matrix_->weight(index_,i);
83  }
84
85
86  double DataLookupWeighted1D::operator()(const size_t i) const
87  {
88    return column_vector_ ? (*matrix_)(i,index_) : (*matrix_)(index_,i);
89  }
90
91
92  double DataLookupWeighted1D::operator[](const size_t i) const
93  {
94    return this->operator()(i);
95  }
96
97}}} // of namespace classifier, yat, and theplu
Note: See TracBrowser for help on using the repository browser.