source: trunk/c++_tools/classifier/DataLookup1D.cc @ 624

Last change on this file since 624 was 624, checked in by Peter, 15 years ago

fixes #109 and #110

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date ID
File size: 1.4 KB
Line 
1// $Id$
2
3#include <c++_tools/classifier/DataLookup1D.h>
4#include <c++_tools/classifier/DataLookup2D.h>
5#include <c++_tools/classifier/MatrixLookup.h>
6
7#include <cassert>
8#include <iostream>
9#include <iomanip>
10
11namespace theplu {
12namespace classifier {
13
14  DataLookup1D::DataLookup1D(const DataLookup2D& m, const size_t i, 
15                             const bool row_vector)
16    : column_vector_(!row_vector), index_(i), matrix_(&m), owner_(false)
17  {
18    assert( !column_vector_ || i<m.columns());
19    assert( column_vector_ || i<m.rows());
20  }
21 
22  DataLookup1D::DataLookup1D(const size_t size, const double value)
23    : column_vector_(false), index_(0), owner_(true)
24  {
25    matrix_ = new MatrixLookup(1,size,value);
26  }
27
28  DataLookup1D::DataLookup1D(const DataLookup1D& other)
29    : column_vector_(other.column_vector_), index_(other.index_),
30      matrix_(other.matrix_), owner_(false)
31  {
32  }
33
34  DataLookup1D::~DataLookup1D()
35  {
36    if (owner_)
37      delete matrix_;
38  }
39
40
41  double DataLookup1D::operator*(const DataLookup1D& other) const
42  {
43    assert(other.size()==size());
44    double res=0;
45    for (size_t i = 0; i<size(); i++)
46      res += (*this)(i)*other(i);
47    return res;
48  }
49
50
51  std::ostream& operator<<(std::ostream& os, const DataLookup1D& x)
52  {
53    os.setf(std::ios::dec);
54    os.precision(12);
55   
56    for (size_t i=0; i<x.size(); ++i) {
57      os << x(i);
58      if ((i+1)<x.size())
59        os << os.fill();
60    }
61    return os;
62  }
63
64}} // of namespace classifier and namespace theplu
Note: See TracBrowser for help on using the repository browser.