source: trunk/test/kernel_matrix.cc @ 3190

Last change on this file since 3190 was 3190, checked in by Peter, 8 years ago

new class KernelMatrix?. closes #381

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.6 KB
Line 
1// $Id: kernel_matrix.cc 3190 2014-03-30 07:47:40Z peter $
2
3/*
4  Copyright (C) 2014 Peter Johansson
5
6  This file is part of the yat library, http://dev.thep.lu.se/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 3 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 yat. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#include <config.h>
23
24#include "Suite.h"
25
26#include "yat/utility/KernelMatrix.h"
27
28#include <boost/range.hpp>
29
30#include <functional>
31#include <string>
32
33using namespace theplu::yat;
34using utility::KernelMatrix;
35
36struct CharCompare : std::binary_function<char, char, double>
37{
38  double operator()(char a, char b) const
39  {
40    if (a==b)
41      return 1.0;
42    return -3.0;
43  }
44};
45
46int main(int argc, char* argv[])
47{
48  test::Suite suite(argc, argv);
49
50  std::string str1("An example string");
51  std::string str2("An even longer string");
52
53  CharCompare comp;
54  KernelMatrix<std::string, std::string, CharCompare> km(str1, str2, comp);
55  suite.test_concept_container2d(km);
56
57  suite.out() << "rows: " << km.rows() << "\n";
58  suite.add(km.rows() == str1.size());
59  suite.out() << "columns: " << km.rows() << "\n";
60  suite.add(km.columns() == str2.size());
61  suite.out() << km(3,3) << "\n";
62  suite.add(km(3,3) == 1.0);
63
64  return suite.return_value();
65}
Note: See TracBrowser for help on using the repository browser.