1 //=================================================================================================
2 /*!
3 // \file src/mathtest/views/rows/SparseGeneralTest2.cpp
4 // \brief Source file for the Rows sparse general test (part 2)
5 //
6 // Copyright (C) 2012-2020 Klaus Iglberger - All Rights Reserved
7 //
8 // This file is part of the Blaze library. You can redistribute it and/or modify it under
9 // the terms of the New (Revised) BSD License. Redistribution and use in source and binary
10 // forms, with or without modification, are permitted provided that the following conditions
11 // are met:
12 //
13 // 1. Redistributions of source code must retain the above copyright notice, this list of
14 // conditions and the following disclaimer.
15 // 2. Redistributions in binary form must reproduce the above copyright notice, this list
16 // of conditions and the following disclaimer in the documentation and/or other materials
17 // provided with the distribution.
18 // 3. Neither the names of the Blaze development group nor the names of its contributors
19 // may be used to endorse or promote products derived from this software without specific
20 // prior written permission.
21 //
22 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
23 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
25 // SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
27 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28 // BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
31 // DAMAGE.
32 */
33 //=================================================================================================
34
35
36 //*************************************************************************************************
37 // Includes
38 //*************************************************************************************************
39
40 #include <cstdlib>
41 #include <iostream>
42 #include <blaze/math/Views.h>
43 #include <blazetest/mathtest/views/rows/SparseGeneralTest.h>
44
45 #ifdef BLAZE_USE_HPX_THREADS
46 # include <hpx/hpx_main.hpp>
47 #endif
48
49
50 namespace blazetest {
51
52 namespace mathtest {
53
54 namespace views {
55
56 namespace rows {
57
58 //=================================================================================================
59 //
60 // CONSTRUCTORS
61 //
62 //=================================================================================================
63
64 //*************************************************************************************************
65 /*!\brief Constructor for the Rows sparse general test.
66 //
67 // \exception std::runtime_error Operation error detected.
68 */
SparseGeneralTest()69 SparseGeneralTest::SparseGeneralTest()
70 : mat_ ( 5UL, 4UL )
71 , tmat_( 5UL, 4UL )
72 {
73 testScaling();
74 testFunctionCall();
75 testIterator();
76 testNonZeros();
77 testReset();
78 testClear();
79 testReserve();
80 testTrim();
81 testSet();
82 testInsert();
83 testAppend();
84 testErase();
85 testFind();
86 testLowerBound();
87 testUpperBound();
88 testTranspose();
89 testCTranspose();
90 testIsDefault();
91 testIsSame();
92 testSubmatrix();
93 testRow();
94 testRows();
95 testColumn();
96 testBand();
97 }
98 //*************************************************************************************************
99
100
101
102
103 //=================================================================================================
104 //
105 // TEST FUNCTIONS
106 //
107 //=================================================================================================
108
109 //*************************************************************************************************
110 /*!\brief Test of all Rows (self-)scaling operations.
111 //
112 // \return void
113 // \exception std::runtime_error Error detected.
114 //
115 // This function performs a test of all available ways to scale an instance of the Rows
116 // specialization. In case an error is detected, a \a std::runtime_error exception is thrown.
117 */
testScaling()118 void SparseGeneralTest::testScaling()
119 {
120 //=====================================================================================
121 // Row-major self-scaling (M*=s)
122 //=====================================================================================
123
124 {
125 test_ = "Row-major self-scaling (M*=s)";
126
127 initialize();
128
129 auto rs = blaze::rows( mat_, { 2UL, 3UL } );
130
131 rs *= 3;
132
133 checkRows ( rs , 2UL );
134 checkColumns ( rs , 4UL );
135 checkNonZeros( rs , 5UL );
136 checkRows ( mat_, 5UL );
137 checkColumns ( mat_, 4UL );
138 checkNonZeros( mat_, 10UL );
139
140 if( rs(0,0) != -6 || rs(0,1) != 0 || rs(0,2) != -9 || rs(0,3) != 0 ||
141 rs(1,0) != 0 || rs(1,1) != 12 || rs(1,2) != 15 || rs(1,3) != -18 ) {
142 std::ostringstream oss;
143 oss << " Test: " << test_ << "\n"
144 << " Error: Failed self-scaling operation\n"
145 << " Details:\n"
146 << " Result:\n" << rs << "\n"
147 << " Expected result:\n( -6 0 -9 0 )\n( 0 12 15 -18 )\n";
148 throw std::runtime_error( oss.str() );
149 }
150
151 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != 0 || mat_(0,3) != 0 ||
152 mat_(1,0) != 0 || mat_(1,1) != 1 || mat_(1,2) != 0 || mat_(1,3) != 0 ||
153 mat_(2,0) != -6 || mat_(2,1) != 0 || mat_(2,2) != -9 || mat_(2,3) != 0 ||
154 mat_(3,0) != 0 || mat_(3,1) != 12 || mat_(3,2) != 15 || mat_(3,3) != -18 ||
155 mat_(4,0) != 7 || mat_(4,1) != -8 || mat_(4,2) != 9 || mat_(4,3) != 10 ) {
156 std::ostringstream oss;
157 oss << " Test: " << test_ << "\n"
158 << " Error: Failed self-scaling operation\n"
159 << " Details:\n"
160 << " Result:\n" << mat_ << "\n"
161 << " Expected result:\n( 0 0 0 0 )\n"
162 "( 0 1 0 0 )\n"
163 "( -6 0 -9 0 )\n"
164 "( 0 12 15 -18 )\n"
165 "( 7 -8 9 10 )\n";
166 throw std::runtime_error( oss.str() );
167 }
168 }
169
170
171 //=====================================================================================
172 // Row-major self-scaling (M=M*s)
173 //=====================================================================================
174
175 {
176 test_ = "Row-major self-scaling (M=M*s)";
177
178 initialize();
179
180 auto rs = blaze::rows( mat_, { 2UL, 3UL } );
181
182 rs = rs * 3;
183
184 checkRows ( rs , 2UL );
185 checkColumns ( rs , 4UL );
186 checkNonZeros( rs , 5UL );
187 checkRows ( mat_, 5UL );
188 checkColumns ( mat_, 4UL );
189 checkNonZeros( mat_, 10UL );
190
191 if( rs(0,0) != -6 || rs(0,1) != 0 || rs(0,2) != -9 || rs(0,3) != 0 ||
192 rs(1,0) != 0 || rs(1,1) != 12 || rs(1,2) != 15 || rs(1,3) != -18 ) {
193 std::ostringstream oss;
194 oss << " Test: " << test_ << "\n"
195 << " Error: Failed self-scaling operation\n"
196 << " Details:\n"
197 << " Result:\n" << rs << "\n"
198 << " Expected result:\n( -6 0 -9 0 )\n( 0 12 15 -18 )\n";
199 throw std::runtime_error( oss.str() );
200 }
201
202 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != 0 || mat_(0,3) != 0 ||
203 mat_(1,0) != 0 || mat_(1,1) != 1 || mat_(1,2) != 0 || mat_(1,3) != 0 ||
204 mat_(2,0) != -6 || mat_(2,1) != 0 || mat_(2,2) != -9 || mat_(2,3) != 0 ||
205 mat_(3,0) != 0 || mat_(3,1) != 12 || mat_(3,2) != 15 || mat_(3,3) != -18 ||
206 mat_(4,0) != 7 || mat_(4,1) != -8 || mat_(4,2) != 9 || mat_(4,3) != 10 ) {
207 std::ostringstream oss;
208 oss << " Test: " << test_ << "\n"
209 << " Error: Failed self-scaling operation\n"
210 << " Details:\n"
211 << " Result:\n" << mat_ << "\n"
212 << " Expected result:\n( 0 0 0 0 )\n"
213 "( 0 1 0 0 )\n"
214 "( -6 0 -9 0 )\n"
215 "( 0 12 15 -18 )\n"
216 "( 7 -8 9 10 )\n";
217 throw std::runtime_error( oss.str() );
218 }
219 }
220
221
222 //=====================================================================================
223 // Row-major self-scaling (M=s*M)
224 //=====================================================================================
225
226 {
227 test_ = "Row-major self-scaling (M=s*M)";
228
229 initialize();
230
231 auto rs = blaze::rows( mat_, { 2UL, 3UL } );
232
233 rs = 3 * rs;
234
235 checkRows ( rs , 2UL );
236 checkColumns ( rs , 4UL );
237 checkNonZeros( rs , 5UL );
238 checkRows ( mat_, 5UL );
239 checkColumns ( mat_, 4UL );
240 checkNonZeros( mat_, 10UL );
241
242 if( rs(0,0) != -6 || rs(0,1) != 0 || rs(0,2) != -9 || rs(0,3) != 0 ||
243 rs(1,0) != 0 || rs(1,1) != 12 || rs(1,2) != 15 || rs(1,3) != -18 ) {
244 std::ostringstream oss;
245 oss << " Test: " << test_ << "\n"
246 << " Error: Failed self-scaling operation\n"
247 << " Details:\n"
248 << " Result:\n" << rs << "\n"
249 << " Expected result:\n( -6 0 -9 0 )\n( 0 12 15 -18 )\n";
250 throw std::runtime_error( oss.str() );
251 }
252
253 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != 0 || mat_(0,3) != 0 ||
254 mat_(1,0) != 0 || mat_(1,1) != 1 || mat_(1,2) != 0 || mat_(1,3) != 0 ||
255 mat_(2,0) != -6 || mat_(2,1) != 0 || mat_(2,2) != -9 || mat_(2,3) != 0 ||
256 mat_(3,0) != 0 || mat_(3,1) != 12 || mat_(3,2) != 15 || mat_(3,3) != -18 ||
257 mat_(4,0) != 7 || mat_(4,1) != -8 || mat_(4,2) != 9 || mat_(4,3) != 10 ) {
258 std::ostringstream oss;
259 oss << " Test: " << test_ << "\n"
260 << " Error: Failed self-scaling operation\n"
261 << " Details:\n"
262 << " Result:\n" << mat_ << "\n"
263 << " Expected result:\n( 0 0 0 0 )\n"
264 "( 0 1 0 0 )\n"
265 "( -6 0 -9 0 )\n"
266 "( 0 12 15 -18 )\n"
267 "( 7 -8 9 10 )\n";
268 throw std::runtime_error( oss.str() );
269 }
270 }
271
272
273 //=====================================================================================
274 // Row-major self-scaling (M/=s)
275 //=====================================================================================
276
277 {
278 test_ = "Row-major self-scaling (M/=s)";
279
280 initialize();
281
282 auto rs = blaze::rows( mat_, { 2UL, 3UL } );
283
284 rs /= 0.5;
285
286 checkRows ( rs , 2UL );
287 checkColumns ( rs , 4UL );
288 checkNonZeros( rs , 5UL );
289 checkRows ( mat_, 5UL );
290 checkColumns ( mat_, 4UL );
291 checkNonZeros( mat_, 10UL );
292
293 if( rs(0,0) != -4 || rs(0,1) != 0 || rs(0,2) != -6 || rs(0,3) != 0 ||
294 rs(1,0) != 0 || rs(1,1) != 8 || rs(1,2) != 10 || rs(1,3) != -12 ) {
295 std::ostringstream oss;
296 oss << " Test: " << test_ << "\n"
297 << " Error: Failed self-scaling operation\n"
298 << " Details:\n"
299 << " Result:\n" << rs << "\n"
300 << " Expected result:\n( -4 0 -6 0 )\n( 0 8 10 -12 )\n";
301 throw std::runtime_error( oss.str() );
302 }
303
304 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != 0 || mat_(0,3) != 0 ||
305 mat_(1,0) != 0 || mat_(1,1) != 1 || mat_(1,2) != 0 || mat_(1,3) != 0 ||
306 mat_(2,0) != -4 || mat_(2,1) != 0 || mat_(2,2) != -6 || mat_(2,3) != 0 ||
307 mat_(3,0) != 0 || mat_(3,1) != 8 || mat_(3,2) != 10 || mat_(3,3) != -12 ||
308 mat_(4,0) != 7 || mat_(4,1) != -8 || mat_(4,2) != 9 || mat_(4,3) != 10 ) {
309 std::ostringstream oss;
310 oss << " Test: " << test_ << "\n"
311 << " Error: Failed self-scaling operation\n"
312 << " Details:\n"
313 << " Result:\n" << mat_ << "\n"
314 << " Expected result:\n( 0 0 0 0 )\n"
315 "( 0 1 0 0 )\n"
316 "( -4 0 -6 0 )\n"
317 "( 0 8 10 -12 )\n"
318 "( 7 -8 9 10 )\n";
319 throw std::runtime_error( oss.str() );
320 }
321 }
322
323
324 //=====================================================================================
325 // Row-major self-scaling (M=M/s)
326 //=====================================================================================
327
328 {
329 test_ = "Row-major self-scaling (M=M/s)";
330
331 initialize();
332
333 auto rs = blaze::rows( mat_, { 2UL, 3UL } );
334
335 rs = rs / 0.5;
336
337 checkRows ( rs , 2UL );
338 checkColumns ( rs , 4UL );
339 checkNonZeros( rs , 5UL );
340 checkRows ( mat_, 5UL );
341 checkColumns ( mat_, 4UL );
342 checkNonZeros( mat_, 10UL );
343
344 if( rs(0,0) != -4 || rs(0,1) != 0 || rs(0,2) != -6 || rs(0,3) != 0 ||
345 rs(1,0) != 0 || rs(1,1) != 8 || rs(1,2) != 10 || rs(1,3) != -12 ) {
346 std::ostringstream oss;
347 oss << " Test: " << test_ << "\n"
348 << " Error: Failed self-scaling operation\n"
349 << " Details:\n"
350 << " Result:\n" << rs << "\n"
351 << " Expected result:\n( -4 0 -6 0 )\n( 0 8 10 -12 )\n";
352 throw std::runtime_error( oss.str() );
353 }
354
355 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != 0 || mat_(0,3) != 0 ||
356 mat_(1,0) != 0 || mat_(1,1) != 1 || mat_(1,2) != 0 || mat_(1,3) != 0 ||
357 mat_(2,0) != -4 || mat_(2,1) != 0 || mat_(2,2) != -6 || mat_(2,3) != 0 ||
358 mat_(3,0) != 0 || mat_(3,1) != 8 || mat_(3,2) != 10 || mat_(3,3) != -12 ||
359 mat_(4,0) != 7 || mat_(4,1) != -8 || mat_(4,2) != 9 || mat_(4,3) != 10 ) {
360 std::ostringstream oss;
361 oss << " Test: " << test_ << "\n"
362 << " Error: Failed self-scaling operation\n"
363 << " Details:\n"
364 << " Result:\n" << mat_ << "\n"
365 << " Expected result:\n( 0 0 0 0 )\n"
366 "( 0 1 0 0 )\n"
367 "( -4 0 -6 0 )\n"
368 "( 0 8 10 -12 )\n"
369 "( 7 -8 9 10 )\n";
370 throw std::runtime_error( oss.str() );
371 }
372 }
373
374
375 //=====================================================================================
376 // Row-major Rows::scale()
377 //=====================================================================================
378
379 {
380 test_ = "Row-major Rows::scale()";
381
382 initialize();
383
384 // Initialization check
385 auto rs = blaze::rows( mat_, { 2UL, 3UL } );
386
387 checkRows ( rs, 2UL );
388 checkColumns ( rs, 4UL );
389 checkNonZeros( rs, 5UL );
390 checkNonZeros( rs, 0UL, 2UL );
391 checkNonZeros( rs, 1UL, 3UL );
392
393 if( rs(0,0) != -2 || rs(0,1) != 0 || rs(0,2) != -3 || rs(0,3) != 0 ||
394 rs(1,0) != 0 || rs(1,1) != 4 || rs(1,2) != 5 || rs(1,3) != -6 ) {
395 std::ostringstream oss;
396 oss << " Test: " << test_ << "\n"
397 << " Error: Initialization failed\n"
398 << " Details:\n"
399 << " Result:\n" << rs << "\n"
400 << " Expected result:\n( -2 0 -3 0 )\n( 0 4 5 -6 )\n";
401 throw std::runtime_error( oss.str() );
402 }
403
404 // Integral scaling of the matrix
405 rs.scale( 2 );
406
407 checkRows ( rs, 2UL );
408 checkColumns ( rs, 4UL );
409 checkNonZeros( rs, 5UL );
410 checkNonZeros( rs, 0UL, 2UL );
411 checkNonZeros( rs, 1UL, 3UL );
412
413 if( rs(0,0) != -4 || rs(0,1) != 0 || rs(0,2) != -6 || rs(0,3) != 0 ||
414 rs(1,0) != 0 || rs(1,1) != 8 || rs(1,2) != 10 || rs(1,3) != -12 ) {
415 std::ostringstream oss;
416 oss << " Test: " << test_ << "\n"
417 << " Error: Integral scale operation failed\n"
418 << " Details:\n"
419 << " Result:\n" << rs << "\n"
420 << " Expected result:\n( -4 0 -6 0 )\n( 0 5 10 -12 )\n";
421 throw std::runtime_error( oss.str() );
422 }
423
424 // Floating point scaling of the matrix
425 rs.scale( 0.5 );
426
427 checkRows ( rs, 2UL );
428 checkColumns ( rs, 4UL );
429 checkNonZeros( rs, 5UL );
430 checkNonZeros( rs, 0UL, 2UL );
431 checkNonZeros( rs, 1UL, 3UL );
432
433 if( rs(0,0) != -2 || rs(0,1) != 0 || rs(0,2) != -3 || rs(0,3) != 0 ||
434 rs(1,0) != 0 || rs(1,1) != 4 || rs(1,2) != 5 || rs(1,3) != -6 ) {
435 std::ostringstream oss;
436 oss << " Test: " << test_ << "\n"
437 << " Error: Floating point scale operation failed\n"
438 << " Details:\n"
439 << " Result:\n" << rs << "\n"
440 << " Expected result:\n( -2 0 -3 0 )\n( 0 4 5 -6 )\n";
441 throw std::runtime_error( oss.str() );
442 }
443 }
444
445
446 //=====================================================================================
447 // Column-major self-scaling (M*=s)
448 //=====================================================================================
449
450 {
451 test_ = "Column-major self-scaling (M*=s)";
452
453 initialize();
454
455 auto rs = blaze::rows( tmat_, { 2UL, 3UL } );
456
457 rs *= 3;
458
459 checkRows ( rs , 2UL );
460 checkColumns ( rs , 4UL );
461 checkNonZeros( rs , 5UL );
462 checkRows ( tmat_, 5UL );
463 checkColumns ( tmat_, 4UL );
464 checkNonZeros( tmat_, 10UL );
465
466 if( rs(0,0) != -6 || rs(0,1) != 0 || rs(0,2) != -9 || rs(0,3) != 0 ||
467 rs(1,0) != 0 || rs(1,1) != 12 || rs(1,2) != 15 || rs(1,3) != -18 ) {
468 std::ostringstream oss;
469 oss << " Test: " << test_ << "\n"
470 << " Error: Failed self-scaling operation\n"
471 << " Details:\n"
472 << " Result:\n" << rs << "\n"
473 << " Expected result:\n( -6 0 -9 0 )\n( 0 12 15 -18 )\n";
474 throw std::runtime_error( oss.str() );
475 }
476
477 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != 0 || tmat_(0,3) != 0 ||
478 tmat_(1,0) != 0 || tmat_(1,1) != 1 || tmat_(1,2) != 0 || tmat_(1,3) != 0 ||
479 tmat_(2,0) != -6 || tmat_(2,1) != 0 || tmat_(2,2) != -9 || tmat_(2,3) != 0 ||
480 tmat_(3,0) != 0 || tmat_(3,1) != 12 || tmat_(3,2) != 15 || tmat_(3,3) != -18 ||
481 tmat_(4,0) != 7 || tmat_(4,1) != -8 || tmat_(4,2) != 9 || tmat_(4,3) != 10 ) {
482 std::ostringstream oss;
483 oss << " Test: " << test_ << "\n"
484 << " Error: Failed self-scaling operation\n"
485 << " Details:\n"
486 << " Result:\n" << tmat_ << "\n"
487 << " Expected result:\n( 0 0 0 0 )\n"
488 "( 0 1 0 0 )\n"
489 "( -6 0 -9 0 )\n"
490 "( 0 12 15 -18 )\n"
491 "( 7 -8 9 10 )\n";
492 throw std::runtime_error( oss.str() );
493 }
494 }
495
496
497 //=====================================================================================
498 // Column-major self-scaling (M=M*s)
499 //=====================================================================================
500
501 {
502 test_ = "Column-major self-scaling (M=M*s)";
503
504 initialize();
505
506 auto rs = blaze::rows( tmat_, { 2UL, 3UL } );
507
508 rs = rs * 3;
509
510 checkRows ( rs , 2UL );
511 checkColumns ( rs , 4UL );
512 checkNonZeros( rs , 5UL );
513 checkRows ( tmat_, 5UL );
514 checkColumns ( tmat_, 4UL );
515 checkNonZeros( tmat_, 10UL );
516
517 if( rs(0,0) != -6 || rs(0,1) != 0 || rs(0,2) != -9 || rs(0,3) != 0 ||
518 rs(1,0) != 0 || rs(1,1) != 12 || rs(1,2) != 15 || rs(1,3) != -18 ) {
519 std::ostringstream oss;
520 oss << " Test: " << test_ << "\n"
521 << " Error: Failed self-scaling operation\n"
522 << " Details:\n"
523 << " Result:\n" << rs << "\n"
524 << " Expected result:\n( -6 0 -9 0 )\n( 0 12 15 -18 )\n";
525 throw std::runtime_error( oss.str() );
526 }
527
528 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != 0 || tmat_(0,3) != 0 ||
529 tmat_(1,0) != 0 || tmat_(1,1) != 1 || tmat_(1,2) != 0 || tmat_(1,3) != 0 ||
530 tmat_(2,0) != -6 || tmat_(2,1) != 0 || tmat_(2,2) != -9 || tmat_(2,3) != 0 ||
531 tmat_(3,0) != 0 || tmat_(3,1) != 12 || tmat_(3,2) != 15 || tmat_(3,3) != -18 ||
532 tmat_(4,0) != 7 || tmat_(4,1) != -8 || tmat_(4,2) != 9 || tmat_(4,3) != 10 ) {
533 std::ostringstream oss;
534 oss << " Test: " << test_ << "\n"
535 << " Error: Failed self-scaling operation\n"
536 << " Details:\n"
537 << " Result:\n" << tmat_ << "\n"
538 << " Expected result:\n( 0 0 0 0 )\n"
539 "( 0 1 0 0 )\n"
540 "( -6 0 -9 0 )\n"
541 "( 0 12 15 -18 )\n"
542 "( 7 -8 9 10 )\n";
543 throw std::runtime_error( oss.str() );
544 }
545 }
546
547
548 //=====================================================================================
549 // Column-major self-scaling (M=s*M)
550 //=====================================================================================
551
552 {
553 test_ = "Column-major self-scaling (M=s*M)";
554
555 initialize();
556
557 auto rs = blaze::rows( tmat_, { 2UL, 3UL } );
558
559 rs = 3 * rs;
560
561 checkRows ( rs , 2UL );
562 checkColumns ( rs , 4UL );
563 checkNonZeros( rs , 5UL );
564 checkRows ( tmat_, 5UL );
565 checkColumns ( tmat_, 4UL );
566 checkNonZeros( tmat_, 10UL );
567
568 if( rs(0,0) != -6 || rs(0,1) != 0 || rs(0,2) != -9 || rs(0,3) != 0 ||
569 rs(1,0) != 0 || rs(1,1) != 12 || rs(1,2) != 15 || rs(1,3) != -18 ) {
570 std::ostringstream oss;
571 oss << " Test: " << test_ << "\n"
572 << " Error: Failed self-scaling operation\n"
573 << " Details:\n"
574 << " Result:\n" << rs << "\n"
575 << " Expected result:\n( -6 0 -9 0 )\n( 0 12 15 -18 )\n";
576 throw std::runtime_error( oss.str() );
577 }
578
579 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != 0 || tmat_(0,3) != 0 ||
580 tmat_(1,0) != 0 || tmat_(1,1) != 1 || tmat_(1,2) != 0 || tmat_(1,3) != 0 ||
581 tmat_(2,0) != -6 || tmat_(2,1) != 0 || tmat_(2,2) != -9 || tmat_(2,3) != 0 ||
582 tmat_(3,0) != 0 || tmat_(3,1) != 12 || tmat_(3,2) != 15 || tmat_(3,3) != -18 ||
583 tmat_(4,0) != 7 || tmat_(4,1) != -8 || tmat_(4,2) != 9 || tmat_(4,3) != 10 ) {
584 std::ostringstream oss;
585 oss << " Test: " << test_ << "\n"
586 << " Error: Failed self-scaling operation\n"
587 << " Details:\n"
588 << " Result:\n" << tmat_ << "\n"
589 << " Expected result:\n( 0 0 0 0 )\n"
590 "( 0 1 0 0 )\n"
591 "( -6 0 -9 0 )\n"
592 "( 0 12 15 -18 )\n"
593 "( 7 -8 9 10 )\n";
594 throw std::runtime_error( oss.str() );
595 }
596 }
597
598
599 //=====================================================================================
600 // Column-major self-scaling (M/=s)
601 //=====================================================================================
602
603 {
604 test_ = "Column-major self-scaling (M/=s)";
605
606 initialize();
607
608 auto rs = blaze::rows( tmat_, { 2UL, 3UL } );
609
610 rs /= 0.5;
611
612 checkRows ( rs , 2UL );
613 checkColumns ( rs , 4UL );
614 checkNonZeros( rs , 5UL );
615 checkRows ( tmat_, 5UL );
616 checkColumns ( tmat_, 4UL );
617 checkNonZeros( tmat_, 10UL );
618
619 if( rs(0,0) != -4 || rs(0,1) != 0 || rs(0,2) != -6 || rs(0,3) != 0 ||
620 rs(1,0) != 0 || rs(1,1) != 8 || rs(1,2) != 10 || rs(1,3) != -12 ) {
621 std::ostringstream oss;
622 oss << " Test: " << test_ << "\n"
623 << " Error: Failed self-scaling operation\n"
624 << " Details:\n"
625 << " Result:\n" << rs << "\n"
626 << " Expected result:\n( -4 0 -6 0 )\n( 0 8 10 -12 )\n";
627 throw std::runtime_error( oss.str() );
628 }
629
630 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != 0 || tmat_(0,3) != 0 ||
631 tmat_(1,0) != 0 || tmat_(1,1) != 1 || tmat_(1,2) != 0 || tmat_(1,3) != 0 ||
632 tmat_(2,0) != -4 || tmat_(2,1) != 0 || tmat_(2,2) != -6 || tmat_(2,3) != 0 ||
633 tmat_(3,0) != 0 || tmat_(3,1) != 8 || tmat_(3,2) != 10 || tmat_(3,3) != -12 ||
634 tmat_(4,0) != 7 || tmat_(4,1) != -8 || tmat_(4,2) != 9 || tmat_(4,3) != 10 ) {
635 std::ostringstream oss;
636 oss << " Test: " << test_ << "\n"
637 << " Error: Failed self-scaling operation\n"
638 << " Details:\n"
639 << " Result:\n" << tmat_ << "\n"
640 << " Expected result:\n( 0 0 0 0 )\n"
641 "( 0 1 0 0 )\n"
642 "( -4 0 -6 0 )\n"
643 "( 0 8 10 -12 )\n"
644 "( 7 -8 9 10 )\n";
645 throw std::runtime_error( oss.str() );
646 }
647 }
648
649
650 //=====================================================================================
651 // Column-major self-scaling (M=M/s)
652 //=====================================================================================
653
654 {
655 test_ = "Column-major self-scaling (M=M/s)";
656
657 initialize();
658
659 auto rs = blaze::rows( tmat_, { 2UL, 3UL } );
660
661 rs = rs / 0.5;
662
663 checkRows ( rs , 2UL );
664 checkColumns ( rs , 4UL );
665 checkNonZeros( rs , 5UL );
666 checkRows ( tmat_, 5UL );
667 checkColumns ( tmat_, 4UL );
668 checkNonZeros( tmat_, 10UL );
669
670 if( rs(0,0) != -4 || rs(0,1) != 0 || rs(0,2) != -6 || rs(0,3) != 0 ||
671 rs(1,0) != 0 || rs(1,1) != 8 || rs(1,2) != 10 || rs(1,3) != -12 ) {
672 std::ostringstream oss;
673 oss << " Test: " << test_ << "\n"
674 << " Error: Failed self-scaling operation\n"
675 << " Details:\n"
676 << " Result:\n" << rs << "\n"
677 << " Expected result:\n( -4 0 -6 0 )\n( 0 8 10 -12 )\n";
678 throw std::runtime_error( oss.str() );
679 }
680
681 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != 0 || tmat_(0,3) != 0 ||
682 tmat_(1,0) != 0 || tmat_(1,1) != 1 || tmat_(1,2) != 0 || tmat_(1,3) != 0 ||
683 tmat_(2,0) != -4 || tmat_(2,1) != 0 || tmat_(2,2) != -6 || tmat_(2,3) != 0 ||
684 tmat_(3,0) != 0 || tmat_(3,1) != 8 || tmat_(3,2) != 10 || tmat_(3,3) != -12 ||
685 tmat_(4,0) != 7 || tmat_(4,1) != -8 || tmat_(4,2) != 9 || tmat_(4,3) != 10 ) {
686 std::ostringstream oss;
687 oss << " Test: " << test_ << "\n"
688 << " Error: Failed self-scaling operation\n"
689 << " Details:\n"
690 << " Result:\n" << tmat_ << "\n"
691 << " Expected result:\n( 0 0 0 0 )\n"
692 "( 0 1 0 0 )\n"
693 "( -4 0 -6 0 )\n"
694 "( 0 8 10 -12 )\n"
695 "( 7 -8 9 10 )\n";
696 throw std::runtime_error( oss.str() );
697 }
698 }
699
700
701 //=====================================================================================
702 // Column-major Rows::scale()
703 //=====================================================================================
704
705 {
706 test_ = "Column-major Rows::scale()";
707
708 initialize();
709
710 // Initialization check
711 auto rs = blaze::rows( tmat_, { 2UL, 3UL } );
712
713 checkRows ( rs, 2UL );
714 checkColumns ( rs, 4UL );
715 checkNonZeros( rs, 5UL );
716 checkNonZeros( rs, 0UL, 2UL );
717 checkNonZeros( rs, 1UL, 3UL );
718
719 if( rs(0,0) != -2 || rs(0,1) != 0 || rs(0,2) != -3 || rs(0,3) != 0 ||
720 rs(1,0) != 0 || rs(1,1) != 4 || rs(1,2) != 5 || rs(1,3) != -6 ) {
721 std::ostringstream oss;
722 oss << " Test: " << test_ << "\n"
723 << " Error: Initialization failed\n"
724 << " Details:\n"
725 << " Result:\n" << rs << "\n"
726 << " Expected result:\n( -2 0 -3 0 )\n( 0 4 5 -6 )\n";
727 throw std::runtime_error( oss.str() );
728 }
729
730 // Integral scaling of the matrix
731 rs.scale( 2 );
732
733 checkRows ( rs, 2UL );
734 checkColumns ( rs, 4UL );
735 checkNonZeros( rs, 5UL );
736 checkNonZeros( rs, 0UL, 2UL );
737 checkNonZeros( rs, 1UL, 3UL );
738
739 if( rs(0,0) != -4 || rs(0,1) != 0 || rs(0,2) != -6 || rs(0,3) != 0 ||
740 rs(1,0) != 0 || rs(1,1) != 8 || rs(1,2) != 10 || rs(1,3) != -12 ) {
741 std::ostringstream oss;
742 oss << " Test: " << test_ << "\n"
743 << " Error: Integral scale operation failed\n"
744 << " Details:\n"
745 << " Result:\n" << rs << "\n"
746 << " Expected result:\n( -4 0 -6 0 )\n( 0 5 10 -12 )\n";
747 throw std::runtime_error( oss.str() );
748 }
749
750 // Floating point scaling of the matrix
751 rs.scale( 0.5 );
752
753 checkRows ( rs, 2UL );
754 checkColumns ( rs, 4UL );
755 checkNonZeros( rs, 5UL );
756 checkNonZeros( rs, 0UL, 2UL );
757 checkNonZeros( rs, 1UL, 3UL );
758
759 if( rs(0,0) != -2 || rs(0,1) != 0 || rs(0,2) != -3 || rs(0,3) != 0 ||
760 rs(1,0) != 0 || rs(1,1) != 4 || rs(1,2) != 5 || rs(1,3) != -6 ) {
761 std::ostringstream oss;
762 oss << " Test: " << test_ << "\n"
763 << " Error: Floating point scale operation failed\n"
764 << " Details:\n"
765 << " Result:\n" << rs << "\n"
766 << " Expected result:\n( -2 0 -3 0 )\n( 0 4 5 -6 )\n";
767 throw std::runtime_error( oss.str() );
768 }
769 }
770 }
771 //*************************************************************************************************
772
773
774 //*************************************************************************************************
775 /*!\brief Test of the Rows function call operator.
776 //
777 // \return void
778 // \exception std::runtime_error Error detected.
779 //
780 // This function performs a test of adding and accessing elements via the function call operator
781 // of the Rows specialization. In case an error is detected, a \a std::runtime_error exception
782 // is thrown.
783 */
testFunctionCall()784 void SparseGeneralTest::testFunctionCall()
785 {
786 //=====================================================================================
787 // Row-major matrix tests
788 //=====================================================================================
789
790 {
791 test_ = "Row-major Rows::operator()";
792
793 initialize();
794
795 auto rs = blaze::rows( mat_, { 1UL, 2UL, 3UL } );
796
797 // Assignment to the element (1,1)
798 {
799 rs(1,1) = 9;
800
801 checkRows ( rs , 3UL );
802 checkColumns ( rs , 4UL );
803 checkNonZeros( rs , 7UL );
804 checkNonZeros( rs , 0UL, 1UL );
805 checkNonZeros( rs , 1UL, 3UL );
806 checkNonZeros( rs , 2UL, 3UL );
807 checkRows ( mat_, 5UL );
808 checkColumns ( mat_, 4UL );
809 checkNonZeros( mat_, 11UL );
810
811 if( rs(0,0) != 0 || rs(0,1) != 1 || rs(0,2) != 0 || rs(0,3) != 0 ||
812 rs(1,0) != -2 || rs(1,1) != 9 || rs(1,2) != -3 || rs(1,3) != 0 ||
813 rs(2,0) != 0 || rs(2,1) != 4 || rs(2,2) != 5 || rs(2,3) != -6 ) {
814 std::ostringstream oss;
815 oss << " Test: " << test_ << "\n"
816 << " Error: Function call operator failed\n"
817 << " Details:\n"
818 << " Result:\n" << rs << "\n"
819 << " Expected result:\n( 0 1 0 0 )\n( -2 9 -3 0 )\n( 0 4 5 -6 )\n";
820 throw std::runtime_error( oss.str() );
821 }
822
823 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != 0 || mat_(0,3) != 0 ||
824 mat_(1,0) != 0 || mat_(1,1) != 1 || mat_(1,2) != 0 || mat_(1,3) != 0 ||
825 mat_(2,0) != -2 || mat_(2,1) != 9 || mat_(2,2) != -3 || mat_(2,3) != 0 ||
826 mat_(3,0) != 0 || mat_(3,1) != 4 || mat_(3,2) != 5 || mat_(3,3) != -6 ||
827 mat_(4,0) != 7 || mat_(4,1) != -8 || mat_(4,2) != 9 || mat_(4,3) != 10 ) {
828 std::ostringstream oss;
829 oss << " Test: " << test_ << "\n"
830 << " Error: Function call operator failed\n"
831 << " Details:\n"
832 << " Result:\n" << mat_ << "\n"
833 << " Expected result:\n( 0 0 0 0 )\n"
834 "( 0 1 0 0 )\n"
835 "( -2 9 -3 0 )\n"
836 "( 0 4 5 -6 )\n"
837 "( 7 -8 9 10 )\n";
838 throw std::runtime_error( oss.str() );
839 }
840 }
841
842 // Assignment to the element (2,1)
843 {
844 rs(2,1) = 0;
845
846 checkRows ( rs , 3UL );
847 checkColumns ( rs , 4UL );
848 checkNonZeros( rs , 6UL );
849 checkNonZeros( rs , 0UL, 1UL );
850 checkNonZeros( rs , 1UL, 3UL );
851 checkNonZeros( rs , 2UL, 2UL );
852 checkRows ( mat_, 5UL );
853 checkColumns ( mat_, 4UL );
854 checkNonZeros( mat_, 10UL );
855
856 if( rs(0,0) != 0 || rs(0,1) != 1 || rs(0,2) != 0 || rs(0,3) != 0 ||
857 rs(1,0) != -2 || rs(1,1) != 9 || rs(1,2) != -3 || rs(1,3) != 0 ||
858 rs(2,0) != 0 || rs(2,1) != 0 || rs(2,2) != 5 || rs(2,3) != -6 ) {
859 std::ostringstream oss;
860 oss << " Test: " << test_ << "\n"
861 << " Error: Function call operator failed\n"
862 << " Details:\n"
863 << " Result:\n" << rs << "\n"
864 << " Expected result:\n( 0 1 0 0 )\n( -2 9 -3 0 )\n( 0 0 5 -6 )\n";
865 throw std::runtime_error( oss.str() );
866 }
867
868 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != 0 || mat_(0,3) != 0 ||
869 mat_(1,0) != 0 || mat_(1,1) != 1 || mat_(1,2) != 0 || mat_(1,3) != 0 ||
870 mat_(2,0) != -2 || mat_(2,1) != 9 || mat_(2,2) != -3 || mat_(2,3) != 0 ||
871 mat_(3,0) != 0 || mat_(3,1) != 0 || mat_(3,2) != 5 || mat_(3,3) != -6 ||
872 mat_(4,0) != 7 || mat_(4,1) != -8 || mat_(4,2) != 9 || mat_(4,3) != 10 ) {
873 std::ostringstream oss;
874 oss << " Test: " << test_ << "\n"
875 << " Error: Function call operator failed\n"
876 << " Details:\n"
877 << " Result:\n" << mat_ << "\n"
878 << " Expected result:\n( 0 0 0 0 )\n"
879 "( 0 1 0 0 )\n"
880 "( -2 9 -3 0 )\n"
881 "( 0 0 5 -6 )\n"
882 "( 7 -8 9 10 )\n";
883 throw std::runtime_error( oss.str() );
884 }
885 }
886
887 // Assignment to the element (1,2)
888 {
889 rs(1,2) = 11;
890
891 checkRows ( rs , 3UL );
892 checkColumns ( rs , 4UL );
893 checkNonZeros( rs , 6UL );
894 checkNonZeros( rs , 0UL, 1UL );
895 checkNonZeros( rs , 1UL, 3UL );
896 checkNonZeros( rs , 2UL, 2UL );
897 checkRows ( mat_, 5UL );
898 checkColumns ( mat_, 4UL );
899 checkNonZeros( mat_, 10UL );
900
901 if( rs(0,0) != 0 || rs(0,1) != 1 || rs(0,2) != 0 || rs(0,3) != 0 ||
902 rs(1,0) != -2 || rs(1,1) != 9 || rs(1,2) != 11 || rs(1,3) != 0 ||
903 rs(2,0) != 0 || rs(2,1) != 0 || rs(2,2) != 5 || rs(2,3) != -6 ) {
904 std::ostringstream oss;
905 oss << " Test: " << test_ << "\n"
906 << " Error: Function call operator failed\n"
907 << " Details:\n"
908 << " Result:\n" << rs << "\n"
909 << " Expected result:\n( 0 1 0 0 )\n( -2 9 11 0 )\n( 0 0 5 -6 )\n";
910 throw std::runtime_error( oss.str() );
911 }
912
913 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != 0 || mat_(0,3) != 0 ||
914 mat_(1,0) != 0 || mat_(1,1) != 1 || mat_(1,2) != 0 || mat_(1,3) != 0 ||
915 mat_(2,0) != -2 || mat_(2,1) != 9 || mat_(2,2) != 11 || mat_(2,3) != 0 ||
916 mat_(3,0) != 0 || mat_(3,1) != 0 || mat_(3,2) != 5 || mat_(3,3) != -6 ||
917 mat_(4,0) != 7 || mat_(4,1) != -8 || mat_(4,2) != 9 || mat_(4,3) != 10 ) {
918 std::ostringstream oss;
919 oss << " Test: " << test_ << "\n"
920 << " Error: Function call operator failed\n"
921 << " Details:\n"
922 << " Result:\n" << mat_ << "\n"
923 << " Expected result:\n( 0 0 0 0 )\n"
924 "( 0 1 0 0 )\n"
925 "( -2 9 11 0 )\n"
926 "( 0 0 5 -6 )\n"
927 "( 7 -8 9 10 )\n";
928 throw std::runtime_error( oss.str() );
929 }
930 }
931
932 // Addition assignment to the element (0,1)
933 {
934 rs(0,1) += 3;
935
936 checkRows ( rs , 3UL );
937 checkColumns ( rs , 4UL );
938 checkNonZeros( rs , 6UL );
939 checkNonZeros( rs , 0UL, 1UL );
940 checkNonZeros( rs , 1UL, 3UL );
941 checkNonZeros( rs , 2UL, 2UL );
942 checkRows ( mat_, 5UL );
943 checkColumns ( mat_, 4UL );
944 checkNonZeros( mat_, 10UL );
945
946 if( rs(0,0) != 0 || rs(0,1) != 4 || rs(0,2) != 0 || rs(0,3) != 0 ||
947 rs(1,0) != -2 || rs(1,1) != 9 || rs(1,2) != 11 || rs(1,3) != 0 ||
948 rs(2,0) != 0 || rs(2,1) != 0 || rs(2,2) != 5 || rs(2,3) != -6 ) {
949 std::ostringstream oss;
950 oss << " Test: " << test_ << "\n"
951 << " Error: Function call operator failed\n"
952 << " Details:\n"
953 << " Result:\n" << rs << "\n"
954 << " Expected result:\n( 0 4 0 0 )\n( -2 9 11 0 )\n( 0 0 5 -6 )\n";
955 throw std::runtime_error( oss.str() );
956 }
957
958 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != 0 || mat_(0,3) != 0 ||
959 mat_(1,0) != 0 || mat_(1,1) != 4 || mat_(1,2) != 0 || mat_(1,3) != 0 ||
960 mat_(2,0) != -2 || mat_(2,1) != 9 || mat_(2,2) != 11 || mat_(2,3) != 0 ||
961 mat_(3,0) != 0 || mat_(3,1) != 0 || mat_(3,2) != 5 || mat_(3,3) != -6 ||
962 mat_(4,0) != 7 || mat_(4,1) != -8 || mat_(4,2) != 9 || mat_(4,3) != 10 ) {
963 std::ostringstream oss;
964 oss << " Test: " << test_ << "\n"
965 << " Error: Subscript operator failed\n"
966 << " Details:\n"
967 << " Result:\n" << mat_ << "\n"
968 << " Expected result:\n( 0 0 0 0 )\n"
969 "( 0 4 0 0 )\n"
970 "( -2 9 11 0 )\n"
971 "( 0 0 5 -6 )\n"
972 "( 7 -8 9 10 )\n";
973 throw std::runtime_error( oss.str() );
974 }
975 }
976
977 // Subtraction assignment to the element (0,2)
978 {
979 rs(0,2) -= 6;
980
981 checkRows ( rs , 3UL );
982 checkColumns ( rs , 4UL );
983 checkNonZeros( rs , 7UL );
984 checkNonZeros( rs , 0UL, 2UL );
985 checkNonZeros( rs , 1UL, 3UL );
986 checkNonZeros( rs , 2UL, 2UL );
987 checkRows ( mat_, 5UL );
988 checkColumns ( mat_, 4UL );
989 checkNonZeros( mat_, 11UL );
990
991 if( rs(0,0) != 0 || rs(0,1) != 4 || rs(0,2) != -6 || rs(0,3) != 0 ||
992 rs(1,0) != -2 || rs(1,1) != 9 || rs(1,2) != 11 || rs(1,3) != 0 ||
993 rs(2,0) != 0 || rs(2,1) != 0 || rs(2,2) != 5 || rs(2,3) != -6 ) {
994 std::ostringstream oss;
995 oss << " Test: " << test_ << "\n"
996 << " Error: Function call operator failed\n"
997 << " Details:\n"
998 << " Result:\n" << rs << "\n"
999 << " Expected result:\n( 0 4 -6 0 )\n( -2 9 11 0 )\n( 0 0 5 -6 )\n";
1000 throw std::runtime_error( oss.str() );
1001 }
1002
1003 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != 0 || mat_(0,3) != 0 ||
1004 mat_(1,0) != 0 || mat_(1,1) != 4 || mat_(1,2) != -6 || mat_(1,3) != 0 ||
1005 mat_(2,0) != -2 || mat_(2,1) != 9 || mat_(2,2) != 11 || mat_(2,3) != 0 ||
1006 mat_(3,0) != 0 || mat_(3,1) != 0 || mat_(3,2) != 5 || mat_(3,3) != -6 ||
1007 mat_(4,0) != 7 || mat_(4,1) != -8 || mat_(4,2) != 9 || mat_(4,3) != 10 ) {
1008 std::ostringstream oss;
1009 oss << " Test: " << test_ << "\n"
1010 << " Error: Subscript operator failed\n"
1011 << " Details:\n"
1012 << " Result:\n" << mat_ << "\n"
1013 << " Expected result:\n( 0 0 0 0 )\n"
1014 "( 0 4 -6 0 )\n"
1015 "( -2 9 11 0 )\n"
1016 "( 0 0 5 -6 )\n"
1017 "( 7 -8 9 10 )\n";
1018 throw std::runtime_error( oss.str() );
1019 }
1020 }
1021
1022 // Multiplication assignment to the element (1,2)
1023 {
1024 rs(1,2) *= 2;
1025
1026 checkRows ( rs , 3UL );
1027 checkColumns ( rs , 4UL );
1028 checkNonZeros( rs , 7UL );
1029 checkNonZeros( rs , 0UL, 2UL );
1030 checkNonZeros( rs , 1UL, 3UL );
1031 checkNonZeros( rs , 2UL, 2UL );
1032 checkRows ( mat_, 5UL );
1033 checkColumns ( mat_, 4UL );
1034 checkNonZeros( mat_, 11UL );
1035
1036 if( rs(0,0) != 0 || rs(0,1) != 4 || rs(0,2) != -6 || rs(0,3) != 0 ||
1037 rs(1,0) != -2 || rs(1,1) != 9 || rs(1,2) != 22 || rs(1,3) != 0 ||
1038 rs(2,0) != 0 || rs(2,1) != 0 || rs(2,2) != 5 || rs(2,3) != -6 ) {
1039 std::ostringstream oss;
1040 oss << " Test: " << test_ << "\n"
1041 << " Error: Function call operator failed\n"
1042 << " Details:\n"
1043 << " Result:\n" << rs << "\n"
1044 << " Expected result:\n( 0 4 -6 0 )\n( -2 9 22 0 )\n( 0 0 5 -6 )\n";
1045 throw std::runtime_error( oss.str() );
1046 }
1047
1048 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != 0 || mat_(0,3) != 0 ||
1049 mat_(1,0) != 0 || mat_(1,1) != 4 || mat_(1,2) != -6 || mat_(1,3) != 0 ||
1050 mat_(2,0) != -2 || mat_(2,1) != 9 || mat_(2,2) != 22 || mat_(2,3) != 0 ||
1051 mat_(3,0) != 0 || mat_(3,1) != 0 || mat_(3,2) != 5 || mat_(3,3) != -6 ||
1052 mat_(4,0) != 7 || mat_(4,1) != -8 || mat_(4,2) != 9 || mat_(4,3) != 10 ) {
1053 std::ostringstream oss;
1054 oss << " Test: " << test_ << "\n"
1055 << " Error: Subscript operator failed\n"
1056 << " Details:\n"
1057 << " Result:\n" << mat_ << "\n"
1058 << " Expected result:\n( 0 0 0 0 )\n"
1059 "( 0 4 -6 0 )\n"
1060 "( -2 9 22 0 )\n"
1061 "( 0 0 5 -6 )\n"
1062 "( 7 -8 9 10 )\n";
1063 throw std::runtime_error( oss.str() );
1064 }
1065 }
1066
1067 // Division assignment to the element (1,2)
1068 {
1069 rs(1,2) /= 2;
1070
1071 checkRows ( rs , 3UL );
1072 checkColumns ( rs , 4UL );
1073 checkNonZeros( rs , 7UL );
1074 checkNonZeros( rs , 0UL, 2UL );
1075 checkNonZeros( rs , 1UL, 3UL );
1076 checkNonZeros( rs , 2UL, 2UL );
1077 checkRows ( mat_, 5UL );
1078 checkColumns ( mat_, 4UL );
1079 checkNonZeros( mat_, 11UL );
1080
1081 if( rs(0,0) != 0 || rs(0,1) != 4 || rs(0,2) != -6 || rs(0,3) != 0 ||
1082 rs(1,0) != -2 || rs(1,1) != 9 || rs(1,2) != 11 || rs(1,3) != 0 ||
1083 rs(2,0) != 0 || rs(2,1) != 0 || rs(2,2) != 5 || rs(2,3) != -6 ) {
1084 std::ostringstream oss;
1085 oss << " Test: " << test_ << "\n"
1086 << " Error: Function call operator failed\n"
1087 << " Details:\n"
1088 << " Result:\n" << rs << "\n"
1089 << " Expected result:\n( 0 4 -6 0 )\n( -2 9 11 0 )\n( 0 0 5 -6 )\n";
1090 throw std::runtime_error( oss.str() );
1091 }
1092
1093 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != 0 || mat_(0,3) != 0 ||
1094 mat_(1,0) != 0 || mat_(1,1) != 4 || mat_(1,2) != -6 || mat_(1,3) != 0 ||
1095 mat_(2,0) != -2 || mat_(2,1) != 9 || mat_(2,2) != 11 || mat_(2,3) != 0 ||
1096 mat_(3,0) != 0 || mat_(3,1) != 0 || mat_(3,2) != 5 || mat_(3,3) != -6 ||
1097 mat_(4,0) != 7 || mat_(4,1) != -8 || mat_(4,2) != 9 || mat_(4,3) != 10 ) {
1098 std::ostringstream oss;
1099 oss << " Test: " << test_ << "\n"
1100 << " Error: Subscript operator failed\n"
1101 << " Details:\n"
1102 << " Result:\n" << mat_ << "\n"
1103 << " Expected result:\n( 0 0 0 0 )\n"
1104 "( 0 4 -6 0 )\n"
1105 "( -2 9 11 0 )\n"
1106 "( 0 0 5 -6 )\n"
1107 "( 7 -8 9 10 )\n";
1108 throw std::runtime_error( oss.str() );
1109 }
1110 }
1111 }
1112
1113
1114 //=====================================================================================
1115 // Column-major matrix tests
1116 //=====================================================================================
1117
1118 {
1119 test_ = "Column-major Rows::operator()";
1120
1121 initialize();
1122
1123 auto rs = blaze::rows( tmat_, { 1UL, 2UL, 3UL } );
1124
1125 // Assignment to the element (1,1)
1126 {
1127 rs(1,1) = 9;
1128
1129 checkRows ( rs , 3UL );
1130 checkColumns ( rs , 4UL );
1131 checkNonZeros( rs , 7UL );
1132 checkNonZeros( rs , 0UL, 1UL );
1133 checkNonZeros( rs , 1UL, 3UL );
1134 checkNonZeros( rs , 2UL, 3UL );
1135 checkRows ( tmat_, 5UL );
1136 checkColumns ( tmat_, 4UL );
1137 checkNonZeros( tmat_, 11UL );
1138
1139 if( rs(0,0) != 0 || rs(0,1) != 1 || rs(0,2) != 0 || rs(0,3) != 0 ||
1140 rs(1,0) != -2 || rs(1,1) != 9 || rs(1,2) != -3 || rs(1,3) != 0 ||
1141 rs(2,0) != 0 || rs(2,1) != 4 || rs(2,2) != 5 || rs(2,3) != -6 ) {
1142 std::ostringstream oss;
1143 oss << " Test: " << test_ << "\n"
1144 << " Error: Function call operator failed\n"
1145 << " Details:\n"
1146 << " Result:\n" << rs << "\n"
1147 << " Expected result:\n( 0 1 0 0 )\n( -2 9 -3 0 )\n( 0 4 5 -6 )\n";
1148 throw std::runtime_error( oss.str() );
1149 }
1150
1151 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != 0 || tmat_(0,3) != 0 ||
1152 tmat_(1,0) != 0 || tmat_(1,1) != 1 || tmat_(1,2) != 0 || tmat_(1,3) != 0 ||
1153 tmat_(2,0) != -2 || tmat_(2,1) != 9 || tmat_(2,2) != -3 || tmat_(2,3) != 0 ||
1154 tmat_(3,0) != 0 || tmat_(3,1) != 4 || tmat_(3,2) != 5 || tmat_(3,3) != -6 ||
1155 tmat_(4,0) != 7 || tmat_(4,1) != -8 || tmat_(4,2) != 9 || tmat_(4,3) != 10 ) {
1156 std::ostringstream oss;
1157 oss << " Test: " << test_ << "\n"
1158 << " Error: Function call operator failed\n"
1159 << " Details:\n"
1160 << " Result:\n" << tmat_ << "\n"
1161 << " Expected result:\n( 0 0 0 0 )\n"
1162 "( 0 1 0 0 )\n"
1163 "( -2 9 -3 0 )\n"
1164 "( 0 4 5 -6 )\n"
1165 "( 7 -8 9 10 )\n";
1166 throw std::runtime_error( oss.str() );
1167 }
1168 }
1169
1170 // Assignment to the element (2,1)
1171 {
1172 rs(2,1) = 0;
1173
1174 checkRows ( rs , 3UL );
1175 checkColumns ( rs , 4UL );
1176 checkNonZeros( rs , 6UL );
1177 checkNonZeros( rs , 0UL, 1UL );
1178 checkNonZeros( rs , 1UL, 3UL );
1179 checkNonZeros( rs , 2UL, 2UL );
1180 checkRows ( tmat_, 5UL );
1181 checkColumns ( tmat_, 4UL );
1182 checkNonZeros( tmat_, 10UL );
1183
1184 if( rs(0,0) != 0 || rs(0,1) != 1 || rs(0,2) != 0 || rs(0,3) != 0 ||
1185 rs(1,0) != -2 || rs(1,1) != 9 || rs(1,2) != -3 || rs(1,3) != 0 ||
1186 rs(2,0) != 0 || rs(2,1) != 0 || rs(2,2) != 5 || rs(2,3) != -6 ) {
1187 std::ostringstream oss;
1188 oss << " Test: " << test_ << "\n"
1189 << " Error: Function call operator failed\n"
1190 << " Details:\n"
1191 << " Result:\n" << rs << "\n"
1192 << " Expected result:\n( 0 1 0 0 )\n( -2 9 -3 0 )\n( 0 0 5 -6 )\n";
1193 throw std::runtime_error( oss.str() );
1194 }
1195
1196 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != 0 || tmat_(0,3) != 0 ||
1197 tmat_(1,0) != 0 || tmat_(1,1) != 1 || tmat_(1,2) != 0 || tmat_(1,3) != 0 ||
1198 tmat_(2,0) != -2 || tmat_(2,1) != 9 || tmat_(2,2) != -3 || tmat_(2,3) != 0 ||
1199 tmat_(3,0) != 0 || tmat_(3,1) != 0 || tmat_(3,2) != 5 || tmat_(3,3) != -6 ||
1200 tmat_(4,0) != 7 || tmat_(4,1) != -8 || tmat_(4,2) != 9 || tmat_(4,3) != 10 ) {
1201 std::ostringstream oss;
1202 oss << " Test: " << test_ << "\n"
1203 << " Error: Function call operator failed\n"
1204 << " Details:\n"
1205 << " Result:\n" << tmat_ << "\n"
1206 << " Expected result:\n( 0 0 0 0 )\n"
1207 "( 0 1 0 0 )\n"
1208 "( -2 9 -3 0 )\n"
1209 "( 0 0 5 -6 )\n"
1210 "( 7 -8 9 10 )\n";
1211 throw std::runtime_error( oss.str() );
1212 }
1213 }
1214
1215 // Assignment to the element (1,2)
1216 {
1217 rs(1,2) = 11;
1218
1219 checkRows ( rs , 3UL );
1220 checkColumns ( rs , 4UL );
1221 checkNonZeros( rs , 6UL );
1222 checkNonZeros( rs , 0UL, 1UL );
1223 checkNonZeros( rs , 1UL, 3UL );
1224 checkNonZeros( rs , 2UL, 2UL );
1225 checkRows ( tmat_, 5UL );
1226 checkColumns ( tmat_, 4UL );
1227 checkNonZeros( tmat_, 10UL );
1228
1229 if( rs(0,0) != 0 || rs(0,1) != 1 || rs(0,2) != 0 || rs(0,3) != 0 ||
1230 rs(1,0) != -2 || rs(1,1) != 9 || rs(1,2) != 11 || rs(1,3) != 0 ||
1231 rs(2,0) != 0 || rs(2,1) != 0 || rs(2,2) != 5 || rs(2,3) != -6 ) {
1232 std::ostringstream oss;
1233 oss << " Test: " << test_ << "\n"
1234 << " Error: Function call operator failed\n"
1235 << " Details:\n"
1236 << " Result:\n" << rs << "\n"
1237 << " Expected result:\n( 0 1 0 0 )\n( -2 9 11 0 )\n( 0 0 5 -6 )\n";
1238 throw std::runtime_error( oss.str() );
1239 }
1240
1241 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != 0 || tmat_(0,3) != 0 ||
1242 tmat_(1,0) != 0 || tmat_(1,1) != 1 || tmat_(1,2) != 0 || tmat_(1,3) != 0 ||
1243 tmat_(2,0) != -2 || tmat_(2,1) != 9 || tmat_(2,2) != 11 || tmat_(2,3) != 0 ||
1244 tmat_(3,0) != 0 || tmat_(3,1) != 0 || tmat_(3,2) != 5 || tmat_(3,3) != -6 ||
1245 tmat_(4,0) != 7 || tmat_(4,1) != -8 || tmat_(4,2) != 9 || tmat_(4,3) != 10 ) {
1246 std::ostringstream oss;
1247 oss << " Test: " << test_ << "\n"
1248 << " Error: Function call operator failed\n"
1249 << " Details:\n"
1250 << " Result:\n" << tmat_ << "\n"
1251 << " Expected result:\n( 0 0 0 0 )\n"
1252 "( 0 1 0 0 )\n"
1253 "( -2 9 11 0 )\n"
1254 "( 0 0 5 -6 )\n"
1255 "( 7 -8 9 10 )\n";
1256 throw std::runtime_error( oss.str() );
1257 }
1258 }
1259
1260 // Addition assignment to the element (0,1)
1261 {
1262 rs(0,1) += 3;
1263
1264 checkRows ( rs , 3UL );
1265 checkColumns ( rs , 4UL );
1266 checkNonZeros( rs , 6UL );
1267 checkNonZeros( rs , 0UL, 1UL );
1268 checkNonZeros( rs , 1UL, 3UL );
1269 checkNonZeros( rs , 2UL, 2UL );
1270 checkRows ( tmat_, 5UL );
1271 checkColumns ( tmat_, 4UL );
1272 checkNonZeros( tmat_, 10UL );
1273
1274 if( rs(0,0) != 0 || rs(0,1) != 4 || rs(0,2) != 0 || rs(0,3) != 0 ||
1275 rs(1,0) != -2 || rs(1,1) != 9 || rs(1,2) != 11 || rs(1,3) != 0 ||
1276 rs(2,0) != 0 || rs(2,1) != 0 || rs(2,2) != 5 || rs(2,3) != -6 ) {
1277 std::ostringstream oss;
1278 oss << " Test: " << test_ << "\n"
1279 << " Error: Function call operator failed\n"
1280 << " Details:\n"
1281 << " Result:\n" << rs << "\n"
1282 << " Expected result:\n( 0 4 0 0 )\n( -2 9 11 0 )\n( 0 0 5 -6 )\n";
1283 throw std::runtime_error( oss.str() );
1284 }
1285
1286 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != 0 || tmat_(0,3) != 0 ||
1287 tmat_(1,0) != 0 || tmat_(1,1) != 4 || tmat_(1,2) != 0 || tmat_(1,3) != 0 ||
1288 tmat_(2,0) != -2 || tmat_(2,1) != 9 || tmat_(2,2) != 11 || tmat_(2,3) != 0 ||
1289 tmat_(3,0) != 0 || tmat_(3,1) != 0 || tmat_(3,2) != 5 || tmat_(3,3) != -6 ||
1290 tmat_(4,0) != 7 || tmat_(4,1) != -8 || tmat_(4,2) != 9 || tmat_(4,3) != 10 ) {
1291 std::ostringstream oss;
1292 oss << " Test: " << test_ << "\n"
1293 << " Error: Subscript operator failed\n"
1294 << " Details:\n"
1295 << " Result:\n" << tmat_ << "\n"
1296 << " Expected result:\n( 0 0 0 0 )\n"
1297 "( 0 4 0 0 )\n"
1298 "( -2 9 11 0 )\n"
1299 "( 0 0 5 -6 )\n"
1300 "( 7 -8 9 10 )\n";
1301 throw std::runtime_error( oss.str() );
1302 }
1303 }
1304
1305 // Subtraction assignment to the element (0,2)
1306 {
1307 rs(0,2) -= 6;
1308
1309 checkRows ( rs , 3UL );
1310 checkColumns ( rs , 4UL );
1311 checkNonZeros( rs , 7UL );
1312 checkNonZeros( rs , 0UL, 2UL );
1313 checkNonZeros( rs , 1UL, 3UL );
1314 checkNonZeros( rs , 2UL, 2UL );
1315 checkRows ( tmat_, 5UL );
1316 checkColumns ( tmat_, 4UL );
1317 checkNonZeros( tmat_, 11UL );
1318
1319 if( rs(0,0) != 0 || rs(0,1) != 4 || rs(0,2) != -6 || rs(0,3) != 0 ||
1320 rs(1,0) != -2 || rs(1,1) != 9 || rs(1,2) != 11 || rs(1,3) != 0 ||
1321 rs(2,0) != 0 || rs(2,1) != 0 || rs(2,2) != 5 || rs(2,3) != -6 ) {
1322 std::ostringstream oss;
1323 oss << " Test: " << test_ << "\n"
1324 << " Error: Function call operator failed\n"
1325 << " Details:\n"
1326 << " Result:\n" << rs << "\n"
1327 << " Expected result:\n( 0 4 -6 0 )\n( -2 9 11 0 )\n( 0 0 5 -6 )\n";
1328 throw std::runtime_error( oss.str() );
1329 }
1330
1331 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != 0 || tmat_(0,3) != 0 ||
1332 tmat_(1,0) != 0 || tmat_(1,1) != 4 || tmat_(1,2) != -6 || tmat_(1,3) != 0 ||
1333 tmat_(2,0) != -2 || tmat_(2,1) != 9 || tmat_(2,2) != 11 || tmat_(2,3) != 0 ||
1334 tmat_(3,0) != 0 || tmat_(3,1) != 0 || tmat_(3,2) != 5 || tmat_(3,3) != -6 ||
1335 tmat_(4,0) != 7 || tmat_(4,1) != -8 || tmat_(4,2) != 9 || tmat_(4,3) != 10 ) {
1336 std::ostringstream oss;
1337 oss << " Test: " << test_ << "\n"
1338 << " Error: Subscript operator failed\n"
1339 << " Details:\n"
1340 << " Result:\n" << tmat_ << "\n"
1341 << " Expected result:\n( 0 0 0 0 )\n"
1342 "( 0 4 -6 0 )\n"
1343 "( -2 9 11 0 )\n"
1344 "( 0 0 5 -6 )\n"
1345 "( 7 -8 9 10 )\n";
1346 throw std::runtime_error( oss.str() );
1347 }
1348 }
1349
1350 // Multiplication assignment to the element (1,2)
1351 {
1352 rs(1,2) *= 2;
1353
1354 checkRows ( rs , 3UL );
1355 checkColumns ( rs , 4UL );
1356 checkNonZeros( rs , 7UL );
1357 checkNonZeros( rs , 0UL, 2UL );
1358 checkNonZeros( rs , 1UL, 3UL );
1359 checkNonZeros( rs , 2UL, 2UL );
1360 checkRows ( tmat_, 5UL );
1361 checkColumns ( tmat_, 4UL );
1362 checkNonZeros( tmat_, 11UL );
1363
1364 if( rs(0,0) != 0 || rs(0,1) != 4 || rs(0,2) != -6 || rs(0,3) != 0 ||
1365 rs(1,0) != -2 || rs(1,1) != 9 || rs(1,2) != 22 || rs(1,3) != 0 ||
1366 rs(2,0) != 0 || rs(2,1) != 0 || rs(2,2) != 5 || rs(2,3) != -6 ) {
1367 std::ostringstream oss;
1368 oss << " Test: " << test_ << "\n"
1369 << " Error: Function call operator failed\n"
1370 << " Details:\n"
1371 << " Result:\n" << rs << "\n"
1372 << " Expected result:\n( 0 4 -6 0 )\n( -2 9 22 0 )\n( 0 0 5 -6 )\n";
1373 throw std::runtime_error( oss.str() );
1374 }
1375
1376 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != 0 || tmat_(0,3) != 0 ||
1377 tmat_(1,0) != 0 || tmat_(1,1) != 4 || tmat_(1,2) != -6 || tmat_(1,3) != 0 ||
1378 tmat_(2,0) != -2 || tmat_(2,1) != 9 || tmat_(2,2) != 22 || tmat_(2,3) != 0 ||
1379 tmat_(3,0) != 0 || tmat_(3,1) != 0 || tmat_(3,2) != 5 || tmat_(3,3) != -6 ||
1380 tmat_(4,0) != 7 || tmat_(4,1) != -8 || tmat_(4,2) != 9 || tmat_(4,3) != 10 ) {
1381 std::ostringstream oss;
1382 oss << " Test: " << test_ << "\n"
1383 << " Error: Subscript operator failed\n"
1384 << " Details:\n"
1385 << " Result:\n" << tmat_ << "\n"
1386 << " Expected result:\n( 0 0 0 0 )\n"
1387 "( 0 4 -6 0 )\n"
1388 "( -2 9 22 0 )\n"
1389 "( 0 0 5 -6 )\n"
1390 "( 7 -8 9 10 )\n";
1391 throw std::runtime_error( oss.str() );
1392 }
1393 }
1394
1395 // Division assignment to the element (1,2)
1396 {
1397 rs(1,2) /= 2;
1398
1399 checkRows ( rs , 3UL );
1400 checkColumns ( rs , 4UL );
1401 checkNonZeros( rs , 7UL );
1402 checkNonZeros( rs , 0UL, 2UL );
1403 checkNonZeros( rs , 1UL, 3UL );
1404 checkNonZeros( rs , 2UL, 2UL );
1405 checkRows ( tmat_, 5UL );
1406 checkColumns ( tmat_, 4UL );
1407 checkNonZeros( tmat_, 11UL );
1408
1409 if( rs(0,0) != 0 || rs(0,1) != 4 || rs(0,2) != -6 || rs(0,3) != 0 ||
1410 rs(1,0) != -2 || rs(1,1) != 9 || rs(1,2) != 11 || rs(1,3) != 0 ||
1411 rs(2,0) != 0 || rs(2,1) != 0 || rs(2,2) != 5 || rs(2,3) != -6 ) {
1412 std::ostringstream oss;
1413 oss << " Test: " << test_ << "\n"
1414 << " Error: Function call operator failed\n"
1415 << " Details:\n"
1416 << " Result:\n" << rs << "\n"
1417 << " Expected result:\n( 0 4 -6 0 )\n( -2 9 11 0 )\n( 0 0 5 -6 )\n";
1418 throw std::runtime_error( oss.str() );
1419 }
1420
1421 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != 0 || tmat_(0,3) != 0 ||
1422 tmat_(1,0) != 0 || tmat_(1,1) != 4 || tmat_(1,2) != -6 || tmat_(1,3) != 0 ||
1423 tmat_(2,0) != -2 || tmat_(2,1) != 9 || tmat_(2,2) != 11 || tmat_(2,3) != 0 ||
1424 tmat_(3,0) != 0 || tmat_(3,1) != 0 || tmat_(3,2) != 5 || tmat_(3,3) != -6 ||
1425 tmat_(4,0) != 7 || tmat_(4,1) != -8 || tmat_(4,2) != 9 || tmat_(4,3) != 10 ) {
1426 std::ostringstream oss;
1427 oss << " Test: " << test_ << "\n"
1428 << " Error: Subscript operator failed\n"
1429 << " Details:\n"
1430 << " Result:\n" << tmat_ << "\n"
1431 << " Expected result:\n( 0 0 0 0 )\n"
1432 "( 0 4 -6 0 )\n"
1433 "( -2 9 11 0 )\n"
1434 "( 0 0 5 -6 )\n"
1435 "( 7 -8 9 10 )\n";
1436 throw std::runtime_error( oss.str() );
1437 }
1438 }
1439 }
1440 }
1441 //*************************************************************************************************
1442
1443
1444 //*************************************************************************************************
1445 /*!\brief Test of the Rows iterator implementation.
1446 //
1447 // \return void
1448 // \exception std::runtime_error Error detected.
1449 //
1450 // This function performs a test of the iterator implementation of the Rows specialization.
1451 // In case an error is detected, a \a std::runtime_error exception is thrown.
1452 */
testIterator()1453 void SparseGeneralTest::testIterator()
1454 {
1455 //=====================================================================================
1456 // Row-major matrix tests
1457 //=====================================================================================
1458
1459 {
1460 initialize();
1461
1462 // Testing the Iterator default constructor
1463 {
1464 test_ = "Row-major Iterator default constructor";
1465
1466 RT::Iterator it{};
1467
1468 if( it != RT::Iterator() ) {
1469 std::ostringstream oss;
1470 oss << " Test: " << test_ << "\n"
1471 << " Error: Failed iterator default constructor\n";
1472 throw std::runtime_error( oss.str() );
1473 }
1474 }
1475
1476 // Testing the ConstIterator default constructor
1477 {
1478 test_ = "Row-major ConstIterator default constructor";
1479
1480 RT::ConstIterator it{};
1481
1482 if( it != RT::ConstIterator() ) {
1483 std::ostringstream oss;
1484 oss << " Test: " << test_ << "\n"
1485 << " Error: Failed iterator default constructor\n";
1486 throw std::runtime_error( oss.str() );
1487 }
1488 }
1489
1490 // Testing conversion from Iterator to ConstIterator
1491 {
1492 test_ = "Row-major Iterator/ConstIterator conversion";
1493
1494 auto rs = blaze::rows( mat_, { 2UL } );
1495 auto it( begin( rs, 0UL ) );
1496
1497 if( it == end( rs, 0UL ) || it->value() != -2 ) {
1498 std::ostringstream oss;
1499 oss << " Test: " << test_ << "\n"
1500 << " Error: Failed iterator conversion detected\n";
1501 throw std::runtime_error( oss.str() );
1502 }
1503 }
1504
1505 // Counting the number of elements in 1st row via Iterator (end-begin)
1506 {
1507 test_ = "Row-major Iterator subtraction (end-begin)";
1508
1509 auto rs = blaze::rows( mat_, { 1UL } );
1510 const ptrdiff_t number( end( rs, 0UL ) - begin( rs, 0UL ) );
1511
1512 if( number != 1L ) {
1513 std::ostringstream oss;
1514 oss << " Test: " << test_ << "\n"
1515 << " Error: Invalid number of elements detected\n"
1516 << " Details:\n"
1517 << " Number of elements : " << number << "\n"
1518 << " Expected number of elements: 1\n";
1519 throw std::runtime_error( oss.str() );
1520 }
1521 }
1522
1523 // Counting the number of elements in 2nd row via ConstIterator (end-begin)
1524 {
1525 test_ = "Row-major ConstIterator subtraction (end-begin)";
1526
1527 auto rs = blaze::rows( mat_, { 2UL } );
1528 const ptrdiff_t number( cend( rs, 0UL ) - cbegin( rs, 0UL ) );
1529
1530 if( number != 2L ) {
1531 std::ostringstream oss;
1532 oss << " Test: " << test_ << "\n"
1533 << " Error: Invalid number of elements detected\n"
1534 << " Details:\n"
1535 << " Number of elements : " << number << "\n"
1536 << " Expected number of elements: 2\n";
1537 throw std::runtime_error( oss.str() );
1538 }
1539 }
1540
1541 // Testing read-only access via ConstIterator
1542 {
1543 test_ = "Row-major read-only access via ConstIterator";
1544
1545 auto rs = blaze::rows( mat_, { 2UL } );
1546 auto it ( cbegin( rs, 0UL ) );
1547 auto end( cend( rs, 0UL ) );
1548
1549 if( it == end || it->value() != -2 ) {
1550 std::ostringstream oss;
1551 oss << " Test: " << test_ << "\n"
1552 << " Error: Invalid initial iterator detected\n";
1553 throw std::runtime_error( oss.str() );
1554 }
1555
1556 ++it;
1557
1558 if( it == end || it->value() != -3 ) {
1559 std::ostringstream oss;
1560 oss << " Test: " << test_ << "\n"
1561 << " Error: Iterator pre-increment failed\n";
1562 throw std::runtime_error( oss.str() );
1563 }
1564
1565 it++;
1566
1567 if( it != end ) {
1568 std::ostringstream oss;
1569 oss << " Test: " << test_ << "\n"
1570 << " Error: Iterator post-increment failed\n";
1571 throw std::runtime_error( oss.str() );
1572 }
1573 }
1574
1575 // Testing assignment via Iterator
1576 {
1577 test_ = "Row-major assignment via Iterator";
1578
1579 auto rs = blaze::rows( mat_, { 2UL } );
1580 int value = 8;
1581
1582 for( auto it=begin( rs, 0UL ); it!=end( rs, 0UL ); ++it ) {
1583 *it = value++;
1584 }
1585
1586 if( rs(0,0) != 8 || rs(0,1) != 0 || rs(0,2) != 9 || rs(0,3) != 0 ) {
1587 std::ostringstream oss;
1588 oss << " Test: " << test_ << "\n"
1589 << " Error: Assignment via iterator failed\n"
1590 << " Details:\n"
1591 << " Result:\n" << rs << "\n"
1592 << " Expected result:\n( 8 0 9 0 )\n";
1593 throw std::runtime_error( oss.str() );
1594 }
1595
1596 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != 0 || mat_(0,3) != 0 ||
1597 mat_(1,0) != 0 || mat_(1,1) != 1 || mat_(1,2) != 0 || mat_(1,3) != 0 ||
1598 mat_(2,0) != 8 || mat_(2,1) != 0 || mat_(2,2) != 9 || mat_(2,3) != 0 ||
1599 mat_(3,0) != 0 || mat_(3,1) != 4 || mat_(3,2) != 5 || mat_(3,3) != -6 ||
1600 mat_(4,0) != 7 || mat_(4,1) != -8 || mat_(4,2) != 9 || mat_(4,3) != 10 ) {
1601 std::ostringstream oss;
1602 oss << " Test: " << test_ << "\n"
1603 << " Error: Assignment via iterator failed\n"
1604 << " Details:\n"
1605 << " Result:\n" << mat_ << "\n"
1606 << " Expected result:\n( 6 7 8 9 )\n"
1607 "( 0 1 0 0 )\n"
1608 "( 8 0 9 0 )\n"
1609 "( 0 4 5 -6 )\n"
1610 "( 7 -8 9 10 )\n";
1611 throw std::runtime_error( oss.str() );
1612 }
1613 }
1614
1615 // Testing addition assignment via Iterator
1616 {
1617 test_ = "Row-major addition assignment via Iterator";
1618
1619 auto rs = blaze::rows( mat_, { 2UL } );
1620 int value = 2;
1621
1622 for( auto it=begin( rs, 0UL ); it!=end( rs, 0UL ); ++it ) {
1623 *it += value++;
1624 }
1625
1626 if( rs(0,0) != 10 || rs(0,1) != 0 || rs(0,2) != 12 || rs(0,3) != 0 ) {
1627 std::ostringstream oss;
1628 oss << " Test: " << test_ << "\n"
1629 << " Error: Addition assignment via iterator failed\n"
1630 << " Details:\n"
1631 << " Result:\n" << rs << "\n"
1632 << " Expected result:\n( 10 0 12 0 )\n";
1633 throw std::runtime_error( oss.str() );
1634 }
1635
1636 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != 0 || mat_(0,3) != 0 ||
1637 mat_(1,0) != 0 || mat_(1,1) != 1 || mat_(1,2) != 0 || mat_(1,3) != 0 ||
1638 mat_(2,0) != 10 || mat_(2,1) != 0 || mat_(2,2) != 12 || mat_(2,3) != 0 ||
1639 mat_(3,0) != 0 || mat_(3,1) != 4 || mat_(3,2) != 5 || mat_(3,3) != -6 ||
1640 mat_(4,0) != 7 || mat_(4,1) != -8 || mat_(4,2) != 9 || mat_(4,3) != 10 ) {
1641 std::ostringstream oss;
1642 oss << " Test: " << test_ << "\n"
1643 << " Error: Addition assignment via iterator failed\n"
1644 << " Details:\n"
1645 << " Result:\n" << mat_ << "\n"
1646 << " Expected result:\n( 6 7 8 9 )\n"
1647 "( 0 1 0 0 )\n"
1648 "( 10 0 12 0 )\n"
1649 "( 0 4 5 -6 )\n"
1650 "( 7 -8 9 10 )\n";
1651 throw std::runtime_error( oss.str() );
1652 }
1653 }
1654
1655 // Testing subtraction assignment via Iterator
1656 {
1657 test_ = "Row-major subtraction assignment via Iterator";
1658
1659 auto rs = blaze::rows( mat_, { 2UL } );
1660 int value = 2;
1661
1662 for( auto it=begin( rs, 0UL ); it!=end( rs, 0UL ); ++it ) {
1663 *it -= value++;
1664 }
1665
1666 if( rs(0,0) != 8 || rs(0,1) != 0 || rs(0,2) != 9 || rs(0,3) != 0 ) {
1667 std::ostringstream oss;
1668 oss << " Test: " << test_ << "\n"
1669 << " Error: Subtraction assignment via iterator failed\n"
1670 << " Details:\n"
1671 << " Result:\n" << rs << "\n"
1672 << " Expected result:\n( 8 0 9 0 )\n";
1673 throw std::runtime_error( oss.str() );
1674 }
1675
1676 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != 0 || mat_(0,3) != 0 ||
1677 mat_(1,0) != 0 || mat_(1,1) != 1 || mat_(1,2) != 0 || mat_(1,3) != 0 ||
1678 mat_(2,0) != 8 || mat_(2,1) != 0 || mat_(2,2) != 9 || mat_(2,3) != 0 ||
1679 mat_(3,0) != 0 || mat_(3,1) != 4 || mat_(3,2) != 5 || mat_(3,3) != -6 ||
1680 mat_(4,0) != 7 || mat_(4,1) != -8 || mat_(4,2) != 9 || mat_(4,3) != 10 ) {
1681 std::ostringstream oss;
1682 oss << " Test: " << test_ << "\n"
1683 << " Error: Subtraction assignment via iterator failed\n"
1684 << " Details:\n"
1685 << " Result:\n" << mat_ << "\n"
1686 << " Expected result:\n( 6 7 8 9 )\n"
1687 "( 0 1 0 0 )\n"
1688 "( 8 0 9 0 )\n"
1689 "( 0 4 5 -6 )\n"
1690 "( 7 -8 9 10 )\n";
1691 throw std::runtime_error( oss.str() );
1692 }
1693 }
1694
1695 // Testing multiplication assignment via Iterator
1696 {
1697 test_ = "Row-major multiplication assignment via Iterator";
1698
1699 auto rs = blaze::rows( mat_, { 2UL } );
1700 int value = 1;
1701
1702 for( auto it=begin( rs, 0UL ); it!=end( rs, 0UL ); ++it ) {
1703 *it *= value++;
1704 }
1705
1706 if( rs(0,0) != 8 || rs(0,1) != 0 || rs(0,2) != 18 || rs(0,3) != 0 ) {
1707 std::ostringstream oss;
1708 oss << " Test: " << test_ << "\n"
1709 << " Error: Multiplication assignment via iterator failed\n"
1710 << " Details:\n"
1711 << " Result:\n" << rs << "\n"
1712 << " Expected result:\n( 8 0 9 0 )\n";
1713 throw std::runtime_error( oss.str() );
1714 }
1715
1716 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != 0 || mat_(0,3) != 0 ||
1717 mat_(1,0) != 0 || mat_(1,1) != 1 || mat_(1,2) != 0 || mat_(1,3) != 0 ||
1718 mat_(2,0) != 8 || mat_(2,1) != 0 || mat_(2,2) != 18 || mat_(2,3) != 0 ||
1719 mat_(3,0) != 0 || mat_(3,1) != 4 || mat_(3,2) != 5 || mat_(3,3) != -6 ||
1720 mat_(4,0) != 7 || mat_(4,1) != -8 || mat_(4,2) != 9 || mat_(4,3) != 10 ) {
1721 std::ostringstream oss;
1722 oss << " Test: " << test_ << "\n"
1723 << " Error: Multiplication assignment via iterator failed\n"
1724 << " Details:\n"
1725 << " Result:\n" << mat_ << "\n"
1726 << " Expected result:\n( 6 7 8 9 )\n"
1727 "( 0 1 0 0 )\n"
1728 "( 8 0 18 0 )\n"
1729 "( 0 4 5 -6 )\n"
1730 "( 7 -8 9 10 )\n";
1731 throw std::runtime_error( oss.str() );
1732 }
1733 }
1734
1735 // Testing division assignment via Iterator
1736 {
1737 test_ = "Row-major division assignment via Iterator";
1738
1739 auto rs = blaze::rows( mat_, { 2UL } );
1740
1741 for( auto it=begin( rs, 0UL ); it!=end( rs, 0UL ); ++it ) {
1742 *it /= 2;
1743 }
1744
1745 if( rs(0,0) != 4 || rs(0,1) != 0 || rs(0,2) != 9 || rs(0,3) != 0 ) {
1746 std::ostringstream oss;
1747 oss << " Test: " << test_ << "\n"
1748 << " Error: Division assignment via iterator failed\n"
1749 << " Details:\n"
1750 << " Result:\n" << rs << "\n"
1751 << " Expected result:\n( 4 0 9 0 )\n";
1752 throw std::runtime_error( oss.str() );
1753 }
1754
1755 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != 0 || mat_(0,3) != 0 ||
1756 mat_(1,0) != 0 || mat_(1,1) != 1 || mat_(1,2) != 0 || mat_(1,3) != 0 ||
1757 mat_(2,0) != 4 || mat_(2,1) != 0 || mat_(2,2) != 9 || mat_(2,3) != 0 ||
1758 mat_(3,0) != 0 || mat_(3,1) != 4 || mat_(3,2) != 5 || mat_(3,3) != -6 ||
1759 mat_(4,0) != 7 || mat_(4,1) != -8 || mat_(4,2) != 9 || mat_(4,3) != 10 ) {
1760 std::ostringstream oss;
1761 oss << " Test: " << test_ << "\n"
1762 << " Error: Division assignment via iterator failed\n"
1763 << " Details:\n"
1764 << " Result:\n" << mat_ << "\n"
1765 << " Expected result:\n( 6 7 8 9 )\n"
1766 "( 0 1 0 0 )\n"
1767 "( 4 0 9 0 )\n"
1768 "( 0 4 5 -6 )\n"
1769 "( 7 -8 9 10 )\n";
1770 throw std::runtime_error( oss.str() );
1771 }
1772 }
1773 }
1774
1775
1776 //=====================================================================================
1777 // Column-major matrix tests
1778 //=====================================================================================
1779
1780 {
1781 initialize();
1782
1783 // Testing the Iterator default constructor
1784 {
1785 test_ = "Column-major Iterator default constructor";
1786
1787 ORT::Iterator it{};
1788
1789 if( it != ORT::Iterator() ) {
1790 std::ostringstream oss;
1791 oss << " Test: " << test_ << "\n"
1792 << " Error: Failed iterator default constructor\n";
1793 throw std::runtime_error( oss.str() );
1794 }
1795 }
1796
1797 // Testing the ConstIterator default constructor
1798 {
1799 test_ = "Column-major ConstIterator default constructor";
1800
1801 ORT::ConstIterator it{};
1802
1803 if( it != ORT::ConstIterator() ) {
1804 std::ostringstream oss;
1805 oss << " Test: " << test_ << "\n"
1806 << " Error: Failed iterator default constructor\n";
1807 throw std::runtime_error( oss.str() );
1808 }
1809 }
1810
1811 // Testing conversion from Iterator to ConstIterator
1812 {
1813 test_ = "Column-major Iterator/ConstIterator conversion";
1814
1815 auto rs = blaze::rows( tmat_, { 2UL } );
1816 auto it( begin( rs, 0UL ) );
1817
1818 if( it == end( rs, 0UL ) || it->value() != -2 ) {
1819 std::ostringstream oss;
1820 oss << " Test: " << test_ << "\n"
1821 << " Error: Failed iterator conversion detected\n";
1822 throw std::runtime_error( oss.str() );
1823 }
1824 }
1825
1826 // Counting the number of elements in 1st row via Iterator (end-begin)
1827 {
1828 test_ = "Column-major Iterator subtraction (end-begin)";
1829
1830 auto rs = blaze::rows( tmat_, { 1UL } );
1831 const ptrdiff_t number( end( rs, 0UL ) - begin( rs, 0UL ) );
1832
1833 if( number != 1L ) {
1834 std::ostringstream oss;
1835 oss << " Test: " << test_ << "\n"
1836 << " Error: Invalid number of elements detected\n"
1837 << " Details:\n"
1838 << " Number of elements : " << number << "\n"
1839 << " Expected number of elements: 1\n";
1840 throw std::runtime_error( oss.str() );
1841 }
1842 }
1843
1844 // Counting the number of elements in 2nd row via ConstIterator (end-begin)
1845 {
1846 test_ = "Column-major ConstIterator subtraction (end-begin)";
1847
1848 auto rs = blaze::rows( tmat_, { 2UL } );
1849 const ptrdiff_t number( cend( rs, 0UL ) - cbegin( rs, 0UL ) );
1850
1851 if( number != 2L ) {
1852 std::ostringstream oss;
1853 oss << " Test: " << test_ << "\n"
1854 << " Error: Invalid number of elements detected\n"
1855 << " Details:\n"
1856 << " Number of elements : " << number << "\n"
1857 << " Expected number of elements: 2\n";
1858 throw std::runtime_error( oss.str() );
1859 }
1860 }
1861
1862 // Testing read-only access via ConstIterator
1863 {
1864 test_ = "Column-major read-only access via ConstIterator";
1865
1866 auto rs = blaze::rows( tmat_, { 2UL } );
1867 auto it ( cbegin( rs, 0UL ) );
1868 auto end( cend( rs, 0UL ) );
1869
1870 if( it == end || it->value() != -2 ) {
1871 std::ostringstream oss;
1872 oss << " Test: " << test_ << "\n"
1873 << " Error: Invalid initial iterator detected\n";
1874 throw std::runtime_error( oss.str() );
1875 }
1876
1877 ++it;
1878
1879 if( it == end || it->value() != -3 ) {
1880 std::ostringstream oss;
1881 oss << " Test: " << test_ << "\n"
1882 << " Error: Iterator pre-increment failed\n";
1883 throw std::runtime_error( oss.str() );
1884 }
1885
1886 it++;
1887
1888 if( it != end ) {
1889 std::ostringstream oss;
1890 oss << " Test: " << test_ << "\n"
1891 << " Error: Iterator post-increment failed\n";
1892 throw std::runtime_error( oss.str() );
1893 }
1894 }
1895
1896 // Testing assignment via Iterator
1897 {
1898 test_ = "Column-major assignment via Iterator";
1899
1900 auto rs = blaze::rows( tmat_, { 2UL } );
1901 int value = 8;
1902
1903 for( auto it=begin( rs, 0UL ); it!=end( rs, 0UL ); ++it ) {
1904 *it = value++;
1905 }
1906
1907 if( rs(0,0) != 8 || rs(0,1) != 0 || rs(0,2) != 9 || rs(0,3) != 0 ) {
1908 std::ostringstream oss;
1909 oss << " Test: " << test_ << "\n"
1910 << " Error: Assignment via iterator failed\n"
1911 << " Details:\n"
1912 << " Result:\n" << rs << "\n"
1913 << " Expected result:\n( 8 0 9 0 )\n";
1914 throw std::runtime_error( oss.str() );
1915 }
1916
1917 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != 0 || tmat_(0,3) != 0 ||
1918 tmat_(1,0) != 0 || tmat_(1,1) != 1 || tmat_(1,2) != 0 || tmat_(1,3) != 0 ||
1919 tmat_(2,0) != 8 || tmat_(2,1) != 0 || tmat_(2,2) != 9 || tmat_(2,3) != 0 ||
1920 tmat_(3,0) != 0 || tmat_(3,1) != 4 || tmat_(3,2) != 5 || tmat_(3,3) != -6 ||
1921 tmat_(4,0) != 7 || tmat_(4,1) != -8 || tmat_(4,2) != 9 || tmat_(4,3) != 10 ) {
1922 std::ostringstream oss;
1923 oss << " Test: " << test_ << "\n"
1924 << " Error: Assignment via iterator failed\n"
1925 << " Details:\n"
1926 << " Result:\n" << tmat_ << "\n"
1927 << " Expected result:\n( 6 7 8 9 )\n"
1928 "( 0 1 0 0 )\n"
1929 "( 8 0 9 0 )\n"
1930 "( 0 4 5 -6 )\n"
1931 "( 7 -8 9 10 )\n";
1932 throw std::runtime_error( oss.str() );
1933 }
1934 }
1935
1936 // Testing addition assignment via Iterator
1937 {
1938 test_ = "Column-major addition assignment via Iterator";
1939
1940 auto rs = blaze::rows( tmat_, { 2UL } );
1941 int value = 2;
1942
1943 for( auto it=begin( rs, 0UL ); it!=end( rs, 0UL ); ++it ) {
1944 *it += value++;
1945 }
1946
1947 if( rs(0,0) != 10 || rs(0,1) != 0 || rs(0,2) != 12 || rs(0,3) != 0 ) {
1948 std::ostringstream oss;
1949 oss << " Test: " << test_ << "\n"
1950 << " Error: Addition assignment via iterator failed\n"
1951 << " Details:\n"
1952 << " Result:\n" << rs << "\n"
1953 << " Expected result:\n( 10 0 12 0 )\n";
1954 throw std::runtime_error( oss.str() );
1955 }
1956
1957 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != 0 || tmat_(0,3) != 0 ||
1958 tmat_(1,0) != 0 || tmat_(1,1) != 1 || tmat_(1,2) != 0 || tmat_(1,3) != 0 ||
1959 tmat_(2,0) != 10 || tmat_(2,1) != 0 || tmat_(2,2) != 12 || tmat_(2,3) != 0 ||
1960 tmat_(3,0) != 0 || tmat_(3,1) != 4 || tmat_(3,2) != 5 || tmat_(3,3) != -6 ||
1961 tmat_(4,0) != 7 || tmat_(4,1) != -8 || tmat_(4,2) != 9 || tmat_(4,3) != 10 ) {
1962 std::ostringstream oss;
1963 oss << " Test: " << test_ << "\n"
1964 << " Error: Addition assignment via iterator failed\n"
1965 << " Details:\n"
1966 << " Result:\n" << tmat_ << "\n"
1967 << " Expected result:\n( 6 7 8 9 )\n"
1968 "( 0 1 0 0 )\n"
1969 "( 10 0 12 0 )\n"
1970 "( 0 4 5 -6 )\n"
1971 "( 7 -8 9 10 )\n";
1972 throw std::runtime_error( oss.str() );
1973 }
1974 }
1975
1976 // Testing subtraction assignment via Iterator
1977 {
1978 test_ = "Column-major subtraction assignment via Iterator";
1979
1980 auto rs = blaze::rows( tmat_, { 2UL } );
1981 int value = 2;
1982
1983 for( auto it=begin( rs, 0UL ); it!=end( rs, 0UL ); ++it ) {
1984 *it -= value++;
1985 }
1986
1987 if( rs(0,0) != 8 || rs(0,1) != 0 || rs(0,2) != 9 || rs(0,3) != 0 ) {
1988 std::ostringstream oss;
1989 oss << " Test: " << test_ << "\n"
1990 << " Error: Subtraction assignment via iterator failed\n"
1991 << " Details:\n"
1992 << " Result:\n" << rs << "\n"
1993 << " Expected result:\n( 8 0 9 0 )\n";
1994 throw std::runtime_error( oss.str() );
1995 }
1996
1997 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != 0 || tmat_(0,3) != 0 ||
1998 tmat_(1,0) != 0 || tmat_(1,1) != 1 || tmat_(1,2) != 0 || tmat_(1,3) != 0 ||
1999 tmat_(2,0) != 8 || tmat_(2,1) != 0 || tmat_(2,2) != 9 || tmat_(2,3) != 0 ||
2000 tmat_(3,0) != 0 || tmat_(3,1) != 4 || tmat_(3,2) != 5 || tmat_(3,3) != -6 ||
2001 tmat_(4,0) != 7 || tmat_(4,1) != -8 || tmat_(4,2) != 9 || tmat_(4,3) != 10 ) {
2002 std::ostringstream oss;
2003 oss << " Test: " << test_ << "\n"
2004 << " Error: Subtraction assignment via iterator failed\n"
2005 << " Details:\n"
2006 << " Result:\n" << tmat_ << "\n"
2007 << " Expected result:\n( 6 7 8 9 )\n"
2008 "( 0 1 0 0 )\n"
2009 "( 8 0 9 0 )\n"
2010 "( 0 4 5 -6 )\n"
2011 "( 7 -8 9 10 )\n";
2012 throw std::runtime_error( oss.str() );
2013 }
2014 }
2015
2016 // Testing multiplication assignment via Iterator
2017 {
2018 test_ = "Column-major multiplication assignment via Iterator";
2019
2020 auto rs = blaze::rows( tmat_, { 2UL } );
2021 int value = 1;
2022
2023 for( auto it=begin( rs, 0UL ); it!=end( rs, 0UL ); ++it ) {
2024 *it *= value++;
2025 }
2026
2027 if( rs(0,0) != 8 || rs(0,1) != 0 || rs(0,2) != 18 || rs(0,3) != 0 ) {
2028 std::ostringstream oss;
2029 oss << " Test: " << test_ << "\n"
2030 << " Error: Multiplication assignment via iterator failed\n"
2031 << " Details:\n"
2032 << " Result:\n" << rs << "\n"
2033 << " Expected result:\n( 8 0 9 0 )\n";
2034 throw std::runtime_error( oss.str() );
2035 }
2036
2037 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != 0 || tmat_(0,3) != 0 ||
2038 tmat_(1,0) != 0 || tmat_(1,1) != 1 || tmat_(1,2) != 0 || tmat_(1,3) != 0 ||
2039 tmat_(2,0) != 8 || tmat_(2,1) != 0 || tmat_(2,2) != 18 || tmat_(2,3) != 0 ||
2040 tmat_(3,0) != 0 || tmat_(3,1) != 4 || tmat_(3,2) != 5 || tmat_(3,3) != -6 ||
2041 tmat_(4,0) != 7 || tmat_(4,1) != -8 || tmat_(4,2) != 9 || tmat_(4,3) != 10 ) {
2042 std::ostringstream oss;
2043 oss << " Test: " << test_ << "\n"
2044 << " Error: Multiplication assignment via iterator failed\n"
2045 << " Details:\n"
2046 << " Result:\n" << tmat_ << "\n"
2047 << " Expected result:\n( 6 7 8 9 )\n"
2048 "( 0 1 0 0 )\n"
2049 "( 8 0 18 0 )\n"
2050 "( 0 4 5 -6 )\n"
2051 "( 7 -8 9 10 )\n";
2052 throw std::runtime_error( oss.str() );
2053 }
2054 }
2055
2056 // Testing division assignment via Iterator
2057 {
2058 test_ = "Column-major division assignment via Iterator";
2059
2060 auto rs = blaze::rows( tmat_, { 2UL } );
2061
2062 for( auto it=begin( rs, 0UL ); it!=end( rs, 0UL ); ++it ) {
2063 *it /= 2;
2064 }
2065
2066 if( rs(0,0) != 4 || rs(0,1) != 0 || rs(0,2) != 9 || rs(0,3) != 0 ) {
2067 std::ostringstream oss;
2068 oss << " Test: " << test_ << "\n"
2069 << " Error: Division assignment via iterator failed\n"
2070 << " Details:\n"
2071 << " Result:\n" << rs << "\n"
2072 << " Expected result:\n( 4 0 9 0 )\n";
2073 throw std::runtime_error( oss.str() );
2074 }
2075
2076 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != 0 || tmat_(0,3) != 0 ||
2077 tmat_(1,0) != 0 || tmat_(1,1) != 1 || tmat_(1,2) != 0 || tmat_(1,3) != 0 ||
2078 tmat_(2,0) != 4 || tmat_(2,1) != 0 || tmat_(2,2) != 9 || tmat_(2,3) != 0 ||
2079 tmat_(3,0) != 0 || tmat_(3,1) != 4 || tmat_(3,2) != 5 || tmat_(3,3) != -6 ||
2080 tmat_(4,0) != 7 || tmat_(4,1) != -8 || tmat_(4,2) != 9 || tmat_(4,3) != 10 ) {
2081 std::ostringstream oss;
2082 oss << " Test: " << test_ << "\n"
2083 << " Error: Division assignment via iterator failed\n"
2084 << " Details:\n"
2085 << " Result:\n" << tmat_ << "\n"
2086 << " Expected result:\n( 6 7 8 9 )\n"
2087 "( 0 1 0 0 )\n"
2088 "( 4 0 9 0 )\n"
2089 "( 0 4 5 -6 )\n"
2090 "( 7 -8 9 10 )\n";
2091 throw std::runtime_error( oss.str() );
2092 }
2093 }
2094 }
2095 }
2096 //*************************************************************************************************
2097
2098
2099 //*************************************************************************************************
2100 /*!\brief Test of the \c nonZeros() member function of the Rows class template.
2101 //
2102 // \return void
2103 // \exception std::runtime_error Error detected.
2104 //
2105 // This function performs a test of the \c nonZeros() member function of the Rows specialization.
2106 // In case an error is detected, a \a std::runtime_error exception is thrown.
2107 */
testNonZeros()2108 void SparseGeneralTest::testNonZeros()
2109 {
2110 //=====================================================================================
2111 // Row-major matrix tests
2112 //=====================================================================================
2113
2114 {
2115 test_ = "Row-major Rows::nonZeros()";
2116
2117 initialize();
2118
2119 // Initialization check
2120 auto rs = blaze::rows( mat_, { 1UL, 2UL } );
2121
2122 checkRows ( rs, 2UL );
2123 checkColumns ( rs, 4UL );
2124 checkNonZeros( rs, 3UL );
2125 checkNonZeros( rs, 0UL, 1UL );
2126 checkNonZeros( rs, 1UL, 2UL );
2127
2128 if( rs(0,0) != 0 || rs(0,1) != 1 || rs(0,2) != 0 || rs(0,3) != 0 ||
2129 rs(1,0) != -2 || rs(1,1) != 0 || rs(1,2) != -3 || rs(1,3) != 0 ) {
2130 std::ostringstream oss;
2131 oss << " Test: " << test_ << "\n"
2132 << " Error: Initialization failed\n"
2133 << " Details:\n"
2134 << " Result:\n" << rs << "\n"
2135 << " Expected result:\n( 0 1 0 0 )\n( -2 0 -3 0 )\n";
2136 throw std::runtime_error( oss.str() );
2137 }
2138
2139 // Changing the number of non-zeros via the row selection
2140 rs(1,2) = 0;
2141
2142 checkRows ( rs, 2UL );
2143 checkColumns ( rs, 4UL );
2144 checkNonZeros( rs, 2UL );
2145 checkNonZeros( rs, 0UL, 1UL );
2146 checkNonZeros( rs, 1UL, 1UL );
2147
2148 if( rs(0,0) != 0 || rs(0,1) != 1 || rs(0,2) != 0 || rs(0,3) != 0 ||
2149 rs(1,0) != -2 || rs(1,1) != 0 || rs(1,2) != 0 || rs(1,3) != 0 ) {
2150 std::ostringstream oss;
2151 oss << " Test: " << test_ << "\n"
2152 << " Error: Initialization failed\n"
2153 << " Details:\n"
2154 << " Result:\n" << rs << "\n"
2155 << " Expected result:\n( 0 1 0 0 )\n( -2 0 0 0 )\n";
2156 throw std::runtime_error( oss.str() );
2157 }
2158
2159 // Changing the number of non-zeros via the dense matrix
2160 mat_(2,3) = 5;
2161
2162 checkRows ( rs, 2UL );
2163 checkColumns ( rs, 4UL );
2164 checkNonZeros( rs, 3UL );
2165 checkNonZeros( rs, 0UL, 1UL );
2166 checkNonZeros( rs, 1UL, 2UL );
2167
2168 if( rs(0,0) != 0 || rs(0,1) != 1 || rs(0,2) != 0 || rs(0,3) != 0 ||
2169 rs(1,0) != -2 || rs(1,1) != 0 || rs(1,2) != 0 || rs(1,3) != 5 ) {
2170 std::ostringstream oss;
2171 oss << " Test: " << test_ << "\n"
2172 << " Error: Initialization failed\n"
2173 << " Details:\n"
2174 << " Result:\n" << rs << "\n"
2175 << " Expected result:\n( 0 1 0 0 )\n( -2 0 0 5 )\n";
2176 throw std::runtime_error( oss.str() );
2177 }
2178 }
2179
2180
2181 //=====================================================================================
2182 // Column-major matrix tests
2183 //=====================================================================================
2184
2185 {
2186 test_ = "Column-major Rows::nonZeros()";
2187
2188 initialize();
2189
2190 // Initialization check
2191 auto rs = blaze::rows( tmat_, { 1UL, 2UL } );
2192
2193 checkRows ( rs, 2UL );
2194 checkColumns ( rs, 4UL );
2195 checkNonZeros( rs, 3UL );
2196 checkNonZeros( rs, 0UL, 1UL );
2197 checkNonZeros( rs, 1UL, 2UL );
2198
2199 if( rs(0,0) != 0 || rs(0,1) != 1 || rs(0,2) != 0 || rs(0,3) != 0 ||
2200 rs(1,0) != -2 || rs(1,1) != 0 || rs(1,2) != -3 || rs(1,3) != 0 ) {
2201 std::ostringstream oss;
2202 oss << " Test: " << test_ << "\n"
2203 << " Error: Initialization failed\n"
2204 << " Details:\n"
2205 << " Result:\n" << rs << "\n"
2206 << " Expected result:\n( 0 1 0 0 )\n( -2 0 -3 0 )\n";
2207 throw std::runtime_error( oss.str() );
2208 }
2209
2210 // Changing the number of non-zeros via the row selection
2211 rs(1,2) = 0;
2212
2213 checkRows ( rs, 2UL );
2214 checkColumns ( rs, 4UL );
2215 checkNonZeros( rs, 2UL );
2216 checkNonZeros( rs, 0UL, 1UL );
2217 checkNonZeros( rs, 1UL, 1UL );
2218
2219 if( rs(0,0) != 0 || rs(0,1) != 1 || rs(0,2) != 0 || rs(0,3) != 0 ||
2220 rs(1,0) != -2 || rs(1,1) != 0 || rs(1,2) != 0 || rs(1,3) != 0 ) {
2221 std::ostringstream oss;
2222 oss << " Test: " << test_ << "\n"
2223 << " Error: Initialization failed\n"
2224 << " Details:\n"
2225 << " Result:\n" << rs << "\n"
2226 << " Expected result:\n( 0 1 0 0 )\n( -2 0 0 0 )\n";
2227 throw std::runtime_error( oss.str() );
2228 }
2229
2230 // Changing the number of non-zeros via the dense matrix
2231 tmat_(2,3) = 5;
2232
2233 checkRows ( rs, 2UL );
2234 checkColumns ( rs, 4UL );
2235 checkNonZeros( rs, 3UL );
2236 checkNonZeros( rs, 0UL, 1UL );
2237 checkNonZeros( rs, 1UL, 2UL );
2238
2239 if( rs(0,0) != 0 || rs(0,1) != 1 || rs(0,2) != 0 || rs(0,3) != 0 ||
2240 rs(1,0) != -2 || rs(1,1) != 0 || rs(1,2) != 0 || rs(1,3) != 5 ) {
2241 std::ostringstream oss;
2242 oss << " Test: " << test_ << "\n"
2243 << " Error: Initialization failed\n"
2244 << " Details:\n"
2245 << " Result:\n" << rs << "\n"
2246 << " Expected result:\n( 0 1 0 0 )\n( -2 0 0 5 )\n";
2247 throw std::runtime_error( oss.str() );
2248 }
2249 }
2250 }
2251 //*************************************************************************************************
2252
2253
2254 //*************************************************************************************************
2255 /*!\brief Test of the \c reset() member function of the Rows class template.
2256 //
2257 // \return void
2258 // \exception std::runtime_error Error detected.
2259 //
2260 // This function performs a test of the \c reset() member function of the Rows specialization.
2261 // In case an error is detected, a \a std::runtime_error exception is thrown.
2262 */
testReset()2263 void SparseGeneralTest::testReset()
2264 {
2265 //=====================================================================================
2266 // Row-major single element reset
2267 //=====================================================================================
2268
2269 {
2270 test_ = "Row-major reset() function";
2271
2272 using blaze::reset;
2273 using blaze::isDefault;
2274
2275 initialize();
2276
2277 auto rs = blaze::rows( mat_, { 1UL, 2UL, 3UL } );
2278
2279 reset( rs(0,1) );
2280
2281 checkRows ( rs , 3UL );
2282 checkColumns ( rs , 4UL );
2283 checkNonZeros( rs , 5UL );
2284 checkRows ( mat_, 5UL );
2285 checkColumns ( mat_, 4UL );
2286 checkNonZeros( mat_, 9UL );
2287
2288 if( !isDefault( rs(0,1) ) ) {
2289 std::ostringstream oss;
2290 oss << " Test: " << test_ << "\n"
2291 << " Error: Reset operation failed\n"
2292 << " Details:\n"
2293 << " Result:\n" << rs << "\n"
2294 << " Expected result:\n( 0 0 0 0 )\n( -2 0 -3 0 )\n( 0 4 5 -6 )\n";
2295 throw std::runtime_error( oss.str() );
2296 }
2297
2298 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != 0 || mat_(0,3) != 0 ||
2299 mat_(1,0) != 0 || mat_(1,1) != 0 || mat_(1,2) != 0 || mat_(1,3) != 0 ||
2300 mat_(2,0) != -2 || mat_(2,1) != 0 || mat_(2,2) != -3 || mat_(2,3) != 0 ||
2301 mat_(3,0) != 0 || mat_(3,1) != 4 || mat_(3,2) != 5 || mat_(3,3) != -6 ||
2302 mat_(4,0) != 7 || mat_(4,1) != -8 || mat_(4,2) != 9 || mat_(4,3) != 10 ) {
2303 std::ostringstream oss;
2304 oss << " Test: " << test_ << "\n"
2305 << " Error: Reset operation failed\n"
2306 << " Details:\n"
2307 << " Result:\n" << mat_ << "\n"
2308 << " Expected result:\n( 0 0 0 0 )\n"
2309 "( 0 0 0 0 )\n"
2310 "( -2 0 -3 0 )\n"
2311 "( 0 4 5 -6 )\n"
2312 "( 7 -8 9 10 )\n";
2313 throw std::runtime_error( oss.str() );
2314 }
2315 }
2316
2317
2318 //=====================================================================================
2319 // Row-major reset
2320 //=====================================================================================
2321
2322 {
2323 test_ = "Row-major Rows::reset() (lvalue)";
2324
2325 initialize();
2326
2327 auto rs = blaze::rows( mat_, { 1UL, 2UL, 3UL } );
2328
2329 reset( rs );
2330
2331 checkRows ( rs , 3UL );
2332 checkColumns ( rs , 4UL );
2333 checkNonZeros( rs , 0UL );
2334 checkRows ( mat_, 5UL );
2335 checkColumns ( mat_, 4UL );
2336 checkNonZeros( mat_, 4UL );
2337
2338 if( !isDefault( rs ) ) {
2339 std::ostringstream oss;
2340 oss << " Test: " << test_ << "\n"
2341 << " Error: Reset operation failed\n"
2342 << " Details:\n"
2343 << " Result:\n" << rs << "\n"
2344 << " Expected result:\n( 0 0 0 0 )\n( 0 0 0 0 )\n( 0 0 0 0 )\n";
2345 throw std::runtime_error( oss.str() );
2346 }
2347
2348 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != 0 || mat_(0,3) != 0 ||
2349 mat_(1,0) != 0 || mat_(1,1) != 0 || mat_(1,2) != 0 || mat_(1,3) != 0 ||
2350 mat_(2,0) != 0 || mat_(2,1) != 0 || mat_(2,2) != 0 || mat_(2,3) != 0 ||
2351 mat_(3,0) != 0 || mat_(3,1) != 0 || mat_(3,2) != 0 || mat_(3,3) != 0 ||
2352 mat_(4,0) != 7 || mat_(4,1) != -8 || mat_(4,2) != 9 || mat_(4,3) != 10 ) {
2353 std::ostringstream oss;
2354 oss << " Test: " << test_ << "\n"
2355 << " Error: Reset operation failed\n"
2356 << " Details:\n"
2357 << " Result:\n" << mat_ << "\n"
2358 << " Expected result:\n( 0 0 0 0 )\n"
2359 "( 0 0 0 0 )\n"
2360 "( 0 0 0 0 )\n"
2361 "( 0 0 0 0 )\n"
2362 "( 7 -8 9 10 )\n";
2363 throw std::runtime_error( oss.str() );
2364 }
2365 }
2366
2367 {
2368 test_ = "Row-major Rows::reset() (rvalue)";
2369
2370 initialize();
2371
2372 reset( blaze::rows( mat_, { 1UL, 2UL, 3UL } ) );
2373
2374 checkRows ( mat_, 5UL );
2375 checkColumns ( mat_, 4UL );
2376 checkNonZeros( mat_, 4UL );
2377
2378 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != 0 || mat_(0,3) != 0 ||
2379 mat_(1,0) != 0 || mat_(1,1) != 0 || mat_(1,2) != 0 || mat_(1,3) != 0 ||
2380 mat_(2,0) != 0 || mat_(2,1) != 0 || mat_(2,2) != 0 || mat_(2,3) != 0 ||
2381 mat_(3,0) != 0 || mat_(3,1) != 0 || mat_(3,2) != 0 || mat_(3,3) != 0 ||
2382 mat_(4,0) != 7 || mat_(4,1) != -8 || mat_(4,2) != 9 || mat_(4,3) != 10 ) {
2383 std::ostringstream oss;
2384 oss << " Test: " << test_ << "\n"
2385 << " Error: Reset operation failed\n"
2386 << " Details:\n"
2387 << " Result:\n" << mat_ << "\n"
2388 << " Expected result:\n( 0 0 0 0 )\n"
2389 "( 0 0 0 0 )\n"
2390 "( 0 0 0 0 )\n"
2391 "( 0 0 0 0 )\n"
2392 "( 7 -8 9 10 )\n";
2393 throw std::runtime_error( oss.str() );
2394 }
2395 }
2396
2397
2398 //=====================================================================================
2399 // Column-major single element reset
2400 //=====================================================================================
2401
2402 {
2403 test_ = "Column-major reset() function";
2404
2405 using blaze::reset;
2406 using blaze::isDefault;
2407
2408 initialize();
2409
2410 auto rs = blaze::rows( tmat_, { 1UL, 2UL, 3UL } );
2411
2412 reset( rs(0,1) );
2413
2414 checkRows ( rs , 3UL );
2415 checkColumns ( rs , 4UL );
2416 checkNonZeros( rs , 5UL );
2417 checkRows ( tmat_, 5UL );
2418 checkColumns ( tmat_, 4UL );
2419 checkNonZeros( tmat_, 9UL );
2420
2421 if( !isDefault( rs(0,1) ) ) {
2422 std::ostringstream oss;
2423 oss << " Test: " << test_ << "\n"
2424 << " Error: Reset operation failed\n"
2425 << " Details:\n"
2426 << " Result:\n" << rs << "\n"
2427 << " Expected result:\n( 0 0 0 0 )\n( -2 0 -3 0 )\n( 0 4 5 -6 )\n";
2428 throw std::runtime_error( oss.str() );
2429 }
2430
2431 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != 0 || tmat_(0,3) != 0 ||
2432 tmat_(1,0) != 0 || tmat_(1,1) != 0 || tmat_(1,2) != 0 || tmat_(1,3) != 0 ||
2433 tmat_(2,0) != -2 || tmat_(2,1) != 0 || tmat_(2,2) != -3 || tmat_(2,3) != 0 ||
2434 tmat_(3,0) != 0 || tmat_(3,1) != 4 || tmat_(3,2) != 5 || tmat_(3,3) != -6 ||
2435 tmat_(4,0) != 7 || tmat_(4,1) != -8 || tmat_(4,2) != 9 || tmat_(4,3) != 10 ) {
2436 std::ostringstream oss;
2437 oss << " Test: " << test_ << "\n"
2438 << " Error: Reset operation failed\n"
2439 << " Details:\n"
2440 << " Result:\n" << tmat_ << "\n"
2441 << " Expected result:\n( 0 0 0 0 )\n"
2442 "( 0 0 0 0 )\n"
2443 "( -2 0 -3 0 )\n"
2444 "( 0 4 5 -6 )\n"
2445 "( 7 -8 9 10 )\n";
2446 throw std::runtime_error( oss.str() );
2447 }
2448 }
2449
2450
2451 //=====================================================================================
2452 // Column-major reset
2453 //=====================================================================================
2454
2455 {
2456 test_ = "Column-major Rows::reset() (lvalue)";
2457
2458 initialize();
2459
2460 auto rs = blaze::rows( tmat_, { 1UL, 2UL, 3UL } );
2461
2462 reset( rs );
2463
2464 checkRows ( rs , 3UL );
2465 checkColumns ( rs , 4UL );
2466 checkNonZeros( rs , 0UL );
2467 checkRows ( tmat_, 5UL );
2468 checkColumns ( tmat_, 4UL );
2469 checkNonZeros( tmat_, 4UL );
2470
2471 if( !isDefault( rs ) ) {
2472 std::ostringstream oss;
2473 oss << " Test: " << test_ << "\n"
2474 << " Error: Reset operation failed\n"
2475 << " Details:\n"
2476 << " Result:\n" << rs << "\n"
2477 << " Expected result:\n( 0 0 0 0 )\n( 0 0 0 0 )\n( 0 0 0 0 )\n";
2478 throw std::runtime_error( oss.str() );
2479 }
2480
2481 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != 0 || tmat_(0,3) != 0 ||
2482 tmat_(1,0) != 0 || tmat_(1,1) != 0 || tmat_(1,2) != 0 || tmat_(1,3) != 0 ||
2483 tmat_(2,0) != 0 || tmat_(2,1) != 0 || tmat_(2,2) != 0 || tmat_(2,3) != 0 ||
2484 tmat_(3,0) != 0 || tmat_(3,1) != 0 || tmat_(3,2) != 0 || tmat_(3,3) != 0 ||
2485 tmat_(4,0) != 7 || tmat_(4,1) != -8 || tmat_(4,2) != 9 || tmat_(4,3) != 10 ) {
2486 std::ostringstream oss;
2487 oss << " Test: " << test_ << "\n"
2488 << " Error: Reset operation failed\n"
2489 << " Details:\n"
2490 << " Result:\n" << tmat_ << "\n"
2491 << " Expected result:\n( 0 0 0 0 )\n"
2492 "( 0 0 0 0 )\n"
2493 "( 0 0 0 0 )\n"
2494 "( 0 0 0 0 )\n"
2495 "( 7 -8 9 10 )\n";
2496 throw std::runtime_error( oss.str() );
2497 }
2498 }
2499
2500 {
2501 test_ = "Column-major Rows::reset() (rvalue)";
2502
2503 initialize();
2504
2505 reset( blaze::rows( tmat_, { 1UL, 2UL, 3UL } ) );
2506
2507 checkRows ( tmat_, 5UL );
2508 checkColumns ( tmat_, 4UL );
2509 checkNonZeros( tmat_, 4UL );
2510
2511 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != 0 || tmat_(0,3) != 0 ||
2512 tmat_(1,0) != 0 || tmat_(1,1) != 0 || tmat_(1,2) != 0 || tmat_(1,3) != 0 ||
2513 tmat_(2,0) != 0 || tmat_(2,1) != 0 || tmat_(2,2) != 0 || tmat_(2,3) != 0 ||
2514 tmat_(3,0) != 0 || tmat_(3,1) != 0 || tmat_(3,2) != 0 || tmat_(3,3) != 0 ||
2515 tmat_(4,0) != 7 || tmat_(4,1) != -8 || tmat_(4,2) != 9 || tmat_(4,3) != 10 ) {
2516 std::ostringstream oss;
2517 oss << " Test: " << test_ << "\n"
2518 << " Error: Reset operation failed\n"
2519 << " Details:\n"
2520 << " Result:\n" << tmat_ << "\n"
2521 << " Expected result:\n( 0 0 0 0 )\n"
2522 "( 0 0 0 0 )\n"
2523 "( 0 0 0 0 )\n"
2524 "( 0 0 0 0 )\n"
2525 "( 7 -8 9 10 )\n";
2526 throw std::runtime_error( oss.str() );
2527 }
2528 }
2529 }
2530 //*************************************************************************************************
2531
2532
2533 //*************************************************************************************************
2534 /*!\brief Test of the \c clear() function with the Rows class template.
2535 //
2536 // \return void
2537 // \exception std::runtime_error Error detected.
2538 //
2539 // This function performs a test of the \c clear() function with the Rows specialization.
2540 // In case an error is detected, a \a std::runtime_error exception is thrown.
2541 */
testClear()2542 void SparseGeneralTest::testClear()
2543 {
2544 //=====================================================================================
2545 // Row-major single element clear
2546 //=====================================================================================
2547
2548 {
2549 test_ = "Row-major clear() function";
2550
2551 using blaze::clear;
2552 using blaze::isDefault;
2553
2554 initialize();
2555
2556 auto rs = blaze::rows( mat_, { 1UL, 2UL, 3UL } );
2557
2558 clear( rs(0,1) );
2559
2560 checkRows ( rs , 3UL );
2561 checkColumns ( rs , 4UL );
2562 checkNonZeros( rs , 5UL );
2563 checkRows ( mat_, 5UL );
2564 checkColumns ( mat_, 4UL );
2565 checkNonZeros( mat_, 9UL );
2566
2567 if( !isDefault( rs(0,1) ) ) {
2568 std::ostringstream oss;
2569 oss << " Test: " << test_ << "\n"
2570 << " Error: Clear operation failed\n"
2571 << " Details:\n"
2572 << " Result:\n" << rs << "\n"
2573 << " Expected result:\n( 0 0 0 0 )\n( -2 0 -3 0 )\n( 0 4 5 -6 )\n";
2574 throw std::runtime_error( oss.str() );
2575 }
2576
2577 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != 0 || mat_(0,3) != 0 ||
2578 mat_(1,0) != 0 || mat_(1,1) != 0 || mat_(1,2) != 0 || mat_(1,3) != 0 ||
2579 mat_(2,0) != -2 || mat_(2,1) != 0 || mat_(2,2) != -3 || mat_(2,3) != 0 ||
2580 mat_(3,0) != 0 || mat_(3,1) != 4 || mat_(3,2) != 5 || mat_(3,3) != -6 ||
2581 mat_(4,0) != 7 || mat_(4,1) != -8 || mat_(4,2) != 9 || mat_(4,3) != 10 ) {
2582 std::ostringstream oss;
2583 oss << " Test: " << test_ << "\n"
2584 << " Error: Clear operation failed\n"
2585 << " Details:\n"
2586 << " Result:\n" << mat_ << "\n"
2587 << " Expected result:\n( 0 0 0 0 )\n"
2588 "( 0 0 0 0 )\n"
2589 "( -2 0 -3 0 )\n"
2590 "( 0 4 5 -6 )\n"
2591 "( 7 -8 9 10 )\n";
2592 throw std::runtime_error( oss.str() );
2593 }
2594 }
2595
2596
2597 //=====================================================================================
2598 // Row-major clear
2599 //=====================================================================================
2600
2601 {
2602 test_ = "Row-major Rows::clear() (lvalue)";
2603
2604 initialize();
2605
2606 auto rs = blaze::rows( mat_, { 1UL, 2UL, 3UL } );
2607
2608 clear( rs );
2609
2610 checkRows ( rs , 3UL );
2611 checkColumns ( rs , 4UL );
2612 checkNonZeros( rs , 0UL );
2613 checkRows ( mat_, 5UL );
2614 checkColumns ( mat_, 4UL );
2615 checkNonZeros( mat_, 4UL );
2616
2617 if( !isDefault( rs ) ) {
2618 std::ostringstream oss;
2619 oss << " Test: " << test_ << "\n"
2620 << " Error: Clear operation failed\n"
2621 << " Details:\n"
2622 << " Result:\n" << rs << "\n"
2623 << " Expected result:\n( 0 0 0 0 )\n( 0 0 0 0 )\n( 0 0 0 0 )\n";
2624 throw std::runtime_error( oss.str() );
2625 }
2626
2627 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != 0 || mat_(0,3) != 0 ||
2628 mat_(1,0) != 0 || mat_(1,1) != 0 || mat_(1,2) != 0 || mat_(1,3) != 0 ||
2629 mat_(2,0) != 0 || mat_(2,1) != 0 || mat_(2,2) != 0 || mat_(2,3) != 0 ||
2630 mat_(3,0) != 0 || mat_(3,1) != 0 || mat_(3,2) != 0 || mat_(3,3) != 0 ||
2631 mat_(4,0) != 7 || mat_(4,1) != -8 || mat_(4,2) != 9 || mat_(4,3) != 10 ) {
2632 std::ostringstream oss;
2633 oss << " Test: " << test_ << "\n"
2634 << " Error: Clear operation failed\n"
2635 << " Details:\n"
2636 << " Result:\n" << mat_ << "\n"
2637 << " Expected result:\n( 0 0 0 0 )\n"
2638 "( 0 0 0 0 )\n"
2639 "( 0 0 0 0 )\n"
2640 "( 0 0 0 0 )\n"
2641 "( 7 -8 9 10 )\n";
2642 throw std::runtime_error( oss.str() );
2643 }
2644 }
2645
2646 {
2647 test_ = "Row-major Rows::clear() (rvalue)";
2648
2649 initialize();
2650
2651 clear( blaze::rows( mat_, { 1UL, 2UL, 3UL } ) );
2652
2653 checkRows ( mat_, 5UL );
2654 checkColumns ( mat_, 4UL );
2655 checkNonZeros( mat_, 4UL );
2656
2657 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != 0 || mat_(0,3) != 0 ||
2658 mat_(1,0) != 0 || mat_(1,1) != 0 || mat_(1,2) != 0 || mat_(1,3) != 0 ||
2659 mat_(2,0) != 0 || mat_(2,1) != 0 || mat_(2,2) != 0 || mat_(2,3) != 0 ||
2660 mat_(3,0) != 0 || mat_(3,1) != 0 || mat_(3,2) != 0 || mat_(3,3) != 0 ||
2661 mat_(4,0) != 7 || mat_(4,1) != -8 || mat_(4,2) != 9 || mat_(4,3) != 10 ) {
2662 std::ostringstream oss;
2663 oss << " Test: " << test_ << "\n"
2664 << " Error: Clear operation failed\n"
2665 << " Details:\n"
2666 << " Result:\n" << mat_ << "\n"
2667 << " Expected result:\n( 0 0 0 0 )\n"
2668 "( 0 0 0 0 )\n"
2669 "( 0 0 0 0 )\n"
2670 "( 0 0 0 0 )\n"
2671 "( 7 -8 9 10 )\n";
2672 throw std::runtime_error( oss.str() );
2673 }
2674 }
2675
2676
2677 //=====================================================================================
2678 // Column-major single element clear
2679 //=====================================================================================
2680
2681 {
2682 test_ = "Column-major clear() function";
2683
2684 using blaze::clear;
2685 using blaze::isDefault;
2686
2687 initialize();
2688
2689 auto rs = blaze::rows( tmat_, { 1UL, 2UL, 3UL } );
2690
2691 clear( rs(0,1) );
2692
2693 checkRows ( rs , 3UL );
2694 checkColumns ( rs , 4UL );
2695 checkNonZeros( rs , 5UL );
2696 checkRows ( tmat_, 5UL );
2697 checkColumns ( tmat_, 4UL );
2698 checkNonZeros( tmat_, 9UL );
2699
2700 if( !isDefault( rs(0,1) ) ) {
2701 std::ostringstream oss;
2702 oss << " Test: " << test_ << "\n"
2703 << " Error: Clear operation failed\n"
2704 << " Details:\n"
2705 << " Result:\n" << rs << "\n"
2706 << " Expected result:\n( 0 0 0 0 )\n( -2 0 -3 0 )\n( 0 4 5 -6 )\n";
2707 throw std::runtime_error( oss.str() );
2708 }
2709
2710 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != 0 || tmat_(0,3) != 0 ||
2711 tmat_(1,0) != 0 || tmat_(1,1) != 0 || tmat_(1,2) != 0 || tmat_(1,3) != 0 ||
2712 tmat_(2,0) != -2 || tmat_(2,1) != 0 || tmat_(2,2) != -3 || tmat_(2,3) != 0 ||
2713 tmat_(3,0) != 0 || tmat_(3,1) != 4 || tmat_(3,2) != 5 || tmat_(3,3) != -6 ||
2714 tmat_(4,0) != 7 || tmat_(4,1) != -8 || tmat_(4,2) != 9 || tmat_(4,3) != 10 ) {
2715 std::ostringstream oss;
2716 oss << " Test: " << test_ << "\n"
2717 << " Error: Clear operation failed\n"
2718 << " Details:\n"
2719 << " Result:\n" << tmat_ << "\n"
2720 << " Expected result:\n( 0 0 0 0 )\n"
2721 "( 0 0 0 0 )\n"
2722 "( -2 0 -3 0 )\n"
2723 "( 0 4 5 -6 )\n"
2724 "( 7 -8 9 10 )\n";
2725 throw std::runtime_error( oss.str() );
2726 }
2727 }
2728
2729
2730 //=====================================================================================
2731 // Column-major clear
2732 //=====================================================================================
2733
2734 {
2735 test_ = "Column-major Rows::clear() (lvalue)";
2736
2737 initialize();
2738
2739 auto rs = blaze::rows( tmat_, { 1UL, 2UL, 3UL } );
2740
2741 clear( rs );
2742
2743 checkRows ( rs , 3UL );
2744 checkColumns ( rs , 4UL );
2745 checkNonZeros( rs , 0UL );
2746 checkRows ( tmat_, 5UL );
2747 checkColumns ( tmat_, 4UL );
2748 checkNonZeros( tmat_, 4UL );
2749
2750 if( !isDefault( rs ) ) {
2751 std::ostringstream oss;
2752 oss << " Test: " << test_ << "\n"
2753 << " Error: Clear operation failed\n"
2754 << " Details:\n"
2755 << " Result:\n" << rs << "\n"
2756 << " Expected result:\n( 0 0 0 0 )\n( 0 0 0 0 )\n( 0 0 0 0 )\n";
2757 throw std::runtime_error( oss.str() );
2758 }
2759
2760 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != 0 || tmat_(0,3) != 0 ||
2761 tmat_(1,0) != 0 || tmat_(1,1) != 0 || tmat_(1,2) != 0 || tmat_(1,3) != 0 ||
2762 tmat_(2,0) != 0 || tmat_(2,1) != 0 || tmat_(2,2) != 0 || tmat_(2,3) != 0 ||
2763 tmat_(3,0) != 0 || tmat_(3,1) != 0 || tmat_(3,2) != 0 || tmat_(3,3) != 0 ||
2764 tmat_(4,0) != 7 || tmat_(4,1) != -8 || tmat_(4,2) != 9 || tmat_(4,3) != 10 ) {
2765 std::ostringstream oss;
2766 oss << " Test: " << test_ << "\n"
2767 << " Error: Clear operation failed\n"
2768 << " Details:\n"
2769 << " Result:\n" << tmat_ << "\n"
2770 << " Expected result:\n( 0 0 0 0 )\n"
2771 "( 0 0 0 0 )\n"
2772 "( 0 0 0 0 )\n"
2773 "( 0 0 0 0 )\n"
2774 "( 7 -8 9 10 )\n";
2775 throw std::runtime_error( oss.str() );
2776 }
2777 }
2778
2779 {
2780 test_ = "Column-major Rows::clear() (rvalue)";
2781
2782 initialize();
2783
2784 clear( blaze::rows( tmat_, { 1UL, 2UL, 3UL } ) );
2785
2786 checkRows ( tmat_, 5UL );
2787 checkColumns ( tmat_, 4UL );
2788 checkNonZeros( tmat_, 4UL );
2789
2790 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != 0 || tmat_(0,3) != 0 ||
2791 tmat_(1,0) != 0 || tmat_(1,1) != 0 || tmat_(1,2) != 0 || tmat_(1,3) != 0 ||
2792 tmat_(2,0) != 0 || tmat_(2,1) != 0 || tmat_(2,2) != 0 || tmat_(2,3) != 0 ||
2793 tmat_(3,0) != 0 || tmat_(3,1) != 0 || tmat_(3,2) != 0 || tmat_(3,3) != 0 ||
2794 tmat_(4,0) != 7 || tmat_(4,1) != -8 || tmat_(4,2) != 9 || tmat_(4,3) != 10 ) {
2795 std::ostringstream oss;
2796 oss << " Test: " << test_ << "\n"
2797 << " Error: Clear operation failed\n"
2798 << " Details:\n"
2799 << " Result:\n" << tmat_ << "\n"
2800 << " Expected result:\n( 0 0 0 0 )\n"
2801 "( 0 0 0 0 )\n"
2802 "( 0 0 0 0 )\n"
2803 "( 0 0 0 0 )\n"
2804 "( 7 -8 9 10 )\n";
2805 throw std::runtime_error( oss.str() );
2806 }
2807 }
2808 }
2809 //*************************************************************************************************
2810
2811
2812 //*************************************************************************************************
2813 /*!\brief Test of the \c reserve() member function of the Rows class template.
2814 //
2815 // \return void
2816 // \exception std::runtime_error Error detected.
2817 //
2818 // This function performs a test of the \c reserve() member function of the Rows specialization.
2819 // In case an error is detected, a \a std::runtime_error exception is thrown.
2820 */
testReserve()2821 void SparseGeneralTest::testReserve()
2822 {
2823 //=====================================================================================
2824 // Row-major matrix tests
2825 //=====================================================================================
2826
2827 {
2828 test_ = "Row-major Rows::reserve()";
2829
2830 MT mat( 3UL, 20UL );
2831
2832 auto rs = blaze::rows( mat, { 1UL } );
2833
2834 // Increasing the capacity of the row selection
2835 rs.reserve( 10UL );
2836
2837 checkRows ( rs, 1UL );
2838 checkColumns ( rs, 20UL );
2839 checkCapacity( rs, 10UL );
2840 checkNonZeros( rs, 0UL );
2841
2842 // Further increasing the capacity of the row selection
2843 rs.reserve( 20UL );
2844
2845 checkRows ( rs, 1UL );
2846 checkColumns ( rs, 20UL );
2847 checkCapacity( rs, 20UL );
2848 checkNonZeros( rs, 0UL );
2849 }
2850
2851 {
2852 test_ = "Row-major Rows::reserve( size_t )";
2853
2854 MT mat( 3UL, 20UL );
2855
2856 auto rs = blaze::rows( mat, { 1UL } );
2857
2858 // Increasing the capacity of a single row
2859 rs.reserve( 0UL, 10UL );
2860
2861 checkRows ( rs, 1UL );
2862 checkColumns ( rs, 20UL );
2863 checkCapacity( rs, 10UL );
2864 checkNonZeros( rs, 0UL );
2865
2866 // Further increasing the capacity of a single row
2867 rs.reserve( 0UL, 15UL );
2868
2869 checkRows ( rs, 1UL );
2870 checkColumns ( rs, 20UL );
2871 checkCapacity( rs, 15UL );
2872 checkNonZeros( rs, 0UL );
2873 }
2874
2875
2876 //=====================================================================================
2877 // Column-major matrix tests
2878 //=====================================================================================
2879
2880 {
2881 test_ = "Column-major Rows::reserve()";
2882
2883 OMT mat( 3UL, 20UL );
2884
2885 auto rs = blaze::rows( mat, { 1UL } );
2886
2887 // Increasing the capacity of the row selection
2888 rs.reserve( 10UL );
2889
2890 checkRows ( rs, 1UL );
2891 checkColumns ( rs, 20UL );
2892 checkCapacity( rs, 10UL );
2893 checkNonZeros( rs, 0UL );
2894
2895 // Further increasing the capacity of the row selection
2896 rs.reserve( 20UL );
2897
2898 checkRows ( rs, 1UL );
2899 checkColumns ( rs, 20UL );
2900 checkCapacity( rs, 20UL );
2901 checkNonZeros( rs, 0UL );
2902 }
2903
2904 {
2905 test_ = "Column-major Rows::reserve( size_t )";
2906
2907 OMT mat( 3UL, 20UL );
2908
2909 auto rs = blaze::rows( mat, { 1UL } );
2910
2911 // Increasing the capacity of a single row
2912 rs.reserve( 0UL, 10UL );
2913
2914 checkRows ( rs, 1UL );
2915 checkColumns ( rs, 20UL );
2916 checkCapacity( rs, 10UL );
2917 checkNonZeros( rs, 0UL );
2918
2919 // Further increasing the capacity of a single row
2920 rs.reserve( 0UL, 15UL );
2921
2922 checkRows ( rs, 1UL );
2923 checkColumns ( rs, 20UL );
2924 checkCapacity( rs, 15UL );
2925 checkNonZeros( rs, 0UL );
2926 }
2927 }
2928 //*************************************************************************************************
2929
2930
2931 //*************************************************************************************************
2932 /*!\brief Test of the \c trim() member functions of the Rows class template.
2933 //
2934 // \return void
2935 // \exception std::runtime_error Error detected.
2936 //
2937 // This function performs a test of the \c trim() member functions of the Rows specialization.
2938 // In case an error is detected, a \a std::runtime_error exception is thrown.
2939 */
testTrim()2940 void SparseGeneralTest::testTrim()
2941 {
2942 //=====================================================================================
2943 // Row-major matrix tests
2944 //=====================================================================================
2945
2946 {
2947 test_ = "Row-major Rows::trim()";
2948
2949 initialize();
2950
2951 auto rs = blaze::rows( mat_, { 2UL, 3UL } );
2952
2953 // Increasing the row capacity of the matrix
2954 rs.reserve( 0UL, 10UL );
2955 rs.reserve( 1UL, 20UL );
2956
2957 checkRows ( rs , 2UL );
2958 checkColumns ( rs , 4UL );
2959 checkCapacity( rs , 30UL );
2960 checkCapacity( rs , 0UL, 10UL );
2961 checkCapacity( rs , 1UL, 20UL );
2962 checkCapacity( mat_, 30UL );
2963 checkCapacity( mat_, 2UL, 10UL );
2964 checkCapacity( mat_, 3UL, 20UL );
2965
2966 // Trimming the matrix
2967 rs.trim();
2968
2969 checkRows ( rs , 2UL );
2970 checkColumns ( rs , 4UL );
2971 checkCapacity( rs , 30UL );
2972 checkCapacity( rs , 0UL, rs.nonZeros( 0UL ) );
2973 checkCapacity( rs , 1UL, rs.nonZeros( 1UL ) );
2974 checkCapacity( mat_, 30UL );
2975 checkCapacity( mat_, 2UL, mat_.nonZeros( 2UL ) );
2976 checkCapacity( mat_, 3UL, mat_.nonZeros( 3UL ) );
2977 }
2978
2979 {
2980 test_ = "Row-major Rows::trim( size_t )";
2981
2982 initialize();
2983
2984 auto rs = blaze::rows( mat_, { 2UL, 3UL } );
2985
2986 // Increasing the row capacity of the matrix
2987 rs.reserve( 0UL, 10UL );
2988 rs.reserve( 1UL, 20UL );
2989
2990 checkRows ( rs , 2UL );
2991 checkColumns ( rs , 4UL );
2992 checkCapacity( rs , 30UL );
2993 checkCapacity( rs , 0UL, 10UL );
2994 checkCapacity( rs , 1UL, 20UL );
2995 checkCapacity( mat_, 30UL );
2996 checkCapacity( mat_, 2UL, 10UL );
2997 checkCapacity( mat_, 3UL, 20UL );
2998
2999 // Trimming the 0th row
3000 rs.trim( 0UL );
3001
3002 checkRows ( rs , 2UL );
3003 checkColumns ( rs , 4UL );
3004 checkCapacity( rs , 30UL );
3005 checkCapacity( rs , 0UL, rs.nonZeros( 0UL ) );
3006 checkCapacity( rs , 1UL, 30UL - rs.nonZeros( 0UL ) );
3007 checkCapacity( mat_, 30UL );
3008 checkCapacity( mat_, 2UL, mat_.nonZeros( 2UL ) );
3009 checkCapacity( mat_, 3UL, 30UL - mat_.nonZeros( 2UL ) );
3010
3011 // Trimming the 1st row
3012 rs.trim( 1UL );
3013
3014 checkRows ( rs , 2UL );
3015 checkColumns ( rs , 4UL );
3016 checkCapacity( rs , 30UL );
3017 checkCapacity( rs , 0UL, rs.nonZeros( 0UL ) );
3018 checkCapacity( rs , 1UL, rs.nonZeros( 1UL ) );
3019 checkCapacity( mat_, 30UL );
3020 checkCapacity( mat_, 2UL, mat_.nonZeros( 2UL ) );
3021 checkCapacity( mat_, 3UL, mat_.nonZeros( 3UL ) );
3022 }
3023
3024
3025 //=====================================================================================
3026 // Column-major matrix tests
3027 //=====================================================================================
3028
3029 // No column-major matrix test required
3030 }
3031 //*************************************************************************************************
3032
3033
3034 //*************************************************************************************************
3035 /*!\brief Test of the \c set() member function of the Rows class template.
3036 //
3037 // \return void
3038 // \exception std::runtime_error Error detected.
3039 //
3040 // This function performs a test of the \c set() member function of the Rows specialization.
3041 // In case an error is detected, a \a std::runtime_error exception is thrown.
3042 */
testSet()3043 void SparseGeneralTest::testSet()
3044 {
3045 //=====================================================================================
3046 // Row-major matrix tests
3047 //=====================================================================================
3048
3049 {
3050 test_ = "Row-major Rows::set()";
3051
3052 initialize();
3053
3054 auto rs = blaze::rows( mat_, { 0UL, 1UL } );
3055
3056 // Setting a non-zero element at the end of the 0th row
3057 rs.set( 0UL, 3UL, 1 );
3058
3059 checkRows ( rs , 2UL );
3060 checkColumns ( rs , 4UL );
3061 checkNonZeros( rs , 2UL );
3062 checkRows ( mat_, 5UL );
3063 checkColumns ( mat_, 4UL );
3064 checkNonZeros( mat_, 11UL );
3065
3066 if( rs(0,0) != 0 || rs(0,1) != 0 || rs(0,2) != 0 || rs(0,3) != 1 ||
3067 rs(1,0) != 0 || rs(1,1) != 1 || rs(1,2) != 0 || rs(1,3) != 0 ) {
3068 std::ostringstream oss;
3069 oss << " Test: " << test_ << "\n"
3070 << " Error: Setting a non-zero element failed\n"
3071 << " Details:\n"
3072 << " Result:\n" << rs << "\n"
3073 << " Expected result:\n( 0 0 0 1 )\n( 0 1 0 0 )\n";
3074 throw std::runtime_error( oss.str() );
3075 }
3076
3077 // Setting a non-zero element at the beginning of the 0th row
3078 rs.set( 0UL, 0UL, 2 );
3079
3080 checkRows ( rs , 2UL );
3081 checkColumns ( rs , 4UL );
3082 checkNonZeros( rs , 3UL );
3083 checkRows ( mat_, 5UL );
3084 checkColumns ( mat_, 4UL );
3085 checkNonZeros( mat_, 12UL );
3086
3087 if( rs(0,0) != 2 || rs(0,1) != 0 || rs(0,2) != 0 || rs(0,3) != 1 ||
3088 rs(1,0) != 0 || rs(1,1) != 1 || rs(1,2) != 0 || rs(1,3) != 0 ) {
3089 std::ostringstream oss;
3090 oss << " Test: " << test_ << "\n"
3091 << " Error: Setting a non-zero element failed\n"
3092 << " Details:\n"
3093 << " Result:\n" << rs << "\n"
3094 << " Expected result:\n( 2 0 0 1 )\n( 0 1 0 0 )\n";
3095 throw std::runtime_error( oss.str() );
3096 }
3097
3098 // Setting a non-zero element at the center of the 0th row
3099 rs.set( 0UL, 1UL, 3 );
3100
3101 checkRows ( rs , 2UL );
3102 checkColumns ( rs , 4UL );
3103 checkNonZeros( rs , 4UL );
3104 checkRows ( mat_, 5UL );
3105 checkColumns ( mat_, 4UL );
3106 checkNonZeros( mat_, 13UL );
3107
3108 if( rs(0,0) != 2 || rs(0,1) != 3 || rs(0,2) != 0 || rs(0,3) != 1 ||
3109 rs(1,0) != 0 || rs(1,1) != 1 || rs(1,2) != 0 || rs(1,3) != 0 ) {
3110 std::ostringstream oss;
3111 oss << " Test: " << test_ << "\n"
3112 << " Error: Setting a non-zero element failed\n"
3113 << " Details:\n"
3114 << " Result:\n" << rs << "\n"
3115 << " Expected result:\n( 2 3 0 1 )\n( 0 1 0 0 )\n";
3116 throw std::runtime_error( oss.str() );
3117 }
3118
3119 // Setting an already existing element
3120 rs.set( 1UL, 1UL, 4 );
3121
3122 checkRows ( rs , 2UL );
3123 checkColumns ( rs , 4UL );
3124 checkNonZeros( rs , 4UL );
3125 checkRows ( mat_, 5UL );
3126 checkColumns ( mat_, 4UL );
3127 checkNonZeros( mat_, 13UL );
3128
3129 if( rs(0,0) != 2 || rs(0,1) != 3 || rs(0,2) != 0 || rs(0,3) != 1 ||
3130 rs(1,0) != 0 || rs(1,1) != 4 || rs(1,2) != 0 || rs(1,3) != 0 ) {
3131 std::ostringstream oss;
3132 oss << " Test: " << test_ << "\n"
3133 << " Error: Setting a non-zero element failed\n"
3134 << " Details:\n"
3135 << " Result:\n" << rs << "\n"
3136 << " Expected result:\n( 2 3 0 1 )\n( 0 4 0 0 )\n";
3137 throw std::runtime_error( oss.str() );
3138 }
3139 }
3140
3141
3142 //=====================================================================================
3143 // Column-major matrix tests
3144 //=====================================================================================
3145
3146 {
3147 test_ = "Column-major Rows::set()";
3148
3149 initialize();
3150
3151 auto rs = blaze::rows( tmat_, { 0UL, 1UL } );
3152
3153 // Setting a non-zero element at the end of the 0th row
3154 rs.set( 0UL, 3UL, 1 );
3155
3156 checkRows ( rs , 2UL );
3157 checkColumns ( rs , 4UL );
3158 checkNonZeros( rs , 2UL );
3159 checkRows ( tmat_, 5UL );
3160 checkColumns ( tmat_, 4UL );
3161 checkNonZeros( tmat_, 11UL );
3162
3163 if( rs(0,0) != 0 || rs(0,1) != 0 || rs(0,2) != 0 || rs(0,3) != 1 ||
3164 rs(1,0) != 0 || rs(1,1) != 1 || rs(1,2) != 0 || rs(1,3) != 0 ) {
3165 std::ostringstream oss;
3166 oss << " Test: " << test_ << "\n"
3167 << " Error: Setting a non-zero element failed\n"
3168 << " Details:\n"
3169 << " Result:\n" << rs << "\n"
3170 << " Expected result:\n( 0 0 0 1 )\n( 0 1 0 0 )\n";
3171 throw std::runtime_error( oss.str() );
3172 }
3173
3174 // Setting a non-zero element at the beginning of the 0th row
3175 rs.set( 0UL, 0UL, 2 );
3176
3177 checkRows ( rs , 2UL );
3178 checkColumns ( rs , 4UL );
3179 checkNonZeros( rs , 3UL );
3180 checkRows ( tmat_, 5UL );
3181 checkColumns ( tmat_, 4UL );
3182 checkNonZeros( tmat_, 12UL );
3183
3184 if( rs(0,0) != 2 || rs(0,1) != 0 || rs(0,2) != 0 || rs(0,3) != 1 ||
3185 rs(1,0) != 0 || rs(1,1) != 1 || rs(1,2) != 0 || rs(1,3) != 0 ) {
3186 std::ostringstream oss;
3187 oss << " Test: " << test_ << "\n"
3188 << " Error: Setting a non-zero element failed\n"
3189 << " Details:\n"
3190 << " Result:\n" << rs << "\n"
3191 << " Expected result:\n( 2 0 0 1 )\n( 0 1 0 0 )\n";
3192 throw std::runtime_error( oss.str() );
3193 }
3194
3195 // Setting a non-zero element at the center of the 0th row
3196 rs.set( 0UL, 1UL, 3 );
3197
3198 checkRows ( rs , 2UL );
3199 checkColumns ( rs , 4UL );
3200 checkNonZeros( rs , 4UL );
3201 checkRows ( tmat_, 5UL );
3202 checkColumns ( tmat_, 4UL );
3203 checkNonZeros( tmat_, 13UL );
3204
3205 if( rs(0,0) != 2 || rs(0,1) != 3 || rs(0,2) != 0 || rs(0,3) != 1 ||
3206 rs(1,0) != 0 || rs(1,1) != 1 || rs(1,2) != 0 || rs(1,3) != 0 ) {
3207 std::ostringstream oss;
3208 oss << " Test: " << test_ << "\n"
3209 << " Error: Setting a non-zero element failed\n"
3210 << " Details:\n"
3211 << " Result:\n" << rs << "\n"
3212 << " Expected result:\n( 2 3 0 1 )\n( 0 1 0 0 )\n";
3213 throw std::runtime_error( oss.str() );
3214 }
3215
3216 // Setting an already existing element
3217 rs.set( 1UL, 1UL, 4 );
3218
3219 checkRows ( rs , 2UL );
3220 checkColumns ( rs , 4UL );
3221 checkNonZeros( rs , 4UL );
3222 checkRows ( tmat_, 5UL );
3223 checkColumns ( tmat_, 4UL );
3224 checkNonZeros( tmat_, 13UL );
3225
3226 if( rs(0,0) != 2 || rs(0,1) != 3 || rs(0,2) != 0 || rs(0,3) != 1 ||
3227 rs(1,0) != 0 || rs(1,1) != 4 || rs(1,2) != 0 || rs(1,3) != 0 ) {
3228 std::ostringstream oss;
3229 oss << " Test: " << test_ << "\n"
3230 << " Error: Setting a non-zero element failed\n"
3231 << " Details:\n"
3232 << " Result:\n" << rs << "\n"
3233 << " Expected result:\n( 2 3 0 1 )\n( 0 4 0 0 )\n";
3234 throw std::runtime_error( oss.str() );
3235 }
3236 }
3237 }
3238 //*************************************************************************************************
3239
3240
3241 //*************************************************************************************************
3242 /*!\brief Test of the \c insert() member function of the Rows class template.
3243 //
3244 // \return void
3245 // \exception std::runtime_error Error detected.
3246 //
3247 // This function performs a test of the \c insert() member function of the Rows specialization.
3248 // In case an error is detected, a \a std::runtime_error exception is thrown.
3249 */
testInsert()3250 void SparseGeneralTest::testInsert()
3251 {
3252 //=====================================================================================
3253 // Row-major matrix tests
3254 //=====================================================================================
3255
3256 {
3257 test_ = "Row-major Rows::insert()";
3258
3259 initialize();
3260
3261 auto rs = blaze::rows( mat_, { 0UL, 1UL } );
3262
3263 // Inserting a non-zero element at the end of the 0th row
3264 rs.insert( 0UL, 3UL, 1 );
3265
3266 checkRows ( rs , 2UL );
3267 checkColumns ( rs , 4UL );
3268 checkNonZeros( rs , 2UL );
3269 checkRows ( mat_, 5UL );
3270 checkColumns ( mat_, 4UL );
3271 checkNonZeros( mat_, 11UL );
3272
3273 if( rs(0,0) != 0 || rs(0,1) != 0 || rs(0,2) != 0 || rs(0,3) != 1 ||
3274 rs(1,0) != 0 || rs(1,1) != 1 || rs(1,2) != 0 || rs(1,3) != 0 ) {
3275 std::ostringstream oss;
3276 oss << " Test: " << test_ << "\n"
3277 << " Error: Inserting a non-zero element failed\n"
3278 << " Details:\n"
3279 << " Result:\n" << rs << "\n"
3280 << " Expected result:\n( 0 0 0 1 )\n( 0 1 0 0 )\n";
3281 throw std::runtime_error( oss.str() );
3282 }
3283
3284 // Inserting a non-zero element at the beginning of the 0th row
3285 rs.insert( 0UL, 0UL, 2 );
3286
3287 checkRows ( rs , 2UL );
3288 checkColumns ( rs , 4UL );
3289 checkNonZeros( rs , 3UL );
3290 checkRows ( mat_, 5UL );
3291 checkColumns ( mat_, 4UL );
3292 checkNonZeros( mat_, 12UL );
3293
3294 if( rs(0,0) != 2 || rs(0,1) != 0 || rs(0,2) != 0 || rs(0,3) != 1 ||
3295 rs(1,0) != 0 || rs(1,1) != 1 || rs(1,2) != 0 || rs(1,3) != 0 ) {
3296 std::ostringstream oss;
3297 oss << " Test: " << test_ << "\n"
3298 << " Error: Inserting a non-zero element failed\n"
3299 << " Details:\n"
3300 << " Result:\n" << rs << "\n"
3301 << " Expected result:\n( 2 0 0 1 )\n( 0 1 0 0 )\n";
3302 throw std::runtime_error( oss.str() );
3303 }
3304
3305 // Inserting a non-zero element at the center of the 0th row
3306 rs.insert( 0UL, 1UL, 3 );
3307
3308 checkRows ( rs , 2UL );
3309 checkColumns ( rs , 4UL );
3310 checkNonZeros( rs , 4UL );
3311 checkRows ( mat_, 5UL );
3312 checkColumns ( mat_, 4UL );
3313 checkNonZeros( mat_, 13UL );
3314
3315 if( rs(0,0) != 2 || rs(0,1) != 3 || rs(0,2) != 0 || rs(0,3) != 1 ||
3316 rs(1,0) != 0 || rs(1,1) != 1 || rs(1,2) != 0 || rs(1,3) != 0 ) {
3317 std::ostringstream oss;
3318 oss << " Test: " << test_ << "\n"
3319 << " Error: Inserting a non-zero element failed\n"
3320 << " Details:\n"
3321 << " Result:\n" << rs << "\n"
3322 << " Expected result:\n( 2 3 0 1 )\n( 0 1 0 0 )\n";
3323 throw std::runtime_error( oss.str() );
3324 }
3325
3326 // Trying to insert an already existing element
3327 try {
3328 rs.insert( 1UL, 1UL, 4 );
3329
3330 std::ostringstream oss;
3331 oss << " Test: " << test_ << "\n"
3332 << " Error: Inserting an existing element succeeded\n"
3333 << " Details:\n"
3334 << " Result:\n" << rs << "\n"
3335 << " Expected result:\n( 2 3 0 1 )\n( 0 1 0 0 )\n";
3336 throw std::runtime_error( oss.str() );
3337 }
3338 catch( std::invalid_argument& ) {}
3339 }
3340
3341
3342 //=====================================================================================
3343 // Column-major matrix tests
3344 //=====================================================================================
3345
3346 {
3347 test_ = "Column-major Rows::insert()";
3348
3349 initialize();
3350
3351 auto rs = blaze::rows( tmat_, { 0UL, 1UL } );
3352
3353 // Inserting a non-zero element at the end of the 0th row
3354 rs.insert( 0UL, 3UL, 1 );
3355
3356 checkRows ( rs , 2UL );
3357 checkColumns ( rs , 4UL );
3358 checkNonZeros( rs , 2UL );
3359 checkRows ( tmat_, 5UL );
3360 checkColumns ( tmat_, 4UL );
3361 checkNonZeros( tmat_, 11UL );
3362
3363 if( rs(0,0) != 0 || rs(0,1) != 0 || rs(0,2) != 0 || rs(0,3) != 1 ||
3364 rs(1,0) != 0 || rs(1,1) != 1 || rs(1,2) != 0 || rs(1,3) != 0 ) {
3365 std::ostringstream oss;
3366 oss << " Test: " << test_ << "\n"
3367 << " Error: Inserting a non-zero element failed\n"
3368 << " Details:\n"
3369 << " Result:\n" << rs << "\n"
3370 << " Expected result:\n( 0 0 0 1 )\n( 0 1 0 0 )\n";
3371 throw std::runtime_error( oss.str() );
3372 }
3373
3374 // Inserting a non-zero element at the beginning of the 0th row
3375 rs.insert( 0UL, 0UL, 2 );
3376
3377 checkRows ( rs , 2UL );
3378 checkColumns ( rs , 4UL );
3379 checkNonZeros( rs , 3UL );
3380 checkRows ( tmat_, 5UL );
3381 checkColumns ( tmat_, 4UL );
3382 checkNonZeros( tmat_, 12UL );
3383
3384 if( rs(0,0) != 2 || rs(0,1) != 0 || rs(0,2) != 0 || rs(0,3) != 1 ||
3385 rs(1,0) != 0 || rs(1,1) != 1 || rs(1,2) != 0 || rs(1,3) != 0 ) {
3386 std::ostringstream oss;
3387 oss << " Test: " << test_ << "\n"
3388 << " Error: Inserting a non-zero element failed\n"
3389 << " Details:\n"
3390 << " Result:\n" << rs << "\n"
3391 << " Expected result:\n( 2 0 0 1 )\n( 0 1 0 0 )\n";
3392 throw std::runtime_error( oss.str() );
3393 }
3394
3395 // Inserting a non-zero element at the center of the 0th row
3396 rs.insert( 0UL, 1UL, 3 );
3397
3398 checkRows ( rs , 2UL );
3399 checkColumns ( rs , 4UL );
3400 checkNonZeros( rs , 4UL );
3401 checkRows ( tmat_, 5UL );
3402 checkColumns ( tmat_, 4UL );
3403 checkNonZeros( tmat_, 13UL );
3404
3405 if( rs(0,0) != 2 || rs(0,1) != 3 || rs(0,2) != 0 || rs(0,3) != 1 ||
3406 rs(1,0) != 0 || rs(1,1) != 1 || rs(1,2) != 0 || rs(1,3) != 0 ) {
3407 std::ostringstream oss;
3408 oss << " Test: " << test_ << "\n"
3409 << " Error: Inserting a non-zero element failed\n"
3410 << " Details:\n"
3411 << " Result:\n" << rs << "\n"
3412 << " Expected result:\n( 2 3 0 1 )\n( 0 1 0 0 )\n";
3413 throw std::runtime_error( oss.str() );
3414 }
3415
3416 // Trying to insert an already existing element
3417 try {
3418 rs.insert( 1UL, 1UL, 4 );
3419
3420 std::ostringstream oss;
3421 oss << " Test: " << test_ << "\n"
3422 << " Error: Inserting an existing element succeeded\n"
3423 << " Details:\n"
3424 << " Result:\n" << rs << "\n"
3425 << " Expected result:\n( 2 3 0 1 )\n( 0 1 0 0 )\n";
3426 throw std::runtime_error( oss.str() );
3427 }
3428 catch( std::invalid_argument& ) {}
3429 }
3430 }
3431 //*************************************************************************************************
3432
3433
3434 //*************************************************************************************************
3435 /*!\brief Test of the \c append() member function of the Rows class template.
3436 //
3437 // \return void
3438 // \exception std::runtime_error Error detected.
3439 //
3440 // This function performs a test of the \c append() member function of the Rows specialization.
3441 // In case an error is detected, a \a std::runtime_error exception is thrown.
3442 */
testAppend()3443 void SparseGeneralTest::testAppend()
3444 {
3445 //=====================================================================================
3446 // Row-major matrix tests
3447 //=====================================================================================
3448
3449 {
3450 test_ = "Row-major Rows::append()";
3451
3452 // Appending with pre-allocation in each row
3453 {
3454 mat_.reset();
3455
3456 // Initialization check
3457 auto rs = blaze::rows( mat_, { 3UL, 2UL, 1UL, 0UL } );
3458 rs.reserve( 0UL, 2UL );
3459 rs.reserve( 2UL, 1UL );
3460 rs.reserve( 3UL, 2UL );
3461
3462 checkRows ( rs, 4UL );
3463 checkColumns ( rs, 4UL );
3464 checkCapacity( rs, 5UL );
3465 checkNonZeros( rs, 0UL );
3466 checkNonZeros( rs, 0UL, 0UL );
3467 checkNonZeros( rs, 1UL, 0UL );
3468 checkNonZeros( rs, 2UL, 0UL );
3469 checkNonZeros( rs, 3UL, 0UL );
3470
3471 // Appending one non-zero element
3472 rs.append( 2UL, 1UL, 1 );
3473
3474 checkRows ( rs, 4UL );
3475 checkColumns ( rs, 4UL );
3476 checkCapacity( rs, 5UL );
3477 checkNonZeros( rs, 1UL );
3478 checkNonZeros( rs, 0UL, 0UL );
3479 checkNonZeros( rs, 1UL, 0UL );
3480 checkNonZeros( rs, 2UL, 1UL );
3481 checkNonZeros( rs, 3UL, 0UL );
3482
3483 if( rs(2,1) != 1 ) {
3484 std::ostringstream oss;
3485 oss << " Test: " << test_ << "\n"
3486 << " Error: Append operation failed\n"
3487 << " Details:\n"
3488 << " Result:\n" << rs << "\n"
3489 << " Expected result:\n( 0 0 0 0 )\n( 0 0 0 0 )\n( 0 1 0 0 )\n( 0 0 0 0 )\n";
3490 throw std::runtime_error( oss.str() );
3491 }
3492
3493 // Appending two more non-zero elements
3494 rs.append( 0UL, 0UL, 2 );
3495 rs.append( 0UL, 3UL, 3 );
3496
3497 checkRows ( rs, 4UL );
3498 checkColumns ( rs, 4UL );
3499 checkCapacity( rs, 5UL );
3500 checkNonZeros( rs, 3UL );
3501 checkNonZeros( rs, 0UL, 2UL );
3502 checkNonZeros( rs, 1UL, 0UL );
3503 checkNonZeros( rs, 2UL, 1UL );
3504 checkNonZeros( rs, 3UL, 0UL );
3505
3506 if( rs(2,1) != 1 || rs(0,0) != 2 || rs(0,3) != 3 ) {
3507 std::ostringstream oss;
3508 oss << " Test: " << test_ << "\n"
3509 << " Error: Append operation failed\n"
3510 << " Details:\n"
3511 << " Result:\n" << rs << "\n"
3512 << " Expected result:\n( 2 0 0 3 )\n( 0 0 0 0 )\n( 0 1 0 0 )\n( 0 0 0 0 )\n";
3513 throw std::runtime_error( oss.str() );
3514 }
3515
3516 // Appending two more non-zero elements
3517 rs.append( 3UL, 1UL, 4 );
3518 rs.append( 3UL, 2UL, 5 );
3519
3520 checkRows ( rs, 4UL );
3521 checkColumns ( rs, 4UL );
3522 checkCapacity( rs, 5UL );
3523 checkNonZeros( rs, 5UL );
3524 checkNonZeros( rs, 0UL, 2UL );
3525 checkNonZeros( rs, 1UL, 0UL );
3526 checkNonZeros( rs, 2UL, 1UL );
3527 checkNonZeros( rs, 3UL, 2UL );
3528
3529 if( rs(2,1) != 1 || rs(0,0) != 2 || rs(0,3) != 3 ||
3530 rs(3,1) != 4 || rs(3,2) != 5 ) {
3531 std::ostringstream oss;
3532 oss << " Test: " << test_ << "\n"
3533 << " Error: Append operation failed\n"
3534 << " Details:\n"
3535 << " Result:\n" << rs << "\n"
3536 << " Expected result:\n( 2 0 0 3 )\n( 0 0 0 0 )\n( 0 1 0 0 )\n( 0 4 5 0 )\n";
3537 throw std::runtime_error( oss.str() );
3538 }
3539 }
3540
3541 // Appending with row finalization
3542 {
3543 mat_.reset();
3544
3545 // Initialization check
3546 auto rs = blaze::rows( mat_, { 3UL, 2UL, 1UL, 0UL } );
3547 rs.reserve( 0UL, 2UL );
3548 rs.reserve( 2UL, 1UL );
3549 rs.reserve( 3UL, 2UL );
3550
3551 // Appending one non-zero element
3552 rs.append( 0UL, 1UL, 1 );
3553 rs.finalize( 0UL );
3554
3555 checkRows ( rs, 4UL );
3556 checkColumns ( rs, 4UL );
3557 checkCapacity( rs, 5UL );
3558 checkNonZeros( rs, 1UL );
3559 checkNonZeros( rs, 0UL, 1UL );
3560 checkNonZeros( rs, 1UL, 0UL );
3561 checkNonZeros( rs, 2UL, 0UL );
3562 checkNonZeros( rs, 3UL, 0UL );
3563
3564 if( rs(0,1) != 1 ) {
3565 std::ostringstream oss;
3566 oss << " Test: " << test_ << "\n"
3567 << " Error: Append operation failed\n"
3568 << " Details:\n"
3569 << " Result:\n" << rs << "\n"
3570 << " Expected result:\n( 0 1 0 0 )\n( 0 0 0 0 )\n( 0 0 0 0 )\n( 0 0 0 0 )\n";
3571 throw std::runtime_error( oss.str() );
3572 }
3573
3574 // Appending two more non-zero elements
3575 rs.append( 1UL, 1UL, 2 );
3576 rs.append( 1UL, 3UL, 3 );
3577 rs.finalize( 1UL );
3578
3579 checkRows ( rs, 4UL );
3580 checkColumns ( rs, 4UL );
3581 checkCapacity( rs, 5UL );
3582 checkNonZeros( rs, 3UL );
3583 checkNonZeros( rs, 0UL, 1UL );
3584 checkNonZeros( rs, 1UL, 2UL );
3585 checkNonZeros( rs, 2UL, 0UL );
3586 checkNonZeros( rs, 3UL, 0UL );
3587
3588 if( rs(0,1) != 1 || rs(1,1) != 2 || rs(1,3) != 3 ) {
3589 std::ostringstream oss;
3590 oss << " Test: " << test_ << "\n"
3591 << " Error: Append operation failed\n"
3592 << " Details:\n"
3593 << " Result:\n" << rs << "\n"
3594 << " Expected result:\n( 0 1 0 0 )\n( 0 2 0 3 )\n( 0 0 0 0 )\n( 0 0 0 0 )\n";
3595 throw std::runtime_error( oss.str() );
3596 }
3597
3598 // Appending two more non-zero elements
3599 rs.finalize( 2UL );
3600 rs.append( 3UL, 0UL, 4 );
3601 rs.append( 3UL, 1UL, 5 );
3602 rs.finalize( 3UL );
3603
3604 checkRows ( rs, 4UL );
3605 checkColumns ( rs, 4UL );
3606 checkCapacity( rs, 5UL );
3607 checkNonZeros( rs, 5UL );
3608 checkNonZeros( rs, 0UL, 1UL );
3609 checkNonZeros( rs, 1UL, 2UL );
3610 checkNonZeros( rs, 2UL, 0UL );
3611 checkNonZeros( rs, 3UL, 2UL );
3612
3613 if( rs(0,1) != 1 || rs(1,1) != 2 || rs(1,3) != 3 ||
3614 rs(3,0) != 4 || rs(3,1) != 5 ) {
3615 std::ostringstream oss;
3616 oss << " Test: " << test_ << "\n"
3617 << " Error: Append operation failed\n"
3618 << " Details:\n"
3619 << " Result:\n" << rs << "\n"
3620 << " Expected result:\n( 0 1 0 0 )\n( 0 2 0 3 )\n( 0 0 0 0 )\n( 4 5 0 0 )\n";
3621 throw std::runtime_error( oss.str() );
3622 }
3623 }
3624 }
3625
3626
3627 //=====================================================================================
3628 // Column-major matrix tests
3629 //=====================================================================================
3630
3631 {
3632 test_ = "Column-major Rows::append()";
3633
3634 // Appending with pre-allocation in each row
3635 {
3636 tmat_.reset();
3637
3638 // Initialization check
3639 auto rs = blaze::rows( tmat_, { 3UL, 2UL, 1UL, 0UL } );
3640 rs.reserve( 0UL, 2UL );
3641 rs.reserve( 2UL, 1UL );
3642 rs.reserve( 3UL, 2UL );
3643
3644 checkRows ( rs, 4UL );
3645 checkColumns ( rs, 4UL );
3646 checkCapacity( rs, 5UL );
3647 checkNonZeros( rs, 0UL );
3648 checkNonZeros( rs, 0UL, 0UL );
3649 checkNonZeros( rs, 1UL, 0UL );
3650 checkNonZeros( rs, 2UL, 0UL );
3651 checkNonZeros( rs, 3UL, 0UL );
3652
3653 // Appending one non-zero element
3654 rs.append( 2UL, 1UL, 1 );
3655
3656 checkRows ( rs, 4UL );
3657 checkColumns ( rs, 4UL );
3658 checkCapacity( rs, 5UL );
3659 checkNonZeros( rs, 1UL );
3660 checkNonZeros( rs, 0UL, 0UL );
3661 checkNonZeros( rs, 1UL, 0UL );
3662 checkNonZeros( rs, 2UL, 1UL );
3663 checkNonZeros( rs, 3UL, 0UL );
3664
3665 if( rs(2,1) != 1 ) {
3666 std::ostringstream oss;
3667 oss << " Test: " << test_ << "\n"
3668 << " Error: Append operation failed\n"
3669 << " Details:\n"
3670 << " Result:\n" << rs << "\n"
3671 << " Expected result:\n( 0 0 0 0 )\n( 0 0 0 0 )\n( 0 1 0 0 )\n( 0 0 0 0 )\n";
3672 throw std::runtime_error( oss.str() );
3673 }
3674
3675 // Appending two more non-zero elements
3676 rs.append( 0UL, 0UL, 2 );
3677 rs.append( 0UL, 3UL, 3 );
3678
3679 checkRows ( rs, 4UL );
3680 checkColumns ( rs, 4UL );
3681 checkCapacity( rs, 5UL );
3682 checkNonZeros( rs, 3UL );
3683 checkNonZeros( rs, 0UL, 2UL );
3684 checkNonZeros( rs, 1UL, 0UL );
3685 checkNonZeros( rs, 2UL, 1UL );
3686 checkNonZeros( rs, 3UL, 0UL );
3687
3688 if( rs(2,1) != 1 || rs(0,0) != 2 || rs(0,3) != 3 ) {
3689 std::ostringstream oss;
3690 oss << " Test: " << test_ << "\n"
3691 << " Error: Append operation failed\n"
3692 << " Details:\n"
3693 << " Result:\n" << rs << "\n"
3694 << " Expected result:\n( 2 0 0 3 )\n( 0 0 0 0 )\n( 0 1 0 0 )\n( 0 0 0 0 )\n";
3695 throw std::runtime_error( oss.str() );
3696 }
3697
3698 // Appending two more non-zero elements
3699 rs.append( 3UL, 1UL, 4 );
3700 rs.append( 3UL, 2UL, 5 );
3701
3702 checkRows ( rs, 4UL );
3703 checkColumns ( rs, 4UL );
3704 checkCapacity( rs, 5UL );
3705 checkNonZeros( rs, 5UL );
3706 checkNonZeros( rs, 0UL, 2UL );
3707 checkNonZeros( rs, 1UL, 0UL );
3708 checkNonZeros( rs, 2UL, 1UL );
3709 checkNonZeros( rs, 3UL, 2UL );
3710
3711 if( rs(2,1) != 1 || rs(0,0) != 2 || rs(0,3) != 3 ||
3712 rs(3,1) != 4 || rs(3,2) != 5 ) {
3713 std::ostringstream oss;
3714 oss << " Test: " << test_ << "\n"
3715 << " Error: Append operation failed\n"
3716 << " Details:\n"
3717 << " Result:\n" << rs << "\n"
3718 << " Expected result:\n( 2 0 0 3 )\n( 0 0 0 0 )\n( 0 1 0 0 )\n( 0 4 5 0 )\n";
3719 throw std::runtime_error( oss.str() );
3720 }
3721 }
3722
3723 // Appending with row finalization
3724 {
3725 tmat_.reset();
3726
3727 // Initialization check
3728 auto rs = blaze::rows( tmat_, { 3UL, 2UL, 1UL, 0UL } );
3729 rs.reserve( 0UL, 2UL );
3730 rs.reserve( 2UL, 1UL );
3731 rs.reserve( 3UL, 2UL );
3732
3733 // Appending one non-zero element
3734 rs.append( 0UL, 1UL, 1 );
3735 rs.finalize( 0UL );
3736
3737 checkRows ( rs, 4UL );
3738 checkColumns ( rs, 4UL );
3739 checkCapacity( rs, 5UL );
3740 checkNonZeros( rs, 1UL );
3741 checkNonZeros( rs, 0UL, 1UL );
3742 checkNonZeros( rs, 1UL, 0UL );
3743 checkNonZeros( rs, 2UL, 0UL );
3744 checkNonZeros( rs, 3UL, 0UL );
3745
3746 if( rs(0,1) != 1 ) {
3747 std::ostringstream oss;
3748 oss << " Test: " << test_ << "\n"
3749 << " Error: Append operation failed\n"
3750 << " Details:\n"
3751 << " Result:\n" << rs << "\n"
3752 << " Expected result:\n( 0 1 0 0 )\n( 0 0 0 0 )\n( 0 0 0 0 )\n( 0 0 0 0 )\n";
3753 throw std::runtime_error( oss.str() );
3754 }
3755
3756 // Appending two more non-zero elements
3757 rs.append( 1UL, 1UL, 2 );
3758 rs.append( 1UL, 3UL, 3 );
3759 rs.finalize( 1UL );
3760
3761 checkRows ( rs, 4UL );
3762 checkColumns ( rs, 4UL );
3763 checkCapacity( rs, 5UL );
3764 checkNonZeros( rs, 3UL );
3765 checkNonZeros( rs, 0UL, 1UL );
3766 checkNonZeros( rs, 1UL, 2UL );
3767 checkNonZeros( rs, 2UL, 0UL );
3768 checkNonZeros( rs, 3UL, 0UL );
3769
3770 if( rs(0,1) != 1 || rs(1,1) != 2 || rs(1,3) != 3 ) {
3771 std::ostringstream oss;
3772 oss << " Test: " << test_ << "\n"
3773 << " Error: Append operation failed\n"
3774 << " Details:\n"
3775 << " Result:\n" << rs << "\n"
3776 << " Expected result:\n( 0 1 0 0 )\n( 0 2 0 3 )\n( 0 0 0 0 )\n( 0 0 0 0 )\n";
3777 throw std::runtime_error( oss.str() );
3778 }
3779
3780 // Appending two more non-zero elements
3781 rs.finalize( 2UL );
3782 rs.append( 3UL, 0UL, 4 );
3783 rs.append( 3UL, 1UL, 5 );
3784 rs.finalize( 3UL );
3785
3786 checkRows ( rs, 4UL );
3787 checkColumns ( rs, 4UL );
3788 checkCapacity( rs, 5UL );
3789 checkNonZeros( rs, 5UL );
3790 checkNonZeros( rs, 0UL, 1UL );
3791 checkNonZeros( rs, 1UL, 2UL );
3792 checkNonZeros( rs, 2UL, 0UL );
3793 checkNonZeros( rs, 3UL, 2UL );
3794
3795 if( rs(0,1) != 1 || rs(1,1) != 2 || rs(1,3) != 3 ||
3796 rs(3,0) != 4 || rs(3,1) != 5 ) {
3797 std::ostringstream oss;
3798 oss << " Test: " << test_ << "\n"
3799 << " Error: Append operation failed\n"
3800 << " Details:\n"
3801 << " Result:\n" << rs << "\n"
3802 << " Expected result:\n( 0 1 0 0 )\n( 0 2 0 3 )\n( 0 0 0 0 )\n( 4 5 0 0 )\n";
3803 throw std::runtime_error( oss.str() );
3804 }
3805 }
3806 }
3807 }
3808 //*************************************************************************************************
3809
3810
3811 //*************************************************************************************************
3812 /*!\brief Test of the \c erase() member function of the Rows class template.
3813 //
3814 // \return void
3815 // \exception std::runtime_error Error detected.
3816 //
3817 // This function performs a test of the \c erase() member function of the Rows specialization.
3818 // In case an error is detected, a \a std::runtime_error exception is thrown.
3819 */
testErase()3820 void SparseGeneralTest::testErase()
3821 {
3822 //=====================================================================================
3823 // Row-major index-based erase function
3824 //=====================================================================================
3825
3826 {
3827 test_ = "Row-major Rows::erase( size_t, size_t )";
3828
3829 initialize();
3830
3831 auto rs = blaze::rows( mat_, { 3UL, 4UL } );
3832
3833 // Erasing the non-zero element at the end of the 1st row
3834 rs.erase( 1UL, 3UL );
3835
3836 checkRows ( rs , 2UL );
3837 checkColumns ( rs , 4UL );
3838 checkNonZeros( rs , 6UL );
3839 checkRows ( mat_, 5UL );
3840 checkColumns ( mat_, 4UL );
3841 checkNonZeros( mat_, 9UL );
3842
3843 if( rs(0,0) != 0 || rs(0,1) != 4 || rs(0,2) != 5 || rs(0,3) != -6 ||
3844 rs(1,0) != 7 || rs(1,1) != -8 || rs(1,2) != 9 || rs(1,3) != 0 ) {
3845 std::ostringstream oss;
3846 oss << " Test: " << test_ << "\n"
3847 << " Error: Erasing a non-zero element failed\n"
3848 << " Details:\n"
3849 << " Result:\n" << rs << "\n"
3850 << " Expected result:\n( 0 4 5 -6 )\n( 7 -8 9 0 )\n";
3851 throw std::runtime_error( oss.str() );
3852 }
3853
3854 // Erasing the non-zero element at the beginning of the 1st row
3855 rs.erase( 1UL, size_t(0) );
3856
3857 checkRows ( rs , 2UL );
3858 checkColumns ( rs , 4UL );
3859 checkNonZeros( rs , 5UL );
3860 checkRows ( mat_, 5UL );
3861 checkColumns ( mat_, 4UL );
3862 checkNonZeros( mat_, 8UL );
3863
3864 if( rs(0,0) != 0 || rs(0,1) != 4 || rs(0,2) != 5 || rs(0,3) != -6 ||
3865 rs(1,0) != 0 || rs(1,1) != -8 || rs(1,2) != 9 || rs(1,3) != 0 ) {
3866 std::ostringstream oss;
3867 oss << " Test: " << test_ << "\n"
3868 << " Error: Erasing a non-zero element failed\n"
3869 << " Details:\n"
3870 << " Result:\n" << rs << "\n"
3871 << " Expected result:\n( 0 4 5 -6 )\n( 0 -8 9 0 )\n";
3872 throw std::runtime_error( oss.str() );
3873 }
3874
3875 // Erasing the non-zero element at the beginning of the 1st row
3876 rs.erase( 1UL, 1UL );
3877
3878 checkRows ( rs , 2UL );
3879 checkColumns ( rs , 4UL );
3880 checkNonZeros( rs , 4UL );
3881 checkRows ( mat_, 5UL );
3882 checkColumns ( mat_, 4UL );
3883 checkNonZeros( mat_, 7UL );
3884
3885 if( rs(0,0) != 0 || rs(0,1) != 4 || rs(0,2) != 5 || rs(0,3) != -6 ||
3886 rs(1,0) != 0 || rs(1,1) != 0 || rs(1,2) != 9 || rs(1,3) != 0 ) {
3887 std::ostringstream oss;
3888 oss << " Test: " << test_ << "\n"
3889 << " Error: Erasing a non-zero element failed\n"
3890 << " Details:\n"
3891 << " Result:\n" << rs << "\n"
3892 << " Expected result:\n( 0 4 5 -6 )\n( 0 0 9 0 )\n";
3893 throw std::runtime_error( oss.str() );
3894 }
3895
3896 // Trying to erase an already erased element
3897 rs.erase( 1UL, 3UL );
3898
3899 checkRows ( rs , 2UL );
3900 checkColumns ( rs , 4UL );
3901 checkNonZeros( rs , 4UL );
3902 checkRows ( mat_, 5UL );
3903 checkColumns ( mat_, 4UL );
3904 checkNonZeros( mat_, 7UL );
3905
3906 if( rs(0,0) != 0 || rs(0,1) != 4 || rs(0,2) != 5 || rs(0,3) != -6 ||
3907 rs(1,0) != 0 || rs(1,1) != 0 || rs(1,2) != 9 || rs(1,3) != 0 ) {
3908 std::ostringstream oss;
3909 oss << " Test: " << test_ << "\n"
3910 << " Error: Erasing a non-zero element failed\n"
3911 << " Details:\n"
3912 << " Result:\n" << rs << "\n"
3913 << " Expected result:\n( 0 4 5 -6 )\n( 0 0 9 0 )\n";
3914 throw std::runtime_error( oss.str() );
3915 }
3916 }
3917
3918
3919 //=====================================================================================
3920 // Row-major iterator-based erase function
3921 //=====================================================================================
3922
3923 {
3924 test_ = "Row-major Rows::erase( size_t, Iterator )";
3925
3926 initialize();
3927
3928 auto rs = blaze::rows( mat_, { 3UL, 4UL } );
3929
3930 // Erasing the non-zero element at the end of the 1st row
3931 {
3932 auto pos = rs.erase( 1UL, rs.find( 1UL, 3UL ) );
3933
3934 checkRows ( rs , 2UL );
3935 checkColumns ( rs , 4UL );
3936 checkNonZeros( rs , 6UL );
3937 checkRows ( mat_, 5UL );
3938 checkColumns ( mat_, 4UL );
3939 checkNonZeros( mat_, 9UL );
3940
3941 if( pos != rs.end( 1UL ) ) {
3942 std::ostringstream oss;
3943 oss << " Test: " << test_ << "\n"
3944 << " Error: Invalid iterator returned\n"
3945 << " Details:\n"
3946 << " Expected result: the end() iterator\n";
3947 throw std::runtime_error( oss.str() );
3948 }
3949
3950 if( rs(0,0) != 0 || rs(0,1) != 4 || rs(0,2) != 5 || rs(0,3) != -6 ||
3951 rs(1,0) != 7 || rs(1,1) != -8 || rs(1,2) != 9 || rs(1,3) != 0 ) {
3952 std::ostringstream oss;
3953 oss << " Test: " << test_ << "\n"
3954 << " Error: Erasing a non-zero element failed\n"
3955 << " Details:\n"
3956 << " Result:\n" << rs << "\n"
3957 << " Expected result:\n( 0 4 5 -6 )\n( 7 -8 9 0 )\n";
3958 throw std::runtime_error( oss.str() );
3959 }
3960 }
3961
3962 // Erasing the non-zero element at the beginning of the 1st row
3963 {
3964 auto pos = rs.erase( 1UL, rs.find( 1UL, 0UL ) );
3965
3966 checkRows ( rs , 2UL );
3967 checkColumns ( rs , 4UL );
3968 checkNonZeros( rs , 5UL );
3969 checkRows ( mat_, 5UL );
3970 checkColumns ( mat_, 4UL );
3971 checkNonZeros( mat_, 8UL );
3972
3973 if( pos->value() != -8 || pos->index() != 1 ) {
3974 std::ostringstream oss;
3975 oss << " Test: " << test_ << "\n"
3976 << " Error: Invalid iterator returned\n"
3977 << " Details:\n"
3978 << " Value: " << pos->value() << "\n"
3979 << " Index: " << pos->index() << "\n"
3980 << " Expected value: -8\n"
3981 << " Expected index: 1\n";
3982 throw std::runtime_error( oss.str() );
3983 }
3984
3985 if( rs(0,0) != 0 || rs(0,1) != 4 || rs(0,2) != 5 || rs(0,3) != -6 ||
3986 rs(1,0) != 0 || rs(1,1) != -8 || rs(1,2) != 9 || rs(1,3) != 0 ) {
3987 std::ostringstream oss;
3988 oss << " Test: " << test_ << "\n"
3989 << " Error: Erasing a non-zero element failed\n"
3990 << " Details:\n"
3991 << " Result:\n" << rs << "\n"
3992 << " Expected result:\n( 0 4 5 -6 )\n( 0 -8 9 0 )\n";
3993 throw std::runtime_error( oss.str() );
3994 }
3995 }
3996
3997 // Erasing the non-zero element at the beginning of the 1st row
3998 {
3999 auto pos = rs.erase( 1UL, rs.find( 1UL, 1UL ) );
4000
4001 checkRows ( rs , 2UL );
4002 checkColumns ( rs , 4UL );
4003 checkNonZeros( rs , 4UL );
4004 checkRows ( mat_, 5UL );
4005 checkColumns ( mat_, 4UL );
4006 checkNonZeros( mat_, 7UL );
4007
4008 if( pos->value() != 9 || pos->index() != 2 ) {
4009 std::ostringstream oss;
4010 oss << " Test: " << test_ << "\n"
4011 << " Error: Invalid iterator returned\n"
4012 << " Details:\n"
4013 << " Value: " << pos->value() << "\n"
4014 << " Index: " << pos->index() << "\n"
4015 << " Expected value: 9\n"
4016 << " Expected index: 2\n";
4017 throw std::runtime_error( oss.str() );
4018 }
4019
4020 if( rs(0,0) != 0 || rs(0,1) != 4 || rs(0,2) != 5 || rs(0,3) != -6 ||
4021 rs(1,0) != 0 || rs(1,1) != 0 || rs(1,2) != 9 || rs(1,3) != 0 ) {
4022 std::ostringstream oss;
4023 oss << " Test: " << test_ << "\n"
4024 << " Error: Erasing a non-zero element failed\n"
4025 << " Details:\n"
4026 << " Result:\n" << rs << "\n"
4027 << " Expected result:\n( 0 4 5 -6 )\n( 0 -8 9 0 )\n";
4028 throw std::runtime_error( oss.str() );
4029 }
4030 }
4031
4032 // Trying to erase an already erased element
4033 {
4034 auto pos = rs.erase( 1UL, rs.find( 1UL, 3UL ) );
4035
4036 checkRows ( rs , 2UL );
4037 checkColumns ( rs , 4UL );
4038 checkNonZeros( rs , 4UL );
4039 checkRows ( mat_, 5UL );
4040 checkColumns ( mat_, 4UL );
4041 checkNonZeros( mat_, 7UL );
4042
4043 if( pos != rs.end( 1UL ) ) {
4044 std::ostringstream oss;
4045 oss << " Test: " << test_ << "\n"
4046 << " Error: Invalid iterator returned\n"
4047 << " Details:\n"
4048 << " Expected result: the end() iterator\n";
4049 throw std::runtime_error( oss.str() );
4050 }
4051
4052 if( rs(0,0) != 0 || rs(0,1) != 4 || rs(0,2) != 5 || rs(0,3) != -6 ||
4053 rs(1,0) != 0 || rs(1,1) != 0 || rs(1,2) != 9 || rs(1,3) != 0 ) {
4054 std::ostringstream oss;
4055 oss << " Test: " << test_ << "\n"
4056 << " Error: Erasing a zero element failed\n"
4057 << " Details:\n"
4058 << " Result:\n" << rs << "\n"
4059 << " Expected result:\n( 0 4 5 -6 )\n( 0 -8 9 0 )\n";
4060 throw std::runtime_error( oss.str() );
4061 }
4062 }
4063 }
4064
4065
4066 //=====================================================================================
4067 // Row-major iterator-range-based erase function
4068 //=====================================================================================
4069
4070 {
4071 test_ = "Row-major Rows::erase( size_t, Iterator, Iterator )";
4072
4073 initialize();
4074
4075 auto rs = blaze::rows( mat_, { 3UL, 4UL } );
4076
4077 // Erasing the 0th row
4078 {
4079 auto pos = rs.erase( 0UL, rs.begin( 0UL ), rs.end( 0UL ) );
4080
4081 checkRows ( rs , 2UL );
4082 checkColumns ( rs , 4UL );
4083 checkNonZeros( rs , 4UL );
4084 checkRows ( mat_, 5UL );
4085 checkColumns ( mat_, 4UL );
4086 checkNonZeros( mat_, 7UL );
4087
4088 if( pos != rs.end( 0UL ) ) {
4089 std::ostringstream oss;
4090 oss << " Test: " << test_ << "\n"
4091 << " Error: Invalid iterator returned\n"
4092 << " Details:\n"
4093 << " Expected result: the end() iterator\n";
4094 throw std::runtime_error( oss.str() );
4095 }
4096
4097 if( rs(0,0) != 0 || rs(0,1) != 0 || rs(0,2) != 0 || rs(0,3) != 0 ||
4098 rs(1,0) != 7 || rs(1,1) != -8 || rs(1,2) != 9 || rs(1,3) != 10 ) {
4099 std::ostringstream oss;
4100 oss << " Test: " << test_ << "\n"
4101 << " Error: Erasing the 0th row failed\n"
4102 << " Details:\n"
4103 << " Result:\n" << rs << "\n"
4104 << " Expected result:\n( 0 0 0 0 )\n( 7 -8 9 10 )\n";
4105 throw std::runtime_error( oss.str() );
4106 }
4107 }
4108
4109 // Erasing the first half of the 1st row
4110 {
4111 auto pos = rs.erase( 1UL, rs.begin( 1UL ), rs.find( 1UL, 2UL ) );
4112
4113 checkRows ( rs , 2UL );
4114 checkColumns ( rs , 4UL );
4115 checkNonZeros( rs , 2UL );
4116 checkRows ( mat_, 5UL );
4117 checkColumns ( mat_, 4UL );
4118 checkNonZeros( mat_, 5UL );
4119
4120 if( pos->value() != 9 || pos->index() != 2 ) {
4121 std::ostringstream oss;
4122 oss << " Test: " << test_ << "\n"
4123 << " Error: Invalid iterator returned\n"
4124 << " Details:\n"
4125 << " Value: " << pos->value() << "\n"
4126 << " Index: " << pos->index() << "\n"
4127 << " Expected value: 9\n"
4128 << " Expected index: 2\n";
4129 throw std::runtime_error( oss.str() );
4130 }
4131
4132 if( rs(0,0) != 0 || rs(0,1) != 0 || rs(0,2) != 0 || rs(0,3) != 0 ||
4133 rs(1,0) != 0 || rs(1,1) != 0 || rs(1,2) != 9 || rs(1,3) != 10 ) {
4134 std::ostringstream oss;
4135 oss << " Test: " << test_ << "\n"
4136 << " Error: Erasing the first half of the 1st row failed\n"
4137 << " Details:\n"
4138 << " Result:\n" << rs << "\n"
4139 << " Expected result:\n( 0 0 0 0 )\n( 0 0 9 10 )\n";
4140 throw std::runtime_error( oss.str() );
4141 }
4142 }
4143
4144 // Erasing the second half of the 1st row
4145 {
4146 auto pos = rs.erase( 1UL, rs.find( 1UL, 2UL ), rs.end( 1UL ) );
4147
4148 checkRows ( rs , 2UL );
4149 checkColumns ( rs , 4UL );
4150 checkNonZeros( rs , 0UL );
4151 checkRows ( mat_, 5UL );
4152 checkColumns ( mat_, 4UL );
4153 checkNonZeros( mat_, 3UL );
4154
4155 if( pos != rs.end( 1UL ) ) {
4156 std::ostringstream oss;
4157 oss << " Test: " << test_ << "\n"
4158 << " Error: Invalid iterator returned\n"
4159 << " Details:\n"
4160 << " Expected result: the end() iterator\n";
4161 throw std::runtime_error( oss.str() );
4162 }
4163
4164 if( rs(0,0) != 0 || rs(0,1) != 0 || rs(0,2) != 0 || rs(0,3) != 0 ||
4165 rs(1,0) != 0 || rs(1,1) != 0 || rs(1,2) != 0 || rs(1,3) != 0 ) {
4166 std::ostringstream oss;
4167 oss << " Test: " << test_ << "\n"
4168 << " Error: Erasing the second half of the 1st row failed\n"
4169 << " Details:\n"
4170 << " Result:\n" << rs << "\n"
4171 << " Expected result:\n( 0 0 0 0 )\n( 0 0 0 0 )\n";
4172 throw std::runtime_error( oss.str() );
4173 }
4174 }
4175
4176 // Trying to erase an empty range
4177 {
4178 auto pos = rs.erase( 1UL, rs.begin( 1UL ), rs.begin( 1UL ) );
4179
4180 checkRows ( rs , 2UL );
4181 checkColumns ( rs , 4UL );
4182 checkNonZeros( rs , 0UL );
4183 checkRows ( mat_, 5UL );
4184 checkColumns ( mat_, 4UL );
4185 checkNonZeros( mat_, 3UL );
4186
4187 if( pos != rs.begin( 1UL ) ) {
4188 std::ostringstream oss;
4189 oss << " Test: " << test_ << "\n"
4190 << " Error: Invalid iterator returned\n"
4191 << " Details:\n"
4192 << " Expected result: the given end() iterator\n";
4193 throw std::runtime_error( oss.str() );
4194 }
4195
4196 if( rs(0,0) != 0 || rs(0,1) != 0 || rs(0,2) != 0 || rs(0,3) != 0 ||
4197 rs(1,0) != 0 || rs(1,1) != 0 || rs(1,2) != 0 || rs(1,3) != 0 ) {
4198 std::ostringstream oss;
4199 oss << " Test: " << test_ << "\n"
4200 << " Error: Erasing an empty range failed\n"
4201 << " Details:\n"
4202 << " Result:\n" << rs << "\n"
4203 << " Expected result:\n( 0 0 0 0 )\n( 0 0 0 0 )\n";
4204 throw std::runtime_error( oss.str() );
4205 }
4206 }
4207 }
4208
4209
4210 //=====================================================================================
4211 // Row-major erase function with predicate
4212 //=====================================================================================
4213
4214 {
4215 test_ = "Row-major Rows::erase( Predicate )";
4216
4217 initialize();
4218
4219 auto rs = blaze::rows( mat_, { 3UL, 4UL } );
4220
4221 // Erasing a selection of elements
4222 rs.erase( []( int value ) { return value == 4 || value == 10; } );
4223
4224 checkRows ( rs , 2UL );
4225 checkColumns ( rs , 4UL );
4226 checkNonZeros( rs , 5UL );
4227 checkRows ( mat_, 5UL );
4228 checkColumns ( mat_, 4UL );
4229 checkNonZeros( mat_, 8UL );
4230
4231 if( rs(0,0) != 0 || rs(0,1) != 0 || rs(0,2) != 5 || rs(0,3) != -6 ||
4232 rs(1,0) != 7 || rs(1,1) != -8 || rs(1,2) != 9 || rs(1,3) != 0 ) {
4233 std::ostringstream oss;
4234 oss << " Test: " << test_ << "\n"
4235 << " Error: Erasing a selection of elements failed\n"
4236 << " Details:\n"
4237 << " Result:\n" << rs << "\n"
4238 << " Expected result:\n( 0 0 5 -6 )\n( 7 -8 9 0 )\n";
4239 throw std::runtime_error( oss.str() );
4240 }
4241
4242 // Trying to erase all elements with value 1
4243 rs.erase( []( int value ){ return value == 1; } );
4244
4245 checkRows ( rs , 2UL );
4246 checkColumns ( rs , 4UL );
4247 checkNonZeros( rs , 5UL );
4248 checkRows ( mat_, 5UL );
4249 checkColumns ( mat_, 4UL );
4250 checkNonZeros( mat_, 8UL );
4251
4252 if( rs(0,0) != 0 || rs(0,1) != 0 || rs(0,2) != 5 || rs(0,3) != -6 ||
4253 rs(1,0) != 7 || rs(1,1) != -8 || rs(1,2) != 9 || rs(1,3) != 0 ) {
4254 std::ostringstream oss;
4255 oss << " Test: " << test_ << "\n"
4256 << " Error: Erasing all elements with value 1 failed\n"
4257 << " Details:\n"
4258 << " Result:\n" << rs << "\n"
4259 << " Expected result:\n( 0 0 5 -6 )\n( 7 -8 9 0 )\n";
4260 throw std::runtime_error( oss.str() );
4261 }
4262 }
4263
4264
4265 //=====================================================================================
4266 // Row-major iterator-range-based erase function with predicate
4267 //=====================================================================================
4268
4269 {
4270 test_ = "Row-major Rows::erase( size_t, Iterator, Iterator, Predicate )";
4271
4272 initialize();
4273
4274 auto rs = blaze::rows( mat_, { 3UL, 4UL } );
4275
4276 // Erasing a selection of elements
4277 rs.erase( 0UL, rs.begin( 0UL ), rs.find( 0UL, 3UL ),
4278 []( int value ) { return value == 4 || value == 5; } );
4279
4280 checkRows ( rs , 2UL );
4281 checkColumns ( rs , 4UL );
4282 checkNonZeros( rs , 5UL );
4283 checkRows ( mat_, 5UL );
4284 checkColumns ( mat_, 4UL );
4285 checkNonZeros( mat_, 8UL );
4286
4287 if( rs(0,0) != 0 || rs(0,1) != 0 || rs(0,2) != 0 || rs(0,3) != -6 ||
4288 rs(1,0) != 7 || rs(1,1) != -8 || rs(1,2) != 9 || rs(1,3) != 10 ) {
4289 std::ostringstream oss;
4290 oss << " Test: " << test_ << "\n"
4291 << " Error: Erasing a selection of elements failed\n"
4292 << " Details:\n"
4293 << " Result:\n" << rs << "\n"
4294 << " Expected result:\n( 0 0 0 -6 )\n( 7 -8 9 10 )\n";
4295 throw std::runtime_error( oss.str() );
4296 }
4297
4298 // Trying to erase from an empty range
4299 rs.erase( 1UL, rs.begin( 1UL ), rs.begin( 1UL ), []( int ){ return true; } );
4300
4301 checkRows ( rs , 2UL );
4302 checkColumns ( rs , 4UL );
4303 checkNonZeros( rs , 5UL );
4304 checkRows ( mat_, 5UL );
4305 checkColumns ( mat_, 4UL );
4306 checkNonZeros( mat_, 8UL );
4307
4308 if( rs(0,0) != 0 || rs(0,1) != 0 || rs(0,2) != 0 || rs(0,3) != -6 ||
4309 rs(1,0) != 7 || rs(1,1) != -8 || rs(1,2) != 9 || rs(1,3) != 10 ) {
4310 std::ostringstream oss;
4311 oss << " Test: " << test_ << "\n"
4312 << " Error: Erasing from an empty range failed\n"
4313 << " Details:\n"
4314 << " Result:\n" << rs << "\n"
4315 << " Expected result:\n( 0 0 0 -6 )\n( 7 -8 9 10 )\n";
4316 throw std::runtime_error( oss.str() );
4317 }
4318 }
4319
4320
4321 //=====================================================================================
4322 // Column-major index-based erase function
4323 //=====================================================================================
4324
4325 {
4326 test_ = "Column-major Rows::erase( size_t, size_t )";
4327
4328 initialize();
4329
4330 auto rs = blaze::rows( tmat_, { 3UL, 4UL } );
4331
4332 // Erasing the non-zero element at the end of the 1st row
4333 rs.erase( 1UL, 3UL );
4334
4335 checkRows ( rs , 2UL );
4336 checkColumns ( rs , 4UL );
4337 checkNonZeros( rs , 6UL );
4338 checkRows ( tmat_, 5UL );
4339 checkColumns ( tmat_, 4UL );
4340 checkNonZeros( tmat_, 9UL );
4341
4342 if( rs(0,0) != 0 || rs(0,1) != 4 || rs(0,2) != 5 || rs(0,3) != -6 ||
4343 rs(1,0) != 7 || rs(1,1) != -8 || rs(1,2) != 9 || rs(1,3) != 0 ) {
4344 std::ostringstream oss;
4345 oss << " Test: " << test_ << "\n"
4346 << " Error: Erasing a non-zero element failed\n"
4347 << " Details:\n"
4348 << " Result:\n" << rs << "\n"
4349 << " Expected result:\n( 0 4 5 -6 )\n( 7 -8 9 0 )\n";
4350 throw std::runtime_error( oss.str() );
4351 }
4352
4353 // Erasing the non-zero element at the beginning of the 1st row
4354 rs.erase( 1UL, size_t(0) );
4355
4356 checkRows ( rs , 2UL );
4357 checkColumns ( rs , 4UL );
4358 checkNonZeros( rs , 5UL );
4359 checkRows ( tmat_, 5UL );
4360 checkColumns ( tmat_, 4UL );
4361 checkNonZeros( tmat_, 8UL );
4362
4363 if( rs(0,0) != 0 || rs(0,1) != 4 || rs(0,2) != 5 || rs(0,3) != -6 ||
4364 rs(1,0) != 0 || rs(1,1) != -8 || rs(1,2) != 9 || rs(1,3) != 0 ) {
4365 std::ostringstream oss;
4366 oss << " Test: " << test_ << "\n"
4367 << " Error: Erasing a non-zero element failed\n"
4368 << " Details:\n"
4369 << " Result:\n" << rs << "\n"
4370 << " Expected result:\n( 0 4 5 -6 )\n( 0 -8 9 0 )\n";
4371 throw std::runtime_error( oss.str() );
4372 }
4373
4374 // Erasing the non-zero element at the beginning of the 1st row
4375 rs.erase( 1UL, 1UL );
4376
4377 checkRows ( rs , 2UL );
4378 checkColumns ( rs , 4UL );
4379 checkNonZeros( rs , 4UL );
4380 checkRows ( tmat_, 5UL );
4381 checkColumns ( tmat_, 4UL );
4382 checkNonZeros( tmat_, 7UL );
4383
4384 if( rs(0,0) != 0 || rs(0,1) != 4 || rs(0,2) != 5 || rs(0,3) != -6 ||
4385 rs(1,0) != 0 || rs(1,1) != 0 || rs(1,2) != 9 || rs(1,3) != 0 ) {
4386 std::ostringstream oss;
4387 oss << " Test: " << test_ << "\n"
4388 << " Error: Erasing a non-zero element failed\n"
4389 << " Details:\n"
4390 << " Result:\n" << rs << "\n"
4391 << " Expected result:\n( 0 4 5 -6 )\n( 0 0 9 0 )\n";
4392 throw std::runtime_error( oss.str() );
4393 }
4394
4395 // Trying to erase an already erased element
4396 rs.erase( 1UL, 3UL );
4397
4398 checkRows ( rs , 2UL );
4399 checkColumns ( rs , 4UL );
4400 checkNonZeros( rs , 4UL );
4401 checkRows ( tmat_, 5UL );
4402 checkColumns ( tmat_, 4UL );
4403 checkNonZeros( tmat_, 7UL );
4404
4405 if( rs(0,0) != 0 || rs(0,1) != 4 || rs(0,2) != 5 || rs(0,3) != -6 ||
4406 rs(1,0) != 0 || rs(1,1) != 0 || rs(1,2) != 9 || rs(1,3) != 0 ) {
4407 std::ostringstream oss;
4408 oss << " Test: " << test_ << "\n"
4409 << " Error: Erasing a non-zero element failed\n"
4410 << " Details:\n"
4411 << " Result:\n" << rs << "\n"
4412 << " Expected result:\n( 0 4 5 -6 )\n( 0 0 9 0 )\n";
4413 throw std::runtime_error( oss.str() );
4414 }
4415 }
4416
4417
4418 //=====================================================================================
4419 // Column-major iterator-based erase function
4420 //=====================================================================================
4421
4422 {
4423 test_ = "Column-major Rows::erase( size_t, Iterator )";
4424
4425 initialize();
4426
4427 auto rs = blaze::rows( tmat_, { 3UL, 4UL } );
4428
4429 // Erasing the non-zero element at the end of the 1st row
4430 {
4431 auto pos = rs.erase( 1UL, rs.find( 1UL, 3UL ) );
4432
4433 checkRows ( rs , 2UL );
4434 checkColumns ( rs , 4UL );
4435 checkNonZeros( rs , 6UL );
4436 checkRows ( tmat_, 5UL );
4437 checkColumns ( tmat_, 4UL );
4438 checkNonZeros( tmat_, 9UL );
4439
4440 if( pos != rs.end( 1UL ) ) {
4441 std::ostringstream oss;
4442 oss << " Test: " << test_ << "\n"
4443 << " Error: Invalid iterator returned\n"
4444 << " Details:\n"
4445 << " Expected result: the end() iterator\n";
4446 throw std::runtime_error( oss.str() );
4447 }
4448
4449 if( rs(0,0) != 0 || rs(0,1) != 4 || rs(0,2) != 5 || rs(0,3) != -6 ||
4450 rs(1,0) != 7 || rs(1,1) != -8 || rs(1,2) != 9 || rs(1,3) != 0 ) {
4451 std::ostringstream oss;
4452 oss << " Test: " << test_ << "\n"
4453 << " Error: Erasing a non-zero element failed\n"
4454 << " Details:\n"
4455 << " Result:\n" << rs << "\n"
4456 << " Expected result:\n( 0 4 5 -6 )\n( 7 -8 9 0 )\n";
4457 throw std::runtime_error( oss.str() );
4458 }
4459 }
4460
4461 // Erasing the non-zero element at the beginning of the 1st row
4462 {
4463 auto pos = rs.erase( 1UL, rs.find( 1UL, 0UL ) );
4464
4465 checkRows ( rs , 2UL );
4466 checkColumns ( rs , 4UL );
4467 checkNonZeros( rs , 5UL );
4468 checkRows ( tmat_, 5UL );
4469 checkColumns ( tmat_, 4UL );
4470 checkNonZeros( tmat_, 8UL );
4471
4472 if( pos->value() != -8 || pos->index() != 1 ) {
4473 std::ostringstream oss;
4474 oss << " Test: " << test_ << "\n"
4475 << " Error: Invalid iterator returned\n"
4476 << " Details:\n"
4477 << " Value: " << pos->value() << "\n"
4478 << " Index: " << pos->index() << "\n"
4479 << " Expected value: -8\n"
4480 << " Expected index: 1\n";
4481 throw std::runtime_error( oss.str() );
4482 }
4483
4484 if( rs(0,0) != 0 || rs(0,1) != 4 || rs(0,2) != 5 || rs(0,3) != -6 ||
4485 rs(1,0) != 0 || rs(1,1) != -8 || rs(1,2) != 9 || rs(1,3) != 0 ) {
4486 std::ostringstream oss;
4487 oss << " Test: " << test_ << "\n"
4488 << " Error: Erasing a non-zero element failed\n"
4489 << " Details:\n"
4490 << " Result:\n" << rs << "\n"
4491 << " Expected result:\n( 0 4 5 -6 )\n( 0 -8 9 0 )\n";
4492 throw std::runtime_error( oss.str() );
4493 }
4494 }
4495
4496 // Erasing the non-zero element at the beginning of the 1st row
4497 {
4498 auto pos = rs.erase( 1UL, rs.find( 1UL, 1UL ) );
4499
4500 checkRows ( rs , 2UL );
4501 checkColumns ( rs , 4UL );
4502 checkNonZeros( rs , 4UL );
4503 checkRows ( tmat_, 5UL );
4504 checkColumns ( tmat_, 4UL );
4505 checkNonZeros( tmat_, 7UL );
4506
4507 if( pos->value() != 9 || pos->index() != 2 ) {
4508 std::ostringstream oss;
4509 oss << " Test: " << test_ << "\n"
4510 << " Error: Invalid iterator returned\n"
4511 << " Details:\n"
4512 << " Value: " << pos->value() << "\n"
4513 << " Index: " << pos->index() << "\n"
4514 << " Expected value: 9\n"
4515 << " Expected index: 2\n";
4516 throw std::runtime_error( oss.str() );
4517 }
4518
4519 if( rs(0,0) != 0 || rs(0,1) != 4 || rs(0,2) != 5 || rs(0,3) != -6 ||
4520 rs(1,0) != 0 || rs(1,1) != 0 || rs(1,2) != 9 || rs(1,3) != 0 ) {
4521 std::ostringstream oss;
4522 oss << " Test: " << test_ << "\n"
4523 << " Error: Erasing a non-zero element failed\n"
4524 << " Details:\n"
4525 << " Result:\n" << rs << "\n"
4526 << " Expected result:\n( 0 4 5 -6 )\n( 0 -8 9 0 )\n";
4527 throw std::runtime_error( oss.str() );
4528 }
4529 }
4530
4531 // Trying to erase an already erased element
4532 {
4533 auto pos = rs.erase( 1UL, rs.find( 1UL, 3UL ) );
4534
4535 checkRows ( rs , 2UL );
4536 checkColumns ( rs , 4UL );
4537 checkNonZeros( rs , 4UL );
4538 checkRows ( tmat_, 5UL );
4539 checkColumns ( tmat_, 4UL );
4540 checkNonZeros( tmat_, 7UL );
4541
4542 if( pos != rs.end( 1UL ) ) {
4543 std::ostringstream oss;
4544 oss << " Test: " << test_ << "\n"
4545 << " Error: Invalid iterator returned\n"
4546 << " Details:\n"
4547 << " Expected result: the end() iterator\n";
4548 throw std::runtime_error( oss.str() );
4549 }
4550
4551 if( rs(0,0) != 0 || rs(0,1) != 4 || rs(0,2) != 5 || rs(0,3) != -6 ||
4552 rs(1,0) != 0 || rs(1,1) != 0 || rs(1,2) != 9 || rs(1,3) != 0 ) {
4553 std::ostringstream oss;
4554 oss << " Test: " << test_ << "\n"
4555 << " Error: Erasing a zero element failed\n"
4556 << " Details:\n"
4557 << " Result:\n" << rs << "\n"
4558 << " Expected result:\n( 0 4 5 -6 )\n( 0 -8 9 0 )\n";
4559 throw std::runtime_error( oss.str() );
4560 }
4561 }
4562 }
4563
4564
4565 //=====================================================================================
4566 // Column-major iterator-range-based erase function
4567 //=====================================================================================
4568
4569 {
4570 test_ = "Column-major Rows::erase( size_t, Iterator, Iterator )";
4571
4572 initialize();
4573
4574 auto rs = blaze::rows( tmat_, { 3UL, 4UL } );
4575
4576 // Erasing the 0th row
4577 {
4578 auto pos = rs.erase( 0UL, rs.begin( 0UL ), rs.end( 0UL ) );
4579
4580 checkRows ( rs , 2UL );
4581 checkColumns ( rs , 4UL );
4582 checkNonZeros( rs , 4UL );
4583 checkRows ( tmat_, 5UL );
4584 checkColumns ( tmat_, 4UL );
4585 checkNonZeros( tmat_, 7UL );
4586
4587 if( pos != rs.end( 0UL ) ) {
4588 std::ostringstream oss;
4589 oss << " Test: " << test_ << "\n"
4590 << " Error: Invalid iterator returned\n"
4591 << " Details:\n"
4592 << " Expected result: the end() iterator\n";
4593 throw std::runtime_error( oss.str() );
4594 }
4595
4596 if( rs(0,0) != 0 || rs(0,1) != 0 || rs(0,2) != 0 || rs(0,3) != 0 ||
4597 rs(1,0) != 7 || rs(1,1) != -8 || rs(1,2) != 9 || rs(1,3) != 10 ) {
4598 std::ostringstream oss;
4599 oss << " Test: " << test_ << "\n"
4600 << " Error: Erasing the 0th row failed\n"
4601 << " Details:\n"
4602 << " Result:\n" << rs << "\n"
4603 << " Expected result:\n( 0 0 0 0 )\n( 7 -8 9 10 )\n";
4604 throw std::runtime_error( oss.str() );
4605 }
4606 }
4607
4608 // Erasing the first half of the 1st row
4609 {
4610 auto pos = rs.erase( 1UL, rs.begin( 1UL ), rs.find( 1UL, 2UL ) );
4611
4612 checkRows ( rs , 2UL );
4613 checkColumns ( rs , 4UL );
4614 checkNonZeros( rs , 2UL );
4615 checkRows ( tmat_, 5UL );
4616 checkColumns ( tmat_, 4UL );
4617 checkNonZeros( tmat_, 5UL );
4618
4619 if( pos->value() != 9 || pos->index() != 2 ) {
4620 std::ostringstream oss;
4621 oss << " Test: " << test_ << "\n"
4622 << " Error: Invalid iterator returned\n"
4623 << " Details:\n"
4624 << " Value: " << pos->value() << "\n"
4625 << " Index: " << pos->index() << "\n"
4626 << " Expected value: 9\n"
4627 << " Expected index: 2\n";
4628 throw std::runtime_error( oss.str() );
4629 }
4630
4631 if( rs(0,0) != 0 || rs(0,1) != 0 || rs(0,2) != 0 || rs(0,3) != 0 ||
4632 rs(1,0) != 0 || rs(1,1) != 0 || rs(1,2) != 9 || rs(1,3) != 10 ) {
4633 std::ostringstream oss;
4634 oss << " Test: " << test_ << "\n"
4635 << " Error: Erasing the first half of the 1st row failed\n"
4636 << " Details:\n"
4637 << " Result:\n" << rs << "\n"
4638 << " Expected result:\n( 0 0 0 0 )\n( 0 0 9 10 )\n";
4639 throw std::runtime_error( oss.str() );
4640 }
4641 }
4642
4643 // Erasing the second half of the 1st row
4644 {
4645 auto pos = rs.erase( 1UL, rs.find( 1UL, 2UL ), rs.end( 1UL ) );
4646
4647 checkRows ( rs , 2UL );
4648 checkColumns ( rs , 4UL );
4649 checkNonZeros( rs , 0UL );
4650 checkRows ( tmat_, 5UL );
4651 checkColumns ( tmat_, 4UL );
4652 checkNonZeros( tmat_, 3UL );
4653
4654 if( pos != rs.end( 1UL ) ) {
4655 std::ostringstream oss;
4656 oss << " Test: " << test_ << "\n"
4657 << " Error: Invalid iterator returned\n"
4658 << " Details:\n"
4659 << " Expected result: the end() iterator\n";
4660 throw std::runtime_error( oss.str() );
4661 }
4662
4663 if( rs(0,0) != 0 || rs(0,1) != 0 || rs(0,2) != 0 || rs(0,3) != 0 ||
4664 rs(1,0) != 0 || rs(1,1) != 0 || rs(1,2) != 0 || rs(1,3) != 0 ) {
4665 std::ostringstream oss;
4666 oss << " Test: " << test_ << "\n"
4667 << " Error: Erasing the second half of the 1st row failed\n"
4668 << " Details:\n"
4669 << " Result:\n" << rs << "\n"
4670 << " Expected result:\n( 0 0 0 0 )\n( 0 0 0 0 )\n";
4671 throw std::runtime_error( oss.str() );
4672 }
4673 }
4674
4675 // Trying to erase an empty range
4676 {
4677 auto pos = rs.erase( 1UL, rs.begin( 1UL ), rs.begin( 1UL ) );
4678
4679 checkRows ( rs , 2UL );
4680 checkColumns ( rs , 4UL );
4681 checkNonZeros( rs , 0UL );
4682 checkRows ( tmat_, 5UL );
4683 checkColumns ( tmat_, 4UL );
4684 checkNonZeros( tmat_, 3UL );
4685
4686 if( pos != rs.begin( 1UL ) ) {
4687 std::ostringstream oss;
4688 oss << " Test: " << test_ << "\n"
4689 << " Error: Invalid iterator returned\n"
4690 << " Details:\n"
4691 << " Expected result: the given end() iterator\n";
4692 throw std::runtime_error( oss.str() );
4693 }
4694
4695 if( rs(0,0) != 0 || rs(0,1) != 0 || rs(0,2) != 0 || rs(0,3) != 0 ||
4696 rs(1,0) != 0 || rs(1,1) != 0 || rs(1,2) != 0 || rs(1,3) != 0 ) {
4697 std::ostringstream oss;
4698 oss << " Test: " << test_ << "\n"
4699 << " Error: Erasing an empty range failed\n"
4700 << " Details:\n"
4701 << " Result:\n" << rs << "\n"
4702 << " Expected result:\n( 0 0 0 0 )\n( 0 0 0 0 )\n";
4703 throw std::runtime_error( oss.str() );
4704 }
4705 }
4706 }
4707
4708
4709 //=====================================================================================
4710 // Column-major erase function with predicate
4711 //=====================================================================================
4712
4713 {
4714 test_ = "Column-major Rows::erase( Predicate )";
4715
4716 initialize();
4717
4718 auto rs = blaze::rows( tmat_, { 3UL, 4UL } );
4719
4720 // Erasing a selection of elements
4721 rs.erase( []( int value ) { return value == 4 || value == 10; } );
4722
4723 checkRows ( rs , 2UL );
4724 checkColumns ( rs , 4UL );
4725 checkNonZeros( rs , 5UL );
4726 checkRows ( tmat_, 5UL );
4727 checkColumns ( tmat_, 4UL );
4728 checkNonZeros( tmat_, 8UL );
4729
4730 if( rs(0,0) != 0 || rs(0,1) != 0 || rs(0,2) != 5 || rs(0,3) != -6 ||
4731 rs(1,0) != 7 || rs(1,1) != -8 || rs(1,2) != 9 || rs(1,3) != 0 ) {
4732 std::ostringstream oss;
4733 oss << " Test: " << test_ << "\n"
4734 << " Error: Erasing a selection of elements failed\n"
4735 << " Details:\n"
4736 << " Result:\n" << rs << "\n"
4737 << " Expected result:\n( 0 0 5 -6 )\n( 7 -8 9 0 )\n";
4738 throw std::runtime_error( oss.str() );
4739 }
4740
4741 // Trying to erase all elements with value 1
4742 rs.erase( []( int value ){ return value == 1; } );
4743
4744 checkRows ( rs , 2UL );
4745 checkColumns ( rs , 4UL );
4746 checkNonZeros( rs , 5UL );
4747 checkRows ( tmat_, 5UL );
4748 checkColumns ( tmat_, 4UL );
4749 checkNonZeros( tmat_, 8UL );
4750
4751 if( rs(0,0) != 0 || rs(0,1) != 0 || rs(0,2) != 5 || rs(0,3) != -6 ||
4752 rs(1,0) != 7 || rs(1,1) != -8 || rs(1,2) != 9 || rs(1,3) != 0 ) {
4753 std::ostringstream oss;
4754 oss << " Test: " << test_ << "\n"
4755 << " Error: Erasing all elements with value 1 failed\n"
4756 << " Details:\n"
4757 << " Result:\n" << rs << "\n"
4758 << " Expected result:\n( 0 0 5 -6 )\n( 7 -8 9 0 )\n";
4759 throw std::runtime_error( oss.str() );
4760 }
4761 }
4762
4763
4764 //=====================================================================================
4765 // Column-major iterator-range-based erase function with predicate
4766 //=====================================================================================
4767
4768 {
4769 test_ = "Column-major Rows::erase( size_t, Iterator, Iterator, Predicate )";
4770
4771 initialize();
4772
4773 auto rs = blaze::rows( tmat_, { 3UL, 4UL } );
4774
4775 // Erasing a selection of elements
4776 rs.erase( 0UL, rs.begin( 0UL ), rs.find( 0UL, 3UL ),
4777 []( int value ) { return value == 4 || value == 5; } );
4778
4779 checkRows ( rs , 2UL );
4780 checkColumns ( rs , 4UL );
4781 checkNonZeros( rs , 5UL );
4782 checkRows ( tmat_, 5UL );
4783 checkColumns ( tmat_, 4UL );
4784 checkNonZeros( tmat_, 8UL );
4785
4786 if( rs(0,0) != 0 || rs(0,1) != 0 || rs(0,2) != 0 || rs(0,3) != -6 ||
4787 rs(1,0) != 7 || rs(1,1) != -8 || rs(1,2) != 9 || rs(1,3) != 10 ) {
4788 std::ostringstream oss;
4789 oss << " Test: " << test_ << "\n"
4790 << " Error: Erasing a selection of elements failed\n"
4791 << " Details:\n"
4792 << " Result:\n" << rs << "\n"
4793 << " Expected result:\n( 0 0 0 -6 )\n( 7 -8 9 10 )\n";
4794 throw std::runtime_error( oss.str() );
4795 }
4796
4797 // Trying to erase from an empty range
4798 rs.erase( 1UL, rs.begin( 1UL ), rs.begin( 1UL ), []( int ){ return true; } );
4799
4800 checkRows ( rs , 2UL );
4801 checkColumns ( rs , 4UL );
4802 checkNonZeros( rs , 5UL );
4803 checkRows ( tmat_, 5UL );
4804 checkColumns ( tmat_, 4UL );
4805 checkNonZeros( tmat_, 8UL );
4806
4807 if( rs(0,0) != 0 || rs(0,1) != 0 || rs(0,2) != 0 || rs(0,3) != -6 ||
4808 rs(1,0) != 7 || rs(1,1) != -8 || rs(1,2) != 9 || rs(1,3) != 10 ) {
4809 std::ostringstream oss;
4810 oss << " Test: " << test_ << "\n"
4811 << " Error: Erasing from an empty range failed\n"
4812 << " Details:\n"
4813 << " Result:\n" << rs << "\n"
4814 << " Expected result:\n( 0 0 0 -6 )\n( 7 -8 9 10 )\n";
4815 throw std::runtime_error( oss.str() );
4816 }
4817 }
4818 }
4819 //*************************************************************************************************
4820
4821
4822 //*************************************************************************************************
4823 /*!\brief Test of the \c find() member function of the Rows class template.
4824 //
4825 // \return void
4826 // \exception std::runtime_error Error detected.
4827 //
4828 // This function performs a test of the \c find() member function of the Rows specialization.
4829 // In case an error is detected, a \a std::runtime_error exception is thrown.
4830 */
testFind()4831 void SparseGeneralTest::testFind()
4832 {
4833 //=====================================================================================
4834 // Row-major matrix tests
4835 //=====================================================================================
4836
4837 {
4838 test_ = "Row-major Rows::find()";
4839
4840 initialize();
4841
4842 auto rs = blaze::rows( mat_, { 1UL, 2UL, 3UL } );
4843
4844 checkRows ( rs, 3UL );
4845 checkColumns ( rs, 4UL );
4846 checkNonZeros( rs, 6UL );
4847 checkNonZeros( rs, 0UL, 1UL );
4848 checkNonZeros( rs, 1UL, 2UL );
4849 checkNonZeros( rs, 2UL, 3UL );
4850
4851 // Searching for the first element
4852 {
4853 auto pos( rs.find( 0UL, 1UL ) );
4854
4855 if( pos == rs.end( 0UL ) ) {
4856 std::ostringstream oss;
4857 oss << " Test: " << test_ << "\n"
4858 << " Error: Element could not be found\n"
4859 << " Details:\n"
4860 << " Required position = (0,1)\n"
4861 << " Current row selection:\n" << rs << "\n";
4862 throw std::runtime_error( oss.str() );
4863 }
4864 else if( pos->index() != 1 || pos->value() != 1 ) {
4865 std::ostringstream oss;
4866 oss << " Test: " << test_ << "\n"
4867 << " Error: Wrong element found\n"
4868 << " Details:\n"
4869 << " Required index = 1\n"
4870 << " Found index = " << pos->index() << "\n"
4871 << " Expected value = 1\n"
4872 << " Value at index = " << pos->value() << "\n"
4873 << " Current row selection:\n" << rs << "\n";
4874 throw std::runtime_error( oss.str() );
4875 }
4876 }
4877
4878 // Searching for the second element
4879 {
4880 auto pos( rs.find( 1UL, 2UL ) );
4881
4882 if( pos == rs.end( 1UL ) ) {
4883 std::ostringstream oss;
4884 oss << " Test: " << test_ << "\n"
4885 << " Error: Element could not be found\n"
4886 << " Details:\n"
4887 << " Required position = (1,2)\n"
4888 << " Current row selection:\n" << rs << "\n";
4889 throw std::runtime_error( oss.str() );
4890 }
4891 else if( pos->index() != 2 || pos->value() != -3 ) {
4892 std::ostringstream oss;
4893 oss << " Test: " << test_ << "\n"
4894 << " Error: Wrong element found\n"
4895 << " Details:\n"
4896 << " Required index = 2\n"
4897 << " Found index = " << pos->index() << "\n"
4898 << " Expected value = -3\n"
4899 << " Value at index = " << pos->value() << "\n"
4900 << " Current row selection:\n" << rs << "\n";
4901 throw std::runtime_error( oss.str() );
4902 }
4903 }
4904
4905 // Searching for a non-existing non-zero element
4906 {
4907 auto pos( rs.find( 1UL, 1UL ) );
4908
4909 if( pos != rs.end( 1UL ) ) {
4910 std::ostringstream oss;
4911 oss << " Test: " << test_ << "\n"
4912 << " Error: Non-existing element could be found\n"
4913 << " Details:\n"
4914 << " Required index = 0\n"
4915 << " Found index = " << pos->index() << "\n"
4916 << " Expected value = 0\n"
4917 << " Value at index = " << pos->value() << "\n"
4918 << " Current row selection:\n" << rs << "\n";
4919 throw std::runtime_error( oss.str() );
4920 }
4921 }
4922 }
4923
4924
4925 //=====================================================================================
4926 // Column-major matrix tests
4927 //=====================================================================================
4928
4929 {
4930 test_ = "Column-major Rows::find()";
4931
4932 initialize();
4933
4934 auto rs = blaze::rows( tmat_, { 1UL, 2UL, 3UL } );
4935
4936 checkRows ( rs, 3UL );
4937 checkColumns ( rs, 4UL );
4938 checkNonZeros( rs, 6UL );
4939 checkNonZeros( rs, 0UL, 1UL );
4940 checkNonZeros( rs, 1UL, 2UL );
4941 checkNonZeros( rs, 2UL, 3UL );
4942
4943 // Searching for the first element
4944 {
4945 auto pos( rs.find( 0UL, 1UL ) );
4946
4947 if( pos == rs.end( 0UL ) ) {
4948 std::ostringstream oss;
4949 oss << " Test: " << test_ << "\n"
4950 << " Error: Element could not be found\n"
4951 << " Details:\n"
4952 << " Required position = (0,1)\n"
4953 << " Current row selection:\n" << rs << "\n";
4954 throw std::runtime_error( oss.str() );
4955 }
4956 else if( pos->index() != 1 || pos->value() != 1 ) {
4957 std::ostringstream oss;
4958 oss << " Test: " << test_ << "\n"
4959 << " Error: Wrong element found\n"
4960 << " Details:\n"
4961 << " Required index = 1\n"
4962 << " Found index = " << pos->index() << "\n"
4963 << " Expected value = 1\n"
4964 << " Value at index = " << pos->value() << "\n"
4965 << " Current row selection:\n" << rs << "\n";
4966 throw std::runtime_error( oss.str() );
4967 }
4968 }
4969
4970 // Searching for the second element
4971 {
4972 auto pos( rs.find( 1UL, 2UL ) );
4973
4974 if( pos == rs.end( 1UL ) ) {
4975 std::ostringstream oss;
4976 oss << " Test: " << test_ << "\n"
4977 << " Error: Element could not be found\n"
4978 << " Details:\n"
4979 << " Required position = (1,2)\n"
4980 << " Current row selection:\n" << rs << "\n";
4981 throw std::runtime_error( oss.str() );
4982 }
4983 else if( pos->index() != 2 || pos->value() != -3 ) {
4984 std::ostringstream oss;
4985 oss << " Test: " << test_ << "\n"
4986 << " Error: Wrong element found\n"
4987 << " Details:\n"
4988 << " Required index = 2\n"
4989 << " Found index = " << pos->index() << "\n"
4990 << " Expected value = -3\n"
4991 << " Value at index = " << pos->value() << "\n"
4992 << " Current row selection:\n" << rs << "\n";
4993 throw std::runtime_error( oss.str() );
4994 }
4995 }
4996
4997 // Searching for a non-existing non-zero element
4998 {
4999 auto pos( rs.find( 1UL, 1UL ) );
5000
5001 if( pos != rs.end( 1UL ) ) {
5002 std::ostringstream oss;
5003 oss << " Test: " << test_ << "\n"
5004 << " Error: Non-existing element could be found\n"
5005 << " Details:\n"
5006 << " Required index = 0\n"
5007 << " Found index = " << pos->index() << "\n"
5008 << " Expected value = 0\n"
5009 << " Value at index = " << pos->value() << "\n"
5010 << " Current row selection:\n" << rs << "\n";
5011 throw std::runtime_error( oss.str() );
5012 }
5013 }
5014 }
5015 }
5016 //*************************************************************************************************
5017
5018
5019 //*************************************************************************************************
5020 /*!\brief Test of the \c lowerBound() member function of the Rows class template.
5021 //
5022 // \return void
5023 // \exception std::runtime_error Error detected.
5024 //
5025 // This function performs a test of the \c lowerBound() member function of the Rows
5026 // specialization. In case an error is detected, a \a std::runtime_error exception is thrown.
5027 */
testLowerBound()5028 void SparseGeneralTest::testLowerBound()
5029 {
5030 //=====================================================================================
5031 // Row-major matrix tests
5032 //=====================================================================================
5033
5034 {
5035 test_ = "Row-major Rows::lowerBound()";
5036
5037 auto rs = blaze::rows( mat_, { 1UL } );
5038
5039 checkRows ( rs, 1UL );
5040 checkColumns ( rs, 4UL );
5041 checkNonZeros( rs, 1UL );
5042 checkNonZeros( rs, 0UL, 1UL );
5043
5044 // Determining the lower bound for position (0,0)
5045 {
5046 auto pos( rs.lowerBound( 0UL, 0UL ) );
5047
5048 if( pos == rs.end( 0UL ) ) {
5049 std::ostringstream oss;
5050 oss << " Test: " << test_ << "\n"
5051 << " Error: Lower bound could not be determined\n"
5052 << " Details:\n"
5053 << " Required position = (0,0)\n"
5054 << " Current row selection:\n" << rs << "\n";
5055 throw std::runtime_error( oss.str() );
5056 }
5057 else if( pos->index() != 1 || pos->value() != 1 ) {
5058 std::ostringstream oss;
5059 oss << " Test: " << test_ << "\n"
5060 << " Error: Wrong element found\n"
5061 << " Details:\n"
5062 << " Required index = 1\n"
5063 << " Found index = " << pos->index() << "\n"
5064 << " Expected value = 1\n"
5065 << " Value at index = " << pos->value() << "\n"
5066 << " Current row selection:\n" << rs << "\n";
5067 throw std::runtime_error( oss.str() );
5068 }
5069 }
5070
5071 // Determining the lower bound for position (0,1)
5072 {
5073 auto pos( rs.lowerBound( 0UL, 1UL ) );
5074
5075 if( pos == rs.end( 0UL ) ) {
5076 std::ostringstream oss;
5077 oss << " Test: " << test_ << "\n"
5078 << " Error: Lower bound could not be determined\n"
5079 << " Details:\n"
5080 << " Required position = (0,1)\n"
5081 << " Current row selection:\n" << rs << "\n";
5082 throw std::runtime_error( oss.str() );
5083 }
5084 else if( pos->index() != 1 || pos->value() != 1 ) {
5085 std::ostringstream oss;
5086 oss << " Test: " << test_ << "\n"
5087 << " Error: Wrong element found\n"
5088 << " Details:\n"
5089 << " Required index = 1\n"
5090 << " Found index = " << pos->index() << "\n"
5091 << " Expected value = 1\n"
5092 << " Value at index = " << pos->value() << "\n"
5093 << " Current row selection:\n" << rs << "\n";
5094 throw std::runtime_error( oss.str() );
5095 }
5096 }
5097
5098 // Determining the lower bound for position (0,2)
5099 {
5100 auto pos( rs.lowerBound( 0UL, 2UL ) );
5101
5102 if( pos != rs.end( 0UL ) ) {
5103 std::ostringstream oss;
5104 oss << " Test: " << test_ << "\n"
5105 << " Error: Lower bound could not be determined\n"
5106 << " Details:\n"
5107 << " Required position = (0,2)\n"
5108 << " Current row selection:\n" << rs << "\n";
5109 throw std::runtime_error( oss.str() );
5110 }
5111 }
5112 }
5113
5114
5115 //=====================================================================================
5116 // Column-major matrix tests
5117 //=====================================================================================
5118
5119 {
5120 test_ = "Column-major Rows::lowerBound()";
5121
5122 auto rs = blaze::rows( tmat_, { 1UL } );
5123
5124 checkRows ( rs, 1UL );
5125 checkColumns ( rs, 4UL );
5126 checkNonZeros( rs, 1UL );
5127 checkNonZeros( rs, 0UL, 1UL );
5128
5129 // Determining the lower bound for position (0,0)
5130 {
5131 auto pos( rs.lowerBound( 0UL, 0UL ) );
5132
5133 if( pos == rs.end( 0UL ) ) {
5134 std::ostringstream oss;
5135 oss << " Test: " << test_ << "\n"
5136 << " Error: Lower bound could not be determined\n"
5137 << " Details:\n"
5138 << " Required position = (0,0)\n"
5139 << " Current row selection:\n" << rs << "\n";
5140 throw std::runtime_error( oss.str() );
5141 }
5142 else if( pos->index() != 1 || pos->value() != 1 ) {
5143 std::ostringstream oss;
5144 oss << " Test: " << test_ << "\n"
5145 << " Error: Wrong element found\n"
5146 << " Details:\n"
5147 << " Required index = 1\n"
5148 << " Found index = " << pos->index() << "\n"
5149 << " Expected value = 1\n"
5150 << " Value at index = " << pos->value() << "\n"
5151 << " Current row selection:\n" << rs << "\n";
5152 throw std::runtime_error( oss.str() );
5153 }
5154 }
5155
5156 // Determining the lower bound for position (0,1)
5157 {
5158 auto pos( rs.lowerBound( 0UL, 1UL ) );
5159
5160 if( pos == rs.end( 0UL ) ) {
5161 std::ostringstream oss;
5162 oss << " Test: " << test_ << "\n"
5163 << " Error: Lower bound could not be determined\n"
5164 << " Details:\n"
5165 << " Required position = (0,1)\n"
5166 << " Current row selection:\n" << rs << "\n";
5167 throw std::runtime_error( oss.str() );
5168 }
5169 else if( pos->index() != 1 || pos->value() != 1 ) {
5170 std::ostringstream oss;
5171 oss << " Test: " << test_ << "\n"
5172 << " Error: Wrong element found\n"
5173 << " Details:\n"
5174 << " Required index = 1\n"
5175 << " Found index = " << pos->index() << "\n"
5176 << " Expected value = 1\n"
5177 << " Value at index = " << pos->value() << "\n"
5178 << " Current row selection:\n" << rs << "\n";
5179 throw std::runtime_error( oss.str() );
5180 }
5181 }
5182
5183 // Determining the lower bound for position (0,2)
5184 {
5185 auto pos( rs.lowerBound( 0UL, 2UL ) );
5186
5187 if( pos != rs.end( 0UL ) ) {
5188 std::ostringstream oss;
5189 oss << " Test: " << test_ << "\n"
5190 << " Error: Lower bound could not be determined\n"
5191 << " Details:\n"
5192 << " Required position = (0,2)\n"
5193 << " Current row selection:\n" << rs << "\n";
5194 throw std::runtime_error( oss.str() );
5195 }
5196 }
5197 }
5198 }
5199 //*************************************************************************************************
5200
5201
5202 //*************************************************************************************************
5203 /*!\brief Test of the \c upperBound() member function of the Rows class template.
5204 //
5205 // \return void
5206 // \exception std::runtime_error Error detected.
5207 //
5208 // This function performs a test of the \c upperBound() member function of the Rows
5209 // specialization. In case an error is detected, a \a std::runtime_error exception is thrown.
5210 */
testUpperBound()5211 void SparseGeneralTest::testUpperBound()
5212 {
5213 //=====================================================================================
5214 // Row-major matrix tests
5215 //=====================================================================================
5216
5217 {
5218 test_ = "Row-major Rows::upperBound()";
5219
5220 auto rs = blaze::rows( mat_, { 1UL } );
5221
5222 checkRows ( rs, 1UL );
5223 checkColumns ( rs, 4UL );
5224 checkNonZeros( rs, 1UL );
5225 checkNonZeros( rs, 0UL, 1UL );
5226
5227 // Determining the upper bound for position (0,0)
5228 {
5229 auto pos( rs.upperBound( 0UL, 0UL ) );
5230
5231 if( pos == rs.end( 0UL ) ) {
5232 std::ostringstream oss;
5233 oss << " Test: " << test_ << "\n"
5234 << " Error: Upper bound could not be determined\n"
5235 << " Details:\n"
5236 << " Required position = (0,0)\n"
5237 << " Current row selection:\n" << rs << "\n";
5238 throw std::runtime_error( oss.str() );
5239 }
5240 else if( pos->index() != 1 || pos->value() != 1 ) {
5241 std::ostringstream oss;
5242 oss << " Test: " << test_ << "\n"
5243 << " Error: Wrong element found\n"
5244 << " Details:\n"
5245 << " Required index = 1\n"
5246 << " Found index = " << pos->index() << "\n"
5247 << " Expected value = 1\n"
5248 << " Value at index = " << pos->value() << "\n"
5249 << " Current row selection:\n" << rs << "\n";
5250 throw std::runtime_error( oss.str() );
5251 }
5252 }
5253
5254 // Determining the upper bound for position (0,1)
5255 {
5256 auto pos( rs.upperBound( 0UL, 1UL ) );
5257
5258 if( pos != rs.end( 0UL ) ) {
5259 std::ostringstream oss;
5260 oss << " Test: " << test_ << "\n"
5261 << " Error: Upper bound could not be determined\n"
5262 << " Details:\n"
5263 << " Required position = (0,1)\n"
5264 << " Current row selection:\n" << rs << "\n";
5265 throw std::runtime_error( oss.str() );
5266 }
5267 }
5268
5269 // Determining the upper bound for position (0,2)
5270 {
5271 auto pos( rs.upperBound( 0UL, 2UL ) );
5272
5273 if( pos != rs.end( 0UL ) ) {
5274 std::ostringstream oss;
5275 oss << " Test: " << test_ << "\n"
5276 << " Error: Upper bound could not be determined\n"
5277 << " Details:\n"
5278 << " Required position = (0,2)\n"
5279 << " Current row selection:\n" << rs << "\n";
5280 throw std::runtime_error( oss.str() );
5281 }
5282 }
5283 }
5284
5285
5286 //=====================================================================================
5287 // Column-major matrix tests
5288 //=====================================================================================
5289
5290 {
5291 test_ = "Column-major Rows::upperBound()";
5292
5293 auto rs = blaze::rows( tmat_, { 1UL } );
5294
5295 checkRows ( rs, 1UL );
5296 checkColumns ( rs, 4UL );
5297 checkNonZeros( rs, 1UL );
5298 checkNonZeros( rs, 0UL, 1UL );
5299
5300 // Determining the upper bound for position (0,0)
5301 {
5302 auto pos( rs.upperBound( 0UL, 0UL ) );
5303
5304 if( pos == rs.end( 0UL ) ) {
5305 std::ostringstream oss;
5306 oss << " Test: " << test_ << "\n"
5307 << " Error: Upper bound could not be determined\n"
5308 << " Details:\n"
5309 << " Required position = (0,0)\n"
5310 << " Current row selection:\n" << rs << "\n";
5311 throw std::runtime_error( oss.str() );
5312 }
5313 else if( pos->index() != 1 || pos->value() != 1 ) {
5314 std::ostringstream oss;
5315 oss << " Test: " << test_ << "\n"
5316 << " Error: Wrong element found\n"
5317 << " Details:\n"
5318 << " Required index = 1\n"
5319 << " Found index = " << pos->index() << "\n"
5320 << " Expected value = 1\n"
5321 << " Value at index = " << pos->value() << "\n"
5322 << " Current row selection:\n" << rs << "\n";
5323 throw std::runtime_error( oss.str() );
5324 }
5325 }
5326
5327 // Determining the upper bound for position (0,1)
5328 {
5329 auto pos( rs.upperBound( 0UL, 1UL ) );
5330
5331 if( pos != rs.end( 0UL ) ) {
5332 std::ostringstream oss;
5333 oss << " Test: " << test_ << "\n"
5334 << " Error: Upper bound could not be determined\n"
5335 << " Details:\n"
5336 << " Required position = (0,1)\n"
5337 << " Current row selection:\n" << rs << "\n";
5338 throw std::runtime_error( oss.str() );
5339 }
5340 }
5341
5342 // Determining the upper bound for position (0,2)
5343 {
5344 auto pos( rs.upperBound( 0UL, 2UL ) );
5345
5346 if( pos != rs.end( 0UL ) ) {
5347 std::ostringstream oss;
5348 oss << " Test: " << test_ << "\n"
5349 << " Error: Upper bound could not be determined\n"
5350 << " Details:\n"
5351 << " Required position = (0,2)\n"
5352 << " Current row selection:\n" << rs << "\n";
5353 throw std::runtime_error( oss.str() );
5354 }
5355 }
5356 }
5357 }
5358 //*************************************************************************************************
5359
5360
5361 //*************************************************************************************************
5362 /*!\brief Test of the \c transpose() member functions of the Rows class template.
5363 //
5364 // \return void
5365 // \exception std::runtime_error Error detected.
5366 //
5367 // This function performs a test of the \c transpose() member function of the Rows
5368 // specialization. Additionally, it performs a test of self-transpose via the \c trans()
5369 // function. In case an error is detected, a \a std::runtime_error exception is thrown.
5370 */
testTranspose()5371 void SparseGeneralTest::testTranspose()
5372 {
5373 //=====================================================================================
5374 // Row-major matrix tests
5375 //=====================================================================================
5376
5377 {
5378 test_ = "Row-major self-transpose via transpose()";
5379
5380 initialize();
5381
5382 auto rs = blaze::rows( mat_, { 3UL, 2UL, 1UL, 4UL } );
5383
5384 transpose( rs );
5385
5386 checkRows ( rs , 4UL );
5387 checkColumns ( rs , 4UL );
5388 checkNonZeros( rs , 10UL );
5389 checkRows ( mat_, 5UL );
5390 checkColumns ( mat_, 4UL );
5391 checkNonZeros( mat_, 10UL );
5392
5393 if( rs(0,0) != 0 || rs(0,1) != -2 || rs(0,2) != 0 || rs(0,3) != 7 ||
5394 rs(1,0) != 4 || rs(1,1) != 0 || rs(1,2) != 1 || rs(1,3) != -8 ||
5395 rs(2,0) != 5 || rs(2,1) != -3 || rs(2,2) != 0 || rs(2,3) != 9 ||
5396 rs(3,0) != -6 || rs(3,1) != 0 || rs(3,2) != 0 || rs(3,3) != 10 ) {
5397 std::ostringstream oss;
5398 oss << " Test: " << test_ << "\n"
5399 << " Error: Transpose operation failed\n"
5400 << " Details:\n"
5401 << " Result:\n" << rs << "\n"
5402 << " Expected result:\n( 0 -2 0 7 )\n"
5403 "( 4 0 1 -8 )\n"
5404 "( 5 -3 0 9 )\n"
5405 "( -6 0 0 10 )\n";
5406 throw std::runtime_error( oss.str() );
5407 }
5408
5409 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != 0 || mat_(0,3) != 0 ||
5410 mat_(1,0) != 5 || mat_(1,1) != -3 || mat_(1,2) != 0 || mat_(1,3) != 9 ||
5411 mat_(2,0) != 4 || mat_(2,1) != 0 || mat_(2,2) != 1 || mat_(2,3) != -8 ||
5412 mat_(3,0) != 0 || mat_(3,1) != -2 || mat_(3,2) != 0 || mat_(3,3) != 7 ||
5413 mat_(4,0) != -6 || mat_(4,1) != 0 || mat_(4,2) != 0 || mat_(4,3) != 10 ) {
5414 std::ostringstream oss;
5415 oss << " Test: " << test_ << "\n"
5416 << " Error: Transpose operation failed\n"
5417 << " Details:\n"
5418 << " Result:\n" << mat_ << "\n"
5419 << " Expected result:\n( 0 0 0 0 )\n"
5420 "( 5 -3 0 9 )\n"
5421 "( 4 0 1 -8 )\n"
5422 "( 0 -2 0 7 )\n"
5423 "( -6 0 0 10 )\n";
5424 throw std::runtime_error( oss.str() );
5425 }
5426 }
5427
5428 {
5429 test_ = "Row-major self-transpose via trans()";
5430
5431 initialize();
5432
5433 auto rs = blaze::rows( mat_, { 3UL, 2UL, 1UL, 4UL } );
5434
5435 rs = trans( rs );
5436
5437 checkRows ( rs , 4UL );
5438 checkColumns ( rs , 4UL );
5439 checkNonZeros( rs , 10UL );
5440 checkRows ( mat_, 5UL );
5441 checkColumns ( mat_, 4UL );
5442 checkNonZeros( mat_, 10UL );
5443
5444 if( rs(0,0) != 0 || rs(0,1) != -2 || rs(0,2) != 0 || rs(0,3) != 7 ||
5445 rs(1,0) != 4 || rs(1,1) != 0 || rs(1,2) != 1 || rs(1,3) != -8 ||
5446 rs(2,0) != 5 || rs(2,1) != -3 || rs(2,2) != 0 || rs(2,3) != 9 ||
5447 rs(3,0) != -6 || rs(3,1) != 0 || rs(3,2) != 0 || rs(3,3) != 10 ) {
5448 std::ostringstream oss;
5449 oss << " Test: " << test_ << "\n"
5450 << " Error: Transpose operation failed\n"
5451 << " Details:\n"
5452 << " Result:\n" << rs << "\n"
5453 << " Expected result:\n( 0 -2 0 7 )\n"
5454 "( 4 0 1 -8 )\n"
5455 "( 5 -3 0 9 )\n"
5456 "( -6 0 0 10 )\n";
5457 throw std::runtime_error( oss.str() );
5458 }
5459
5460 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != 0 || mat_(0,3) != 0 ||
5461 mat_(1,0) != 5 || mat_(1,1) != -3 || mat_(1,2) != 0 || mat_(1,3) != 9 ||
5462 mat_(2,0) != 4 || mat_(2,1) != 0 || mat_(2,2) != 1 || mat_(2,3) != -8 ||
5463 mat_(3,0) != 0 || mat_(3,1) != -2 || mat_(3,2) != 0 || mat_(3,3) != 7 ||
5464 mat_(4,0) != -6 || mat_(4,1) != 0 || mat_(4,2) != 0 || mat_(4,3) != 10 ) {
5465 std::ostringstream oss;
5466 oss << " Test: " << test_ << "\n"
5467 << " Error: Transpose operation failed\n"
5468 << " Details:\n"
5469 << " Result:\n" << mat_ << "\n"
5470 << " Expected result:\n( 0 0 0 0 )\n"
5471 "( 5 -3 0 9 )\n"
5472 "( 4 0 1 -8 )\n"
5473 "( 0 -2 0 7 )\n"
5474 "( -6 0 0 10 )\n";
5475 throw std::runtime_error( oss.str() );
5476 }
5477 }
5478
5479
5480 //=====================================================================================
5481 // Column-major matrix tests
5482 //=====================================================================================
5483
5484 {
5485 test_ = "Column-major self-transpose via transpose()";
5486
5487 initialize();
5488
5489 auto rs = blaze::rows( tmat_, { 3UL, 2UL, 1UL, 4UL } );
5490
5491 transpose( rs );
5492
5493 checkRows ( rs , 4UL );
5494 checkColumns ( rs , 4UL );
5495 checkNonZeros( rs , 10UL );
5496 checkRows ( tmat_, 5UL );
5497 checkColumns ( tmat_, 4UL );
5498 checkNonZeros( tmat_, 10UL );
5499
5500 if( rs(0,0) != 0 || rs(0,1) != -2 || rs(0,2) != 0 || rs(0,3) != 7 ||
5501 rs(1,0) != 4 || rs(1,1) != 0 || rs(1,2) != 1 || rs(1,3) != -8 ||
5502 rs(2,0) != 5 || rs(2,1) != -3 || rs(2,2) != 0 || rs(2,3) != 9 ||
5503 rs(3,0) != -6 || rs(3,1) != 0 || rs(3,2) != 0 || rs(3,3) != 10 ) {
5504 std::ostringstream oss;
5505 oss << " Test: " << test_ << "\n"
5506 << " Error: Transpose operation failed\n"
5507 << " Details:\n"
5508 << " Result:\n" << rs << "\n"
5509 << " Expected result:\n( 0 -2 0 7 )\n"
5510 "( 4 0 1 -8 )\n"
5511 "( 5 -3 0 9 )\n"
5512 "( -6 0 0 10 )\n";
5513 throw std::runtime_error( oss.str() );
5514 }
5515
5516 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != 0 || tmat_(0,3) != 0 ||
5517 tmat_(1,0) != 5 || tmat_(1,1) != -3 || tmat_(1,2) != 0 || tmat_(1,3) != 9 ||
5518 tmat_(2,0) != 4 || tmat_(2,1) != 0 || tmat_(2,2) != 1 || tmat_(2,3) != -8 ||
5519 tmat_(3,0) != 0 || tmat_(3,1) != -2 || tmat_(3,2) != 0 || tmat_(3,3) != 7 ||
5520 tmat_(4,0) != -6 || tmat_(4,1) != 0 || tmat_(4,2) != 0 || tmat_(4,3) != 10 ) {
5521 std::ostringstream oss;
5522 oss << " Test: " << test_ << "\n"
5523 << " Error: Transpose operation failed\n"
5524 << " Details:\n"
5525 << " Result:\n" << tmat_ << "\n"
5526 << " Expected result:\n( 0 0 0 0 )\n"
5527 "( 5 -3 0 9 )\n"
5528 "( 4 0 1 -8 )\n"
5529 "( 0 -2 0 7 )\n"
5530 "( -6 0 0 10 )\n";
5531 throw std::runtime_error( oss.str() );
5532 }
5533 }
5534
5535 {
5536 test_ = "Column-major self-transpose via trans()";
5537
5538 initialize();
5539
5540 auto rs = blaze::rows( tmat_, { 3UL, 2UL, 1UL, 4UL } );
5541
5542 rs = trans( rs );
5543
5544 checkRows ( rs , 4UL );
5545 checkColumns ( rs , 4UL );
5546 checkNonZeros( rs , 10UL );
5547 checkRows ( tmat_, 5UL );
5548 checkColumns ( tmat_, 4UL );
5549 checkNonZeros( tmat_, 10UL );
5550
5551 if( rs(0,0) != 0 || rs(0,1) != -2 || rs(0,2) != 0 || rs(0,3) != 7 ||
5552 rs(1,0) != 4 || rs(1,1) != 0 || rs(1,2) != 1 || rs(1,3) != -8 ||
5553 rs(2,0) != 5 || rs(2,1) != -3 || rs(2,2) != 0 || rs(2,3) != 9 ||
5554 rs(3,0) != -6 || rs(3,1) != 0 || rs(3,2) != 0 || rs(3,3) != 10 ) {
5555 std::ostringstream oss;
5556 oss << " Test: " << test_ << "\n"
5557 << " Error: Transpose operation failed\n"
5558 << " Details:\n"
5559 << " Result:\n" << rs << "\n"
5560 << " Expected result:\n( 0 -2 0 7 )\n"
5561 "( 4 0 1 -8 )\n"
5562 "( 5 -3 0 9 )\n"
5563 "( -6 0 0 10 )\n";
5564 throw std::runtime_error( oss.str() );
5565 }
5566
5567 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != 0 || tmat_(0,3) != 0 ||
5568 tmat_(1,0) != 5 || tmat_(1,1) != -3 || tmat_(1,2) != 0 || tmat_(1,3) != 9 ||
5569 tmat_(2,0) != 4 || tmat_(2,1) != 0 || tmat_(2,2) != 1 || tmat_(2,3) != -8 ||
5570 tmat_(3,0) != 0 || tmat_(3,1) != -2 || tmat_(3,2) != 0 || tmat_(3,3) != 7 ||
5571 tmat_(4,0) != -6 || tmat_(4,1) != 0 || tmat_(4,2) != 0 || tmat_(4,3) != 10 ) {
5572 std::ostringstream oss;
5573 oss << " Test: " << test_ << "\n"
5574 << " Error: Transpose operation failed\n"
5575 << " Details:\n"
5576 << " Result:\n" << tmat_ << "\n"
5577 << " Expected result:\n( 0 0 0 0 )\n"
5578 "( 5 -3 0 9 )\n"
5579 "( 4 0 1 -8 )\n"
5580 "( 0 -2 0 7 )\n"
5581 "( -6 0 0 10 )\n";
5582 throw std::runtime_error( oss.str() );
5583 }
5584 }
5585 }
5586 //*************************************************************************************************
5587
5588
5589 //*************************************************************************************************
5590 /*!\brief Test of the \c ctranspose() member functions of the Rows class template.
5591 //
5592 // \return void
5593 // \exception std::runtime_error Error detected.
5594 //
5595 // This function performs a test of the \c ctranspose() member function of the Rows
5596 // specialization. Additionally, it performs a test of self-transpose via the \c ctrans()
5597 // function. In case an error is detected, a \a std::runtime_error exception is thrown.
5598 */
testCTranspose()5599 void SparseGeneralTest::testCTranspose()
5600 {
5601 //=====================================================================================
5602 // Row-major matrix tests
5603 //=====================================================================================
5604
5605 {
5606 test_ = "Row-major self-transpose via ctranspose()";
5607
5608 initialize();
5609
5610 auto rs = blaze::rows( mat_, { 3UL, 2UL, 1UL, 4UL } );
5611
5612 ctranspose( rs );
5613
5614 checkRows ( rs , 4UL );
5615 checkColumns ( rs , 4UL );
5616 checkNonZeros( rs , 10UL );
5617 checkRows ( mat_, 5UL );
5618 checkColumns ( mat_, 4UL );
5619 checkNonZeros( mat_, 10UL );
5620
5621 if( rs(0,0) != 0 || rs(0,1) != -2 || rs(0,2) != 0 || rs(0,3) != 7 ||
5622 rs(1,0) != 4 || rs(1,1) != 0 || rs(1,2) != 1 || rs(1,3) != -8 ||
5623 rs(2,0) != 5 || rs(2,1) != -3 || rs(2,2) != 0 || rs(2,3) != 9 ||
5624 rs(3,0) != -6 || rs(3,1) != 0 || rs(3,2) != 0 || rs(3,3) != 10 ) {
5625 std::ostringstream oss;
5626 oss << " Test: " << test_ << "\n"
5627 << " Error: Transpose operation failed\n"
5628 << " Details:\n"
5629 << " Result:\n" << rs << "\n"
5630 << " Expected result:\n( 0 -2 0 7 )\n"
5631 "( 4 0 1 -8 )\n"
5632 "( 5 -3 0 9 )\n"
5633 "( -6 0 0 10 )\n";
5634 throw std::runtime_error( oss.str() );
5635 }
5636
5637 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != 0 || mat_(0,3) != 0 ||
5638 mat_(1,0) != 5 || mat_(1,1) != -3 || mat_(1,2) != 0 || mat_(1,3) != 9 ||
5639 mat_(2,0) != 4 || mat_(2,1) != 0 || mat_(2,2) != 1 || mat_(2,3) != -8 ||
5640 mat_(3,0) != 0 || mat_(3,1) != -2 || mat_(3,2) != 0 || mat_(3,3) != 7 ||
5641 mat_(4,0) != -6 || mat_(4,1) != 0 || mat_(4,2) != 0 || mat_(4,3) != 10 ) {
5642 std::ostringstream oss;
5643 oss << " Test: " << test_ << "\n"
5644 << " Error: Transpose operation failed\n"
5645 << " Details:\n"
5646 << " Result:\n" << mat_ << "\n"
5647 << " Expected result:\n( 0 0 0 0 )\n"
5648 "( 5 -3 0 9 )\n"
5649 "( 4 0 1 -8 )\n"
5650 "( 0 -2 0 7 )\n"
5651 "( -6 0 0 10 )\n";
5652 throw std::runtime_error( oss.str() );
5653 }
5654 }
5655
5656 {
5657 test_ = "Row-major self-transpose via ctrans()";
5658
5659 initialize();
5660
5661 auto rs = blaze::rows( mat_, { 3UL, 2UL, 1UL, 4UL } );
5662
5663 rs = ctrans( rs );
5664
5665 checkRows ( rs , 4UL );
5666 checkColumns ( rs , 4UL );
5667 checkNonZeros( rs , 10UL );
5668 checkRows ( mat_, 5UL );
5669 checkColumns ( mat_, 4UL );
5670 checkNonZeros( mat_, 10UL );
5671
5672 if( rs(0,0) != 0 || rs(0,1) != -2 || rs(0,2) != 0 || rs(0,3) != 7 ||
5673 rs(1,0) != 4 || rs(1,1) != 0 || rs(1,2) != 1 || rs(1,3) != -8 ||
5674 rs(2,0) != 5 || rs(2,1) != -3 || rs(2,2) != 0 || rs(2,3) != 9 ||
5675 rs(3,0) != -6 || rs(3,1) != 0 || rs(3,2) != 0 || rs(3,3) != 10 ) {
5676 std::ostringstream oss;
5677 oss << " Test: " << test_ << "\n"
5678 << " Error: Transpose operation failed\n"
5679 << " Details:\n"
5680 << " Result:\n" << rs << "\n"
5681 << " Expected result:\n( 0 -2 0 7 )\n"
5682 "( 4 0 1 -8 )\n"
5683 "( 5 -3 0 9 )\n"
5684 "( -6 0 0 10 )\n";
5685 throw std::runtime_error( oss.str() );
5686 }
5687
5688 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != 0 || mat_(0,3) != 0 ||
5689 mat_(1,0) != 5 || mat_(1,1) != -3 || mat_(1,2) != 0 || mat_(1,3) != 9 ||
5690 mat_(2,0) != 4 || mat_(2,1) != 0 || mat_(2,2) != 1 || mat_(2,3) != -8 ||
5691 mat_(3,0) != 0 || mat_(3,1) != -2 || mat_(3,2) != 0 || mat_(3,3) != 7 ||
5692 mat_(4,0) != -6 || mat_(4,1) != 0 || mat_(4,2) != 0 || mat_(4,3) != 10 ) {
5693 std::ostringstream oss;
5694 oss << " Test: " << test_ << "\n"
5695 << " Error: Transpose operation failed\n"
5696 << " Details:\n"
5697 << " Result:\n" << mat_ << "\n"
5698 << " Expected result:\n( 0 0 0 0 )\n"
5699 "( 5 -3 0 9 )\n"
5700 "( 4 0 1 -8 )\n"
5701 "( 0 -2 0 7 )\n"
5702 "( -6 0 0 10 )\n";
5703 throw std::runtime_error( oss.str() );
5704 }
5705 }
5706
5707
5708 //=====================================================================================
5709 // Column-major matrix tests
5710 //=====================================================================================
5711
5712 {
5713 test_ = "Column-major self-transpose via ctranspose()";
5714
5715 initialize();
5716
5717 auto rs = blaze::rows( tmat_, { 3UL, 2UL, 1UL, 4UL } );
5718
5719 ctranspose( rs );
5720
5721 checkRows ( rs , 4UL );
5722 checkColumns ( rs , 4UL );
5723 checkNonZeros( rs , 10UL );
5724 checkRows ( tmat_, 5UL );
5725 checkColumns ( tmat_, 4UL );
5726 checkNonZeros( tmat_, 10UL );
5727
5728 if( rs(0,0) != 0 || rs(0,1) != -2 || rs(0,2) != 0 || rs(0,3) != 7 ||
5729 rs(1,0) != 4 || rs(1,1) != 0 || rs(1,2) != 1 || rs(1,3) != -8 ||
5730 rs(2,0) != 5 || rs(2,1) != -3 || rs(2,2) != 0 || rs(2,3) != 9 ||
5731 rs(3,0) != -6 || rs(3,1) != 0 || rs(3,2) != 0 || rs(3,3) != 10 ) {
5732 std::ostringstream oss;
5733 oss << " Test: " << test_ << "\n"
5734 << " Error: Transpose operation failed\n"
5735 << " Details:\n"
5736 << " Result:\n" << rs << "\n"
5737 << " Expected result:\n( 0 -2 0 7 )\n"
5738 "( 4 0 1 -8 )\n"
5739 "( 5 -3 0 9 )\n"
5740 "( -6 0 0 10 )\n";
5741 throw std::runtime_error( oss.str() );
5742 }
5743
5744 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != 0 || tmat_(0,3) != 0 ||
5745 tmat_(1,0) != 5 || tmat_(1,1) != -3 || tmat_(1,2) != 0 || tmat_(1,3) != 9 ||
5746 tmat_(2,0) != 4 || tmat_(2,1) != 0 || tmat_(2,2) != 1 || tmat_(2,3) != -8 ||
5747 tmat_(3,0) != 0 || tmat_(3,1) != -2 || tmat_(3,2) != 0 || tmat_(3,3) != 7 ||
5748 tmat_(4,0) != -6 || tmat_(4,1) != 0 || tmat_(4,2) != 0 || tmat_(4,3) != 10 ) {
5749 std::ostringstream oss;
5750 oss << " Test: " << test_ << "\n"
5751 << " Error: Transpose operation failed\n"
5752 << " Details:\n"
5753 << " Result:\n" << tmat_ << "\n"
5754 << " Expected result:\n( 0 0 0 0 )\n"
5755 "( 5 -3 0 9 )\n"
5756 "( 4 0 1 -8 )\n"
5757 "( 0 -2 0 7 )\n"
5758 "( -6 0 0 10 )\n";
5759 throw std::runtime_error( oss.str() );
5760 }
5761 }
5762
5763 {
5764 test_ = "Column-major self-transpose via ctrans()";
5765
5766 initialize();
5767
5768 auto rs = blaze::rows( tmat_, { 3UL, 2UL, 1UL, 4UL } );
5769
5770 rs = ctrans( rs );
5771
5772 checkRows ( rs , 4UL );
5773 checkColumns ( rs , 4UL );
5774 checkNonZeros( rs , 10UL );
5775 checkRows ( tmat_, 5UL );
5776 checkColumns ( tmat_, 4UL );
5777 checkNonZeros( tmat_, 10UL );
5778
5779 if( rs(0,0) != 0 || rs(0,1) != -2 || rs(0,2) != 0 || rs(0,3) != 7 ||
5780 rs(1,0) != 4 || rs(1,1) != 0 || rs(1,2) != 1 || rs(1,3) != -8 ||
5781 rs(2,0) != 5 || rs(2,1) != -3 || rs(2,2) != 0 || rs(2,3) != 9 ||
5782 rs(3,0) != -6 || rs(3,1) != 0 || rs(3,2) != 0 || rs(3,3) != 10 ) {
5783 std::ostringstream oss;
5784 oss << " Test: " << test_ << "\n"
5785 << " Error: Transpose operation failed\n"
5786 << " Details:\n"
5787 << " Result:\n" << rs << "\n"
5788 << " Expected result:\n( 0 -2 0 7 )\n"
5789 "( 4 0 1 -8 )\n"
5790 "( 5 -3 0 9 )\n"
5791 "( -6 0 0 10 )\n";
5792 throw std::runtime_error( oss.str() );
5793 }
5794
5795 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != 0 || tmat_(0,3) != 0 ||
5796 tmat_(1,0) != 5 || tmat_(1,1) != -3 || tmat_(1,2) != 0 || tmat_(1,3) != 9 ||
5797 tmat_(2,0) != 4 || tmat_(2,1) != 0 || tmat_(2,2) != 1 || tmat_(2,3) != -8 ||
5798 tmat_(3,0) != 0 || tmat_(3,1) != -2 || tmat_(3,2) != 0 || tmat_(3,3) != 7 ||
5799 tmat_(4,0) != -6 || tmat_(4,1) != 0 || tmat_(4,2) != 0 || tmat_(4,3) != 10 ) {
5800 std::ostringstream oss;
5801 oss << " Test: " << test_ << "\n"
5802 << " Error: Transpose operation failed\n"
5803 << " Details:\n"
5804 << " Result:\n" << tmat_ << "\n"
5805 << " Expected result:\n( 0 0 0 0 )\n"
5806 "( 5 -3 0 9 )\n"
5807 "( 4 0 1 -8 )\n"
5808 "( 0 -2 0 7 )\n"
5809 "( -6 0 0 10 )\n";
5810 throw std::runtime_error( oss.str() );
5811 }
5812 }
5813 }
5814 //*************************************************************************************************
5815
5816
5817 //*************************************************************************************************
5818 /*!\brief Test of the \c isDefault() function with the Rows class template.
5819 //
5820 // \return void
5821 // \exception std::runtime_error Error detected.
5822 //
5823 // This function performs a test of the \c isDefault() function with the Rows specialization.
5824 // In case an error is detected, a \a std::runtime_error exception is thrown.
5825 */
testIsDefault()5826 void SparseGeneralTest::testIsDefault()
5827 {
5828 //=====================================================================================
5829 // Row-major matrix tests
5830 //=====================================================================================
5831
5832 {
5833 test_ = "Row-major isDefault() function";
5834
5835 using blaze::isDefault;
5836
5837 initialize();
5838
5839 // isDefault with default row selection
5840 {
5841 auto rs = blaze::rows( mat_, { 0UL } );
5842
5843 if( isDefault( rs(0,1) ) != true ) {
5844 std::ostringstream oss;
5845 oss << " Test: " << test_ << "\n"
5846 << " Error: Invalid isDefault evaluation\n"
5847 << " Details:\n"
5848 << " Row element: " << rs(0,1) << "\n";
5849 throw std::runtime_error( oss.str() );
5850 }
5851
5852 if( isDefault( rs ) != true ) {
5853 std::ostringstream oss;
5854 oss << " Test: " << test_ << "\n"
5855 << " Error: Invalid isDefault evaluation\n"
5856 << " Details:\n"
5857 << " Row selection:\n" << rs << "\n";
5858 throw std::runtime_error( oss.str() );
5859 }
5860 }
5861
5862 // isDefault with non-default row selection
5863 {
5864 auto rs = blaze::rows( mat_, { 1UL } );
5865
5866 if( isDefault( rs(0,1) ) != false ) {
5867 std::ostringstream oss;
5868 oss << " Test: " << test_ << "\n"
5869 << " Error: Invalid isDefault evaluation\n"
5870 << " Details:\n"
5871 << " Row element: " << rs(0,1) << "\n";
5872 throw std::runtime_error( oss.str() );
5873 }
5874
5875 if( isDefault( rs ) != false ) {
5876 std::ostringstream oss;
5877 oss << " Test: " << test_ << "\n"
5878 << " Error: Invalid isDefault evaluation\n"
5879 << " Details:\n"
5880 << " Row selection:\n" << rs << "\n";
5881 throw std::runtime_error( oss.str() );
5882 }
5883 }
5884 }
5885
5886
5887 //=====================================================================================
5888 // Column-major matrix tests
5889 //=====================================================================================
5890
5891 {
5892 test_ = "Column-major isDefault() function";
5893
5894 using blaze::isDefault;
5895
5896 initialize();
5897
5898 // isDefault with default row selection
5899 {
5900 auto rs = blaze::rows( tmat_, { 0UL } );
5901
5902 if( isDefault( rs(0,1) ) != true ) {
5903 std::ostringstream oss;
5904 oss << " Test: " << test_ << "\n"
5905 << " Error: Invalid isDefault evaluation\n"
5906 << " Details:\n"
5907 << " Row element: " << rs(0,1) << "\n";
5908 throw std::runtime_error( oss.str() );
5909 }
5910
5911 if( isDefault( rs ) != true ) {
5912 std::ostringstream oss;
5913 oss << " Test: " << test_ << "\n"
5914 << " Error: Invalid isDefault evaluation\n"
5915 << " Details:\n"
5916 << " Row selection:\n" << rs << "\n";
5917 throw std::runtime_error( oss.str() );
5918 }
5919 }
5920
5921 // isDefault with non-default row selection
5922 {
5923 auto rs = blaze::rows( tmat_, { 1UL } );
5924
5925 if( isDefault( rs(0,1) ) != false ) {
5926 std::ostringstream oss;
5927 oss << " Test: " << test_ << "\n"
5928 << " Error: Invalid isDefault evaluation\n"
5929 << " Details:\n"
5930 << " Row element: " << rs(0,1) << "\n";
5931 throw std::runtime_error( oss.str() );
5932 }
5933
5934 if( isDefault( rs ) != false ) {
5935 std::ostringstream oss;
5936 oss << " Test: " << test_ << "\n"
5937 << " Error: Invalid isDefault evaluation\n"
5938 << " Details:\n"
5939 << " Row selection:\n" << rs << "\n";
5940 throw std::runtime_error( oss.str() );
5941 }
5942 }
5943 }
5944 }
5945 //*************************************************************************************************
5946
5947
5948 //*************************************************************************************************
5949 /*!\brief Test of the \c isSame() function with the Rows class template.
5950 //
5951 // \return void
5952 // \exception std::runtime_error Error detected.
5953 //
5954 // This function performs a test of the \c isSame() function with the Rows specialization.
5955 // In case an error is detected, a \a std::runtime_error exception is thrown.
5956 */
testIsSame()5957 void SparseGeneralTest::testIsSame()
5958 {
5959 //=====================================================================================
5960 // Row-major matrix tests
5961 //=====================================================================================
5962
5963 {
5964 test_ = "Row-major isSame() function";
5965
5966 // isSame with matrix and matching row selection
5967 {
5968 auto rs = blaze::rows( mat_, { 0UL, 1UL, 2UL, 3UL, 4UL } );
5969
5970 if( blaze::isSame( rs, mat_ ) == false ) {
5971 std::ostringstream oss;
5972 oss << " Test: " << test_ << "\n"
5973 << " Error: Invalid isSame evaluation\n"
5974 << " Details:\n"
5975 << " Matrix:\n" << mat_ << "\n"
5976 << " Row selection:\n" << rs << "\n";
5977 throw std::runtime_error( oss.str() );
5978 }
5979
5980 if( blaze::isSame( mat_, rs ) == false ) {
5981 std::ostringstream oss;
5982 oss << " Test: " << test_ << "\n"
5983 << " Error: Invalid isSame evaluation\n"
5984 << " Details:\n"
5985 << " Matrix:\n" << mat_ << "\n"
5986 << " Row selection:\n" << rs << "\n";
5987 throw std::runtime_error( oss.str() );
5988 }
5989 }
5990
5991 // isSame with matrix and non-matching row selection (different number of rows)
5992 {
5993 auto rs = blaze::rows( mat_, { 0UL, 1UL, 2UL, 3UL } );
5994
5995 if( blaze::isSame( rs, mat_ ) == true ) {
5996 std::ostringstream oss;
5997 oss << " Test: " << test_ << "\n"
5998 << " Error: Invalid isSame evaluation\n"
5999 << " Details:\n"
6000 << " Matrix:\n" << mat_ << "\n"
6001 << " Row selection:\n" << rs << "\n";
6002 throw std::runtime_error( oss.str() );
6003 }
6004
6005 if( blaze::isSame( mat_, rs ) == true ) {
6006 std::ostringstream oss;
6007 oss << " Test: " << test_ << "\n"
6008 << " Error: Invalid isSame evaluation\n"
6009 << " Details:\n"
6010 << " Matrix:\n" << mat_ << "\n"
6011 << " Row selection:\n" << rs << "\n";
6012 throw std::runtime_error( oss.str() );
6013 }
6014 }
6015
6016 // isSame with matrix and non-matching row selection (different order of rows)
6017 {
6018 auto rs = blaze::rows( mat_, { 0UL, 2UL, 1UL, 3UL, 4UL } );
6019
6020 if( blaze::isSame( rs, mat_ ) == true ) {
6021 std::ostringstream oss;
6022 oss << " Test: " << test_ << "\n"
6023 << " Error: Invalid isSame evaluation\n"
6024 << " Details:\n"
6025 << " Matrix:\n" << mat_ << "\n"
6026 << " Row selection:\n" << rs << "\n";
6027 throw std::runtime_error( oss.str() );
6028 }
6029
6030 if( blaze::isSame( mat_, rs ) == true ) {
6031 std::ostringstream oss;
6032 oss << " Test: " << test_ << "\n"
6033 << " Error: Invalid isSame evaluation\n"
6034 << " Details:\n"
6035 << " Matrix:\n" << mat_ << "\n"
6036 << " Row selection:\n" << rs << "\n";
6037 throw std::runtime_error( oss.str() );
6038 }
6039 }
6040
6041 // isSame with matrix and non-matching row selection (repeating rows)
6042 {
6043 auto rs = blaze::rows( mat_, { 0UL, 1UL, 1UL, 3UL, 4UL } );
6044
6045 if( blaze::isSame( rs, mat_ ) == true ) {
6046 std::ostringstream oss;
6047 oss << " Test: " << test_ << "\n"
6048 << " Error: Invalid isSame evaluation\n"
6049 << " Details:\n"
6050 << " Matrix:\n" << mat_ << "\n"
6051 << " Row selection:\n" << rs << "\n";
6052 throw std::runtime_error( oss.str() );
6053 }
6054
6055 if( blaze::isSame( mat_, rs ) == true ) {
6056 std::ostringstream oss;
6057 oss << " Test: " << test_ << "\n"
6058 << " Error: Invalid isSame evaluation\n"
6059 << " Details:\n"
6060 << " Matrix:\n" << mat_ << "\n"
6061 << " Row selection:\n" << rs << "\n";
6062 throw std::runtime_error( oss.str() );
6063 }
6064 }
6065
6066 // isSame with submatrix and matching row selection
6067 {
6068 auto rs = blaze::rows( mat_, { 1UL, 2UL, 3UL } );
6069 auto sm = blaze::submatrix( mat_, 1UL, 0UL, 3UL, 4UL );
6070
6071 if( blaze::isSame( rs, sm ) == false ) {
6072 std::ostringstream oss;
6073 oss << " Test: " << test_ << "\n"
6074 << " Error: Invalid isSame evaluation\n"
6075 << " Details:\n"
6076 << " Submatrix:\n" << sm << "\n"
6077 << " Row selection:\n" << rs << "\n";
6078 throw std::runtime_error( oss.str() );
6079 }
6080
6081 if( blaze::isSame( sm, rs ) == false ) {
6082 std::ostringstream oss;
6083 oss << " Test: " << test_ << "\n"
6084 << " Error: Invalid isSame evaluation\n"
6085 << " Details:\n"
6086 << " Submatrix:\n" << sm << "\n"
6087 << " Row selection:\n" << rs << "\n";
6088 throw std::runtime_error( oss.str() );
6089 }
6090 }
6091
6092 // isSame with submatrix and non-matching row selection (different number of rows)
6093 {
6094 auto rs = blaze::rows( mat_, { 1UL, 2UL, 3UL } );
6095 auto sm = blaze::submatrix( mat_, 1UL, 0UL, 2UL, 4UL );
6096
6097 if( blaze::isSame( rs, sm ) == true ) {
6098 std::ostringstream oss;
6099 oss << " Test: " << test_ << "\n"
6100 << " Error: Invalid isSame evaluation\n"
6101 << " Details:\n"
6102 << " Submatrix:\n" << sm << "\n"
6103 << " Row selection:\n" << rs << "\n";
6104 throw std::runtime_error( oss.str() );
6105 }
6106
6107 if( blaze::isSame( sm, rs ) == true ) {
6108 std::ostringstream oss;
6109 oss << " Test: " << test_ << "\n"
6110 << " Error: Invalid isSame evaluation\n"
6111 << " Details:\n"
6112 << " Submatrix:\n" << sm << "\n"
6113 << " Row selection:\n" << rs << "\n";
6114 throw std::runtime_error( oss.str() );
6115 }
6116 }
6117
6118 // isSame with submatrix and non-matching row selection (different number of columns)
6119 {
6120 auto rs = blaze::rows( mat_, { 1UL, 2UL, 3UL } );
6121 auto sm = blaze::submatrix( mat_, 1UL, 0UL, 3UL, 3UL );
6122
6123 if( blaze::isSame( rs, sm ) == true ) {
6124 std::ostringstream oss;
6125 oss << " Test: " << test_ << "\n"
6126 << " Error: Invalid isSame evaluation\n"
6127 << " Details:\n"
6128 << " Submatrix:\n" << sm << "\n"
6129 << " Row selection:\n" << rs << "\n";
6130 throw std::runtime_error( oss.str() );
6131 }
6132
6133 if( blaze::isSame( sm, rs ) == true ) {
6134 std::ostringstream oss;
6135 oss << " Test: " << test_ << "\n"
6136 << " Error: Invalid isSame evaluation\n"
6137 << " Details:\n"
6138 << " Submatrix:\n" << sm << "\n"
6139 << " Row selection:\n" << rs << "\n";
6140 throw std::runtime_error( oss.str() );
6141 }
6142 }
6143
6144 // isSame with submatrix and non-matching row selection (different order of rows)
6145 {
6146 auto rs = blaze::rows( mat_, { 1UL, 3UL, 2UL } );
6147 auto sm = blaze::submatrix( mat_, 1UL, 0UL, 3UL, 4UL );
6148
6149 if( blaze::isSame( rs, sm ) == true ) {
6150 std::ostringstream oss;
6151 oss << " Test: " << test_ << "\n"
6152 << " Error: Invalid isSame evaluation\n"
6153 << " Details:\n"
6154 << " Submatrix:\n" << sm << "\n"
6155 << " Row selection:\n" << rs << "\n";
6156 throw std::runtime_error( oss.str() );
6157 }
6158
6159 if( blaze::isSame( sm, rs ) == true ) {
6160 std::ostringstream oss;
6161 oss << " Test: " << test_ << "\n"
6162 << " Error: Invalid isSame evaluation\n"
6163 << " Details:\n"
6164 << " Submatrix:\n" << sm << "\n"
6165 << " Row selection:\n" << rs << "\n";
6166 throw std::runtime_error( oss.str() );
6167 }
6168 }
6169
6170 // isSame with submatrix and non-matching row selection (repeating rows)
6171 {
6172 auto rs = blaze::rows( mat_, { 1UL, 3UL, 3UL } );
6173 auto sm = blaze::submatrix( mat_, 1UL, 0UL, 3UL, 4UL );
6174
6175 if( blaze::isSame( rs, sm ) == true ) {
6176 std::ostringstream oss;
6177 oss << " Test: " << test_ << "\n"
6178 << " Error: Invalid isSame evaluation\n"
6179 << " Details:\n"
6180 << " Submatrix:\n" << sm << "\n"
6181 << " Row selection:\n" << rs << "\n";
6182 throw std::runtime_error( oss.str() );
6183 }
6184
6185 if( blaze::isSame( sm, rs ) == true ) {
6186 std::ostringstream oss;
6187 oss << " Test: " << test_ << "\n"
6188 << " Error: Invalid isSame evaluation\n"
6189 << " Details:\n"
6190 << " Submatrix:\n" << sm << "\n"
6191 << " Row selection:\n" << rs << "\n";
6192 throw std::runtime_error( oss.str() );
6193 }
6194 }
6195
6196 // isSame with submatrix and non-matching row selection (different row index)
6197 {
6198 auto rs = blaze::rows( mat_, { 1UL, 2UL, 3UL } );
6199 auto sm = blaze::submatrix( mat_, 2UL, 0UL, 3UL, 4UL );
6200
6201 if( blaze::isSame( rs, sm ) == true ) {
6202 std::ostringstream oss;
6203 oss << " Test: " << test_ << "\n"
6204 << " Error: Invalid isSame evaluation\n"
6205 << " Details:\n"
6206 << " Submatrix:\n" << sm << "\n"
6207 << " Row selection:\n" << rs << "\n";
6208 throw std::runtime_error( oss.str() );
6209 }
6210
6211 if( blaze::isSame( sm, rs ) == true ) {
6212 std::ostringstream oss;
6213 oss << " Test: " << test_ << "\n"
6214 << " Error: Invalid isSame evaluation\n"
6215 << " Details:\n"
6216 << " Submatrix:\n" << sm << "\n"
6217 << " Row selection:\n" << rs << "\n";
6218 throw std::runtime_error( oss.str() );
6219 }
6220 }
6221
6222 // isSame with matching row selections
6223 {
6224 auto rs1 = blaze::rows( mat_, { 0UL, 3UL, 1UL } );
6225 auto rs2 = blaze::rows( mat_, { 0UL, 3UL, 1UL } );
6226
6227 if( blaze::isSame( rs1, rs2 ) == false ) {
6228 std::ostringstream oss;
6229 oss << " Test: " << test_ << "\n"
6230 << " Error: Invalid isSame evaluation\n"
6231 << " Details:\n"
6232 << " First row selection:\n" << rs1 << "\n"
6233 << " Second row selection:\n" << rs2 << "\n";
6234 throw std::runtime_error( oss.str() );
6235 }
6236 }
6237
6238 // isSame with non-matching row selections (different number of rows)
6239 {
6240 auto rs1 = blaze::rows( mat_, { 0UL, 3UL, 1UL } );
6241 auto rs2 = blaze::rows( mat_, { 0UL, 3UL, 1UL, 2UL } );
6242
6243 if( blaze::isSame( rs1, rs2 ) == true ) {
6244 std::ostringstream oss;
6245 oss << " Test: " << test_ << "\n"
6246 << " Error: Invalid isSame evaluation\n"
6247 << " Details:\n"
6248 << " First row selection:\n" << rs1 << "\n"
6249 << " Second row selection:\n" << rs2 << "\n";
6250 throw std::runtime_error( oss.str() );
6251 }
6252 }
6253
6254 // isSame with non-matching row selections (different order of rows)
6255 {
6256 auto rs1 = blaze::rows( mat_, { 0UL, 3UL, 1UL } );
6257 auto rs2 = blaze::rows( mat_, { 0UL, 1UL, 3UL } );
6258
6259 if( blaze::isSame( rs1, rs2 ) == true ) {
6260 std::ostringstream oss;
6261 oss << " Test: " << test_ << "\n"
6262 << " Error: Invalid isSame evaluation\n"
6263 << " Details:\n"
6264 << " First row selection:\n" << rs1 << "\n"
6265 << " Second row selection:\n" << rs2 << "\n";
6266 throw std::runtime_error( oss.str() );
6267 }
6268 }
6269
6270 // isSame with non-matching row selections (repeating rows)
6271 {
6272 auto rs1 = blaze::rows( mat_, { 0UL, 3UL, 1UL } );
6273 auto rs2 = blaze::rows( mat_, { 0UL, 1UL, 1UL } );
6274
6275 if( blaze::isSame( rs1, rs2 ) == true ) {
6276 std::ostringstream oss;
6277 oss << " Test: " << test_ << "\n"
6278 << " Error: Invalid isSame evaluation\n"
6279 << " Details:\n"
6280 << " First row selection:\n" << rs1 << "\n"
6281 << " Second row selection:\n" << rs2 << "\n";
6282 throw std::runtime_error( oss.str() );
6283 }
6284 }
6285 }
6286
6287
6288 //=====================================================================================
6289 // Column-major matrix tests
6290 //=====================================================================================
6291
6292 {
6293 test_ = "Column-major isSame() function";
6294
6295 // isSame with matrix and matching row selection
6296 {
6297 auto rs = blaze::rows( tmat_, { 0UL, 1UL, 2UL, 3UL, 4UL } );
6298
6299 if( blaze::isSame( rs, tmat_ ) == false ) {
6300 std::ostringstream oss;
6301 oss << " Test: " << test_ << "\n"
6302 << " Error: Invalid isSame evaluation\n"
6303 << " Details:\n"
6304 << " Matrix:\n" << tmat_ << "\n"
6305 << " Row selection:\n" << rs << "\n";
6306 throw std::runtime_error( oss.str() );
6307 }
6308
6309 if( blaze::isSame( tmat_, rs ) == false ) {
6310 std::ostringstream oss;
6311 oss << " Test: " << test_ << "\n"
6312 << " Error: Invalid isSame evaluation\n"
6313 << " Details:\n"
6314 << " Matrix:\n" << tmat_ << "\n"
6315 << " Row selection:\n" << rs << "\n";
6316 throw std::runtime_error( oss.str() );
6317 }
6318 }
6319
6320 // isSame with matrix and non-matching row selection (different number of rows)
6321 {
6322 auto rs = blaze::rows( tmat_, { 0UL, 1UL, 2UL, 3UL } );
6323
6324 if( blaze::isSame( rs, tmat_ ) == true ) {
6325 std::ostringstream oss;
6326 oss << " Test: " << test_ << "\n"
6327 << " Error: Invalid isSame evaluation\n"
6328 << " Details:\n"
6329 << " Matrix:\n" << tmat_ << "\n"
6330 << " Row selection:\n" << rs << "\n";
6331 throw std::runtime_error( oss.str() );
6332 }
6333
6334 if( blaze::isSame( tmat_, rs ) == true ) {
6335 std::ostringstream oss;
6336 oss << " Test: " << test_ << "\n"
6337 << " Error: Invalid isSame evaluation\n"
6338 << " Details:\n"
6339 << " Matrix:\n" << tmat_ << "\n"
6340 << " Row selection:\n" << rs << "\n";
6341 throw std::runtime_error( oss.str() );
6342 }
6343 }
6344
6345 // isSame with matrix and non-matching row selection (different order of rows)
6346 {
6347 auto rs = blaze::rows( tmat_, { 0UL, 2UL, 1UL, 3UL, 4UL } );
6348
6349 if( blaze::isSame( rs, tmat_ ) == true ) {
6350 std::ostringstream oss;
6351 oss << " Test: " << test_ << "\n"
6352 << " Error: Invalid isSame evaluation\n"
6353 << " Details:\n"
6354 << " Matrix:\n" << tmat_ << "\n"
6355 << " Row selection:\n" << rs << "\n";
6356 throw std::runtime_error( oss.str() );
6357 }
6358
6359 if( blaze::isSame( tmat_, rs ) == true ) {
6360 std::ostringstream oss;
6361 oss << " Test: " << test_ << "\n"
6362 << " Error: Invalid isSame evaluation\n"
6363 << " Details:\n"
6364 << " Matrix:\n" << tmat_ << "\n"
6365 << " Row selection:\n" << rs << "\n";
6366 throw std::runtime_error( oss.str() );
6367 }
6368 }
6369
6370 // isSame with matrix and non-matching row selection (repeating rows)
6371 {
6372 auto rs = blaze::rows( tmat_, { 0UL, 1UL, 1UL, 3UL, 4UL } );
6373
6374 if( blaze::isSame( rs, tmat_ ) == true ) {
6375 std::ostringstream oss;
6376 oss << " Test: " << test_ << "\n"
6377 << " Error: Invalid isSame evaluation\n"
6378 << " Details:\n"
6379 << " Matrix:\n" << tmat_ << "\n"
6380 << " Row selection:\n" << rs << "\n";
6381 throw std::runtime_error( oss.str() );
6382 }
6383
6384 if( blaze::isSame( tmat_, rs ) == true ) {
6385 std::ostringstream oss;
6386 oss << " Test: " << test_ << "\n"
6387 << " Error: Invalid isSame evaluation\n"
6388 << " Details:\n"
6389 << " Matrix:\n" << tmat_ << "\n"
6390 << " Row selection:\n" << rs << "\n";
6391 throw std::runtime_error( oss.str() );
6392 }
6393 }
6394
6395 // isSame with submatrix and matching row selection
6396 {
6397 auto rs = blaze::rows( tmat_, { 1UL, 2UL, 3UL } );
6398 auto sm = blaze::submatrix( tmat_, 1UL, 0UL, 3UL, 4UL );
6399
6400 if( blaze::isSame( rs, sm ) == false ) {
6401 std::ostringstream oss;
6402 oss << " Test: " << test_ << "\n"
6403 << " Error: Invalid isSame evaluation\n"
6404 << " Details:\n"
6405 << " Submatrix:\n" << sm << "\n"
6406 << " Row selection:\n" << rs << "\n";
6407 throw std::runtime_error( oss.str() );
6408 }
6409
6410 if( blaze::isSame( sm, rs ) == false ) {
6411 std::ostringstream oss;
6412 oss << " Test: " << test_ << "\n"
6413 << " Error: Invalid isSame evaluation\n"
6414 << " Details:\n"
6415 << " Submatrix:\n" << sm << "\n"
6416 << " Row selection:\n" << rs << "\n";
6417 throw std::runtime_error( oss.str() );
6418 }
6419 }
6420
6421 // isSame with submatrix and non-matching row selection (different number of rows)
6422 {
6423 auto rs = blaze::rows( tmat_, { 1UL, 2UL, 3UL } );
6424 auto sm = blaze::submatrix( tmat_, 1UL, 0UL, 2UL, 4UL );
6425
6426 if( blaze::isSame( rs, sm ) == true ) {
6427 std::ostringstream oss;
6428 oss << " Test: " << test_ << "\n"
6429 << " Error: Invalid isSame evaluation\n"
6430 << " Details:\n"
6431 << " Submatrix:\n" << sm << "\n"
6432 << " Row selection:\n" << rs << "\n";
6433 throw std::runtime_error( oss.str() );
6434 }
6435
6436 if( blaze::isSame( sm, rs ) == true ) {
6437 std::ostringstream oss;
6438 oss << " Test: " << test_ << "\n"
6439 << " Error: Invalid isSame evaluation\n"
6440 << " Details:\n"
6441 << " Submatrix:\n" << sm << "\n"
6442 << " Row selection:\n" << rs << "\n";
6443 throw std::runtime_error( oss.str() );
6444 }
6445 }
6446
6447 // isSame with submatrix and non-matching row selection (different number of columns)
6448 {
6449 auto rs = blaze::rows( tmat_, { 1UL, 2UL, 3UL } );
6450 auto sm = blaze::submatrix( tmat_, 1UL, 0UL, 3UL, 3UL );
6451
6452 if( blaze::isSame( rs, sm ) == true ) {
6453 std::ostringstream oss;
6454 oss << " Test: " << test_ << "\n"
6455 << " Error: Invalid isSame evaluation\n"
6456 << " Details:\n"
6457 << " Submatrix:\n" << sm << "\n"
6458 << " Row selection:\n" << rs << "\n";
6459 throw std::runtime_error( oss.str() );
6460 }
6461
6462 if( blaze::isSame( sm, rs ) == true ) {
6463 std::ostringstream oss;
6464 oss << " Test: " << test_ << "\n"
6465 << " Error: Invalid isSame evaluation\n"
6466 << " Details:\n"
6467 << " Submatrix:\n" << sm << "\n"
6468 << " Row selection:\n" << rs << "\n";
6469 throw std::runtime_error( oss.str() );
6470 }
6471 }
6472
6473 // isSame with submatrix and non-matching row selection (different order of rows)
6474 {
6475 auto rs = blaze::rows( tmat_, { 1UL, 3UL, 2UL } );
6476 auto sm = blaze::submatrix( tmat_, 1UL, 0UL, 3UL, 4UL );
6477
6478 if( blaze::isSame( rs, sm ) == true ) {
6479 std::ostringstream oss;
6480 oss << " Test: " << test_ << "\n"
6481 << " Error: Invalid isSame evaluation\n"
6482 << " Details:\n"
6483 << " Submatrix:\n" << sm << "\n"
6484 << " Row selection:\n" << rs << "\n";
6485 throw std::runtime_error( oss.str() );
6486 }
6487
6488 if( blaze::isSame( sm, rs ) == true ) {
6489 std::ostringstream oss;
6490 oss << " Test: " << test_ << "\n"
6491 << " Error: Invalid isSame evaluation\n"
6492 << " Details:\n"
6493 << " Submatrix:\n" << sm << "\n"
6494 << " Row selection:\n" << rs << "\n";
6495 throw std::runtime_error( oss.str() );
6496 }
6497 }
6498
6499 // isSame with submatrix and non-matching row selection (repeating rows)
6500 {
6501 auto rs = blaze::rows( tmat_, { 1UL, 3UL, 3UL } );
6502 auto sm = blaze::submatrix( tmat_, 1UL, 0UL, 3UL, 4UL );
6503
6504 if( blaze::isSame( rs, sm ) == true ) {
6505 std::ostringstream oss;
6506 oss << " Test: " << test_ << "\n"
6507 << " Error: Invalid isSame evaluation\n"
6508 << " Details:\n"
6509 << " Submatrix:\n" << sm << "\n"
6510 << " Row selection:\n" << rs << "\n";
6511 throw std::runtime_error( oss.str() );
6512 }
6513
6514 if( blaze::isSame( sm, rs ) == true ) {
6515 std::ostringstream oss;
6516 oss << " Test: " << test_ << "\n"
6517 << " Error: Invalid isSame evaluation\n"
6518 << " Details:\n"
6519 << " Submatrix:\n" << sm << "\n"
6520 << " Row selection:\n" << rs << "\n";
6521 throw std::runtime_error( oss.str() );
6522 }
6523 }
6524
6525 // isSame with submatrix and non-matching row selection (different row index)
6526 {
6527 auto rs = blaze::rows( tmat_, { 1UL, 2UL, 3UL } );
6528 auto sm = blaze::submatrix( tmat_, 2UL, 0UL, 3UL, 4UL );
6529
6530 if( blaze::isSame( rs, sm ) == true ) {
6531 std::ostringstream oss;
6532 oss << " Test: " << test_ << "\n"
6533 << " Error: Invalid isSame evaluation\n"
6534 << " Details:\n"
6535 << " Submatrix:\n" << sm << "\n"
6536 << " Row selection:\n" << rs << "\n";
6537 throw std::runtime_error( oss.str() );
6538 }
6539
6540 if( blaze::isSame( sm, rs ) == true ) {
6541 std::ostringstream oss;
6542 oss << " Test: " << test_ << "\n"
6543 << " Error: Invalid isSame evaluation\n"
6544 << " Details:\n"
6545 << " Submatrix:\n" << sm << "\n"
6546 << " Row selection:\n" << rs << "\n";
6547 throw std::runtime_error( oss.str() );
6548 }
6549 }
6550
6551 // isSame with matching row selections
6552 {
6553 auto rs1 = blaze::rows( tmat_, { 0UL, 3UL, 1UL } );
6554 auto rs2 = blaze::rows( tmat_, { 0UL, 3UL, 1UL } );
6555
6556 if( blaze::isSame( rs1, rs2 ) == false ) {
6557 std::ostringstream oss;
6558 oss << " Test: " << test_ << "\n"
6559 << " Error: Invalid isSame evaluation\n"
6560 << " Details:\n"
6561 << " First row selection:\n" << rs1 << "\n"
6562 << " Second row selection:\n" << rs2 << "\n";
6563 throw std::runtime_error( oss.str() );
6564 }
6565 }
6566
6567 // isSame with non-matching row selections (different number of rows)
6568 {
6569 auto rs1 = blaze::rows( tmat_, { 0UL, 3UL, 1UL } );
6570 auto rs2 = blaze::rows( tmat_, { 0UL, 3UL, 1UL, 2UL } );
6571
6572 if( blaze::isSame( rs1, rs2 ) == true ) {
6573 std::ostringstream oss;
6574 oss << " Test: " << test_ << "\n"
6575 << " Error: Invalid isSame evaluation\n"
6576 << " Details:\n"
6577 << " First row selection:\n" << rs1 << "\n"
6578 << " Second row selection:\n" << rs2 << "\n";
6579 throw std::runtime_error( oss.str() );
6580 }
6581 }
6582
6583 // isSame with non-matching row selections (different order of rows)
6584 {
6585 auto rs1 = blaze::rows( tmat_, { 0UL, 3UL, 1UL } );
6586 auto rs2 = blaze::rows( tmat_, { 0UL, 1UL, 3UL } );
6587
6588 if( blaze::isSame( rs1, rs2 ) == true ) {
6589 std::ostringstream oss;
6590 oss << " Test: " << test_ << "\n"
6591 << " Error: Invalid isSame evaluation\n"
6592 << " Details:\n"
6593 << " First row selection:\n" << rs1 << "\n"
6594 << " Second row selection:\n" << rs2 << "\n";
6595 throw std::runtime_error( oss.str() );
6596 }
6597 }
6598
6599 // isSame with non-matching row selections (repeating rows)
6600 {
6601 auto rs1 = blaze::rows( tmat_, { 0UL, 3UL, 1UL } );
6602 auto rs2 = blaze::rows( tmat_, { 0UL, 1UL, 1UL } );
6603
6604 if( blaze::isSame( rs1, rs2 ) == true ) {
6605 std::ostringstream oss;
6606 oss << " Test: " << test_ << "\n"
6607 << " Error: Invalid isSame evaluation\n"
6608 << " Details:\n"
6609 << " First row selection:\n" << rs1 << "\n"
6610 << " Second row selection:\n" << rs2 << "\n";
6611 throw std::runtime_error( oss.str() );
6612 }
6613 }
6614 }
6615 }
6616 //*************************************************************************************************
6617
6618
6619 //*************************************************************************************************
6620 /*!\brief Test of the \c blaze::submatrix() function with the Rows class template.
6621 //
6622 // \return void
6623 // \exception std::runtime_error Error detected.
6624 //
6625 // This function performs a test of the \c blaze::submatrix() function with the Rows
6626 // specialization. In case an error is detected, a \a std::runtime_error exception is thrown.
6627 */
testSubmatrix()6628 void SparseGeneralTest::testSubmatrix()
6629 {
6630 //=====================================================================================
6631 // Row-major matrix tests
6632 //=====================================================================================
6633
6634 {
6635 test_ = "Row-major submatrix() function";
6636
6637 initialize();
6638
6639 {
6640 auto rs = blaze::rows( mat_, { 3UL, 1UL, 4UL } );
6641 auto sm = blaze::submatrix( rs, 0UL, 1UL, 3UL, 2UL );
6642
6643 if( sm(0,0) != 4 || sm(0,1) != 5 ||
6644 sm(1,0) != 1 || sm(1,1) != 0 ||
6645 sm(2,0) != -8 || sm(2,1) != 9 ) {
6646 std::ostringstream oss;
6647 oss << " Test: " << test_ << "\n"
6648 << " Error: Function call operator access failed\n"
6649 << " Details:\n"
6650 << " Result:\n" << sm << "\n"
6651 << " Expected result:\n( 4 5 )\n"
6652 "( 1 0 )\n"
6653 "( -8 9 )\n";
6654 throw std::runtime_error( oss.str() );
6655 }
6656
6657 if( sm.begin(1UL)->value() != 1 ) {
6658 std::ostringstream oss;
6659 oss << " Test: " << test_ << "\n"
6660 << " Error: Iterator access failed\n"
6661 << " Details:\n"
6662 << " Result: " << sm.begin(1UL)->value() << "\n"
6663 << " Expected result: 1\n";
6664 throw std::runtime_error( oss.str() );
6665 }
6666 }
6667
6668 try {
6669 auto rs = blaze::rows( mat_, { 3UL, 1UL, 4UL } );
6670 auto sm = blaze::submatrix( rs, 3UL, 1UL, 3UL, 2UL );
6671
6672 std::ostringstream oss;
6673 oss << " Test: " << test_ << "\n"
6674 << " Error: Setup of out-of-bounds submatrix succeeded\n"
6675 << " Details:\n"
6676 << " Result:\n" << sm << "\n";
6677 throw std::runtime_error( oss.str() );
6678 }
6679 catch( std::invalid_argument& ) {}
6680
6681 try {
6682 auto rs = blaze::rows( mat_, { 3UL, 1UL, 4UL } );
6683 auto sm = blaze::submatrix( rs, 0UL, 4UL, 3UL, 2UL );
6684
6685 std::ostringstream oss;
6686 oss << " Test: " << test_ << "\n"
6687 << " Error: Setup of out-of-bounds submatrix succeeded\n"
6688 << " Details:\n"
6689 << " Result:\n" << sm << "\n";
6690 throw std::runtime_error( oss.str() );
6691 }
6692 catch( std::invalid_argument& ) {}
6693
6694 try {
6695 auto rs = blaze::rows( mat_, { 3UL, 1UL, 4UL } );
6696 auto sm = blaze::submatrix( rs, 0UL, 1UL, 4UL, 2UL );
6697
6698 std::ostringstream oss;
6699 oss << " Test: " << test_ << "\n"
6700 << " Error: Setup of out-of-bounds submatrix succeeded\n"
6701 << " Details:\n"
6702 << " Result:\n" << sm << "\n";
6703 throw std::runtime_error( oss.str() );
6704 }
6705 catch( std::invalid_argument& ) {}
6706
6707 try {
6708 auto rs = blaze::rows( mat_, { 3UL, 1UL, 4UL } );
6709 auto sm = blaze::submatrix( rs, 0UL, 1UL, 3UL, 4UL );
6710
6711 std::ostringstream oss;
6712 oss << " Test: " << test_ << "\n"
6713 << " Error: Setup of out-of-bounds submatrix succeeded\n"
6714 << " Details:\n"
6715 << " Result:\n" << sm << "\n";
6716 throw std::runtime_error( oss.str() );
6717 }
6718 catch( std::invalid_argument& ) {}
6719 }
6720
6721
6722 //=====================================================================================
6723 // Column-major matrix tests
6724 //=====================================================================================
6725
6726 {
6727 test_ = "Column-major submatrix() function";
6728
6729 initialize();
6730
6731 {
6732 auto rs = blaze::rows( tmat_, { 3UL, 1UL, 4UL } );
6733 auto sm = blaze::submatrix( rs, 0UL, 1UL, 3UL, 2UL );
6734
6735 if( sm(0,0) != 4 || sm(0,1) != 5 ||
6736 sm(1,0) != 1 || sm(1,1) != 0 ||
6737 sm(2,0) != -8 || sm(2,1) != 9 ) {
6738 std::ostringstream oss;
6739 oss << " Test: " << test_ << "\n"
6740 << " Error: Function call operator access failed\n"
6741 << " Details:\n"
6742 << " Result:\n" << sm << "\n"
6743 << " Expected result:\n( 4 5 )\n"
6744 "( 1 0 )\n"
6745 "( -8 9 )\n";
6746 throw std::runtime_error( oss.str() );
6747 }
6748
6749 if( sm.begin(1UL)->value() != 1 ) {
6750 std::ostringstream oss;
6751 oss << " Test: " << test_ << "\n"
6752 << " Error: Iterator access failed\n"
6753 << " Details:\n"
6754 << " Result: " << sm.begin(1UL)->value() << "\n"
6755 << " Expected result: 1\n";
6756 throw std::runtime_error( oss.str() );
6757 }
6758 }
6759
6760 try {
6761 auto rs = blaze::rows( tmat_, { 3UL, 1UL, 4UL } );
6762 auto sm = blaze::submatrix( rs, 3UL, 1UL, 3UL, 2UL );
6763
6764 std::ostringstream oss;
6765 oss << " Test: " << test_ << "\n"
6766 << " Error: Setup of out-of-bounds submatrix succeeded\n"
6767 << " Details:\n"
6768 << " Result:\n" << sm << "\n";
6769 throw std::runtime_error( oss.str() );
6770 }
6771 catch( std::invalid_argument& ) {}
6772
6773 try {
6774 auto rs = blaze::rows( tmat_, { 3UL, 1UL, 4UL } );
6775 auto sm = blaze::submatrix( rs, 0UL, 4UL, 3UL, 2UL );
6776
6777 std::ostringstream oss;
6778 oss << " Test: " << test_ << "\n"
6779 << " Error: Setup of out-of-bounds submatrix succeeded\n"
6780 << " Details:\n"
6781 << " Result:\n" << sm << "\n";
6782 throw std::runtime_error( oss.str() );
6783 }
6784 catch( std::invalid_argument& ) {}
6785
6786 try {
6787 auto rs = blaze::rows( tmat_, { 3UL, 1UL, 4UL } );
6788 auto sm = blaze::submatrix( rs, 0UL, 1UL, 4UL, 2UL );
6789
6790 std::ostringstream oss;
6791 oss << " Test: " << test_ << "\n"
6792 << " Error: Setup of out-of-bounds submatrix succeeded\n"
6793 << " Details:\n"
6794 << " Result:\n" << sm << "\n";
6795 throw std::runtime_error( oss.str() );
6796 }
6797 catch( std::invalid_argument& ) {}
6798
6799 try {
6800 auto rs = blaze::rows( tmat_, { 3UL, 1UL, 4UL } );
6801 auto sm = blaze::submatrix( rs, 0UL, 1UL, 3UL, 4UL );
6802
6803 std::ostringstream oss;
6804 oss << " Test: " << test_ << "\n"
6805 << " Error: Setup of out-of-bounds submatrix succeeded\n"
6806 << " Details:\n"
6807 << " Result:\n" << sm << "\n";
6808 throw std::runtime_error( oss.str() );
6809 }
6810 catch( std::invalid_argument& ) {}
6811 }
6812 }
6813 //*************************************************************************************************
6814
6815
6816 //*************************************************************************************************
6817 /*!\brief Test of the \c row() function with the Rows class template.
6818 //
6819 // \return void
6820 // \exception std::runtime_error Error detected.
6821 //
6822 // This function performs a test of the \c row() function with the Rows specialization.
6823 // In case an error is detected, a \a std::runtime_error exception is thrown.
6824 */
testRow()6825 void SparseGeneralTest::testRow()
6826 {
6827 //=====================================================================================
6828 // Row-major matrix tests
6829 //=====================================================================================
6830
6831 {
6832 test_ = "Row-major row() function";
6833
6834 initialize();
6835
6836 {
6837 auto rs = blaze::rows( mat_, { 3UL, 1UL, 4UL } );
6838 auto row1 = row( rs, 1UL );
6839
6840 if( row1[0] != 0 || row1[1] != 1 || row1[2] != 0 || row1[3] != 0 ) {
6841 std::ostringstream oss;
6842 oss << " Test: " << test_ << "\n"
6843 << " Error: Subscript operator access failed\n"
6844 << " Details:\n"
6845 << " Result:\n" << row1 << "\n"
6846 << " Expected result:\n( 0 1 0 0 )\n";
6847 throw std::runtime_error( oss.str() );
6848 }
6849
6850 if( row1.begin()->value() != 1 ) {
6851 std::ostringstream oss;
6852 oss << " Test: " << test_ << "\n"
6853 << " Error: Iterator access failed\n"
6854 << " Details:\n"
6855 << " Result: " << row1.begin()->value() << "\n"
6856 << " Expected result: 1\n";
6857 throw std::runtime_error( oss.str() );
6858 }
6859 }
6860
6861 try {
6862 auto rs = blaze::rows( mat_, { 3UL, 1UL, 4UL } );
6863 auto row3 = blaze::row( rs, 3UL );
6864
6865 std::ostringstream oss;
6866 oss << " Test: " << test_ << "\n"
6867 << " Error: Setup of out-of-bounds row succeeded\n"
6868 << " Details:\n"
6869 << " Result:\n" << row3 << "\n";
6870 throw std::runtime_error( oss.str() );
6871 }
6872 catch( std::invalid_argument& ) {}
6873 }
6874
6875
6876 //=====================================================================================
6877 // Column-major matrix tests
6878 //=====================================================================================
6879
6880 {
6881 test_ = "Column-major row() function";
6882
6883 initialize();
6884
6885 {
6886 auto rs = blaze::rows( tmat_, { 3UL, 1UL, 4UL } );
6887 auto row1 = row( rs, 1UL );
6888
6889 if( row1[0] != 0 || row1[1] != 1 || row1[2] != 0 || row1[3] != 0 ) {
6890 std::ostringstream oss;
6891 oss << " Test: " << test_ << "\n"
6892 << " Error: Subscript operator access failed\n"
6893 << " Details:\n"
6894 << " Result:\n" << row1 << "\n"
6895 << " Expected result:\n( 0 1 0 0 )\n";
6896 throw std::runtime_error( oss.str() );
6897 }
6898
6899 if( row1.begin()->value() != 1 ) {
6900 std::ostringstream oss;
6901 oss << " Test: " << test_ << "\n"
6902 << " Error: Iterator access failed\n"
6903 << " Details:\n"
6904 << " Result: " << row1.begin()->value() << "\n"
6905 << " Expected result: 1\n";
6906 throw std::runtime_error( oss.str() );
6907 }
6908 }
6909
6910 try {
6911 auto rs = blaze::rows( mat_, { 3UL, 1UL, 4UL } );
6912 auto row3 = blaze::row( rs, 3UL );
6913
6914 std::ostringstream oss;
6915 oss << " Test: " << test_ << "\n"
6916 << " Error: Setup of out-of-bounds row succeeded\n"
6917 << " Details:\n"
6918 << " Result:\n" << row3 << "\n";
6919 throw std::runtime_error( oss.str() );
6920 }
6921 catch( std::invalid_argument& ) {}
6922 }
6923 }
6924 //*************************************************************************************************
6925
6926
6927 //*************************************************************************************************
6928 /*!\brief Test of the \c rows() function with the Rows class template.
6929 //
6930 // \return void
6931 // \exception std::runtime_error Error detected.
6932 //
6933 // This function performs a test of the \c rows() function with the Rows specialization.
6934 // In case an error is detected, a \a std::runtime_error exception is thrown.
6935 */
testRows()6936 void SparseGeneralTest::testRows()
6937 {
6938 //=====================================================================================
6939 // Row-major matrix tests (initializer_list)
6940 //=====================================================================================
6941
6942 {
6943 test_ = "Row-major rows() function (initializer_list)";
6944
6945 initialize();
6946
6947 {
6948 auto rs1 = blaze::rows( mat_, { 3UL, 1UL, 4UL } );
6949 auto rs2 = blaze::rows( rs1, { 1UL, 0UL, 2UL } );
6950
6951 if( rs2(0,0) != 0 || rs2(0,1) != 1 || rs2(0,2) != 0 || rs2(0,3) != 0 ||
6952 rs2(1,0) != 0 || rs2(1,1) != 4 || rs2(1,2) != 5 || rs2(1,3) != -6 ||
6953 rs2(2,0) != 7 || rs2(2,1) != -8 || rs2(2,2) != 9 || rs2(2,3) != 10 ) {
6954 std::ostringstream oss;
6955 oss << " Test: " << test_ << "\n"
6956 << " Error: Function call operator access failed\n"
6957 << " Details:\n"
6958 << " Result:\n" << rs2 << "\n"
6959 << " Expected result:\n( 0 1 0 0 )\n( 0 4 5 -6 )\n( 7 -8 9 10 )\n";
6960 throw std::runtime_error( oss.str() );
6961 }
6962
6963 if( rs2.begin( 2UL )->value() != 7 ) {
6964 std::ostringstream oss;
6965 oss << " Test: " << test_ << "\n"
6966 << " Error: Iterator access failed\n"
6967 << " Details:\n"
6968 << " Result: " << rs2.begin( 2UL )->value() << "\n"
6969 << " Expected result: 7\n";
6970 throw std::runtime_error( oss.str() );
6971 }
6972 }
6973
6974 try {
6975 auto rs1 = blaze::rows( mat_, { 3UL, 1UL, 4UL } );
6976 auto rs2 = blaze::rows( rs1, { 3UL } );
6977
6978 std::ostringstream oss;
6979 oss << " Test: " << test_ << "\n"
6980 << " Error: Setup of out-of-bounds row selection succeeded\n"
6981 << " Details:\n"
6982 << " Result:\n" << rs2 << "\n";
6983 throw std::runtime_error( oss.str() );
6984 }
6985 catch( std::invalid_argument& ) {}
6986 }
6987
6988
6989 //=====================================================================================
6990 // Row-major matrix tests (std::array)
6991 //=====================================================================================
6992
6993 {
6994 test_ = "Row-major rows() function (std::array)";
6995
6996 initialize();
6997
6998 {
6999 std::array<int,3UL> indices{ 1UL, 0UL, 2UL };
7000
7001 auto rs1 = blaze::rows( mat_, { 3UL, 1UL, 4UL } );
7002 auto rs2 = blaze::rows( rs1, indices );
7003
7004 if( rs2(0,0) != 0 || rs2(0,1) != 1 || rs2(0,2) != 0 || rs2(0,3) != 0 ||
7005 rs2(1,0) != 0 || rs2(1,1) != 4 || rs2(1,2) != 5 || rs2(1,3) != -6 ||
7006 rs2(2,0) != 7 || rs2(2,1) != -8 || rs2(2,2) != 9 || rs2(2,3) != 10 ) {
7007 std::ostringstream oss;
7008 oss << " Test: " << test_ << "\n"
7009 << " Error: Function call operator access failed\n"
7010 << " Details:\n"
7011 << " Result:\n" << rs2 << "\n"
7012 << " Expected result:\n( 0 1 0 0 )\n( 0 4 5 -6 )\n( 7 -8 9 10 )\n";
7013 throw std::runtime_error( oss.str() );
7014 }
7015
7016 if( rs2.begin( 2UL )->value() != 7 ) {
7017 std::ostringstream oss;
7018 oss << " Test: " << test_ << "\n"
7019 << " Error: Iterator access failed\n"
7020 << " Details:\n"
7021 << " Result: " << rs2.begin( 2UL )->value() << "\n"
7022 << " Expected result: 7\n";
7023 throw std::runtime_error( oss.str() );
7024 }
7025 }
7026
7027 try {
7028 std::array<int,1UL> indices{ 3UL };
7029
7030 auto rs1 = blaze::rows( mat_, { 3UL, 1UL, 4UL } );
7031 auto rs2 = blaze::rows( rs1, indices );
7032
7033 std::ostringstream oss;
7034 oss << " Test: " << test_ << "\n"
7035 << " Error: Setup of out-of-bounds row selection succeeded\n"
7036 << " Details:\n"
7037 << " Result:\n" << rs2 << "\n";
7038 throw std::runtime_error( oss.str() );
7039 }
7040 catch( std::invalid_argument& ) {}
7041 }
7042
7043
7044 //=====================================================================================
7045 // Row-major matrix tests (lambda expression)
7046 //=====================================================================================
7047
7048 {
7049 test_ = "Row-major rows() function (lambda expression)";
7050
7051 initialize();
7052
7053 {
7054 auto rs1 = blaze::rows( mat_, { 3UL, 1UL, 4UL } );
7055 auto rs2 = blaze::rows( rs1, []( size_t i ){ return (4UL-i)%3UL; }, 3UL );
7056
7057 if( rs2(0,0) != 0 || rs2(0,1) != 1 || rs2(0,2) != 0 || rs2(0,3) != 0 ||
7058 rs2(1,0) != 0 || rs2(1,1) != 4 || rs2(1,2) != 5 || rs2(1,3) != -6 ||
7059 rs2(2,0) != 7 || rs2(2,1) != -8 || rs2(2,2) != 9 || rs2(2,3) != 10 ) {
7060 std::ostringstream oss;
7061 oss << " Test: " << test_ << "\n"
7062 << " Error: Function call operator access failed\n"
7063 << " Details:\n"
7064 << " Result:\n" << rs2 << "\n"
7065 << " Expected result:\n( 0 1 0 0 )\n( 0 4 5 -6 )\n( 7 -8 9 10 )\n";
7066 throw std::runtime_error( oss.str() );
7067 }
7068
7069 if( rs2.begin( 2UL )->value() != 7 ) {
7070 std::ostringstream oss;
7071 oss << " Test: " << test_ << "\n"
7072 << " Error: Iterator access failed\n"
7073 << " Details:\n"
7074 << " Result: " << rs2.begin( 2UL )->value() << "\n"
7075 << " Expected result: 7\n";
7076 throw std::runtime_error( oss.str() );
7077 }
7078 }
7079
7080 try {
7081 auto rs1 = blaze::rows( mat_, { 3UL, 1UL, 4UL } );
7082 auto rs2 = blaze::rows( rs1, []( size_t ){ return 3UL; }, 1UL );
7083
7084 std::ostringstream oss;
7085 oss << " Test: " << test_ << "\n"
7086 << " Error: Setup of out-of-bounds row selection succeeded\n"
7087 << " Details:\n"
7088 << " Result:\n" << rs2 << "\n";
7089 throw std::runtime_error( oss.str() );
7090 }
7091 catch( std::invalid_argument& ) {}
7092 }
7093
7094
7095 //=====================================================================================
7096 // Column-major matrix tests (initializer_list)
7097 //=====================================================================================
7098
7099 {
7100 test_ = "Column-major rows() function (initializer_list)";
7101
7102 initialize();
7103
7104 {
7105 auto rs1 = blaze::rows( tmat_, { 3UL, 1UL, 4UL } );
7106 auto rs2 = blaze::rows( rs1, { 1UL, 0UL, 2UL } );
7107
7108 if( rs2(0,0) != 0 || rs2(0,1) != 1 || rs2(0,2) != 0 || rs2(0,3) != 0 ||
7109 rs2(1,0) != 0 || rs2(1,1) != 4 || rs2(1,2) != 5 || rs2(1,3) != -6 ||
7110 rs2(2,0) != 7 || rs2(2,1) != -8 || rs2(2,2) != 9 || rs2(2,3) != 10 ) {
7111 std::ostringstream oss;
7112 oss << " Test: " << test_ << "\n"
7113 << " Error: Function call operator access failed\n"
7114 << " Details:\n"
7115 << " Result:\n" << rs2 << "\n"
7116 << " Expected result:\n( 0 1 0 0 )\n( 0 4 5 -6 )\n( 7 -8 9 10 )\n";
7117 throw std::runtime_error( oss.str() );
7118 }
7119
7120 if( rs2.begin( 2UL )->value() != 7 ) {
7121 std::ostringstream oss;
7122 oss << " Test: " << test_ << "\n"
7123 << " Error: Iterator access failed\n"
7124 << " Details:\n"
7125 << " Result: " << rs2.begin( 2UL )->value() << "\n"
7126 << " Expected result: 7\n";
7127 throw std::runtime_error( oss.str() );
7128 }
7129 }
7130
7131 try {
7132 auto rs1 = blaze::rows( tmat_, { 3UL, 1UL, 4UL } );
7133 auto rs2 = blaze::rows( rs1, { 3UL } );
7134
7135 std::ostringstream oss;
7136 oss << " Test: " << test_ << "\n"
7137 << " Error: Setup of out-of-bounds row selection succeeded\n"
7138 << " Details:\n"
7139 << " Result:\n" << rs2 << "\n";
7140 throw std::runtime_error( oss.str() );
7141 }
7142 catch( std::invalid_argument& ) {}
7143 }
7144
7145
7146 //=====================================================================================
7147 // Column-major matrix tests (std::array)
7148 //=====================================================================================
7149
7150 {
7151 test_ = "Column-major rows() function (std::array)";
7152
7153 initialize();
7154
7155 {
7156 std::array<int,3UL> indices{ 1UL, 0UL, 2UL };
7157
7158 auto rs1 = blaze::rows( tmat_, { 3UL, 1UL, 4UL } );
7159 auto rs2 = blaze::rows( rs1, indices );
7160
7161 if( rs2(0,0) != 0 || rs2(0,1) != 1 || rs2(0,2) != 0 || rs2(0,3) != 0 ||
7162 rs2(1,0) != 0 || rs2(1,1) != 4 || rs2(1,2) != 5 || rs2(1,3) != -6 ||
7163 rs2(2,0) != 7 || rs2(2,1) != -8 || rs2(2,2) != 9 || rs2(2,3) != 10 ) {
7164 std::ostringstream oss;
7165 oss << " Test: " << test_ << "\n"
7166 << " Error: Function call operator access failed\n"
7167 << " Details:\n"
7168 << " Result:\n" << rs2 << "\n"
7169 << " Expected result:\n( 0 1 0 0 )\n( 0 4 5 -6 )\n( 7 -8 9 10 )\n";
7170 throw std::runtime_error( oss.str() );
7171 }
7172
7173 if( rs2.begin( 2UL )->value() != 7 ) {
7174 std::ostringstream oss;
7175 oss << " Test: " << test_ << "\n"
7176 << " Error: Iterator access failed\n"
7177 << " Details:\n"
7178 << " Result: " << rs2.begin( 2UL )->value() << "\n"
7179 << " Expected result: 7\n";
7180 throw std::runtime_error( oss.str() );
7181 }
7182 }
7183
7184 try {
7185 std::array<int,1UL> indices{ 3UL };
7186
7187 auto rs1 = blaze::rows( tmat_, { 3UL, 1UL, 4UL } );
7188 auto rs2 = blaze::rows( rs1, indices );
7189
7190 std::ostringstream oss;
7191 oss << " Test: " << test_ << "\n"
7192 << " Error: Setup of out-of-bounds row selection succeeded\n"
7193 << " Details:\n"
7194 << " Result:\n" << rs2 << "\n";
7195 throw std::runtime_error( oss.str() );
7196 }
7197 catch( std::invalid_argument& ) {}
7198 }
7199
7200
7201 //=====================================================================================
7202 // Column-major matrix tests (lambda expression)
7203 //=====================================================================================
7204
7205 {
7206 test_ = "Column-major rows() function (lambda expression)";
7207
7208 initialize();
7209
7210 {
7211 auto rs1 = blaze::rows( tmat_, { 3UL, 1UL, 4UL } );
7212 auto rs2 = blaze::rows( rs1, []( size_t i ){ return (4UL-i)%3UL; }, 3UL );
7213
7214 if( rs2(0,0) != 0 || rs2(0,1) != 1 || rs2(0,2) != 0 || rs2(0,3) != 0 ||
7215 rs2(1,0) != 0 || rs2(1,1) != 4 || rs2(1,2) != 5 || rs2(1,3) != -6 ||
7216 rs2(2,0) != 7 || rs2(2,1) != -8 || rs2(2,2) != 9 || rs2(2,3) != 10 ) {
7217 std::ostringstream oss;
7218 oss << " Test: " << test_ << "\n"
7219 << " Error: Function call operator access failed\n"
7220 << " Details:\n"
7221 << " Result:\n" << rs2 << "\n"
7222 << " Expected result:\n( 0 1 0 0 )\n( 0 4 5 -6 )\n( 7 -8 9 10 )\n";
7223 throw std::runtime_error( oss.str() );
7224 }
7225
7226 if( rs2.begin( 2UL )->value() != 7 ) {
7227 std::ostringstream oss;
7228 oss << " Test: " << test_ << "\n"
7229 << " Error: Iterator access failed\n"
7230 << " Details:\n"
7231 << " Result: " << rs2.begin( 2UL )->value() << "\n"
7232 << " Expected result: 7\n";
7233 throw std::runtime_error( oss.str() );
7234 }
7235 }
7236
7237 try {
7238 auto rs1 = blaze::rows( tmat_, { 3UL, 1UL, 4UL } );
7239 auto rs2 = blaze::rows( rs1, []( size_t ){ return 3UL; }, 1UL );
7240
7241 std::ostringstream oss;
7242 oss << " Test: " << test_ << "\n"
7243 << " Error: Setup of out-of-bounds row selection succeeded\n"
7244 << " Details:\n"
7245 << " Result:\n" << rs2 << "\n";
7246 throw std::runtime_error( oss.str() );
7247 }
7248 catch( std::invalid_argument& ) {}
7249 }
7250 }
7251 //*************************************************************************************************
7252
7253
7254 //*************************************************************************************************
7255 /*!\brief Test of the \c column() function with the Rows class template.
7256 //
7257 // \return void
7258 // \exception std::runtime_error Error detected.
7259 //
7260 // This function performs a test of the \c column() function with the Rows specialization.
7261 // In case an error is detected, a \a std::runtime_error exception is thrown.
7262 */
testColumn()7263 void SparseGeneralTest::testColumn()
7264 {
7265 //=====================================================================================
7266 // Row-major matrix tests
7267 //=====================================================================================
7268
7269 {
7270 test_ = "Row-major column() function";
7271
7272 initialize();
7273
7274 {
7275 auto rs = blaze::rows( mat_, { 3UL, 1UL, 4UL } );
7276 auto col1 = blaze::column( rs, 1UL );
7277
7278 if( col1[0] != 4 || col1[1] != 1 || col1[2] != -8 ) {
7279 std::ostringstream oss;
7280 oss << " Test: " << test_ << "\n"
7281 << " Error: Subscript operator access failed\n"
7282 << " Details:\n"
7283 << " Result:\n" << col1 << "\n"
7284 << " Expected result:\n( 4 1 -8 )\n";
7285 throw std::runtime_error( oss.str() );
7286 }
7287
7288 if( col1.begin()->value() != 4 ) {
7289 std::ostringstream oss;
7290 oss << " Test: " << test_ << "\n"
7291 << " Error: Iterator access failed\n"
7292 << " Details:\n"
7293 << " Result: " << col1.begin()->value() << "\n"
7294 << " Expected result: 4\n";
7295 throw std::runtime_error( oss.str() );
7296 }
7297 }
7298
7299 try {
7300 auto rs = blaze::rows( mat_, { 3UL, 1UL, 4UL } );
7301 auto col4 = blaze::column( rs, 4UL );
7302
7303 std::ostringstream oss;
7304 oss << " Test: " << test_ << "\n"
7305 << " Error: Setup of out-of-bounds column succeeded\n"
7306 << " Details:\n"
7307 << " Result:\n" << col4 << "\n";
7308 throw std::runtime_error( oss.str() );
7309 }
7310 catch( std::invalid_argument& ) {}
7311 }
7312
7313
7314 //=====================================================================================
7315 // Column-major matrix tests
7316 //=====================================================================================
7317
7318 {
7319 test_ = "Column-major column() function";
7320
7321 initialize();
7322
7323 {
7324 auto rs = blaze::rows( tmat_, { 3UL, 1UL, 4UL } );
7325 auto col1 = blaze::column( rs, 1UL );
7326
7327 if( col1[0] != 4 || col1[1] != 1 || col1[2] != -8 ) {
7328 std::ostringstream oss;
7329 oss << " Test: " << test_ << "\n"
7330 << " Error: Subscript operator access failed\n"
7331 << " Details:\n"
7332 << " Result:\n" << col1 << "\n"
7333 << " Expected result:\n( 4 1 -8 )\n";
7334 throw std::runtime_error( oss.str() );
7335 }
7336
7337 if( col1.begin()->value() != 4 ) {
7338 std::ostringstream oss;
7339 oss << " Test: " << test_ << "\n"
7340 << " Error: Iterator access failed\n"
7341 << " Details:\n"
7342 << " Result: " << col1.begin()->value() << "\n"
7343 << " Expected result: 4\n";
7344 throw std::runtime_error( oss.str() );
7345 }
7346 }
7347
7348 try {
7349 auto rs = blaze::rows( tmat_, { 3UL, 1UL, 4UL } );
7350 auto col4 = blaze::column( rs, 4UL );
7351
7352 std::ostringstream oss;
7353 oss << " Test: " << test_ << "\n"
7354 << " Error: Setup of out-of-bounds column succeeded\n"
7355 << " Details:\n"
7356 << " Result:\n" << col4 << "\n";
7357 throw std::runtime_error( oss.str() );
7358 }
7359 catch( std::invalid_argument& ) {}
7360 }
7361 }
7362 //*************************************************************************************************
7363
7364
7365 //*************************************************************************************************
7366 /*!\brief Test of the \c columns() function with the Rows class template.
7367 //
7368 // \return void
7369 // \exception std::runtime_error Error detected.
7370 //
7371 // This function performs a test of the \c columns() function with the Rows specialization.
7372 // In case an error is detected, a \a std::runtime_error exception is thrown.
7373 */
testColumns()7374 void SparseGeneralTest::testColumns()
7375 {
7376 //=====================================================================================
7377 // Row-major matrix tests (initializer_list)
7378 //=====================================================================================
7379
7380 {
7381 test_ = "Row-major columns() function (initializer_list)";
7382
7383 initialize();
7384
7385 {
7386 auto rs = blaze::rows( mat_, { 3UL, 1UL, 4UL } );
7387 auto cs = blaze::columns( rs, { 1UL, 0UL, 2UL } );
7388
7389 if( cs(0,0) != 4 || cs(0,1) != 0 || cs(0,2) != 5 ||
7390 cs(1,0) != 1 || cs(1,1) != 0 || cs(1,2) != 0 ||
7391 cs(2,0) != -8 || cs(2,1) != 7 || cs(2,2) != 9 ) {
7392 std::ostringstream oss;
7393 oss << " Test: " << test_ << "\n"
7394 << " Error: Function call operator access failed\n"
7395 << " Details:\n"
7396 << " Result:\n" << cs << "\n"
7397 << " Expected result:\n( 4 0 5 )\n( 1 0 0 )\n( -8 7 9 )\n";
7398 throw std::runtime_error( oss.str() );
7399 }
7400
7401 if( cs.begin( 2UL )->value() != 5 ) {
7402 std::ostringstream oss;
7403 oss << " Test: " << test_ << "\n"
7404 << " Error: Iterator access failed\n"
7405 << " Details:\n"
7406 << " Result: " << cs.begin( 2UL )->value() << "\n"
7407 << " Expected result: 5\n";
7408 throw std::runtime_error( oss.str() );
7409 }
7410 }
7411
7412 try {
7413 auto rs = blaze::rows( mat_, { 3UL, 1UL, 4UL } );
7414 auto cs = blaze::columns( rs, { 4UL } );
7415
7416 std::ostringstream oss;
7417 oss << " Test: " << test_ << "\n"
7418 << " Error: Setup of out-of-bounds column selection succeeded\n"
7419 << " Details:\n"
7420 << " Result:\n" << cs << "\n";
7421 throw std::runtime_error( oss.str() );
7422 }
7423 catch( std::invalid_argument& ) {}
7424 }
7425
7426
7427 //=====================================================================================
7428 // Row-major matrix tests (std::array)
7429 //=====================================================================================
7430
7431 {
7432 test_ = "Row-major columns() function (std::array)";
7433
7434 initialize();
7435
7436 {
7437 std::array<int,3UL> indices{ 1UL, 0UL, 2UL };
7438
7439 auto rs = blaze::rows( mat_, { 3UL, 1UL, 4UL } );
7440 auto cs = blaze::columns( rs, indices );
7441
7442 if( cs(0,0) != 4 || cs(0,1) != 0 || cs(0,2) != 5 ||
7443 cs(1,0) != 1 || cs(1,1) != 0 || cs(1,2) != 0 ||
7444 cs(2,0) != -8 || cs(2,1) != 7 || cs(2,2) != 9 ) {
7445 std::ostringstream oss;
7446 oss << " Test: " << test_ << "\n"
7447 << " Error: Function call operator access failed\n"
7448 << " Details:\n"
7449 << " Result:\n" << cs << "\n"
7450 << " Expected result:\n( 4 0 5 )\n( 1 0 0 )\n( -8 7 9 )\n";
7451 throw std::runtime_error( oss.str() );
7452 }
7453
7454 if( cs.begin( 2UL )->value() != 5 ) {
7455 std::ostringstream oss;
7456 oss << " Test: " << test_ << "\n"
7457 << " Error: Iterator access failed\n"
7458 << " Details:\n"
7459 << " Result: " << cs.begin( 2UL )->value() << "\n"
7460 << " Expected result: 5\n";
7461 throw std::runtime_error( oss.str() );
7462 }
7463 }
7464
7465 try {
7466 std::array<int,1UL> indices{ 4UL };
7467
7468 auto rs = blaze::rows( mat_, { 3UL, 1UL, 4UL } );
7469 auto cs = blaze::columns( rs, indices );
7470
7471 std::ostringstream oss;
7472 oss << " Test: " << test_ << "\n"
7473 << " Error: Setup of out-of-bounds column selection succeeded\n"
7474 << " Details:\n"
7475 << " Result:\n" << cs << "\n";
7476 throw std::runtime_error( oss.str() );
7477 }
7478 catch( std::invalid_argument& ) {}
7479 }
7480
7481
7482 //=====================================================================================
7483 // Row-major matrix tests (lambda expression)
7484 //=====================================================================================
7485
7486 {
7487 test_ = "Row-major columns() function (lambda expression)";
7488
7489 initialize();
7490
7491 {
7492 auto rs = blaze::rows( mat_, { 3UL, 1UL, 4UL } );
7493 auto cs = blaze::columns( rs, []( size_t i ){ return (4UL-i)%3UL; }, 3UL );
7494
7495 if( cs(0,0) != 4 || cs(0,1) != 0 || cs(0,2) != 5 ||
7496 cs(1,0) != 1 || cs(1,1) != 0 || cs(1,2) != 0 ||
7497 cs(2,0) != -8 || cs(2,1) != 7 || cs(2,2) != 9 ) {
7498 std::ostringstream oss;
7499 oss << " Test: " << test_ << "\n"
7500 << " Error: Function call operator access failed\n"
7501 << " Details:\n"
7502 << " Result:\n" << cs << "\n"
7503 << " Expected result:\n( 4 0 5 )\n( 1 0 0 )\n( -8 7 9 )\n";
7504 throw std::runtime_error( oss.str() );
7505 }
7506
7507 if( cs.begin( 2UL )->value() != 5 ) {
7508 std::ostringstream oss;
7509 oss << " Test: " << test_ << "\n"
7510 << " Error: Iterator access failed\n"
7511 << " Details:\n"
7512 << " Result: " << cs.begin( 2UL )->value() << "\n"
7513 << " Expected result: 5\n";
7514 throw std::runtime_error( oss.str() );
7515 }
7516 }
7517
7518 try {
7519 auto rs = blaze::rows( mat_, { 3UL, 1UL, 4UL } );
7520 auto cs = blaze::columns( rs, []( size_t ){ return 4UL; }, 1UL );
7521
7522 std::ostringstream oss;
7523 oss << " Test: " << test_ << "\n"
7524 << " Error: Setup of out-of-bounds column selection succeeded\n"
7525 << " Details:\n"
7526 << " Result:\n" << cs << "\n";
7527 throw std::runtime_error( oss.str() );
7528 }
7529 catch( std::invalid_argument& ) {}
7530 }
7531
7532
7533 //=====================================================================================
7534 // Column-major matrix tests (initializer_list)
7535 //=====================================================================================
7536
7537 {
7538 test_ = "Column-major columns() function (initializer_list)";
7539
7540 initialize();
7541
7542 {
7543 auto rs = blaze::rows( tmat_, { 3UL, 1UL, 4UL } );
7544 auto cs = blaze::columns( rs, { 1UL, 0UL, 2UL } );
7545
7546 if( cs(0,0) != 4 || cs(0,1) != 0 || cs(0,2) != 5 ||
7547 cs(1,0) != 1 || cs(1,1) != 0 || cs(1,2) != 0 ||
7548 cs(2,0) != -8 || cs(2,1) != 7 || cs(2,2) != 9 ) {
7549 std::ostringstream oss;
7550 oss << " Test: " << test_ << "\n"
7551 << " Error: Function call operator access failed\n"
7552 << " Details:\n"
7553 << " Result:\n" << cs << "\n"
7554 << " Expected result:\n( 4 0 5 )\n( 1 0 0 )\n( -8 7 9 )\n";
7555 throw std::runtime_error( oss.str() );
7556 }
7557
7558 if( cs.begin( 2UL )->value() != 5 ) {
7559 std::ostringstream oss;
7560 oss << " Test: " << test_ << "\n"
7561 << " Error: Iterator access failed\n"
7562 << " Details:\n"
7563 << " Result: " << cs.begin( 2UL )->value() << "\n"
7564 << " Expected result: 5\n";
7565 throw std::runtime_error( oss.str() );
7566 }
7567 }
7568
7569 try {
7570 auto rs = blaze::rows( tmat_, { 3UL, 1UL, 4UL } );
7571 auto cs = blaze::columns( rs, { 4UL } );
7572
7573 std::ostringstream oss;
7574 oss << " Test: " << test_ << "\n"
7575 << " Error: Setup of out-of-bounds column selection succeeded\n"
7576 << " Details:\n"
7577 << " Result:\n" << cs << "\n";
7578 throw std::runtime_error( oss.str() );
7579 }
7580 catch( std::invalid_argument& ) {}
7581 }
7582
7583
7584 //=====================================================================================
7585 // Column-major matrix tests (std::array)
7586 //=====================================================================================
7587
7588 {
7589 test_ = "Column-major columns() function (std::array)";
7590
7591 initialize();
7592
7593 {
7594 std::array<int,3UL> indices{ 1UL, 0UL, 2UL };
7595
7596 auto rs = blaze::rows( tmat_, { 3UL, 1UL, 4UL } );
7597 auto cs = blaze::columns( rs, indices );
7598
7599 if( cs(0,0) != 4 || cs(0,1) != 0 || cs(0,2) != 5 ||
7600 cs(1,0) != 1 || cs(1,1) != 0 || cs(1,2) != 0 ||
7601 cs(2,0) != -8 || cs(2,1) != 7 || cs(2,2) != 9 ) {
7602 std::ostringstream oss;
7603 oss << " Test: " << test_ << "\n"
7604 << " Error: Function call operator access failed\n"
7605 << " Details:\n"
7606 << " Result:\n" << cs << "\n"
7607 << " Expected result:\n( 4 0 5 )\n( 1 0 0 )\n( -8 7 9 )\n";
7608 throw std::runtime_error( oss.str() );
7609 }
7610
7611 if( cs.begin( 2UL )->value() != 5 ) {
7612 std::ostringstream oss;
7613 oss << " Test: " << test_ << "\n"
7614 << " Error: Iterator access failed\n"
7615 << " Details:\n"
7616 << " Result: " << cs.begin( 2UL )->value() << "\n"
7617 << " Expected result: 5\n";
7618 throw std::runtime_error( oss.str() );
7619 }
7620 }
7621
7622 try {
7623 std::array<int,1UL> indices{ 4UL };
7624
7625 auto rs = blaze::rows( tmat_, { 3UL, 1UL, 4UL } );
7626 auto cs = blaze::columns( rs, indices );
7627
7628 std::ostringstream oss;
7629 oss << " Test: " << test_ << "\n"
7630 << " Error: Setup of out-of-bounds column selection succeeded\n"
7631 << " Details:\n"
7632 << " Result:\n" << cs << "\n";
7633 throw std::runtime_error( oss.str() );
7634 }
7635 catch( std::invalid_argument& ) {}
7636 }
7637
7638
7639 //=====================================================================================
7640 // Column-major matrix tests (lambda expression)
7641 //=====================================================================================
7642
7643 {
7644 test_ = "Column-major columns() function (lambda expression)";
7645
7646 initialize();
7647
7648 {
7649 auto rs = blaze::rows( tmat_, { 3UL, 1UL, 4UL } );
7650 auto cs = blaze::columns( rs, []( size_t i ){ return (4UL-i)%3UL; }, 3UL );
7651
7652 if( cs(0,0) != 4 || cs(0,1) != 0 || cs(0,2) != 5 ||
7653 cs(1,0) != 1 || cs(1,1) != 0 || cs(1,2) != 0 ||
7654 cs(2,0) != -8 || cs(2,1) != 7 || cs(2,2) != 9 ) {
7655 std::ostringstream oss;
7656 oss << " Test: " << test_ << "\n"
7657 << " Error: Function call operator access failed\n"
7658 << " Details:\n"
7659 << " Result:\n" << cs << "\n"
7660 << " Expected result:\n( 4 0 5 )\n( 1 0 0 )\n( -8 7 9 )\n";
7661 throw std::runtime_error( oss.str() );
7662 }
7663
7664 if( cs.begin( 2UL )->value() != 5 ) {
7665 std::ostringstream oss;
7666 oss << " Test: " << test_ << "\n"
7667 << " Error: Iterator access failed\n"
7668 << " Details:\n"
7669 << " Result: " << cs.begin( 2UL )->value() << "\n"
7670 << " Expected result: 5\n";
7671 throw std::runtime_error( oss.str() );
7672 }
7673 }
7674
7675 try {
7676 auto rs = blaze::rows( tmat_, { 3UL, 1UL, 4UL } );
7677 auto cs = blaze::columns( rs, []( size_t ){ return 4UL; }, 1UL );
7678
7679 std::ostringstream oss;
7680 oss << " Test: " << test_ << "\n"
7681 << " Error: Setup of out-of-bounds column selection succeeded\n"
7682 << " Details:\n"
7683 << " Result:\n" << cs << "\n";
7684 throw std::runtime_error( oss.str() );
7685 }
7686 catch( std::invalid_argument& ) {}
7687 }
7688 }
7689 //*************************************************************************************************
7690
7691
7692 //*************************************************************************************************
7693 /*!\brief Test of the \c band() function with the Rows class template.
7694 //
7695 // \return void
7696 // \exception std::runtime_error Error detected.
7697 //
7698 // This function performs a test of the \c band() function with the Rows specialization.
7699 // In case an error is detected, a \a std::runtime_error exception is thrown.
7700 */
testBand()7701 void SparseGeneralTest::testBand()
7702 {
7703 //=====================================================================================
7704 // Row-major matrix tests
7705 //=====================================================================================
7706
7707 {
7708 test_ = "Row-major band() function";
7709
7710 initialize();
7711
7712 {
7713 auto rs = blaze::rows( mat_, { 3UL, 1UL, 4UL } );
7714 auto b1 = blaze::band( rs, 1L );
7715
7716 if( b1[0] != 4 || b1[1] != 0 || b1[2] != 10 ) {
7717 std::ostringstream oss;
7718 oss << " Test: " << test_ << "\n"
7719 << " Error: Subscript operator access failed\n"
7720 << " Details:\n"
7721 << " Result:\n" << b1 << "\n"
7722 << " Expected result\n: ( 4 0 10 )\n";
7723 throw std::runtime_error( oss.str() );
7724 }
7725
7726 if( b1.begin()->value() != 4 ) {
7727 std::ostringstream oss;
7728 oss << " Test: " << test_ << "\n"
7729 << " Error: Iterator access failed\n"
7730 << " Details:\n"
7731 << " Result: " << b1.begin()->value() << "\n"
7732 << " Expected result: 4\n";
7733 throw std::runtime_error( oss.str() );
7734 }
7735 }
7736
7737 try {
7738 auto rs = blaze::rows( mat_, { 3UL, 1UL, 4UL } );
7739 auto b4 = blaze::band( rs, 4L );
7740
7741 std::ostringstream oss;
7742 oss << " Test: " << test_ << "\n"
7743 << " Error: Setup of out-of-bounds band succeeded\n"
7744 << " Details:\n"
7745 << " Result:\n" << b4 << "\n";
7746 throw std::runtime_error( oss.str() );
7747 }
7748 catch( std::invalid_argument& ) {}
7749
7750 try {
7751 auto rs = blaze::rows( mat_, { 3UL, 1UL, 4UL } );
7752 auto b3 = blaze::band( rs, -3L );
7753
7754 std::ostringstream oss;
7755 oss << " Test: " << test_ << "\n"
7756 << " Error: Setup of out-of-bounds band succeeded\n"
7757 << " Details:\n"
7758 << " Result:\n" << b3 << "\n";
7759 throw std::runtime_error( oss.str() );
7760 }
7761 catch( std::invalid_argument& ) {}
7762 }
7763
7764
7765 //=====================================================================================
7766 // Column-major matrix tests
7767 //=====================================================================================
7768
7769 {
7770 test_ = "Column-major band() function";
7771
7772 initialize();
7773
7774 {
7775 auto rs = blaze::rows( tmat_, { 3UL, 1UL, 4UL } );
7776 auto b1 = blaze::band( rs, 1L );
7777
7778 if( b1[0] != 4 || b1[1] != 0 || b1[2] != 10 ) {
7779 std::ostringstream oss;
7780 oss << " Test: " << test_ << "\n"
7781 << " Error: Subscript operator access failed\n"
7782 << " Details:\n"
7783 << " Result:\n" << b1 << "\n"
7784 << " Expected result\n: ( 4 0 10 )\n";
7785 throw std::runtime_error( oss.str() );
7786 }
7787
7788 if( b1.begin()->value() != 4 ) {
7789 std::ostringstream oss;
7790 oss << " Test: " << test_ << "\n"
7791 << " Error: Iterator access failed\n"
7792 << " Details:\n"
7793 << " Result: " << b1.begin()->value() << "\n"
7794 << " Expected result: 4\n";
7795 throw std::runtime_error( oss.str() );
7796 }
7797 }
7798
7799 try {
7800 auto rs = blaze::rows( tmat_, { 3UL, 1UL, 4UL } );
7801 auto b4 = blaze::band( rs, 4L );
7802
7803 std::ostringstream oss;
7804 oss << " Test: " << test_ << "\n"
7805 << " Error: Setup of out-of-bounds band succeeded\n"
7806 << " Details:\n"
7807 << " Result:\n" << b4 << "\n";
7808 throw std::runtime_error( oss.str() );
7809 }
7810 catch( std::invalid_argument& ) {}
7811
7812 try {
7813 auto rs = blaze::rows( tmat_, { 3UL, 1UL, 4UL } );
7814 auto b3 = blaze::band( rs, -3L );
7815
7816 std::ostringstream oss;
7817 oss << " Test: " << test_ << "\n"
7818 << " Error: Setup of out-of-bounds band succeeded\n"
7819 << " Details:\n"
7820 << " Result:\n" << b3 << "\n";
7821 throw std::runtime_error( oss.str() );
7822 }
7823 catch( std::invalid_argument& ) {}
7824 }
7825 }
7826 //*************************************************************************************************
7827
7828
7829
7830
7831 //=================================================================================================
7832 //
7833 // UTILITY FUNCTIONS
7834 //
7835 //=================================================================================================
7836
7837 //*************************************************************************************************
7838 /*!\brief Initialization of all member matrices.
7839 //
7840 // \return void
7841 // \exception std::runtime_error Error detected.
7842 //
7843 // This function initializes all member matrices to specific predetermined values.
7844 */
initialize()7845 void SparseGeneralTest::initialize()
7846 {
7847 // Initializing the row-major dynamic matrix
7848 mat_.reset();
7849 mat_(1,1) = 1;
7850 mat_(2,0) = -2;
7851 mat_(2,2) = -3;
7852 mat_(3,1) = 4;
7853 mat_(3,2) = 5;
7854 mat_(3,3) = -6;
7855 mat_(4,0) = 7;
7856 mat_(4,1) = -8;
7857 mat_(4,2) = 9;
7858 mat_(4,3) = 10;
7859
7860 // Initializing the column-major dynamic matrix
7861 tmat_.reset();
7862 tmat_(1,1) = 1;
7863 tmat_(2,0) = -2;
7864 tmat_(2,2) = -3;
7865 tmat_(3,1) = 4;
7866 tmat_(3,2) = 5;
7867 tmat_(3,3) = -6;
7868 tmat_(4,0) = 7;
7869 tmat_(4,1) = -8;
7870 tmat_(4,2) = 9;
7871 tmat_(4,3) = 10;
7872 }
7873 //*************************************************************************************************
7874
7875 } // namespace rows
7876
7877 } // namespace views
7878
7879 } // namespace mathtest
7880
7881 } // namespace blazetest
7882
7883
7884
7885
7886 //=================================================================================================
7887 //
7888 // MAIN FUNCTION
7889 //
7890 //=================================================================================================
7891
7892 //*************************************************************************************************
main()7893 int main()
7894 {
7895 std::cout << " Running Rows sparse general test (part 2)..." << std::endl;
7896
7897 try
7898 {
7899 RUN_ROWS_SPARSEGENERAL_TEST;
7900 }
7901 catch( std::exception& ex ) {
7902 std::cerr << "\n\n ERROR DETECTED during Rows sparse general test (part 2):\n"
7903 << ex.what() << "\n";
7904 return EXIT_FAILURE;
7905 }
7906
7907 return EXIT_SUCCESS;
7908 }
7909 //*************************************************************************************************
7910