271 |
14 Apr 05 |
peter |
// $Id$ |
271 |
14 Apr 05 |
peter |
2 |
|
675 |
10 Oct 06 |
jari |
3 |
/* |
2119 |
12 Dec 09 |
peter |
Copyright (C) 2005 Jari Häkkinen, Peter Johansson |
2119 |
12 Dec 09 |
peter |
Copyright (C) 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér |
2119 |
12 Dec 09 |
peter |
Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson |
4207 |
26 Aug 22 |
peter |
Copyright (C) 2010, 2012, 2022 Peter Johansson |
271 |
14 Apr 05 |
peter |
8 |
|
1437 |
25 Aug 08 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
675 |
10 Oct 06 |
jari |
10 |
|
675 |
10 Oct 06 |
jari |
The yat library is free software; you can redistribute it and/or |
675 |
10 Oct 06 |
jari |
modify it under the terms of the GNU General Public License as |
1486 |
09 Sep 08 |
jari |
published by the Free Software Foundation; either version 3 of the |
675 |
10 Oct 06 |
jari |
License, or (at your option) any later version. |
675 |
10 Oct 06 |
jari |
15 |
|
675 |
10 Oct 06 |
jari |
The yat library is distributed in the hope that it will be useful, |
675 |
10 Oct 06 |
jari |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
675 |
10 Oct 06 |
jari |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
675 |
10 Oct 06 |
jari |
General Public License for more details. |
675 |
10 Oct 06 |
jari |
20 |
|
675 |
10 Oct 06 |
jari |
You should have received a copy of the GNU General Public License |
1487 |
10 Sep 08 |
jari |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
675 |
10 Oct 06 |
jari |
23 |
*/ |
675 |
10 Oct 06 |
jari |
24 |
|
2881 |
18 Nov 12 |
peter |
25 |
#include <config.h> |
2881 |
18 Nov 12 |
peter |
26 |
|
1240 |
16 Mar 08 |
peter |
27 |
#include "Suite.h" |
1240 |
16 Mar 08 |
peter |
28 |
|
4132 |
21 Jan 22 |
peter |
29 |
#include "yat/utility/concept_check.h" |
1121 |
22 Feb 08 |
peter |
30 |
#include "yat/utility/Matrix.h" |
675 |
10 Oct 06 |
jari |
31 |
|
4132 |
21 Jan 22 |
peter |
32 |
#include <boost/concept_check.hpp> |
4132 |
21 Jan 22 |
peter |
33 |
|
2735 |
29 May 12 |
peter |
34 |
#include <cmath> |
679 |
11 Oct 06 |
markus |
35 |
#include <cstdio> |
271 |
14 Apr 05 |
peter |
36 |
#include <fstream> |
271 |
14 Apr 05 |
peter |
37 |
#include <iostream> |
271 |
14 Apr 05 |
peter |
38 |
|
4124 |
13 Jan 22 |
peter |
39 |
using namespace theplu::yat; |
4124 |
13 Jan 22 |
peter |
40 |
|
4124 |
13 Jan 22 |
peter |
41 |
void test_assignment(test::Suite& suite); |
4124 |
13 Jan 22 |
peter |
42 |
|
420 |
02 Dec 05 |
jari |
43 |
class matrixwrapper |
420 |
02 Dec 05 |
jari |
44 |
{ |
420 |
02 Dec 05 |
jari |
45 |
public: |
420 |
02 Dec 05 |
jari |
46 |
matrixwrapper(size_t i,size_t j,double value=7) |
420 |
02 Dec 05 |
jari |
47 |
: m_(i,j,value) {} |
420 |
02 Dec 05 |
jari |
48 |
|
4124 |
13 Jan 22 |
peter |
49 |
utility::VectorView row(const size_t& i) |
4124 |
13 Jan 22 |
peter |
50 |
{ return m_.row_view(i); } |
420 |
02 Dec 05 |
jari |
51 |
|
4124 |
13 Jan 22 |
peter |
52 |
const utility::MatrixBase& matrix_base(void) const |
4124 |
13 Jan 22 |
peter |
53 |
{ return m_; } |
420 |
02 Dec 05 |
jari |
54 |
|
4124 |
13 Jan 22 |
peter |
55 |
const utility::MatrixMutable& matrix_mutable(void) const |
4124 |
13 Jan 22 |
peter |
56 |
{ return m_; } |
4124 |
13 Jan 22 |
peter |
57 |
|
4124 |
13 Jan 22 |
peter |
58 |
utility::MatrixMutable& matrix_mutable(void) |
4124 |
13 Jan 22 |
peter |
59 |
{ return m_; } |
4124 |
13 Jan 22 |
peter |
60 |
|
4124 |
13 Jan 22 |
peter |
61 |
const utility::Matrix& matrix(void) const |
4124 |
13 Jan 22 |
peter |
62 |
{ return m_; } |
4124 |
13 Jan 22 |
peter |
63 |
|
4124 |
13 Jan 22 |
peter |
64 |
utility::Matrix& matrix(void) |
4124 |
13 Jan 22 |
peter |
65 |
{ return m_; } |
4124 |
13 Jan 22 |
peter |
66 |
|
420 |
02 Dec 05 |
jari |
67 |
private: |
4124 |
13 Jan 22 |
peter |
68 |
utility::Matrix m_; |
420 |
02 Dec 05 |
jari |
69 |
}; |
420 |
02 Dec 05 |
jari |
70 |
|
420 |
02 Dec 05 |
jari |
71 |
|
1240 |
16 Mar 08 |
peter |
72 |
int main(int argc, char* argv[]) |
420 |
02 Dec 05 |
jari |
73 |
{ |
1240 |
16 Mar 08 |
peter |
74 |
test::Suite suite(argc, argv); |
420 |
02 Dec 05 |
jari |
75 |
|
2735 |
29 May 12 |
peter |
76 |
suite.err() << "Testing Matrix class" << std::endl; |
1121 |
22 Feb 08 |
peter |
77 |
utility::Matrix unit3x3(3,3); |
762 |
20 Feb 07 |
jari |
78 |
for (size_t i=0; i<unit3x3.rows(); ++i) |
762 |
20 Feb 07 |
jari |
79 |
unit3x3(i,i)=1; |
271 |
14 Apr 05 |
peter |
80 |
|
1360 |
26 Jun 08 |
peter |
81 |
suite.add(suite.test_stream(unit3x3)); |
1360 |
26 Jun 08 |
peter |
82 |
|
1240 |
16 Mar 08 |
peter |
83 |
suite.err() << "\tcopy constructor and operator!=" << std::endl; |
1121 |
22 Feb 08 |
peter |
84 |
utility::Matrix m(3,3,9); |
1121 |
22 Feb 08 |
peter |
85 |
utility::Matrix m2(m); |
271 |
14 Apr 05 |
peter |
86 |
if (m2!=m) |
1240 |
16 Mar 08 |
peter |
87 |
suite.add(false); |
420 |
02 Dec 05 |
jari |
88 |
|
1240 |
16 Mar 08 |
peter |
89 |
suite.err() << "\toutput operator and istream constructor" << std::endl; |
420 |
02 Dec 05 |
jari |
// Checking that the matrix output operator writes a file that the |
420 |
02 Dec 05 |
jari |
// input operator can read. |
1251 |
03 Apr 08 |
peter |
92 |
std::ofstream my_out("/tmp/yat_test_matrix.txt"); |
271 |
14 Apr 05 |
peter |
93 |
my_out << m2; |
271 |
14 Apr 05 |
peter |
94 |
my_out.close(); |
1251 |
03 Apr 08 |
peter |
95 |
std::ifstream is("/tmp/yat_test_matrix.txt"); |
1121 |
22 Feb 08 |
peter |
96 |
utility::Matrix m3(is); |
271 |
14 Apr 05 |
peter |
97 |
is.close(); |
271 |
14 Apr 05 |
peter |
98 |
if (m3!=m2) |
1240 |
16 Mar 08 |
peter |
99 |
suite.add(false); |
1251 |
03 Apr 08 |
peter |
100 |
std::remove("/tmp/yat_test_matrix.txt"); |
271 |
14 Apr 05 |
peter |
101 |
|
1240 |
16 Mar 08 |
peter |
102 |
suite.err() << "\toperator*=(double)" << std::endl; |
1121 |
22 Feb 08 |
peter |
103 |
utility::Matrix m4(3,3,1); |
393 |
14 Sep 05 |
peter |
104 |
m4 *= 9; |
420 |
02 Dec 05 |
jari |
105 |
if (m4!=m) { |
1240 |
16 Mar 08 |
peter |
106 |
suite.add(false); |
1240 |
16 Mar 08 |
peter |
107 |
suite.err() << "error operator*=(double)" << std::endl; |
271 |
14 Apr 05 |
peter |
108 |
} |
271 |
14 Apr 05 |
peter |
109 |
|
1251 |
03 Apr 08 |
peter |
110 |
is.open(test::filename("data/knni_matrix.data").c_str()); |
420 |
02 Dec 05 |
jari |
// The stream input is a proper matrix file, with some stray empty |
420 |
02 Dec 05 |
jari |
// lines and other whitespaces. The file is not expected to break |
420 |
02 Dec 05 |
jari |
// things. |
1121 |
22 Feb 08 |
peter |
114 |
utility::Matrix m5(is); |
420 |
02 Dec 05 |
jari |
115 |
is.close(); |
420 |
02 Dec 05 |
jari |
116 |
double m5_sum=0; |
420 |
02 Dec 05 |
jari |
117 |
for (size_t i=0; i<m5.rows(); ++i) |
420 |
02 Dec 05 |
jari |
118 |
for (size_t j=0; j<m5.columns(); ++j) |
420 |
02 Dec 05 |
jari |
119 |
m5_sum+=m5(i,j); |
393 |
14 Sep 05 |
peter |
120 |
|
793 |
11 Mar 07 |
jari |
// checking that copy constructor creates an independent object when |
793 |
11 Mar 07 |
jari |
// a non-view matrix is copied |
793 |
11 Mar 07 |
jari |
123 |
{ |
1240 |
16 Mar 08 |
peter |
124 |
suite.err() << "\tcopy constructor" << std::endl; |
1121 |
22 Feb 08 |
peter |
125 |
utility::Matrix m2(m5); |
2735 |
29 May 12 |
peter |
126 |
if (!suite.add(m2.rows()==m5.rows())) |
2735 |
29 May 12 |
peter |
127 |
suite.err() << "m2.rows() != m5.rows()\n"; |
2735 |
29 May 12 |
peter |
128 |
else if (!suite.add(m2.columns()==m5.columns())) |
2735 |
29 May 12 |
peter |
129 |
suite.err() << "m2.columns != m5.columns()\n"; |
2735 |
29 May 12 |
peter |
130 |
else if (!suite.add(&m2 != &m5)) |
2735 |
29 May 12 |
peter |
131 |
suite.err() << "m2 and m5 are the same instance\n"; |
2735 |
29 May 12 |
peter |
132 |
else { |
2735 |
29 May 12 |
peter |
133 |
for (size_t i=0; i<m2.rows(); ++i) |
2735 |
29 May 12 |
peter |
134 |
for (size_t j=0; j<m2.columns(); ++j) { |
2735 |
29 May 12 |
peter |
135 |
if (m2(i,j)!=m5(i,j)) { |
2735 |
29 May 12 |
peter |
136 |
if (std::isnan(m2(i,j)) && std::isnan(m5(i,j))) |
2735 |
29 May 12 |
peter |
137 |
continue; |
2735 |
29 May 12 |
peter |
138 |
suite.add(false); |
2735 |
29 May 12 |
peter |
139 |
suite.err() << "element " << i << " " << j << ": " << m2(i,j) |
2735 |
29 May 12 |
peter |
140 |
<< " " << m5(i,j) << "\n"; |
2735 |
29 May 12 |
peter |
141 |
} |
2735 |
29 May 12 |
peter |
142 |
} |
2735 |
29 May 12 |
peter |
143 |
} |
793 |
11 Mar 07 |
jari |
144 |
} |
793 |
11 Mar 07 |
jari |
145 |
|
1240 |
16 Mar 08 |
peter |
146 |
suite.err() << "\tsub-(row)vector" << std::endl; |
420 |
02 Dec 05 |
jari |
// Checking that the row view works, i.e. mutation to the view are |
420 |
02 Dec 05 |
jari |
// reflected in the viewed object. |
1098 |
18 Feb 08 |
jari |
149 |
double m5_sum2=0; |
793 |
11 Mar 07 |
jari |
150 |
for (size_t i=0; i<m5.rows(); ++i) |
793 |
11 Mar 07 |
jari |
151 |
for (size_t j=0; j<m5.columns(); ++j) |
793 |
11 Mar 07 |
jari |
152 |
m5_sum2+=m5(i,j); |
1015 |
01 Feb 08 |
peter |
153 |
utility::VectorView v5subrow(m5,3); |
420 |
02 Dec 05 |
jari |
154 |
double v5subrow_sum=0; |
420 |
02 Dec 05 |
jari |
155 |
for (size_t i=0; i<v5subrow.size(); ++i) { |
420 |
02 Dec 05 |
jari |
156 |
v5subrow_sum+=v5subrow(i); |
1151 |
25 Feb 08 |
peter |
157 |
v5subrow(i)=0; |
420 |
02 Dec 05 |
jari |
158 |
} |
420 |
02 Dec 05 |
jari |
159 |
double m5_sum3=0; |
420 |
02 Dec 05 |
jari |
160 |
for (size_t i=0; i<m5.rows(); ++i) |
420 |
02 Dec 05 |
jari |
161 |
for (size_t j=0; j<m5.columns(); ++j) |
420 |
02 Dec 05 |
jari |
162 |
m5_sum3+=m5(i,j); |
420 |
02 Dec 05 |
jari |
163 |
if (m5_sum3-m5_sum2+v5subrow_sum>1e-13) { |
1240 |
16 Mar 08 |
peter |
164 |
suite.add(false); |
1240 |
16 Mar 08 |
peter |
165 |
suite.err() << "error sub-vector test 1" << std::endl; |
420 |
02 Dec 05 |
jari |
166 |
} |
420 |
02 Dec 05 |
jari |
167 |
|
1240 |
16 Mar 08 |
peter |
168 |
suite.err() << "\tsub-(column)vector" << std::endl; |
420 |
02 Dec 05 |
jari |
// Checking that the column view works, i.e. mutation to the view |
420 |
02 Dec 05 |
jari |
// are reflected in the viewed object. |
793 |
11 Mar 07 |
jari |
171 |
m5_sum3=0; |
793 |
11 Mar 07 |
jari |
172 |
for (size_t i=0; i<m5.rows(); ++i) |
793 |
11 Mar 07 |
jari |
173 |
for (size_t j=0; j<m5.columns(); ++j) |
793 |
11 Mar 07 |
jari |
174 |
m5_sum3+=m5(i,j); |
1028 |
03 Feb 08 |
peter |
175 |
utility::VectorView v5subcolumn = m5.column_view(0); |
420 |
02 Dec 05 |
jari |
176 |
double v5subcolumn_sum=0; |
420 |
02 Dec 05 |
jari |
177 |
for (size_t i=0; i<v5subcolumn.size(); ++i) { |
420 |
02 Dec 05 |
jari |
178 |
v5subcolumn_sum+=v5subcolumn(i); |
420 |
02 Dec 05 |
jari |
179 |
v5subcolumn(i)=1; |
420 |
02 Dec 05 |
jari |
180 |
} |
420 |
02 Dec 05 |
jari |
181 |
double m5_sum4=0; |
420 |
02 Dec 05 |
jari |
182 |
for (size_t i=0; i<m5.rows(); ++i) |
420 |
02 Dec 05 |
jari |
183 |
for (size_t j=0; j<m5.columns(); ++j) |
420 |
02 Dec 05 |
jari |
184 |
m5_sum4+=m5(i,j); |
420 |
02 Dec 05 |
jari |
185 |
if (m5_sum4-m5_sum3-v5subcolumn.size()+v5subcolumn_sum>1e-13) { |
1240 |
16 Mar 08 |
peter |
186 |
suite.add(false); |
1240 |
16 Mar 08 |
peter |
187 |
suite.err() << "error sub-vector test 2" << std::endl; |
420 |
02 Dec 05 |
jari |
188 |
} |
793 |
11 Mar 07 |
jari |
189 |
|
420 |
02 Dec 05 |
jari |
// Checking that the column view above mutates the values in the row |
420 |
02 Dec 05 |
jari |
// view. |
420 |
02 Dec 05 |
jari |
192 |
double v5subrow_sum2=0; |
420 |
02 Dec 05 |
jari |
193 |
for (size_t i=0; i<v5subrow.size(); ++i) |
420 |
02 Dec 05 |
jari |
194 |
v5subrow_sum2+=v5subrow(i); |
420 |
02 Dec 05 |
jari |
195 |
if (v5subrow_sum2-v5subcolumn(3)>1e-13) { |
1240 |
16 Mar 08 |
peter |
196 |
suite.add(false); |
1240 |
16 Mar 08 |
peter |
197 |
suite.err() << "error sub-vector test 3" << std::endl; |
420 |
02 Dec 05 |
jari |
198 |
} |
420 |
02 Dec 05 |
jari |
199 |
|
1240 |
16 Mar 08 |
peter |
200 |
suite.err() << "\tsub-vector and vector copying" << std::endl; |
420 |
02 Dec 05 |
jari |
// Checking that a view is not inherited through the copy |
420 |
02 Dec 05 |
jari |
// contructor. |
1120 |
21 Feb 08 |
peter |
203 |
utility::Vector v6(v5subrow); |
830 |
24 Mar 07 |
jari |
204 |
v6.all(2); |
420 |
02 Dec 05 |
jari |
205 |
double v5subrow_sum3=0; |
420 |
02 Dec 05 |
jari |
206 |
for (size_t i=0; i<v5subrow.size(); ++i) |
420 |
02 Dec 05 |
jari |
207 |
v5subrow_sum3+=v5subrow(i); |
420 |
02 Dec 05 |
jari |
208 |
if (v5subrow_sum3-v5subrow_sum2>1e-13) { |
1240 |
16 Mar 08 |
peter |
209 |
suite.add(false); |
1240 |
16 Mar 08 |
peter |
210 |
suite.err() << "error sub-vector test 4" << std::endl; |
420 |
02 Dec 05 |
jari |
211 |
} |
420 |
02 Dec 05 |
jari |
// Checking that values in a vector is copied into a viewed matrix. |
830 |
24 Mar 07 |
jari |
213 |
v5subrow = v6; |
420 |
02 Dec 05 |
jari |
214 |
double m5_sum5=0; |
420 |
02 Dec 05 |
jari |
215 |
for (size_t i=0; i<m5.rows(); ++i) |
420 |
02 Dec 05 |
jari |
216 |
for (size_t j=0; j<m5.columns(); ++j) |
420 |
02 Dec 05 |
jari |
217 |
m5_sum5+=m5(i,j); |
420 |
02 Dec 05 |
jari |
218 |
if (m5_sum5-m5_sum4-v5subrow.size()*2+v5subrow_sum3>1e-13) { |
1240 |
16 Mar 08 |
peter |
219 |
suite.add(false); |
1240 |
16 Mar 08 |
peter |
220 |
suite.err() << "error sub-vector test 5" << std::endl; |
420 |
02 Dec 05 |
jari |
221 |
} |
420 |
02 Dec 05 |
jari |
222 |
|
420 |
02 Dec 05 |
jari |
// Checking that the memberfunction matrixwrapper::row() returns a |
420 |
02 Dec 05 |
jari |
// view |
1240 |
16 Mar 08 |
peter |
225 |
suite.err() << "\tthat class member returns a view" << std::endl; |
420 |
02 Dec 05 |
jari |
226 |
matrixwrapper mw(5,2); |
1015 |
01 Feb 08 |
peter |
227 |
utility::VectorView mwrow=mw.row(2); |
420 |
02 Dec 05 |
jari |
228 |
if (mwrow.gsl_vector_p()->data != &(mw.matrix()(2,0))) { |
1240 |
16 Mar 08 |
peter |
229 |
suite.add(false); |
1240 |
16 Mar 08 |
peter |
230 |
suite.err() << "error sub-vector test 7" << std::endl; |
420 |
02 Dec 05 |
jari |
231 |
} |
420 |
02 Dec 05 |
jari |
232 |
|
1240 |
16 Mar 08 |
peter |
233 |
suite.err() << "\tmatrix::nan()" << std::endl; |
1251 |
03 Apr 08 |
peter |
234 |
is.open(test::filename("data/sorlie_centroid_data.txt").c_str()); |
1121 |
22 Feb 08 |
peter |
235 |
utility::Matrix* m_nan = new utility::Matrix(is,'\t'); |
1121 |
22 Feb 08 |
peter |
236 |
utility::Matrix m_weight; |
774 |
01 Mar 07 |
jari |
237 |
utility::nan(*m_nan,m_weight); |
516 |
20 Feb 06 |
peter |
238 |
is.close(); |
516 |
20 Feb 06 |
peter |
239 |
if (m_weight(0,0)!=1){ |
1240 |
16 Mar 08 |
peter |
240 |
suite.err() << "error in matrix::nan(): element(0,0) is " << m_weight(0,0) |
516 |
20 Feb 06 |
peter |
241 |
<< " expected 1." << std::endl; |
1240 |
16 Mar 08 |
peter |
242 |
suite.add(false); |
516 |
20 Feb 06 |
peter |
243 |
} |
516 |
20 Feb 06 |
peter |
244 |
if (m_weight(3,2)!=0){ |
1240 |
16 Mar 08 |
peter |
245 |
suite.err() << "error in matrix::nan(): element(3,2) is " << m_weight(3,2) |
516 |
20 Feb 06 |
peter |
246 |
<< " expected 0." << std::endl; |
1240 |
16 Mar 08 |
peter |
247 |
suite.add(false); |
516 |
20 Feb 06 |
peter |
248 |
} |
516 |
20 Feb 06 |
peter |
249 |
delete m_nan; |
516 |
20 Feb 06 |
peter |
250 |
|
1240 |
16 Mar 08 |
peter |
251 |
suite.err() << "\toperator*=(matrix&)" << std::endl; |
1121 |
22 Feb 08 |
peter |
252 |
utility::Matrix m6(unit3x3); |
762 |
20 Feb 07 |
jari |
253 |
m6 *= m; |
762 |
20 Feb 07 |
jari |
254 |
if (m6!=m) { |
1240 |
16 Mar 08 |
peter |
255 |
suite.add(false); |
1240 |
16 Mar 08 |
peter |
256 |
suite.err() << "error operator*=(matrix) 1" << std::endl; |
762 |
20 Feb 07 |
jari |
257 |
} |
762 |
20 Feb 07 |
jari |
258 |
m6 *= unit3x3; |
762 |
20 Feb 07 |
jari |
259 |
if (m6!=m) { |
1240 |
16 Mar 08 |
peter |
260 |
suite.add(false); |
1240 |
16 Mar 08 |
peter |
261 |
suite.err() << "error operator*=(matrix) 2" << std::endl; |
762 |
20 Feb 07 |
jari |
262 |
} |
1121 |
22 Feb 08 |
peter |
263 |
m6*= utility::Matrix(3,4,1.0); |
1121 |
22 Feb 08 |
peter |
264 |
m6*= utility::Matrix(4,3,1.0); |
1121 |
22 Feb 08 |
peter |
265 |
m6*= utility::Matrix(3,5,2.0); |
1121 |
22 Feb 08 |
peter |
266 |
m6*= utility::Matrix(5,5,2.0); |
1121 |
22 Feb 08 |
peter |
267 |
m6*= utility::Matrix(5,3,2.0); |
796 |
12 Mar 07 |
jari |
268 |
m6*= unit3x3; |
762 |
20 Feb 07 |
jari |
269 |
|
4124 |
13 Jan 22 |
peter |
270 |
std::cerr << "m7\n"; |
1598 |
24 Oct 08 |
peter |
271 |
utility::Matrix m7(0,0); |
1598 |
24 Oct 08 |
peter |
272 |
m7.resize(1,1); |
1598 |
24 Oct 08 |
peter |
273 |
m7 = utility::Matrix(0,0); |
1598 |
24 Oct 08 |
peter |
274 |
m7.resize(0,0); |
1598 |
24 Oct 08 |
peter |
275 |
m7 = utility::Matrix(0,0); |
1598 |
24 Oct 08 |
peter |
276 |
|
4124 |
13 Jan 22 |
peter |
277 |
std::cerr << "m8\n"; |
2735 |
29 May 12 |
peter |
278 |
utility::Matrix m8(10,10,2); |
2735 |
29 May 12 |
peter |
279 |
if (!suite.add(suite.equal(trace(m8), 20))) { |
2735 |
29 May 12 |
peter |
280 |
suite.err() << "trace failed\n"; |
2735 |
29 May 12 |
peter |
281 |
} |
2143 |
15 Jan 10 |
peter |
282 |
const utility::Matrix const_m(2,2,0); |
2143 |
15 Jan 10 |
peter |
283 |
utility::Matrix mutable_m(2,2,0); |
2143 |
15 Jan 10 |
peter |
// concept compiler tests |
2143 |
15 Jan 10 |
peter |
285 |
suite.test_concept_container2d(const_m); |
2143 |
15 Jan 10 |
peter |
286 |
suite.test_concept_mutable_container2d(mutable_m); |
2143 |
15 Jan 10 |
peter |
287 |
|
4124 |
13 Jan 22 |
peter |
288 |
test_assignment(suite); |
4132 |
21 Jan 22 |
peter |
289 |
|
4132 |
21 Jan 22 |
peter |
// test concepts |
4132 |
21 Jan 22 |
peter |
291 |
BOOST_CONCEPT_ASSERT((utility::Container2D<utility::MatrixBase>)); |
4132 |
21 Jan 22 |
peter |
292 |
BOOST_CONCEPT_ASSERT((utility::Mutable_Container2D<utility::MatrixMutable>)); |
4132 |
21 Jan 22 |
peter |
293 |
BOOST_CONCEPT_ASSERT((utility::Mutable_Container2D<utility::Matrix>)); |
4132 |
21 Jan 22 |
peter |
294 |
|
2735 |
29 May 12 |
peter |
295 |
return suite.return_value(); |
271 |
14 Apr 05 |
peter |
296 |
} |
4124 |
13 Jan 22 |
peter |
297 |
|
4124 |
13 Jan 22 |
peter |
298 |
|
4124 |
13 Jan 22 |
peter |
299 |
void test_assignment(test::Suite& suite) |
4124 |
13 Jan 22 |
peter |
300 |
{ |
4124 |
13 Jan 22 |
peter |
301 |
|
4124 |
13 Jan 22 |
peter |
302 |
{ |
4124 |
13 Jan 22 |
peter |
303 |
suite.out() << "test copy construction\n"; |
4124 |
13 Jan 22 |
peter |
304 |
matrixwrapper A(4,3,0); |
4124 |
13 Jan 22 |
peter |
305 |
utility::Matrix B(A.matrix_base()); |
4124 |
13 Jan 22 |
peter |
306 |
suite.add(suite.equal_matrix(A.matrix(), B)); |
4124 |
13 Jan 22 |
peter |
307 |
utility::Matrix C(A.matrix_mutable()); |
4124 |
13 Jan 22 |
peter |
308 |
suite.add(suite.equal_matrix(A.matrix(), C)); |
4124 |
13 Jan 22 |
peter |
309 |
} |
4124 |
13 Jan 22 |
peter |
310 |
|
4124 |
13 Jan 22 |
peter |
311 |
|
4124 |
13 Jan 22 |
peter |
// test Matrix LHS |
4124 |
13 Jan 22 |
peter |
313 |
{ |
4124 |
13 Jan 22 |
peter |
314 |
matrixwrapper A(4,5,0); |
4124 |
13 Jan 22 |
peter |
315 |
|
4124 |
13 Jan 22 |
peter |
// self-assignment |
4124 |
13 Jan 22 |
peter |
317 |
A.matrix() = A.matrix_base(); |
4124 |
13 Jan 22 |
peter |
318 |
A.matrix() = A.matrix_mutable(); |
4124 |
13 Jan 22 |
peter |
319 |
|
4124 |
13 Jan 22 |
peter |
320 |
const matrixwrapper B(4,3,1.0); |
4124 |
13 Jan 22 |
peter |
321 |
A.matrix() = B.matrix_base(); |
4124 |
13 Jan 22 |
peter |
322 |
suite.add(suite.equal_matrix(A.matrix(), B.matrix())); |
4124 |
13 Jan 22 |
peter |
323 |
const matrixwrapper C(4,3,2.0); |
4124 |
13 Jan 22 |
peter |
324 |
A.matrix() = C.matrix_mutable(); |
4124 |
13 Jan 22 |
peter |
325 |
suite.add(suite.equal_matrix(A.matrix(), C.matrix())); |
4124 |
13 Jan 22 |
peter |
326 |
|
4124 |
13 Jan 22 |
peter |
// move assignment |
4124 |
13 Jan 22 |
peter |
328 |
matrixwrapper D(4,3,1.0); |
4124 |
13 Jan 22 |
peter |
329 |
utility::Matrix D_copy(D.matrix()); |
4124 |
13 Jan 22 |
peter |
330 |
A.matrix() = std::move(D.matrix_mutable()); |
4124 |
13 Jan 22 |
peter |
331 |
suite.add(suite.equal_matrix(A.matrix(), D_copy)); |
4124 |
13 Jan 22 |
peter |
332 |
} |
4124 |
13 Jan 22 |
peter |
333 |
|
4124 |
13 Jan 22 |
peter |
// test MatrixMutable LHS |
4124 |
13 Jan 22 |
peter |
335 |
{ |
4124 |
13 Jan 22 |
peter |
336 |
matrixwrapper A(4,5,0); |
4124 |
13 Jan 22 |
peter |
337 |
|
4124 |
13 Jan 22 |
peter |
// self-assignment |
4124 |
13 Jan 22 |
peter |
339 |
A.matrix_mutable() = A.matrix_base(); |
4124 |
13 Jan 22 |
peter |
340 |
A.matrix_mutable() = A.matrix(); |
4124 |
13 Jan 22 |
peter |
341 |
|
4124 |
13 Jan 22 |
peter |
342 |
const matrixwrapper B(4,3,1.0); |
4124 |
13 Jan 22 |
peter |
343 |
A.matrix_mutable() = B.matrix_base(); |
4124 |
13 Jan 22 |
peter |
344 |
suite.add(suite.equal_matrix(A.matrix(), B.matrix())); |
4124 |
13 Jan 22 |
peter |
345 |
const matrixwrapper C(4,3,2.0); |
4124 |
13 Jan 22 |
peter |
346 |
A.matrix_mutable() = C.matrix_mutable(); |
4124 |
13 Jan 22 |
peter |
347 |
suite.add(suite.equal_matrix(A.matrix(), C.matrix())); |
4124 |
13 Jan 22 |
peter |
348 |
const matrixwrapper D(4,3,3.0); |
4124 |
13 Jan 22 |
peter |
349 |
A.matrix_mutable() = D.matrix(); |
4124 |
13 Jan 22 |
peter |
350 |
suite.add(suite.equal_matrix(A.matrix(), D.matrix())); |
4124 |
13 Jan 22 |
peter |
351 |
|
4124 |
13 Jan 22 |
peter |
// move assignment |
4124 |
13 Jan 22 |
peter |
353 |
matrixwrapper E(4,3,1.0); |
4124 |
13 Jan 22 |
peter |
354 |
utility::Matrix E_copy(E.matrix()); |
4124 |
13 Jan 22 |
peter |
355 |
A.matrix_mutable() = std::move(E.matrix_mutable()); |
4124 |
13 Jan 22 |
peter |
356 |
suite.add(suite.equal_matrix(A.matrix(), E_copy)); |
4124 |
13 Jan 22 |
peter |
357 |
|
4124 |
13 Jan 22 |
peter |
358 |
matrixwrapper F(4,3,1.0); |
4124 |
13 Jan 22 |
peter |
359 |
utility::Matrix F_copy(F.matrix()); |
4124 |
13 Jan 22 |
peter |
360 |
A.matrix_mutable() = std::move(F.matrix()); |
4124 |
13 Jan 22 |
peter |
361 |
suite.add(suite.equal_matrix(A.matrix(), F_copy)); |
4124 |
13 Jan 22 |
peter |
362 |
} |
4124 |
13 Jan 22 |
peter |
363 |
|
4124 |
13 Jan 22 |
peter |
364 |
} |