source: trunk/lib/classifier/DataLookup1D.cc @ 537

Last change on this file since 537 was 537, checked in by Peter, 16 years ago

forked tests and fixed bugs

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