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

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

set properties

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