1587 |
17 Oct 08 |
peter |
// $Id$ |
1587 |
17 Oct 08 |
peter |
2 |
|
1587 |
17 Oct 08 |
peter |
3 |
/* |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2008, 2010, 2012 Peter Johansson |
1587 |
17 Oct 08 |
peter |
5 |
|
1587 |
17 Oct 08 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
1587 |
17 Oct 08 |
peter |
7 |
|
1587 |
17 Oct 08 |
peter |
The yat library is free software; you can redistribute it and/or |
1587 |
17 Oct 08 |
peter |
modify it under the terms of the GNU General Public License as |
1587 |
17 Oct 08 |
peter |
published by the Free Software Foundation; either version 3 of the |
1587 |
17 Oct 08 |
peter |
License, or (at your option) any later version. |
1587 |
17 Oct 08 |
peter |
12 |
|
1587 |
17 Oct 08 |
peter |
The yat library is distributed in the hope that it will be useful, |
1587 |
17 Oct 08 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
1587 |
17 Oct 08 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
1587 |
17 Oct 08 |
peter |
General Public License for more details. |
1587 |
17 Oct 08 |
peter |
17 |
|
1587 |
17 Oct 08 |
peter |
You should have received a copy of the GNU General Public License |
1587 |
17 Oct 08 |
peter |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
1587 |
17 Oct 08 |
peter |
20 |
*/ |
1587 |
17 Oct 08 |
peter |
21 |
|
2881 |
18 Nov 12 |
peter |
22 |
#include <config.h> |
2881 |
18 Nov 12 |
peter |
23 |
|
1587 |
17 Oct 08 |
peter |
24 |
#include "Suite.h" |
1587 |
17 Oct 08 |
peter |
25 |
|
1587 |
17 Oct 08 |
peter |
26 |
#include "yat/utility/MatrixWeighted.h" |
1587 |
17 Oct 08 |
peter |
27 |
#include "yat/classifier/MatrixLookupWeighted.h" |
1587 |
17 Oct 08 |
peter |
28 |
|
1587 |
17 Oct 08 |
peter |
29 |
#include <fstream> |
1587 |
17 Oct 08 |
peter |
30 |
#include <iostream> |
1587 |
17 Oct 08 |
peter |
31 |
#include <vector> |
1587 |
17 Oct 08 |
peter |
32 |
|
1587 |
17 Oct 08 |
peter |
33 |
using namespace theplu::yat; |
1587 |
17 Oct 08 |
peter |
34 |
|
1587 |
17 Oct 08 |
peter |
35 |
utility::MatrixWeighted matrix_weighted(size_t n); |
1587 |
17 Oct 08 |
peter |
36 |
bool compare(const classifier::MatrixLookupWeighted&, |
1587 |
17 Oct 08 |
peter |
37 |
const utility::MatrixWeighted, |
1587 |
17 Oct 08 |
peter |
38 |
const utility::Index& row_index, |
1587 |
17 Oct 08 |
peter |
39 |
const utility::Index& col_index, |
1587 |
17 Oct 08 |
peter |
40 |
test::Suite& suite); |
1587 |
17 Oct 08 |
peter |
41 |
|
1587 |
17 Oct 08 |
peter |
42 |
int main(int argc, char* argv[]) |
1587 |
17 Oct 08 |
peter |
43 |
{ |
1587 |
17 Oct 08 |
peter |
44 |
using namespace theplu::yat::classifier; |
1587 |
17 Oct 08 |
peter |
45 |
|
1587 |
17 Oct 08 |
peter |
46 |
test::Suite suite(argc, argv); |
1587 |
17 Oct 08 |
peter |
47 |
|
1587 |
17 Oct 08 |
peter |
48 |
suite.err() << "\nTesting MatrixLookupWeighted" << std::endl; |
4200 |
19 Aug 22 |
peter |
49 |
suite.err() << " Testing\n" |
1587 |
17 Oct 08 |
peter |
50 |
<< " MatrixLookupWeighted(const utility::MatrixWeighted&,\n" |
1587 |
17 Oct 08 |
peter |
51 |
<< " const utility::Index& rows,\n" |
1587 |
17 Oct 08 |
peter |
52 |
<< " const utility::Index& columns); " |
1587 |
17 Oct 08 |
peter |
53 |
<< "..."; |
1587 |
17 Oct 08 |
peter |
54 |
utility::MatrixWeighted mw = matrix_weighted(10); |
1587 |
17 Oct 08 |
peter |
55 |
std::vector<size_t> index; |
1587 |
17 Oct 08 |
peter |
56 |
index.push_back(1); |
1587 |
17 Oct 08 |
peter |
57 |
index.push_back(5); |
1587 |
17 Oct 08 |
peter |
58 |
index.push_back(3); |
1587 |
17 Oct 08 |
peter |
59 |
utility::Index row_index(5); |
1587 |
17 Oct 08 |
peter |
60 |
utility::Index column_index(index); |
1587 |
17 Oct 08 |
peter |
61 |
MatrixLookupWeighted mlw(mw, row_index, column_index); |
1587 |
17 Oct 08 |
peter |
62 |
if (compare(mlw, mw, row_index, column_index, suite)) |
1587 |
17 Oct 08 |
peter |
63 |
suite.err() << "ok.\n"; |
1587 |
17 Oct 08 |
peter |
64 |
else |
1587 |
17 Oct 08 |
peter |
65 |
suite.err() << "failed.\n"; |
1587 |
17 Oct 08 |
peter |
66 |
|
1587 |
17 Oct 08 |
peter |
67 |
|
4200 |
19 Aug 22 |
peter |
68 |
suite.err() << " Testing\n" |
1587 |
17 Oct 08 |
peter |
69 |
<< " MatrixLookupWeighted(const utility::MatrixWeighted&); " |
1587 |
17 Oct 08 |
peter |
70 |
<< "..."; |
1587 |
17 Oct 08 |
peter |
71 |
MatrixLookupWeighted mlw2(mw); |
4200 |
19 Aug 22 |
peter |
72 |
if (compare(mlw2, mw, utility::Index(mw.rows()), utility::Index(mw.columns()), |
1587 |
17 Oct 08 |
peter |
73 |
suite)) |
1587 |
17 Oct 08 |
peter |
74 |
suite.err() << "ok.\n"; |
1587 |
17 Oct 08 |
peter |
75 |
else |
1587 |
17 Oct 08 |
peter |
76 |
suite.err() << "failed.\n"; |
1587 |
17 Oct 08 |
peter |
77 |
|
4200 |
19 Aug 22 |
peter |
78 |
suite.err() << " Testing\n" |
1587 |
17 Oct 08 |
peter |
79 |
<< " MatrixLookupWeighted(const MatrixLookupWeighted&); " |
1587 |
17 Oct 08 |
peter |
80 |
<< "..."; |
1587 |
17 Oct 08 |
peter |
81 |
MatrixLookupWeighted mlw3(mlw); |
1587 |
17 Oct 08 |
peter |
82 |
if (compare(mlw3, mw, row_index, column_index, suite)) |
1587 |
17 Oct 08 |
peter |
83 |
suite.err() << "ok.\n"; |
1587 |
17 Oct 08 |
peter |
84 |
else |
1587 |
17 Oct 08 |
peter |
85 |
suite.err() << "failed.\n"; |
1587 |
17 Oct 08 |
peter |
86 |
|
2143 |
15 Jan 10 |
peter |
87 |
classifier::MatrixLookupWeighted const_m(2,2); |
2143 |
15 Jan 10 |
peter |
88 |
suite.test_concept_container2d(const_m); |
2143 |
15 Jan 10 |
peter |
89 |
|
1587 |
17 Oct 08 |
peter |
90 |
return suite.return_value(); |
1587 |
17 Oct 08 |
peter |
91 |
} |
1587 |
17 Oct 08 |
peter |
92 |
|
1587 |
17 Oct 08 |
peter |
93 |
bool compare(const classifier::MatrixLookupWeighted& mlw, |
1587 |
17 Oct 08 |
peter |
94 |
const utility::MatrixWeighted mw, |
1587 |
17 Oct 08 |
peter |
95 |
const utility::Index& row_index, |
1587 |
17 Oct 08 |
peter |
96 |
const utility::Index& column_index, |
1587 |
17 Oct 08 |
peter |
97 |
test::Suite& suite) |
1587 |
17 Oct 08 |
peter |
98 |
{ |
1587 |
17 Oct 08 |
peter |
99 |
bool ok=true; |
1587 |
17 Oct 08 |
peter |
100 |
ok &= (mlw.rows() == row_index.size()); |
1587 |
17 Oct 08 |
peter |
101 |
ok &= (mlw.columns() == column_index.size()); |
1587 |
17 Oct 08 |
peter |
102 |
for (size_t i=0; i<mlw.rows() && ok; ++i) { |
1587 |
17 Oct 08 |
peter |
103 |
for (size_t j=0; j<mlw.columns(); ++j) { |
1587 |
17 Oct 08 |
peter |
104 |
ok &= (mlw(i,j) == mw(row_index[i], column_index[j])); |
1587 |
17 Oct 08 |
peter |
105 |
} |
1587 |
17 Oct 08 |
peter |
106 |
} |
1587 |
17 Oct 08 |
peter |
107 |
suite.add(ok); |
1587 |
17 Oct 08 |
peter |
108 |
return ok; |
1587 |
17 Oct 08 |
peter |
109 |
} |
1587 |
17 Oct 08 |
peter |
110 |
|
1587 |
17 Oct 08 |
peter |
111 |
|
1587 |
17 Oct 08 |
peter |
112 |
utility::MatrixWeighted matrix_weighted(size_t n) |
1587 |
17 Oct 08 |
peter |
113 |
{ |
1587 |
17 Oct 08 |
peter |
114 |
utility::MatrixWeighted res(n,n); |
1587 |
17 Oct 08 |
peter |
115 |
for (size_t i=0;i<n;i++) |
1587 |
17 Oct 08 |
peter |
116 |
for (size_t j=0;j<n;j++) |
1587 |
17 Oct 08 |
peter |
117 |
res(i,j).data()=10*i+j; |
1587 |
17 Oct 08 |
peter |
118 |
return res; |
1587 |
17 Oct 08 |
peter |
119 |
} |