1 //=================================================================================================
2 /*!
3 // \file src/mathtest/views/columns/SparseGeneralTest1.cpp
4 // \brief Source file for the Columns sparse general test (part 1)
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/DynamicMatrix.h>
43 #include <blaze/math/DynamicVector.h>
44 #include <blazetest/mathtest/views/columns/SparseGeneralTest.h>
45
46 #ifdef BLAZE_USE_HPX_THREADS
47 # include <hpx/hpx_main.hpp>
48 #endif
49
50
51 namespace blazetest {
52
53 namespace mathtest {
54
55 namespace views {
56
57 namespace columns {
58
59 //=================================================================================================
60 //
61 // CONSTRUCTORS
62 //
63 //=================================================================================================
64
65 //*************************************************************************************************
66 /*!\brief Constructor for the Columns sparse general test.
67 //
68 // \exception std::runtime_error Operation error detected.
69 */
SparseGeneralTest()70 SparseGeneralTest::SparseGeneralTest()
71 : mat_ ( 4UL, 5UL )
72 , tmat_( 4UL, 5UL )
73 {
74 testConstructors();
75 testAssignment();
76 testAddAssign();
77 testSubAssign();
78 testSchurAssign();
79 testMultAssign();
80 }
81 //*************************************************************************************************
82
83
84
85
86 //=================================================================================================
87 //
88 // TEST FUNCTIONS
89 //
90 //=================================================================================================
91
92 //*************************************************************************************************
93 /*!\brief Test of the Columns constructors.
94 //
95 // \return void
96 // \exception std::runtime_error Error detected.
97 //
98 // This function performs a test of all constructors of the Columns specialization. In case
99 // an error is detected, a \a std::runtime_error exception is thrown.
100 */
testConstructors()101 void SparseGeneralTest::testConstructors()
102 {
103 using blaze::index_sequence;
104 using blaze::initializer_list;
105
106
107 //=====================================================================================
108 // Row-major setup via index_sequence
109 //=====================================================================================
110
111 {
112 test_ = "Row-major Columns constructor (index_sequence)";
113
114 initialize();
115
116 // Setup of a regular column selection
117 {
118 auto cs = blaze::columns( mat_, index_sequence<0,4,2>() );
119
120 if( cs.rows() != mat_.rows() || cs.columns() != 3UL ||
121 cs(0,0) != mat_(0,0) || cs(0,1) != mat_(0,4) || cs(0,2) != mat_(0,2) ||
122 cs(1,0) != mat_(1,0) || cs(1,1) != mat_(1,4) || cs(1,2) != mat_(1,2) ||
123 cs(2,0) != mat_(2,0) || cs(2,1) != mat_(2,4) || cs(2,2) != mat_(2,2) ||
124 cs(3,0) != mat_(3,0) || cs(3,1) != mat_(3,4) || cs(3,2) != mat_(3,2) ) {
125 std::ostringstream oss;
126 oss << " Test: " << test_ << "\n"
127 << " Error: Setup of column selection failed\n"
128 << " Details:\n"
129 << " Result:\n" << cs << "\n";
130 throw std::runtime_error( oss.str() );
131 }
132 }
133
134 // Trying to setup an out-of-bounds column selection
135 try {
136 auto cs = blaze::columns( mat_, index_sequence<5>() );
137
138 std::ostringstream oss;
139 oss << " Test: " << test_ << "\n"
140 << " Error: Setup of out-of-bounds column selection succeeded\n"
141 << " Details:\n"
142 << " Result:\n" << cs << "\n";
143 throw std::runtime_error( oss.str() );
144 }
145 catch( std::invalid_argument& ) {}
146
147 // Setup of a column selection on a compile-time column selection
148 {
149 auto cs1 = blaze::columns( mat_, index_sequence<0,4,2>() );
150 auto cs2 = blaze::columns( cs1, index_sequence<2,1>() );
151
152 if( cs2.rows() != mat_.rows() || cs2.columns() != 2UL ||
153 cs2(0,0) != mat_(0,2) || cs2(0,1) != mat_(0,4) ||
154 cs2(1,0) != mat_(1,2) || cs2(1,1) != mat_(1,4) ||
155 cs2(2,0) != mat_(2,2) || cs2(2,1) != mat_(2,4) ||
156 cs2(3,0) != mat_(3,2) || cs2(3,1) != mat_(3,4) ) {
157 std::ostringstream oss;
158 oss << " Test: " << test_ << "\n"
159 << " Error: Setup of column selection failed\n"
160 << " Details:\n"
161 << " Result:\n" << cs2 << "\n";
162 throw std::runtime_error( oss.str() );
163 }
164 }
165
166 // Setup of a column selection on an explicit column selection
167 {
168 auto cs1 = blaze::columns( mat_, { 0, 4, 2 } );
169 auto cs2 = blaze::columns( cs1, index_sequence<2,1>() );
170
171 if( cs2.rows() != mat_.rows() || cs2.columns() != 2UL ||
172 cs2(0,0) != mat_(0,2) || cs2(0,1) != mat_(0,4) ||
173 cs2(1,0) != mat_(1,2) || cs2(1,1) != mat_(1,4) ||
174 cs2(2,0) != mat_(2,2) || cs2(2,1) != mat_(2,4) ||
175 cs2(3,0) != mat_(3,2) || cs2(3,1) != mat_(3,4) ) {
176 std::ostringstream oss;
177 oss << " Test: " << test_ << "\n"
178 << " Error: Setup of column selection failed\n"
179 << " Details:\n"
180 << " Result:\n" << cs2 << "\n";
181 throw std::runtime_error( oss.str() );
182 }
183 }
184
185 // Setup of a column selection on an implicit column selection
186 {
187 const std::array<size_t,3UL> indices{ 0, 4, 2 };
188 auto cs1 = blaze::columns( mat_, [indices]( size_t i ){ return indices[i]; }, 3UL );
189 auto cs2 = blaze::columns( cs1, index_sequence<2,1>() );
190
191 if( cs2.rows() != mat_.rows() || cs2.columns() != 2UL ||
192 cs2(0,0) != mat_(0,2) || cs2(0,1) != mat_(0,4) ||
193 cs2(1,0) != mat_(1,2) || cs2(1,1) != mat_(1,4) ||
194 cs2(2,0) != mat_(2,2) || cs2(2,1) != mat_(2,4) ||
195 cs2(3,0) != mat_(3,2) || cs2(3,1) != mat_(3,4) ) {
196 std::ostringstream oss;
197 oss << " Test: " << test_ << "\n"
198 << " Error: Setup of column selection failed\n"
199 << " Details:\n"
200 << " Result:\n" << cs2 << "\n";
201 throw std::runtime_error( oss.str() );
202 }
203 }
204 }
205
206
207 //=====================================================================================
208 // Row-major setup via initializer_list
209 //=====================================================================================
210
211 {
212 test_ = "Row-major Columns constructor (initializer_list)";
213
214 initialize();
215
216 // Setup of empty column selection
217 {
218 std::initializer_list<size_t> indices{};
219 auto cs = blaze::columns( mat_, indices );
220
221 if( cs.rows() != mat_.rows() || cs.columns() != 0UL ) {
222 std::ostringstream oss;
223 oss << " Test: " << test_ << "\n"
224 << " Error: Setup of empty column selection failed\n"
225 << " Details:\n"
226 << " Result:\n" << cs << "\n";
227 throw std::runtime_error( oss.str() );
228 }
229 }
230
231 // Setup of a regular column selection
232 {
233 auto cs = blaze::columns( mat_, { 0, 4, 2 } );
234
235 if( cs.rows() != mat_.rows() || cs.columns() != 3UL ||
236 cs(0,0) != mat_(0,0) || cs(0,1) != mat_(0,4) || cs(0,2) != mat_(0,2) ||
237 cs(1,0) != mat_(1,0) || cs(1,1) != mat_(1,4) || cs(1,2) != mat_(1,2) ||
238 cs(2,0) != mat_(2,0) || cs(2,1) != mat_(2,4) || cs(2,2) != mat_(2,2) ||
239 cs(3,0) != mat_(3,0) || cs(3,1) != mat_(3,4) || cs(3,2) != mat_(3,2) ) {
240 std::ostringstream oss;
241 oss << " Test: " << test_ << "\n"
242 << " Error: Setup of column selection failed\n"
243 << " Details:\n"
244 << " Result:\n" << cs << "\n";
245 throw std::runtime_error( oss.str() );
246 }
247 }
248
249 // Trying to setup an out-of-bounds column selection
250 try {
251 auto cs = blaze::columns( mat_, { 5 } );
252
253 std::ostringstream oss;
254 oss << " Test: " << test_ << "\n"
255 << " Error: Setup of out-of-bounds column selection succeeded\n"
256 << " Details:\n"
257 << " Result:\n" << cs << "\n";
258 throw std::runtime_error( oss.str() );
259 }
260 catch( std::invalid_argument& ) {}
261
262 // Setup of a column selection on a compile-time column selection
263 {
264 auto cs1 = blaze::columns( mat_, index_sequence<0,4,2>() );
265 auto cs2 = blaze::columns( cs1, { 2, 1 } );
266
267 if( cs2.rows() != mat_.rows() || cs2.columns() != 2UL ||
268 cs2(0,0) != mat_(0,2) || cs2(0,1) != mat_(0,4) ||
269 cs2(1,0) != mat_(1,2) || cs2(1,1) != mat_(1,4) ||
270 cs2(2,0) != mat_(2,2) || cs2(2,1) != mat_(2,4) ||
271 cs2(3,0) != mat_(3,2) || cs2(3,1) != mat_(3,4) ) {
272 std::ostringstream oss;
273 oss << " Test: " << test_ << "\n"
274 << " Error: Setup of column selection failed\n"
275 << " Details:\n"
276 << " Result:\n" << cs2 << "\n";
277 throw std::runtime_error( oss.str() );
278 }
279 }
280
281 // Setup of a column selection on an explicit column selection
282 {
283 auto cs1 = blaze::columns( mat_, { 0, 4, 2 } );
284 auto cs2 = blaze::columns( cs1, { 2, 1 } );
285
286 if( cs2.rows() != mat_.rows() || cs2.columns() != 2UL ||
287 cs2(0,0) != mat_(0,2) || cs2(0,1) != mat_(0,4) ||
288 cs2(1,0) != mat_(1,2) || cs2(1,1) != mat_(1,4) ||
289 cs2(2,0) != mat_(2,2) || cs2(2,1) != mat_(2,4) ||
290 cs2(3,0) != mat_(3,2) || cs2(3,1) != mat_(3,4) ) {
291 std::ostringstream oss;
292 oss << " Test: " << test_ << "\n"
293 << " Error: Setup of column selection failed\n"
294 << " Details:\n"
295 << " Result:\n" << cs2 << "\n";
296 throw std::runtime_error( oss.str() );
297 }
298 }
299
300 // Setup of a column selection on an implicit column selection
301 {
302 const std::array<size_t,3UL> indices{ 0, 4, 2 };
303 auto cs1 = blaze::columns( mat_, [indices]( size_t i ){ return indices[i]; }, 3UL );
304 auto cs2 = blaze::columns( cs1, { 2, 1 } );
305
306 if( cs2.rows() != mat_.rows() || cs2.columns() != 2UL ||
307 cs2(0,0) != mat_(0,2) || cs2(0,1) != mat_(0,4) ||
308 cs2(1,0) != mat_(1,2) || cs2(1,1) != mat_(1,4) ||
309 cs2(2,0) != mat_(2,2) || cs2(2,1) != mat_(2,4) ||
310 cs2(3,0) != mat_(3,2) || cs2(3,1) != mat_(3,4) ) {
311 std::ostringstream oss;
312 oss << " Test: " << test_ << "\n"
313 << " Error: Setup of column selection failed\n"
314 << " Details:\n"
315 << " Result:\n" << cs2 << "\n";
316 throw std::runtime_error( oss.str() );
317 }
318 }
319 }
320
321
322 //=====================================================================================
323 // Row-major setup via std::vector
324 //=====================================================================================
325
326 {
327 test_ = "Row-major Columns constructor (std::vector)";
328
329 initialize();
330
331 // Setup of empty column selection
332 {
333 std::vector<size_t> indices;
334 auto cs = blaze::columns( mat_, indices );
335
336 if( cs.rows() != mat_.rows() || cs.columns() != 0UL ) {
337 std::ostringstream oss;
338 oss << " Test: " << test_ << "\n"
339 << " Error: Setup of empty column selection failed\n"
340 << " Details:\n"
341 << " Result:\n" << cs << "\n";
342 throw std::runtime_error( oss.str() );
343 }
344 }
345
346 // Setup of a regular column selection
347 {
348 const std::vector<size_t> indices{ 0, 4, 2 };
349 auto cs = blaze::columns( mat_, indices );
350
351 if( cs.rows() != mat_.rows() || cs.columns() != 3UL ||
352 cs(0,0) != mat_(0,0) || cs(0,1) != mat_(0,4) || cs(0,2) != mat_(0,2) ||
353 cs(1,0) != mat_(1,0) || cs(1,1) != mat_(1,4) || cs(1,2) != mat_(1,2) ||
354 cs(2,0) != mat_(2,0) || cs(2,1) != mat_(2,4) || cs(2,2) != mat_(2,2) ||
355 cs(3,0) != mat_(3,0) || cs(3,1) != mat_(3,4) || cs(3,2) != mat_(3,2) ) {
356 std::ostringstream oss;
357 oss << " Test: " << test_ << "\n"
358 << " Error: Setup of column selection failed\n"
359 << " Details:\n"
360 << " Result:\n" << cs << "\n";
361 throw std::runtime_error( oss.str() );
362 }
363 }
364
365 // Trying to setup an out-of-bounds column selection
366 try {
367 std::vector<size_t> indices{ 5 };
368 auto cs = blaze::columns( mat_, indices );
369
370 std::ostringstream oss;
371 oss << " Test: " << test_ << "\n"
372 << " Error: Setup of out-of-bounds column selection succeeded\n"
373 << " Details:\n"
374 << " Result:\n" << cs << "\n";
375 throw std::runtime_error( oss.str() );
376 }
377 catch( std::invalid_argument& ) {}
378
379 // Setup of a column selection on a compile-time column selection
380 {
381 auto cs1 = blaze::columns( mat_, index_sequence<0,4,2>() );
382
383 const std::vector<size_t> indices{ 2, 1 };
384 auto cs2 = blaze::columns( cs1, indices );
385
386 if( cs2.rows() != mat_.rows() || cs2.columns() != 2UL ||
387 cs2(0,0) != mat_(0,2) || cs2(0,1) != mat_(0,4) ||
388 cs2(1,0) != mat_(1,2) || cs2(1,1) != mat_(1,4) ||
389 cs2(2,0) != mat_(2,2) || cs2(2,1) != mat_(2,4) ||
390 cs2(3,0) != mat_(3,2) || cs2(3,1) != mat_(3,4) ) {
391 std::ostringstream oss;
392 oss << " Test: " << test_ << "\n"
393 << " Error: Setup of column selection failed\n"
394 << " Details:\n"
395 << " Result:\n" << cs2 << "\n";
396 throw std::runtime_error( oss.str() );
397 }
398 }
399
400 // Setup of a column selection on an explicit column selection
401 {
402 auto cs1 = blaze::columns( mat_, { 0, 4, 2 } );
403
404 const std::vector<size_t> indices{ 2, 1 };
405 auto cs2 = blaze::columns( cs1, indices );
406
407 if( cs2.rows() != mat_.rows() || cs2.columns() != 2UL ||
408 cs2(0,0) != mat_(0,2) || cs2(0,1) != mat_(0,4) ||
409 cs2(1,0) != mat_(1,2) || cs2(1,1) != mat_(1,4) ||
410 cs2(2,0) != mat_(2,2) || cs2(2,1) != mat_(2,4) ||
411 cs2(3,0) != mat_(3,2) || cs2(3,1) != mat_(3,4) ) {
412 std::ostringstream oss;
413 oss << " Test: " << test_ << "\n"
414 << " Error: Setup of column selection failed\n"
415 << " Details:\n"
416 << " Result:\n" << cs2 << "\n";
417 throw std::runtime_error( oss.str() );
418 }
419 }
420
421 // Setup of a column selection on an implicit column selection
422 {
423 const std::array<size_t,3UL> indices1{ 0, 4, 2 };
424 auto cs1 = blaze::columns( mat_, [indices1]( size_t i ){ return indices1[i]; }, 3UL );
425
426 const std::vector<size_t> indices2{ 2, 1 };
427 auto cs2 = blaze::columns( cs1, indices2 );
428
429 if( cs2.rows() != mat_.rows() || cs2.columns() != 2UL ||
430 cs2(0,0) != mat_(0,2) || cs2(0,1) != mat_(0,4) ||
431 cs2(1,0) != mat_(1,2) || cs2(1,1) != mat_(1,4) ||
432 cs2(2,0) != mat_(2,2) || cs2(2,1) != mat_(2,4) ||
433 cs2(3,0) != mat_(3,2) || cs2(3,1) != mat_(3,4) ) {
434 std::ostringstream oss;
435 oss << " Test: " << test_ << "\n"
436 << " Error: Setup of column selection failed\n"
437 << " Details:\n"
438 << " Result:\n" << cs2 << "\n";
439 throw std::runtime_error( oss.str() );
440 }
441 }
442 }
443
444
445 //=====================================================================================
446 // Row-major setup via std::array
447 //=====================================================================================
448
449 {
450 test_ = "Row-major Columns constructor (std::array)";
451
452 initialize();
453
454 // Setup of a regular column selection
455 {
456 const std::array<size_t,3UL> indices{ 0, 4, 2 };
457 auto cs = blaze::columns( mat_, indices );
458
459 if( cs.rows() != mat_.rows() || cs.columns() != 3UL ||
460 cs(0,0) != mat_(0,0) || cs(0,1) != mat_(0,4) || cs(0,2) != mat_(0,2) ||
461 cs(1,0) != mat_(1,0) || cs(1,1) != mat_(1,4) || cs(1,2) != mat_(1,2) ||
462 cs(2,0) != mat_(2,0) || cs(2,1) != mat_(2,4) || cs(2,2) != mat_(2,2) ||
463 cs(3,0) != mat_(3,0) || cs(3,1) != mat_(3,4) || cs(3,2) != mat_(3,2) ) {
464 std::ostringstream oss;
465 oss << " Test: " << test_ << "\n"
466 << " Error: Setup of column selection failed\n"
467 << " Details:\n"
468 << " Result:\n" << cs << "\n";
469 throw std::runtime_error( oss.str() );
470 }
471 }
472
473 // Trying to setup an out-of-bounds column selection
474 try {
475 std::array<size_t,1UL> indices{ 5 };
476 auto cs = blaze::columns( mat_, indices );
477
478 std::ostringstream oss;
479 oss << " Test: " << test_ << "\n"
480 << " Error: Setup of out-of-bounds column selection succeeded\n"
481 << " Details:\n"
482 << " Result:\n" << cs << "\n";
483 throw std::runtime_error( oss.str() );
484 }
485 catch( std::invalid_argument& ) {}
486
487 // Setup of a column selection on a compile-time column selection
488 {
489 auto cs1 = blaze::columns( mat_, index_sequence<0,4,2>() );
490
491 const std::array<size_t,2UL> indices{ 2, 1 };
492 auto cs2 = blaze::columns( cs1, indices );
493
494 if( cs2.rows() != mat_.rows() || cs2.columns() != 2UL ||
495 cs2(0,0) != mat_(0,2) || cs2(0,1) != mat_(0,4) ||
496 cs2(1,0) != mat_(1,2) || cs2(1,1) != mat_(1,4) ||
497 cs2(2,0) != mat_(2,2) || cs2(2,1) != mat_(2,4) ||
498 cs2(3,0) != mat_(3,2) || cs2(3,1) != mat_(3,4) ) {
499 std::ostringstream oss;
500 oss << " Test: " << test_ << "\n"
501 << " Error: Setup of column selection failed\n"
502 << " Details:\n"
503 << " Result:\n" << cs2 << "\n";
504 throw std::runtime_error( oss.str() );
505 }
506 }
507
508 // Setup of a column selection on an explicit column selection
509 {
510 auto cs1 = blaze::columns( mat_, { 0, 4, 2 } );
511
512 const std::array<size_t,2UL> indices{ 2, 1 };
513 auto cs2 = blaze::columns( cs1, indices );
514
515 if( cs2.rows() != mat_.rows() || cs2.columns() != 2UL ||
516 cs2(0,0) != mat_(0,2) || cs2(0,1) != mat_(0,4) ||
517 cs2(1,0) != mat_(1,2) || cs2(1,1) != mat_(1,4) ||
518 cs2(2,0) != mat_(2,2) || cs2(2,1) != mat_(2,4) ||
519 cs2(3,0) != mat_(3,2) || cs2(3,1) != mat_(3,4) ) {
520 std::ostringstream oss;
521 oss << " Test: " << test_ << "\n"
522 << " Error: Setup of column selection failed\n"
523 << " Details:\n"
524 << " Result:\n" << cs2 << "\n";
525 throw std::runtime_error( oss.str() );
526 }
527 }
528
529 // Setup of a column selection on an implicit column selection
530 {
531 const std::array<size_t,3UL> indices1{ 0, 4, 2 };
532 auto cs1 = blaze::columns( mat_, [indices1]( size_t i ){ return indices1[i]; }, 3UL );
533
534 const std::array<size_t,2UL> indices{ 2, 1 };
535 auto cs2 = blaze::columns( cs1, indices );
536
537 if( cs2.rows() != mat_.rows() || cs2.columns() != 2UL ||
538 cs2(0,0) != mat_(0,2) || cs2(0,1) != mat_(0,4) ||
539 cs2(1,0) != mat_(1,2) || cs2(1,1) != mat_(1,4) ||
540 cs2(2,0) != mat_(2,2) || cs2(2,1) != mat_(2,4) ||
541 cs2(3,0) != mat_(3,2) || cs2(3,1) != mat_(3,4) ) {
542 std::ostringstream oss;
543 oss << " Test: " << test_ << "\n"
544 << " Error: Setup of column selection failed\n"
545 << " Details:\n"
546 << " Result:\n" << cs2 << "\n";
547 throw std::runtime_error( oss.str() );
548 }
549 }
550 }
551
552
553 //=====================================================================================
554 // Row-major setup via lambda expression
555 //=====================================================================================
556
557 {
558 test_ = "Row-major Columns constructor (lambda expression)";
559
560 initialize();
561
562 // Setup of empty column selection
563 {
564 auto cs = blaze::columns( mat_, []( size_t ){ return 0UL; }, 0UL );
565
566 if( cs.rows() != mat_.rows() || cs.columns() != 0UL ) {
567 std::ostringstream oss;
568 oss << " Test: " << test_ << "\n"
569 << " Error: Setup of empty column selection failed\n"
570 << " Details:\n"
571 << " Result:\n" << cs << "\n";
572 throw std::runtime_error( oss.str() );
573 }
574 }
575
576 // Setup of a regular column selection
577 {
578 const std::array<size_t,3UL> indices{ 0, 4, 2 };
579 auto cs = blaze::columns( mat_, [indices]( size_t i ){ return indices[i]; }, 3UL );
580
581 if( cs.rows() != mat_.rows() || cs.columns() != 3UL ||
582 cs(0,0) != mat_(0,0) || cs(0,1) != mat_(0,4) || cs(0,2) != mat_(0,2) ||
583 cs(1,0) != mat_(1,0) || cs(1,1) != mat_(1,4) || cs(1,2) != mat_(1,2) ||
584 cs(2,0) != mat_(2,0) || cs(2,1) != mat_(2,4) || cs(2,2) != mat_(2,2) ||
585 cs(3,0) != mat_(3,0) || cs(3,1) != mat_(3,4) || cs(3,2) != mat_(3,2) ) {
586 std::ostringstream oss;
587 oss << " Test: " << test_ << "\n"
588 << " Error: Setup of column selection failed\n"
589 << " Details:\n"
590 << " Result:\n" << cs << "\n";
591 throw std::runtime_error( oss.str() );
592 }
593 }
594
595 // Trying to setup an out-of-bounds column selection
596 try {
597 auto cs = blaze::columns( mat_, []( size_t ){ return 5UL; }, 1UL );
598
599 std::ostringstream oss;
600 oss << " Test: " << test_ << "\n"
601 << " Error: Setup of out-of-bounds column selection succeeded\n"
602 << " Details:\n"
603 << " Result:\n" << cs << "\n";
604 throw std::runtime_error( oss.str() );
605 }
606 catch( std::invalid_argument& ) {}
607
608 // Setup of a column selection on a compile-time column selection
609 {
610 auto cs1 = blaze::columns( mat_, index_sequence<0,4,2>() );
611
612 const std::array<size_t,2UL> indices{ 2, 1 };
613 auto cs2 = blaze::columns( cs1, [indices]( size_t i ){ return indices[i]; }, 2UL );
614
615 if( cs2.rows() != mat_.rows() || cs2.columns() != 2UL ||
616 cs2(0,0) != mat_(0,2) || cs2(0,1) != mat_(0,4) ||
617 cs2(1,0) != mat_(1,2) || cs2(1,1) != mat_(1,4) ||
618 cs2(2,0) != mat_(2,2) || cs2(2,1) != mat_(2,4) ||
619 cs2(3,0) != mat_(3,2) || cs2(3,1) != mat_(3,4) ) {
620 std::ostringstream oss;
621 oss << " Test: " << test_ << "\n"
622 << " Error: Setup of column selection failed\n"
623 << " Details:\n"
624 << " Result:\n" << cs2 << "\n";
625 throw std::runtime_error( oss.str() );
626 }
627 }
628
629 // Setup of a column selection on an explicit column selection
630 {
631 auto cs1 = blaze::columns( mat_, { 0, 4, 2 } );
632
633 const std::array<size_t,2UL> indices{ 2, 1 };
634 auto cs2 = blaze::columns( cs1, [indices]( size_t i ){ return indices[i]; }, 2UL );
635
636 if( cs2.rows() != mat_.rows() || cs2.columns() != 2UL ||
637 cs2(0,0) != mat_(0,2) || cs2(0,1) != mat_(0,4) ||
638 cs2(1,0) != mat_(1,2) || cs2(1,1) != mat_(1,4) ||
639 cs2(2,0) != mat_(2,2) || cs2(2,1) != mat_(2,4) ||
640 cs2(3,0) != mat_(3,2) || cs2(3,1) != mat_(3,4) ) {
641 std::ostringstream oss;
642 oss << " Test: " << test_ << "\n"
643 << " Error: Setup of column selection failed\n"
644 << " Details:\n"
645 << " Result:\n" << cs2 << "\n";
646 throw std::runtime_error( oss.str() );
647 }
648 }
649
650 // Setup of a column selection on an implicit column selection
651 {
652 const std::array<size_t,3UL> indices1{ 0, 4, 2 };
653 auto cs1 = blaze::columns( mat_, [indices1]( size_t i ){ return indices1[i]; }, 3UL );
654
655 const std::array<size_t,2UL> indices2{ 2, 1 };
656 auto cs2 = blaze::columns( cs1, [indices2]( size_t i ){ return indices2[i]; }, 2UL );
657
658 if( cs2.rows() != mat_.rows() || cs2.columns() != 2UL ||
659 cs2(0,0) != mat_(0,2) || cs2(0,1) != mat_(0,4) ||
660 cs2(1,0) != mat_(1,2) || cs2(1,1) != mat_(1,4) ||
661 cs2(2,0) != mat_(2,2) || cs2(2,1) != mat_(2,4) ||
662 cs2(3,0) != mat_(3,2) || cs2(3,1) != mat_(3,4) ) {
663 std::ostringstream oss;
664 oss << " Test: " << test_ << "\n"
665 << " Error: Setup of column selection failed\n"
666 << " Details:\n"
667 << " Result:\n" << cs2 << "\n";
668 throw std::runtime_error( oss.str() );
669 }
670 }
671 }
672
673
674 //=====================================================================================
675 // Row-major setup of random in-bounds element selection
676 //=====================================================================================
677
678 {
679 test_ = "Column-major Columns constructor (stress test)";
680
681 initialize();
682
683 for( size_t rep=0UL; rep<100UL; ++rep )
684 {
685 blaze::DynamicVector<size_t> indices( blaze::rand<size_t>( 1UL, 20UL ) );
686 randomize( indices, 0UL, mat_.rows()-1UL );
687 auto cs = blaze::columns( mat_, indices.data(), indices.size() );
688
689 for( size_t i=0UL; i<cs.rows(); ++i ) {
690 for( size_t j=0UL; j<cs.columns(); ++j ) {
691 if( cs(i,j) != mat_(i,indices[j]) ) {
692 std::ostringstream oss;
693 oss << " Test: " << test_ << "\n"
694 << " Error: Setup of column selection failed\n"
695 << " Details:\n"
696 << " Indices:\n" << indices << "\n"
697 << " Column selection:\n" << cs << "\n"
698 << " Matrix:\n" << mat_ << "\n";
699 throw std::runtime_error( oss.str() );
700 }
701 }
702 }
703 }
704 }
705
706
707 //=====================================================================================
708 // Column-major setup via index_sequence
709 //=====================================================================================
710
711 {
712 test_ = "Column-major Columns constructor (index_sequence)";
713
714 initialize();
715
716 // Setup of a regular column selection
717 {
718 auto cs = blaze::columns( tmat_, index_sequence<0,4,2>() );
719
720 if( cs.rows() != tmat_.rows() || cs.columns() != 3UL ||
721 cs(0,0) != tmat_(0,0) || cs(0,1) != tmat_(0,4) || cs(0,2) != tmat_(0,2) ||
722 cs(1,0) != tmat_(1,0) || cs(1,1) != tmat_(1,4) || cs(1,2) != tmat_(1,2) ||
723 cs(2,0) != tmat_(2,0) || cs(2,1) != tmat_(2,4) || cs(2,2) != tmat_(2,2) ||
724 cs(3,0) != tmat_(3,0) || cs(3,1) != tmat_(3,4) || cs(3,2) != tmat_(3,2) ) {
725 std::ostringstream oss;
726 oss << " Test: " << test_ << "\n"
727 << " Error: Setup of column selection failed\n"
728 << " Details:\n"
729 << " Result:\n" << cs << "\n";
730 throw std::runtime_error( oss.str() );
731 }
732 }
733
734 // Trying to setup an out-of-bounds column selection
735 try {
736 auto cs = blaze::columns( tmat_, index_sequence<5>() );
737
738 std::ostringstream oss;
739 oss << " Test: " << test_ << "\n"
740 << " Error: Setup of out-of-bounds column selection succeeded\n"
741 << " Details:\n"
742 << " Result:\n" << cs << "\n";
743 throw std::runtime_error( oss.str() );
744 }
745 catch( std::invalid_argument& ) {}
746
747 // Setup of a column selection on a compile-time column selection
748 {
749 auto cs1 = blaze::columns( tmat_, index_sequence<0,4,2>() );
750 auto cs2 = blaze::columns( cs1, index_sequence<2,1>() );
751
752 if( cs2.rows() != tmat_.rows() || cs2.columns() != 2UL ||
753 cs2(0,0) != tmat_(0,2) || cs2(0,1) != tmat_(0,4) ||
754 cs2(1,0) != tmat_(1,2) || cs2(1,1) != tmat_(1,4) ||
755 cs2(2,0) != tmat_(2,2) || cs2(2,1) != tmat_(2,4) ||
756 cs2(3,0) != tmat_(3,2) || cs2(3,1) != tmat_(3,4) ) {
757 std::ostringstream oss;
758 oss << " Test: " << test_ << "\n"
759 << " Error: Setup of column selection failed\n"
760 << " Details:\n"
761 << " Result:\n" << cs2 << "\n";
762 throw std::runtime_error( oss.str() );
763 }
764 }
765
766 // Setup of a column selection on an explicit column selection
767 {
768 auto cs1 = blaze::columns( tmat_, { 0, 4, 2 } );
769 auto cs2 = blaze::columns( cs1, index_sequence<2,1>() );
770
771 if( cs2.rows() != tmat_.rows() || cs2.columns() != 2UL ||
772 cs2(0,0) != tmat_(0,2) || cs2(0,1) != tmat_(0,4) ||
773 cs2(1,0) != tmat_(1,2) || cs2(1,1) != tmat_(1,4) ||
774 cs2(2,0) != tmat_(2,2) || cs2(2,1) != tmat_(2,4) ||
775 cs2(3,0) != tmat_(3,2) || cs2(3,1) != tmat_(3,4) ) {
776 std::ostringstream oss;
777 oss << " Test: " << test_ << "\n"
778 << " Error: Setup of column selection failed\n"
779 << " Details:\n"
780 << " Result:\n" << cs2 << "\n";
781 throw std::runtime_error( oss.str() );
782 }
783 }
784
785 // Setup of a column selection on an implicit column selection
786 {
787 const std::array<size_t,3UL> indices{ 0, 4, 2 };
788 auto cs1 = blaze::columns( tmat_, [indices]( size_t i ){ return indices[i]; }, 3UL );
789 auto cs2 = blaze::columns( cs1, index_sequence<2,1>() );
790
791 if( cs2.rows() != tmat_.rows() || cs2.columns() != 2UL ||
792 cs2(0,0) != tmat_(0,2) || cs2(0,1) != tmat_(0,4) ||
793 cs2(1,0) != tmat_(1,2) || cs2(1,1) != tmat_(1,4) ||
794 cs2(2,0) != tmat_(2,2) || cs2(2,1) != tmat_(2,4) ||
795 cs2(3,0) != tmat_(3,2) || cs2(3,1) != tmat_(3,4) ) {
796 std::ostringstream oss;
797 oss << " Test: " << test_ << "\n"
798 << " Error: Setup of column selection failed\n"
799 << " Details:\n"
800 << " Result:\n" << cs2 << "\n";
801 throw std::runtime_error( oss.str() );
802 }
803 }
804 }
805
806
807 //=====================================================================================
808 // Column-major setup via initializer_list
809 //=====================================================================================
810
811 {
812 test_ = "Column-major Columns constructor (initializer_list)";
813
814 initialize();
815
816 // Setup of empty column selection
817 {
818 std::initializer_list<size_t> indices{};
819 auto cs = blaze::columns( tmat_, indices );
820
821 if( cs.rows() != tmat_.rows() || cs.columns() != 0UL ) {
822 std::ostringstream oss;
823 oss << " Test: " << test_ << "\n"
824 << " Error: Setup of empty column selection failed\n"
825 << " Details:\n"
826 << " Result:\n" << cs << "\n";
827 throw std::runtime_error( oss.str() );
828 }
829 }
830
831 // Setup of a regular column selection
832 {
833 auto cs = blaze::columns( tmat_, { 0, 4, 2 } );
834
835 if( cs.rows() != tmat_.rows() || cs.columns() != 3UL ||
836 cs(0,0) != tmat_(0,0) || cs(0,1) != tmat_(0,4) || cs(0,2) != tmat_(0,2) ||
837 cs(1,0) != tmat_(1,0) || cs(1,1) != tmat_(1,4) || cs(1,2) != tmat_(1,2) ||
838 cs(2,0) != tmat_(2,0) || cs(2,1) != tmat_(2,4) || cs(2,2) != tmat_(2,2) ||
839 cs(3,0) != tmat_(3,0) || cs(3,1) != tmat_(3,4) || cs(3,2) != tmat_(3,2) ) {
840 std::ostringstream oss;
841 oss << " Test: " << test_ << "\n"
842 << " Error: Setup of column selection failed\n"
843 << " Details:\n"
844 << " Result:\n" << cs << "\n";
845 throw std::runtime_error( oss.str() );
846 }
847 }
848
849 // Trying to setup an out-of-bounds column selection
850 try {
851 auto cs = blaze::columns( tmat_, { 5 } );
852
853 std::ostringstream oss;
854 oss << " Test: " << test_ << "\n"
855 << " Error: Setup of out-of-bounds column selection succeeded\n"
856 << " Details:\n"
857 << " Result:\n" << cs << "\n";
858 throw std::runtime_error( oss.str() );
859 }
860 catch( std::invalid_argument& ) {}
861
862 // Setup of a column selection on a compile-time column selection
863 {
864 auto cs1 = blaze::columns( tmat_, index_sequence<0,4,2>() );
865 auto cs2 = blaze::columns( cs1, { 2, 1 } );
866
867 if( cs2.rows() != tmat_.rows() || cs2.columns() != 2UL ||
868 cs2(0,0) != tmat_(0,2) || cs2(0,1) != tmat_(0,4) ||
869 cs2(1,0) != tmat_(1,2) || cs2(1,1) != tmat_(1,4) ||
870 cs2(2,0) != tmat_(2,2) || cs2(2,1) != tmat_(2,4) ||
871 cs2(3,0) != tmat_(3,2) || cs2(3,1) != tmat_(3,4) ) {
872 std::ostringstream oss;
873 oss << " Test: " << test_ << "\n"
874 << " Error: Setup of column selection failed\n"
875 << " Details:\n"
876 << " Result:\n" << cs2 << "\n";
877 throw std::runtime_error( oss.str() );
878 }
879 }
880
881 // Setup of a column selection on an explicit column selection
882 {
883 auto cs1 = blaze::columns( tmat_, { 0, 4, 2 } );
884 auto cs2 = blaze::columns( cs1, { 2, 1 } );
885
886 if( cs2.rows() != tmat_.rows() || cs2.columns() != 2UL ||
887 cs2(0,0) != tmat_(0,2) || cs2(0,1) != tmat_(0,4) ||
888 cs2(1,0) != tmat_(1,2) || cs2(1,1) != tmat_(1,4) ||
889 cs2(2,0) != tmat_(2,2) || cs2(2,1) != tmat_(2,4) ||
890 cs2(3,0) != tmat_(3,2) || cs2(3,1) != tmat_(3,4) ) {
891 std::ostringstream oss;
892 oss << " Test: " << test_ << "\n"
893 << " Error: Setup of column selection failed\n"
894 << " Details:\n"
895 << " Result:\n" << cs2 << "\n";
896 throw std::runtime_error( oss.str() );
897 }
898 }
899
900 // Setup of a column selection on an implicit column selection
901 {
902 const std::array<size_t,3UL> indices{ 0, 4, 2 };
903 auto cs1 = blaze::columns( tmat_, [indices]( size_t i ){ return indices[i]; }, 3UL );
904 auto cs2 = blaze::columns( cs1, { 2, 1 } );
905
906 if( cs2.rows() != tmat_.rows() || cs2.columns() != 2UL ||
907 cs2(0,0) != tmat_(0,2) || cs2(0,1) != tmat_(0,4) ||
908 cs2(1,0) != tmat_(1,2) || cs2(1,1) != tmat_(1,4) ||
909 cs2(2,0) != tmat_(2,2) || cs2(2,1) != tmat_(2,4) ||
910 cs2(3,0) != tmat_(3,2) || cs2(3,1) != tmat_(3,4) ) {
911 std::ostringstream oss;
912 oss << " Test: " << test_ << "\n"
913 << " Error: Setup of column selection failed\n"
914 << " Details:\n"
915 << " Result:\n" << cs2 << "\n";
916 throw std::runtime_error( oss.str() );
917 }
918 }
919 }
920
921
922 //=====================================================================================
923 // Column-major setup via std::vector
924 //=====================================================================================
925
926 {
927 test_ = "Column-major Columns constructor (std::vector)";
928
929 initialize();
930
931 // Setup of empty column selection
932 {
933 std::vector<size_t> indices;
934 auto cs = blaze::columns( tmat_, indices );
935
936 if( cs.rows() != tmat_.rows() || cs.columns() != 0UL ) {
937 std::ostringstream oss;
938 oss << " Test: " << test_ << "\n"
939 << " Error: Setup of empty column selection failed\n"
940 << " Details:\n"
941 << " Result:\n" << cs << "\n";
942 throw std::runtime_error( oss.str() );
943 }
944 }
945
946 // Setup of a regular column selection
947 {
948 const std::vector<size_t> indices{ 0, 4, 2 };
949 auto cs = blaze::columns( tmat_, indices );
950
951 if( cs.rows() != tmat_.rows() || cs.columns() != 3UL ||
952 cs(0,0) != tmat_(0,0) || cs(0,1) != tmat_(0,4) || cs(0,2) != tmat_(0,2) ||
953 cs(1,0) != tmat_(1,0) || cs(1,1) != tmat_(1,4) || cs(1,2) != tmat_(1,2) ||
954 cs(2,0) != tmat_(2,0) || cs(2,1) != tmat_(2,4) || cs(2,2) != tmat_(2,2) ||
955 cs(3,0) != tmat_(3,0) || cs(3,1) != tmat_(3,4) || cs(3,2) != tmat_(3,2) ) {
956 std::ostringstream oss;
957 oss << " Test: " << test_ << "\n"
958 << " Error: Setup of column selection failed\n"
959 << " Details:\n"
960 << " Result:\n" << cs << "\n";
961 throw std::runtime_error( oss.str() );
962 }
963 }
964
965 // Trying to setup an out-of-bounds column selection
966 try {
967 std::vector<size_t> indices{ 5 };
968 auto cs = blaze::columns( tmat_, indices );
969
970 std::ostringstream oss;
971 oss << " Test: " << test_ << "\n"
972 << " Error: Setup of out-of-bounds column selection succeeded\n"
973 << " Details:\n"
974 << " Result:\n" << cs << "\n";
975 throw std::runtime_error( oss.str() );
976 }
977 catch( std::invalid_argument& ) {}
978
979 // Setup of a column selection on a compile-time column selection
980 {
981 auto cs1 = blaze::columns( tmat_, index_sequence<0,4,2>() );
982
983 const std::vector<size_t> indices{ 2, 1 };
984 auto cs2 = blaze::columns( cs1, indices );
985
986 if( cs2.rows() != tmat_.rows() || cs2.columns() != 2UL ||
987 cs2(0,0) != tmat_(0,2) || cs2(0,1) != tmat_(0,4) ||
988 cs2(1,0) != tmat_(1,2) || cs2(1,1) != tmat_(1,4) ||
989 cs2(2,0) != tmat_(2,2) || cs2(2,1) != tmat_(2,4) ||
990 cs2(3,0) != tmat_(3,2) || cs2(3,1) != tmat_(3,4) ) {
991 std::ostringstream oss;
992 oss << " Test: " << test_ << "\n"
993 << " Error: Setup of column selection failed\n"
994 << " Details:\n"
995 << " Result:\n" << cs2 << "\n";
996 throw std::runtime_error( oss.str() );
997 }
998 }
999
1000 // Setup of a column selection on an explicit column selection
1001 {
1002 auto cs1 = blaze::columns( tmat_, { 0, 4, 2 } );
1003
1004 const std::vector<size_t> indices{ 2, 1 };
1005 auto cs2 = blaze::columns( cs1, indices );
1006
1007 if( cs2.rows() != tmat_.rows() || cs2.columns() != 2UL ||
1008 cs2(0,0) != tmat_(0,2) || cs2(0,1) != tmat_(0,4) ||
1009 cs2(1,0) != tmat_(1,2) || cs2(1,1) != tmat_(1,4) ||
1010 cs2(2,0) != tmat_(2,2) || cs2(2,1) != tmat_(2,4) ||
1011 cs2(3,0) != tmat_(3,2) || cs2(3,1) != tmat_(3,4) ) {
1012 std::ostringstream oss;
1013 oss << " Test: " << test_ << "\n"
1014 << " Error: Setup of column selection failed\n"
1015 << " Details:\n"
1016 << " Result:\n" << cs2 << "\n";
1017 throw std::runtime_error( oss.str() );
1018 }
1019 }
1020
1021 // Setup of a column selection on an implicit column selection
1022 {
1023 const std::array<size_t,3UL> indices1{ 0, 4, 2 };
1024 auto cs1 = blaze::columns( tmat_, [indices1]( size_t i ){ return indices1[i]; }, 3UL );
1025
1026 const std::vector<size_t> indices2{ 2, 1 };
1027 auto cs2 = blaze::columns( cs1, indices2 );
1028
1029 if( cs2.rows() != tmat_.rows() || cs2.columns() != 2UL ||
1030 cs2(0,0) != tmat_(0,2) || cs2(0,1) != tmat_(0,4) ||
1031 cs2(1,0) != tmat_(1,2) || cs2(1,1) != tmat_(1,4) ||
1032 cs2(2,0) != tmat_(2,2) || cs2(2,1) != tmat_(2,4) ||
1033 cs2(3,0) != tmat_(3,2) || cs2(3,1) != tmat_(3,4) ) {
1034 std::ostringstream oss;
1035 oss << " Test: " << test_ << "\n"
1036 << " Error: Setup of column selection failed\n"
1037 << " Details:\n"
1038 << " Result:\n" << cs2 << "\n";
1039 throw std::runtime_error( oss.str() );
1040 }
1041 }
1042 }
1043
1044
1045 //=====================================================================================
1046 // Column-major setup via std::array
1047 //=====================================================================================
1048
1049 {
1050 test_ = "Column-major Columns constructor (std::array)";
1051
1052 initialize();
1053
1054 // Setup of a regular column selection
1055 {
1056 const std::array<size_t,3UL> indices{ 0, 4, 2 };
1057 auto cs = blaze::columns( tmat_, indices );
1058
1059 if( cs.rows() != tmat_.rows() || cs.columns() != 3UL ||
1060 cs(0,0) != tmat_(0,0) || cs(0,1) != tmat_(0,4) || cs(0,2) != tmat_(0,2) ||
1061 cs(1,0) != tmat_(1,0) || cs(1,1) != tmat_(1,4) || cs(1,2) != tmat_(1,2) ||
1062 cs(2,0) != tmat_(2,0) || cs(2,1) != tmat_(2,4) || cs(2,2) != tmat_(2,2) ||
1063 cs(3,0) != tmat_(3,0) || cs(3,1) != tmat_(3,4) || cs(3,2) != tmat_(3,2) ) {
1064 std::ostringstream oss;
1065 oss << " Test: " << test_ << "\n"
1066 << " Error: Setup of column selection failed\n"
1067 << " Details:\n"
1068 << " Result:\n" << cs << "\n";
1069 throw std::runtime_error( oss.str() );
1070 }
1071 }
1072
1073 // Trying to setup an out-of-bounds column selection
1074 try {
1075 std::array<size_t,1UL> indices{ 5 };
1076 auto cs = blaze::columns( tmat_, indices );
1077
1078 std::ostringstream oss;
1079 oss << " Test: " << test_ << "\n"
1080 << " Error: Setup of out-of-bounds column selection succeeded\n"
1081 << " Details:\n"
1082 << " Result:\n" << cs << "\n";
1083 throw std::runtime_error( oss.str() );
1084 }
1085 catch( std::invalid_argument& ) {}
1086
1087 // Setup of a column selection on a compile-time column selection
1088 {
1089 auto cs1 = blaze::columns( tmat_, index_sequence<0,4,2>() );
1090
1091 const std::array<size_t,2UL> indices{ 2, 1 };
1092 auto cs2 = blaze::columns( cs1, indices );
1093
1094 if( cs2.rows() != tmat_.rows() || cs2.columns() != 2UL ||
1095 cs2(0,0) != tmat_(0,2) || cs2(0,1) != tmat_(0,4) ||
1096 cs2(1,0) != tmat_(1,2) || cs2(1,1) != tmat_(1,4) ||
1097 cs2(2,0) != tmat_(2,2) || cs2(2,1) != tmat_(2,4) ||
1098 cs2(3,0) != tmat_(3,2) || cs2(3,1) != tmat_(3,4) ) {
1099 std::ostringstream oss;
1100 oss << " Test: " << test_ << "\n"
1101 << " Error: Setup of column selection failed\n"
1102 << " Details:\n"
1103 << " Result:\n" << cs2 << "\n";
1104 throw std::runtime_error( oss.str() );
1105 }
1106 }
1107
1108 // Setup of a column selection on an explicit column selection
1109 {
1110 auto cs1 = blaze::columns( tmat_, { 0, 4, 2 } );
1111
1112 const std::array<size_t,2UL> indices{ 2, 1 };
1113 auto cs2 = blaze::columns( cs1, indices );
1114
1115 if( cs2.rows() != tmat_.rows() || cs2.columns() != 2UL ||
1116 cs2(0,0) != tmat_(0,2) || cs2(0,1) != tmat_(0,4) ||
1117 cs2(1,0) != tmat_(1,2) || cs2(1,1) != tmat_(1,4) ||
1118 cs2(2,0) != tmat_(2,2) || cs2(2,1) != tmat_(2,4) ||
1119 cs2(3,0) != tmat_(3,2) || cs2(3,1) != tmat_(3,4) ) {
1120 std::ostringstream oss;
1121 oss << " Test: " << test_ << "\n"
1122 << " Error: Setup of column selection failed\n"
1123 << " Details:\n"
1124 << " Result:\n" << cs2 << "\n";
1125 throw std::runtime_error( oss.str() );
1126 }
1127 }
1128
1129 // Setup of a column selection on an implicit column selection
1130 {
1131 const std::array<size_t,3UL> indices1{ 0, 4, 2 };
1132 auto cs1 = blaze::columns( tmat_, [indices1]( size_t i ){ return indices1[i]; }, 3UL );
1133
1134 const std::array<size_t,2UL> indices{ 2, 1 };
1135 auto cs2 = blaze::columns( cs1, indices );
1136
1137 if( cs2.rows() != tmat_.rows() || cs2.columns() != 2UL ||
1138 cs2(0,0) != tmat_(0,2) || cs2(0,1) != tmat_(0,4) ||
1139 cs2(1,0) != tmat_(1,2) || cs2(1,1) != tmat_(1,4) ||
1140 cs2(2,0) != tmat_(2,2) || cs2(2,1) != tmat_(2,4) ||
1141 cs2(3,0) != tmat_(3,2) || cs2(3,1) != tmat_(3,4) ) {
1142 std::ostringstream oss;
1143 oss << " Test: " << test_ << "\n"
1144 << " Error: Setup of column selection failed\n"
1145 << " Details:\n"
1146 << " Result:\n" << cs2 << "\n";
1147 throw std::runtime_error( oss.str() );
1148 }
1149 }
1150 }
1151
1152
1153 //=====================================================================================
1154 // Column-major setup via lambda expression
1155 //=====================================================================================
1156
1157 {
1158 test_ = "Column-major Columns constructor (lambda expression)";
1159
1160 initialize();
1161
1162 // Setup of empty column selection
1163 {
1164 auto cs = blaze::columns( tmat_, []( size_t ){ return 0UL; }, 0UL );
1165
1166 if( cs.rows() != tmat_.rows() || cs.columns() != 0UL ) {
1167 std::ostringstream oss;
1168 oss << " Test: " << test_ << "\n"
1169 << " Error: Setup of empty column selection failed\n"
1170 << " Details:\n"
1171 << " Result:\n" << cs << "\n";
1172 throw std::runtime_error( oss.str() );
1173 }
1174 }
1175
1176 // Setup of a regular column selection
1177 {
1178 const std::array<size_t,3UL> indices{ 0, 4, 2 };
1179 auto cs = blaze::columns( tmat_, [indices]( size_t i ){ return indices[i]; }, 3UL );
1180
1181 if( cs.rows() != tmat_.rows() || cs.columns() != 3UL ||
1182 cs(0,0) != tmat_(0,0) || cs(0,1) != tmat_(0,4) || cs(0,2) != tmat_(0,2) ||
1183 cs(1,0) != tmat_(1,0) || cs(1,1) != tmat_(1,4) || cs(1,2) != tmat_(1,2) ||
1184 cs(2,0) != tmat_(2,0) || cs(2,1) != tmat_(2,4) || cs(2,2) != tmat_(2,2) ||
1185 cs(3,0) != tmat_(3,0) || cs(3,1) != tmat_(3,4) || cs(3,2) != tmat_(3,2) ) {
1186 std::ostringstream oss;
1187 oss << " Test: " << test_ << "\n"
1188 << " Error: Setup of column selection failed\n"
1189 << " Details:\n"
1190 << " Result:\n" << cs << "\n";
1191 throw std::runtime_error( oss.str() );
1192 }
1193 }
1194
1195 // Trying to setup an out-of-bounds column selection
1196 try {
1197 auto cs = blaze::columns( tmat_, []( size_t ){ return 5UL; }, 1UL );
1198
1199 std::ostringstream oss;
1200 oss << " Test: " << test_ << "\n"
1201 << " Error: Setup of out-of-bounds column selection succeeded\n"
1202 << " Details:\n"
1203 << " Result:\n" << cs << "\n";
1204 throw std::runtime_error( oss.str() );
1205 }
1206 catch( std::invalid_argument& ) {}
1207
1208 // Setup of a column selection on a compile-time column selection
1209 {
1210 auto cs1 = blaze::columns( tmat_, index_sequence<0,4,2>() );
1211
1212 const std::array<size_t,2UL> indices{ 2, 1 };
1213 auto cs2 = blaze::columns( cs1, [indices]( size_t i ){ return indices[i]; }, 2UL );
1214
1215 if( cs2.rows() != tmat_.rows() || cs2.columns() != 2UL ||
1216 cs2(0,0) != tmat_(0,2) || cs2(0,1) != tmat_(0,4) ||
1217 cs2(1,0) != tmat_(1,2) || cs2(1,1) != tmat_(1,4) ||
1218 cs2(2,0) != tmat_(2,2) || cs2(2,1) != tmat_(2,4) ||
1219 cs2(3,0) != tmat_(3,2) || cs2(3,1) != tmat_(3,4) ) {
1220 std::ostringstream oss;
1221 oss << " Test: " << test_ << "\n"
1222 << " Error: Setup of column selection failed\n"
1223 << " Details:\n"
1224 << " Result:\n" << cs2 << "\n";
1225 throw std::runtime_error( oss.str() );
1226 }
1227 }
1228
1229 // Setup of a column selection on an explicit column selection
1230 {
1231 auto cs1 = blaze::columns( tmat_, { 0, 4, 2 } );
1232
1233 const std::array<size_t,2UL> indices{ 2, 1 };
1234 auto cs2 = blaze::columns( cs1, [indices]( size_t i ){ return indices[i]; }, 2UL );
1235
1236 if( cs2.rows() != tmat_.rows() || cs2.columns() != 2UL ||
1237 cs2(0,0) != tmat_(0,2) || cs2(0,1) != tmat_(0,4) ||
1238 cs2(1,0) != tmat_(1,2) || cs2(1,1) != tmat_(1,4) ||
1239 cs2(2,0) != tmat_(2,2) || cs2(2,1) != tmat_(2,4) ||
1240 cs2(3,0) != tmat_(3,2) || cs2(3,1) != tmat_(3,4) ) {
1241 std::ostringstream oss;
1242 oss << " Test: " << test_ << "\n"
1243 << " Error: Setup of column selection failed\n"
1244 << " Details:\n"
1245 << " Result:\n" << cs2 << "\n";
1246 throw std::runtime_error( oss.str() );
1247 }
1248 }
1249
1250 // Setup of a column selection on an implicit column selection
1251 {
1252 const std::array<size_t,3UL> indices1{ 0, 4, 2 };
1253 auto cs1 = blaze::columns( tmat_, [indices1]( size_t i ){ return indices1[i]; }, 3UL );
1254
1255 const std::array<size_t,2UL> indices2{ 2, 1 };
1256 auto cs2 = blaze::columns( cs1, [indices2]( size_t i ){ return indices2[i]; }, 2UL );
1257
1258 if( cs2.rows() != tmat_.rows() || cs2.columns() != 2UL ||
1259 cs2(0,0) != tmat_(0,2) || cs2(0,1) != tmat_(0,4) ||
1260 cs2(1,0) != tmat_(1,2) || cs2(1,1) != tmat_(1,4) ||
1261 cs2(2,0) != tmat_(2,2) || cs2(2,1) != tmat_(2,4) ||
1262 cs2(3,0) != tmat_(3,2) || cs2(3,1) != tmat_(3,4) ) {
1263 std::ostringstream oss;
1264 oss << " Test: " << test_ << "\n"
1265 << " Error: Setup of column selection failed\n"
1266 << " Details:\n"
1267 << " Result:\n" << cs2 << "\n";
1268 throw std::runtime_error( oss.str() );
1269 }
1270 }
1271 }
1272
1273
1274 //=====================================================================================
1275 // Column-major setup of random in-bounds element selection
1276 //=====================================================================================
1277
1278 {
1279 test_ = "Column-major Columns constructor (stress test)";
1280
1281 initialize();
1282
1283 for( size_t rep=0UL; rep<100UL; ++rep )
1284 {
1285 blaze::DynamicVector<size_t> indices( blaze::rand<size_t>( 1UL, 20UL ) );
1286 randomize( indices, 0UL, tmat_.rows()-1UL );
1287 auto cs = blaze::columns( tmat_, indices.data(), indices.size() );
1288
1289 for( size_t i=0UL; i<cs.rows(); ++i ) {
1290 for( size_t j=0UL; j<cs.columns(); ++j ) {
1291 if( cs(i,j) != tmat_(i,indices[j]) ) {
1292 std::ostringstream oss;
1293 oss << " Test: " << test_ << "\n"
1294 << " Error: Setup of column selection failed\n"
1295 << " Details:\n"
1296 << " Indices:\n" << indices << "\n"
1297 << " Column selection:\n" << cs << "\n"
1298 << " Matrix:\n" << tmat_ << "\n";
1299 throw std::runtime_error( oss.str() );
1300 }
1301 }
1302 }
1303 }
1304 }
1305 }
1306 //*************************************************************************************************
1307
1308
1309 //*************************************************************************************************
1310 /*!\brief Test of the Columns assignment operators.
1311 //
1312 // \return void
1313 // \exception std::runtime_error Error detected.
1314 //
1315 // This function performs a test of all assignment operators of the Columns specialization.
1316 // In case an error is detected, a \a std::runtime_error exception is thrown.
1317 */
testAssignment()1318 void SparseGeneralTest::testAssignment()
1319 {
1320 //=====================================================================================
1321 // Row-major list assignment
1322 //=====================================================================================
1323
1324 {
1325 test_ = "Row-major Columns list assignment (complete list)";
1326
1327 initialize();
1328
1329 auto cs = blaze::columns( mat_, { 3UL, 1UL } );
1330 cs = { { 11, 0 }, { 0, 13 }, { 0, 14 }, { 12, 0 } };
1331
1332 checkRows ( cs , 4UL );
1333 checkColumns ( cs , 2UL );
1334 checkNonZeros( cs , 4UL );
1335 checkRows ( mat_, 4UL );
1336 checkColumns ( mat_, 5UL );
1337 checkNonZeros( mat_, 10UL );
1338
1339 if( cs(0,0) != 11 || cs(0,1) != 0 ||
1340 cs(1,0) != 0 || cs(1,1) != 13 ||
1341 cs(2,0) != 0 || cs(2,1) != 14 ||
1342 cs(3,0) != 12 || cs(3,1) != 0 ) {
1343 std::ostringstream oss;
1344 oss << " Test: " << test_ << "\n"
1345 << " Error: Assignment failed\n"
1346 << " Details:\n"
1347 << " Result:\n" << cs << "\n"
1348 << " Expected result:\n( 11 0 )\n( 0 13 )\n( 0 14 )\n( 12 0 )\n";
1349 throw std::runtime_error( oss.str() );
1350 }
1351
1352 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != -2 || mat_(0,3) != 11 || mat_(0,4) != 7 ||
1353 mat_(1,0) != 0 || mat_(1,1) != 13 || mat_(1,2) != 0 || mat_(1,3) != 0 || mat_(1,4) != -8 ||
1354 mat_(2,0) != 0 || mat_(2,1) != 14 || mat_(2,2) != -3 || mat_(2,3) != 0 || mat_(2,4) != 9 ||
1355 mat_(3,0) != 0 || mat_(3,1) != 0 || mat_(3,2) != 0 || mat_(3,3) != 12 || mat_(3,4) != 10 ) {
1356 std::ostringstream oss;
1357 oss << " Test: " << test_ << "\n"
1358 << " Error: Assignment failed\n"
1359 << " Details:\n"
1360 << " Result:\n" << mat_ << "\n"
1361 << " Expected result:\n( 0 0 -2 11 7 )\n"
1362 "( 0 13 0 0 -8 )\n"
1363 "( 0 14 -3 0 9 )\n"
1364 "( 0 0 0 12 10 )\n";
1365 throw std::runtime_error( oss.str() );
1366 }
1367 }
1368
1369 {
1370 test_ = "Row-major Columns list assignment (incomplete list)";
1371
1372 initialize();
1373
1374 auto cs = blaze::columns( mat_, { 3UL, 1UL } );
1375 cs = { { 11 }, { 0, 13 }, { 0, 14 }, { 12 } };
1376
1377 checkRows ( cs , 4UL );
1378 checkColumns ( cs , 2UL );
1379 checkNonZeros( cs , 4UL );
1380 checkRows ( mat_, 4UL );
1381 checkColumns ( mat_, 5UL );
1382 checkNonZeros( mat_, 10UL );
1383
1384 if( cs(0,0) != 11 || cs(0,1) != 0 ||
1385 cs(1,0) != 0 || cs(1,1) != 13 ||
1386 cs(2,0) != 0 || cs(2,1) != 14 ||
1387 cs(3,0) != 12 || cs(3,1) != 0 ) {
1388 std::ostringstream oss;
1389 oss << " Test: " << test_ << "\n"
1390 << " Error: Assignment failed\n"
1391 << " Details:\n"
1392 << " Result:\n" << cs << "\n"
1393 << " Expected result:\n( 11 0 )\n( 0 13 )\n( 0 14 )\n( 12 0 )\n";
1394 throw std::runtime_error( oss.str() );
1395 }
1396
1397 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != -2 || mat_(0,3) != 11 || mat_(0,4) != 7 ||
1398 mat_(1,0) != 0 || mat_(1,1) != 13 || mat_(1,2) != 0 || mat_(1,3) != 0 || mat_(1,4) != -8 ||
1399 mat_(2,0) != 0 || mat_(2,1) != 14 || mat_(2,2) != -3 || mat_(2,3) != 0 || mat_(2,4) != 9 ||
1400 mat_(3,0) != 0 || mat_(3,1) != 0 || mat_(3,2) != 0 || mat_(3,3) != 12 || mat_(3,4) != 10 ) {
1401 std::ostringstream oss;
1402 oss << " Test: " << test_ << "\n"
1403 << " Error: Assignment failed\n"
1404 << " Details:\n"
1405 << " Result:\n" << mat_ << "\n"
1406 << " Expected result:\n( 0 0 -2 11 7 )\n"
1407 "( 0 13 0 0 -8 )\n"
1408 "( 0 14 -3 0 9 )\n"
1409 "( 0 0 0 12 10 )\n";
1410 throw std::runtime_error( oss.str() );
1411 }
1412 }
1413
1414
1415 //=====================================================================================
1416 // Row-major copy assignment
1417 //=====================================================================================
1418
1419 {
1420 test_ = "Row-major Columns copy assignment (no aliasing)";
1421
1422 initialize();
1423
1424 MT mat{ { 0, 11, 0, 13, 0 },
1425 { 0, 0, 0, 14, 0 },
1426 { 0, 12, 0, 15, 0 },
1427 { 0, 0, 0, 16, 0 } };
1428
1429 auto cs = blaze::columns( mat, { 3UL, 1UL } );
1430 cs = blaze::columns( mat_, { 3UL, 1UL } );
1431
1432 checkRows ( cs , 4UL );
1433 checkColumns ( cs , 2UL );
1434 checkNonZeros( cs , 4UL );
1435 checkRows ( mat, 4UL );
1436 checkColumns ( mat, 5UL );
1437 checkNonZeros( mat, 4UL );
1438
1439 if( cs(0,0) != 0 || cs(0,1) != 0 ||
1440 cs(1,0) != 4 || cs(1,1) != 1 ||
1441 cs(2,0) != 5 || cs(2,1) != 0 ||
1442 cs(3,0) != -6 || cs(3,1) != 0 ) {
1443 std::ostringstream oss;
1444 oss << " Test: " << test_ << "\n"
1445 << " Error: Assignment failed\n"
1446 << " Details:\n"
1447 << " Result:\n" << cs << "\n"
1448 << " Expected result:\n( 0 0 )\n( 4 1 )\n( 5 0 )\n( -6 0 )\n";
1449 throw std::runtime_error( oss.str() );
1450 }
1451
1452 if( mat(0,0) != 0 || mat(0,1) != 0 || mat(0,2) != 0 || mat(0,3) != 0 || mat(0,4) != 0 ||
1453 mat(1,0) != 0 || mat(1,1) != 1 || mat(1,2) != 0 || mat(1,3) != 4 || mat(1,4) != 0 ||
1454 mat(2,0) != 0 || mat(2,1) != 0 || mat(2,2) != 0 || mat(2,3) != 5 || mat(2,4) != 0 ||
1455 mat(3,0) != 0 || mat(3,1) != 0 || mat(3,2) != 0 || mat(3,3) != -6 || mat(3,4) != 0 ) {
1456 std::ostringstream oss;
1457 oss << " Test: " << test_ << "\n"
1458 << " Error: Assignment failed\n"
1459 << " Details:\n"
1460 << " Result:\n" << mat << "\n"
1461 << " Expected result:\n( 0 0 0 0 0 )\n"
1462 "( 0 1 0 4 0 )\n"
1463 "( 0 0 0 5 0 )\n"
1464 "( 0 0 0 -6 0 )\n";
1465 throw std::runtime_error( oss.str() );
1466 }
1467 }
1468
1469 {
1470 test_ = "Row-major Columns copy assignment (aliasing)";
1471
1472 initialize();
1473
1474 auto cs = blaze::columns( mat_, { 3UL, 4UL } );
1475 cs = blaze::columns( mat_, { 2UL, 3UL } );
1476
1477 checkRows ( cs , 4UL );
1478 checkColumns ( cs , 2UL );
1479 checkNonZeros( cs , 5UL );
1480 checkRows ( mat_, 4UL );
1481 checkColumns ( mat_, 5UL );
1482 checkNonZeros( mat_, 8UL );
1483
1484 if( cs(0,0) != -2 || cs(0,1) != 0 ||
1485 cs(1,0) != 0 || cs(1,1) != 4 ||
1486 cs(2,0) != -3 || cs(2,1) != 5 ||
1487 cs(3,0) != 0 || cs(3,1) != -6 ) {
1488 std::ostringstream oss;
1489 oss << " Test: " << test_ << "\n"
1490 << " Error: Assignment failed\n"
1491 << " Details:\n"
1492 << " Result:\n" << cs << "\n"
1493 << " Expected result:\n( -2 0 )\n( 0 4 )\n( -3 5 )\n( 0 -6 )\n";
1494 throw std::runtime_error( oss.str() );
1495 }
1496
1497 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != -2 || mat_(0,3) != -2 || mat_(0,4) != 0 ||
1498 mat_(1,0) != 0 || mat_(1,1) != 1 || mat_(1,2) != 0 || mat_(1,3) != 0 || mat_(1,4) != 4 ||
1499 mat_(2,0) != 0 || mat_(2,1) != 0 || mat_(2,2) != -3 || mat_(2,3) != -3 || mat_(2,4) != 5 ||
1500 mat_(3,0) != 0 || mat_(3,1) != 0 || mat_(3,2) != 0 || mat_(3,3) != 0 || mat_(3,4) != -6 ) {
1501 std::ostringstream oss;
1502 oss << " Test: " << test_ << "\n"
1503 << " Error: Assignment failed\n"
1504 << " Details:\n"
1505 << " Result:\n" << mat_ << "\n"
1506 << " Expected result:\n( 0 0 -2 -2 0 )\n"
1507 "( 0 1 0 0 4 )\n"
1508 "( 0 0 -3 -3 5 )\n"
1509 "( 0 0 0 0 -6 )\n";
1510 throw std::runtime_error( oss.str() );
1511 }
1512 }
1513
1514
1515 //=====================================================================================
1516 // Row-major dense matrix assignment
1517 //=====================================================================================
1518
1519 {
1520 test_ = "Row-major/row-major dense matrix assignment";
1521
1522 initialize();
1523
1524 auto cs = blaze::columns( mat_, { 3UL, 1UL } );
1525
1526 const blaze::DynamicMatrix<int,blaze::rowMajor> mat{ { 11, 0 },
1527 { 0, 13 },
1528 { 0, 14 },
1529 { 12, 0 } };
1530
1531 cs = mat;
1532
1533 checkRows ( cs , 4UL );
1534 checkColumns ( cs , 2UL );
1535 checkNonZeros( cs , 4UL );
1536 checkRows ( mat_, 4UL );
1537 checkColumns ( mat_, 5UL );
1538 checkNonZeros( mat_, 10UL );
1539
1540 if( cs(0,0) != 11 || cs(0,1) != 0 ||
1541 cs(1,0) != 0 || cs(1,1) != 13 ||
1542 cs(2,0) != 0 || cs(2,1) != 14 ||
1543 cs(3,0) != 12 || cs(3,1) != 0 ) {
1544 std::ostringstream oss;
1545 oss << " Test: " << test_ << "\n"
1546 << " Error: Assignment failed\n"
1547 << " Details:\n"
1548 << " Result:\n" << cs << "\n"
1549 << " Expected result:\n( 11 0 )\n( 0 13 )\n( 0 14 )\n( 12 0 )\n";
1550 throw std::runtime_error( oss.str() );
1551 }
1552
1553 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != -2 || mat_(0,3) != 11 || mat_(0,4) != 7 ||
1554 mat_(1,0) != 0 || mat_(1,1) != 13 || mat_(1,2) != 0 || mat_(1,3) != 0 || mat_(1,4) != -8 ||
1555 mat_(2,0) != 0 || mat_(2,1) != 14 || mat_(2,2) != -3 || mat_(2,3) != 0 || mat_(2,4) != 9 ||
1556 mat_(3,0) != 0 || mat_(3,1) != 0 || mat_(3,2) != 0 || mat_(3,3) != 12 || mat_(3,4) != 10 ) {
1557 std::ostringstream oss;
1558 oss << " Test: " << test_ << "\n"
1559 << " Error: Assignment failed\n"
1560 << " Details:\n"
1561 << " Result:\n" << mat_ << "\n"
1562 << " Expected result:\n( 0 0 -2 11 7 )\n"
1563 "( 0 13 0 0 -8 )\n"
1564 "( 0 14 -3 0 9 )\n"
1565 "( 0 0 0 12 10 )\n";
1566 throw std::runtime_error( oss.str() );
1567 }
1568 }
1569
1570 {
1571 test_ = "Row-major/column-major dense matrix assignment";
1572
1573 initialize();
1574
1575 auto cs = blaze::columns( mat_, { 3UL, 1UL } );
1576
1577 const blaze::DynamicMatrix<int,blaze::columnMajor> mat{ { 11, 0 },
1578 { 0, 13 },
1579 { 0, 14 },
1580 { 12, 0 } };
1581
1582 cs = mat;
1583
1584 checkRows ( cs , 4UL );
1585 checkColumns ( cs , 2UL );
1586 checkNonZeros( cs , 4UL );
1587 checkRows ( mat_, 4UL );
1588 checkColumns ( mat_, 5UL );
1589 checkNonZeros( mat_, 10UL );
1590
1591 if( cs(0,0) != 11 || cs(0,1) != 0 ||
1592 cs(1,0) != 0 || cs(1,1) != 13 ||
1593 cs(2,0) != 0 || cs(2,1) != 14 ||
1594 cs(3,0) != 12 || cs(3,1) != 0 ) {
1595 std::ostringstream oss;
1596 oss << " Test: " << test_ << "\n"
1597 << " Error: Assignment failed\n"
1598 << " Details:\n"
1599 << " Result:\n" << cs << "\n"
1600 << " Expected result:\n( 11 0 )\n( 0 13 )\n( 0 14 )\n( 12 0 )\n";
1601 throw std::runtime_error( oss.str() );
1602 }
1603
1604 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != -2 || mat_(0,3) != 11 || mat_(0,4) != 7 ||
1605 mat_(1,0) != 0 || mat_(1,1) != 13 || mat_(1,2) != 0 || mat_(1,3) != 0 || mat_(1,4) != -8 ||
1606 mat_(2,0) != 0 || mat_(2,1) != 14 || mat_(2,2) != -3 || mat_(2,3) != 0 || mat_(2,4) != 9 ||
1607 mat_(3,0) != 0 || mat_(3,1) != 0 || mat_(3,2) != 0 || mat_(3,3) != 12 || mat_(3,4) != 10 ) {
1608 std::ostringstream oss;
1609 oss << " Test: " << test_ << "\n"
1610 << " Error: Assignment failed\n"
1611 << " Details:\n"
1612 << " Result:\n" << mat_ << "\n"
1613 << " Expected result:\n( 0 0 -2 11 7 )\n"
1614 "( 0 13 0 0 -8 )\n"
1615 "( 0 14 -3 0 9 )\n"
1616 "( 0 0 0 12 10 )\n";
1617 throw std::runtime_error( oss.str() );
1618 }
1619 }
1620
1621
1622 //=====================================================================================
1623 // Row-major sparse matrix assignment
1624 //=====================================================================================
1625
1626 {
1627 test_ = "Row-major/row-major sparse matrix assignment";
1628
1629 initialize();
1630
1631 auto cs = blaze::columns( mat_, { 3UL, 1UL } );
1632
1633 const blaze::CompressedMatrix<int,blaze::rowMajor> mat{ { 11, 0 },
1634 { 0, 13 },
1635 { 0, 14 },
1636 { 12, 0 } };
1637
1638 cs = mat;
1639
1640 checkRows ( cs , 4UL );
1641 checkColumns ( cs , 2UL );
1642 checkNonZeros( cs , 4UL );
1643 checkRows ( mat_, 4UL );
1644 checkColumns ( mat_, 5UL );
1645 checkNonZeros( mat_, 10UL );
1646
1647 if( cs(0,0) != 11 || cs(0,1) != 0 ||
1648 cs(1,0) != 0 || cs(1,1) != 13 ||
1649 cs(2,0) != 0 || cs(2,1) != 14 ||
1650 cs(3,0) != 12 || cs(3,1) != 0 ) {
1651 std::ostringstream oss;
1652 oss << " Test: " << test_ << "\n"
1653 << " Error: Assignment failed\n"
1654 << " Details:\n"
1655 << " Result:\n" << cs << "\n"
1656 << " Expected result:\n( 11 0 )\n( 0 13 )\n( 0 14 )\n( 12 0 )\n";
1657 throw std::runtime_error( oss.str() );
1658 }
1659
1660 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != -2 || mat_(0,3) != 11 || mat_(0,4) != 7 ||
1661 mat_(1,0) != 0 || mat_(1,1) != 13 || mat_(1,2) != 0 || mat_(1,3) != 0 || mat_(1,4) != -8 ||
1662 mat_(2,0) != 0 || mat_(2,1) != 14 || mat_(2,2) != -3 || mat_(2,3) != 0 || mat_(2,4) != 9 ||
1663 mat_(3,0) != 0 || mat_(3,1) != 0 || mat_(3,2) != 0 || mat_(3,3) != 12 || mat_(3,4) != 10 ) {
1664 std::ostringstream oss;
1665 oss << " Test: " << test_ << "\n"
1666 << " Error: Assignment failed\n"
1667 << " Details:\n"
1668 << " Result:\n" << mat_ << "\n"
1669 << " Expected result:\n( 0 0 -2 11 7 )\n"
1670 "( 0 13 0 0 -8 )\n"
1671 "( 0 14 -3 0 9 )\n"
1672 "( 0 0 0 12 10 )\n";
1673 throw std::runtime_error( oss.str() );
1674 }
1675 }
1676
1677 {
1678 test_ = "Row-major/column-major sparse matrix assignment";
1679
1680 initialize();
1681
1682 auto cs = blaze::columns( mat_, { 3UL, 1UL } );
1683
1684 const blaze::CompressedMatrix<int,blaze::columnMajor> mat{ { 11, 0 },
1685 { 0, 13 },
1686 { 0, 14 },
1687 { 12, 0 } };
1688
1689 cs = mat;
1690
1691 checkRows ( cs , 4UL );
1692 checkColumns ( cs , 2UL );
1693 checkNonZeros( cs , 4UL );
1694 checkRows ( mat_, 4UL );
1695 checkColumns ( mat_, 5UL );
1696 checkNonZeros( mat_, 10UL );
1697
1698 if( cs(0,0) != 11 || cs(0,1) != 0 ||
1699 cs(1,0) != 0 || cs(1,1) != 13 ||
1700 cs(2,0) != 0 || cs(2,1) != 14 ||
1701 cs(3,0) != 12 || cs(3,1) != 0 ) {
1702 std::ostringstream oss;
1703 oss << " Test: " << test_ << "\n"
1704 << " Error: Assignment failed\n"
1705 << " Details:\n"
1706 << " Result:\n" << cs << "\n"
1707 << " Expected result:\n( 11 0 )\n( 0 13 )\n( 0 14 )\n( 12 0 )\n";
1708 throw std::runtime_error( oss.str() );
1709 }
1710
1711 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != -2 || mat_(0,3) != 11 || mat_(0,4) != 7 ||
1712 mat_(1,0) != 0 || mat_(1,1) != 13 || mat_(1,2) != 0 || mat_(1,3) != 0 || mat_(1,4) != -8 ||
1713 mat_(2,0) != 0 || mat_(2,1) != 14 || mat_(2,2) != -3 || mat_(2,3) != 0 || mat_(2,4) != 9 ||
1714 mat_(3,0) != 0 || mat_(3,1) != 0 || mat_(3,2) != 0 || mat_(3,3) != 12 || mat_(3,4) != 10 ) {
1715 std::ostringstream oss;
1716 oss << " Test: " << test_ << "\n"
1717 << " Error: Assignment failed\n"
1718 << " Details:\n"
1719 << " Result:\n" << mat_ << "\n"
1720 << " Expected result:\n( 0 0 -2 11 7 )\n"
1721 "( 0 13 0 0 -8 )\n"
1722 "( 0 14 -3 0 9 )\n"
1723 "( 0 0 0 12 10 )\n";
1724 throw std::runtime_error( oss.str() );
1725 }
1726 }
1727
1728
1729 //=====================================================================================
1730 // Column-major list assignment
1731 //=====================================================================================
1732
1733 {
1734 test_ = "Column-major Columns list assignment (complete list)";
1735
1736 initialize();
1737
1738 auto cs = blaze::columns( tmat_, { 3UL, 1UL } );
1739 cs = { { 11, 0 }, { 0, 13 }, { 0, 14 }, { 12, 0 } };
1740
1741 checkRows ( cs , 4UL );
1742 checkColumns ( cs , 2UL );
1743 checkNonZeros( cs , 4UL );
1744 checkRows ( mat_, 4UL );
1745 checkColumns ( mat_, 5UL );
1746 checkNonZeros( mat_, 10UL );
1747
1748 if( cs(0,0) != 11 || cs(0,1) != 0 ||
1749 cs(1,0) != 0 || cs(1,1) != 13 ||
1750 cs(2,0) != 0 || cs(2,1) != 14 ||
1751 cs(3,0) != 12 || cs(3,1) != 0 ) {
1752 std::ostringstream oss;
1753 oss << " Test: " << test_ << "\n"
1754 << " Error: Assignment failed\n"
1755 << " Details:\n"
1756 << " Result:\n" << cs << "\n"
1757 << " Expected result:\n( 11 0 )\n( 0 13 )\n( 0 14 )\n( 12 0 )\n";
1758 throw std::runtime_error( oss.str() );
1759 }
1760
1761 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != -2 || tmat_(0,3) != 11 || tmat_(0,4) != 7 ||
1762 tmat_(1,0) != 0 || tmat_(1,1) != 13 || tmat_(1,2) != 0 || tmat_(1,3) != 0 || tmat_(1,4) != -8 ||
1763 tmat_(2,0) != 0 || tmat_(2,1) != 14 || tmat_(2,2) != -3 || tmat_(2,3) != 0 || tmat_(2,4) != 9 ||
1764 tmat_(3,0) != 0 || tmat_(3,1) != 0 || tmat_(3,2) != 0 || tmat_(3,3) != 12 || tmat_(3,4) != 10 ) {
1765 std::ostringstream oss;
1766 oss << " Test: " << test_ << "\n"
1767 << " Error: Assignment failed\n"
1768 << " Details:\n"
1769 << " Result:\n" << tmat_ << "\n"
1770 << " Expected result:\n( 0 0 -2 11 7 )\n"
1771 "( 0 13 0 0 -8 )\n"
1772 "( 0 14 -3 0 9 )\n"
1773 "( 0 0 0 12 10 )\n";
1774 throw std::runtime_error( oss.str() );
1775 }
1776 }
1777
1778 {
1779 test_ = "Column-major Columns list assignment (incomplete list)";
1780
1781 initialize();
1782
1783 auto cs = blaze::columns( tmat_, { 3UL, 1UL } );
1784 cs = { { 11 }, { 0, 13 }, { 0, 14 }, { 12 } };
1785
1786 checkRows ( cs , 4UL );
1787 checkColumns ( cs , 2UL );
1788 checkNonZeros( cs , 4UL );
1789 checkRows ( tmat_, 4UL );
1790 checkColumns ( tmat_, 5UL );
1791 checkNonZeros( tmat_, 10UL );
1792
1793 if( cs(0,0) != 11 || cs(0,1) != 0 ||
1794 cs(1,0) != 0 || cs(1,1) != 13 ||
1795 cs(2,0) != 0 || cs(2,1) != 14 ||
1796 cs(3,0) != 12 || cs(3,1) != 0 ) {
1797 std::ostringstream oss;
1798 oss << " Test: " << test_ << "\n"
1799 << " Error: Assignment failed\n"
1800 << " Details:\n"
1801 << " Result:\n" << cs << "\n"
1802 << " Expected result:\n( 11 0 )\n( 0 13 )\n( 0 14 )\n( 12 0 )\n";
1803 throw std::runtime_error( oss.str() );
1804 }
1805
1806 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != -2 || tmat_(0,3) != 11 || tmat_(0,4) != 7 ||
1807 tmat_(1,0) != 0 || tmat_(1,1) != 13 || tmat_(1,2) != 0 || tmat_(1,3) != 0 || tmat_(1,4) != -8 ||
1808 tmat_(2,0) != 0 || tmat_(2,1) != 14 || tmat_(2,2) != -3 || tmat_(2,3) != 0 || tmat_(2,4) != 9 ||
1809 tmat_(3,0) != 0 || tmat_(3,1) != 0 || tmat_(3,2) != 0 || tmat_(3,3) != 12 || tmat_(3,4) != 10 ) {
1810 std::ostringstream oss;
1811 oss << " Test: " << test_ << "\n"
1812 << " Error: Assignment failed\n"
1813 << " Details:\n"
1814 << " Result:\n" << tmat_ << "\n"
1815 << " Expected result:\n( 0 0 -2 11 7 )\n"
1816 "( 0 13 0 0 -8 )\n"
1817 "( 0 14 -3 0 9 )\n"
1818 "( 0 0 0 12 10 )\n";
1819 throw std::runtime_error( oss.str() );
1820 }
1821 }
1822
1823
1824 //=====================================================================================
1825 // Column-major copy assignment
1826 //=====================================================================================
1827
1828 {
1829 test_ = "Column-major Columns copy assignment (no aliasing)";
1830
1831 initialize();
1832
1833 OMT mat{ { 0, 11, 0, 13, 0 },
1834 { 0, 0, 0, 14, 0 },
1835 { 0, 12, 0, 15, 0 },
1836 { 0, 0, 0, 16, 0 } };
1837
1838 auto cs = blaze::columns( mat, { 3UL, 1UL } );
1839 cs = blaze::columns( tmat_, { 3UL, 1UL } );
1840
1841 checkRows ( cs , 4UL );
1842 checkColumns ( cs , 2UL );
1843 checkNonZeros( cs , 4UL );
1844 checkRows ( mat, 4UL );
1845 checkColumns ( mat, 5UL );
1846 checkNonZeros( mat, 4UL );
1847
1848 if( cs(0,0) != 0 || cs(0,1) != 0 ||
1849 cs(1,0) != 4 || cs(1,1) != 1 ||
1850 cs(2,0) != 5 || cs(2,1) != 0 ||
1851 cs(3,0) != -6 || cs(3,1) != 0 ) {
1852 std::ostringstream oss;
1853 oss << " Test: " << test_ << "\n"
1854 << " Error: Assignment failed\n"
1855 << " Details:\n"
1856 << " Result:\n" << cs << "\n"
1857 << " Expected result:\n( 0 0 )\n( 4 1 )\n( 5 0 )\n( -6 0 )\n";
1858 throw std::runtime_error( oss.str() );
1859 }
1860
1861 if( mat(0,0) != 0 || mat(0,1) != 0 || mat(0,2) != 0 || mat(0,3) != 0 || mat(0,4) != 0 ||
1862 mat(1,0) != 0 || mat(1,1) != 1 || mat(1,2) != 0 || mat(1,3) != 4 || mat(1,4) != 0 ||
1863 mat(2,0) != 0 || mat(2,1) != 0 || mat(2,2) != 0 || mat(2,3) != 5 || mat(2,4) != 0 ||
1864 mat(3,0) != 0 || mat(3,1) != 0 || mat(3,2) != 0 || mat(3,3) != -6 || mat(3,4) != 0 ) {
1865 std::ostringstream oss;
1866 oss << " Test: " << test_ << "\n"
1867 << " Error: Assignment failed\n"
1868 << " Details:\n"
1869 << " Result:\n" << mat << "\n"
1870 << " Expected result:\n( 0 0 0 0 0 )\n"
1871 "( 0 1 0 4 0 )\n"
1872 "( 0 0 0 5 0 )\n"
1873 "( 0 0 0 -6 0 )\n";
1874 throw std::runtime_error( oss.str() );
1875 }
1876 }
1877
1878 {
1879 test_ = "Column-major Columns copy assignment (aliasing)";
1880
1881 initialize();
1882
1883 auto cs = blaze::columns( tmat_, { 3UL, 4UL } );
1884 cs = blaze::columns( tmat_, { 2UL, 3UL } );
1885
1886 checkRows ( cs , 4UL );
1887 checkColumns ( cs , 2UL );
1888 checkNonZeros( cs , 5UL );
1889 checkRows ( tmat_, 4UL );
1890 checkColumns ( tmat_, 5UL );
1891 checkNonZeros( tmat_, 8UL );
1892
1893 if( cs(0,0) != -2 || cs(0,1) != 0 ||
1894 cs(1,0) != 0 || cs(1,1) != 4 ||
1895 cs(2,0) != -3 || cs(2,1) != 5 ||
1896 cs(3,0) != 0 || cs(3,1) != -6 ) {
1897 std::ostringstream oss;
1898 oss << " Test: " << test_ << "\n"
1899 << " Error: Assignment failed\n"
1900 << " Details:\n"
1901 << " Result:\n" << cs << "\n"
1902 << " Expected result:\n( -2 0 )\n( 0 4 )\n( -3 5 )\n( 0 -6 )\n";
1903 throw std::runtime_error( oss.str() );
1904 }
1905
1906 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != -2 || tmat_(0,3) != -2 || tmat_(0,4) != 0 ||
1907 tmat_(1,0) != 0 || tmat_(1,1) != 1 || tmat_(1,2) != 0 || tmat_(1,3) != 0 || tmat_(1,4) != 4 ||
1908 tmat_(2,0) != 0 || tmat_(2,1) != 0 || tmat_(2,2) != -3 || tmat_(2,3) != -3 || tmat_(2,4) != 5 ||
1909 tmat_(3,0) != 0 || tmat_(3,1) != 0 || tmat_(3,2) != 0 || tmat_(3,3) != 0 || tmat_(3,4) != -6 ) {
1910 std::ostringstream oss;
1911 oss << " Test: " << test_ << "\n"
1912 << " Error: Assignment failed\n"
1913 << " Details:\n"
1914 << " Result:\n" << tmat_ << "\n"
1915 << " Expected result:\n( 0 0 -2 -2 0 )\n"
1916 "( 0 1 0 0 4 )\n"
1917 "( 0 0 -3 -3 5 )\n"
1918 "( 0 0 0 0 -6 )\n";
1919 throw std::runtime_error( oss.str() );
1920 }
1921 }
1922
1923
1924 //=====================================================================================
1925 // Column-major dense matrix assignment
1926 //=====================================================================================
1927
1928 {
1929 test_ = "Column-major/row-major dense matrix assignment";
1930
1931 initialize();
1932
1933 auto cs = blaze::columns( tmat_, { 3UL, 1UL } );
1934
1935 const blaze::DynamicMatrix<int,blaze::rowMajor> mat{ { 11, 0 },
1936 { 0, 13 },
1937 { 0, 14 },
1938 { 12, 0 } };
1939
1940 cs = mat;
1941
1942 checkRows ( cs , 4UL );
1943 checkColumns ( cs , 2UL );
1944 checkNonZeros( cs , 4UL );
1945 checkRows ( tmat_, 4UL );
1946 checkColumns ( tmat_, 5UL );
1947 checkNonZeros( tmat_, 10UL );
1948
1949 if( cs(0,0) != 11 || cs(0,1) != 0 ||
1950 cs(1,0) != 0 || cs(1,1) != 13 ||
1951 cs(2,0) != 0 || cs(2,1) != 14 ||
1952 cs(3,0) != 12 || cs(3,1) != 0 ) {
1953 std::ostringstream oss;
1954 oss << " Test: " << test_ << "\n"
1955 << " Error: Assignment failed\n"
1956 << " Details:\n"
1957 << " Result:\n" << cs << "\n"
1958 << " Expected result:\n( 11 0 )\n( 0 13 )\n( 0 14 )\n( 12 0 )\n";
1959 throw std::runtime_error( oss.str() );
1960 }
1961
1962 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != -2 || tmat_(0,3) != 11 || tmat_(0,4) != 7 ||
1963 tmat_(1,0) != 0 || tmat_(1,1) != 13 || tmat_(1,2) != 0 || tmat_(1,3) != 0 || tmat_(1,4) != -8 ||
1964 tmat_(2,0) != 0 || tmat_(2,1) != 14 || tmat_(2,2) != -3 || tmat_(2,3) != 0 || tmat_(2,4) != 9 ||
1965 tmat_(3,0) != 0 || tmat_(3,1) != 0 || tmat_(3,2) != 0 || tmat_(3,3) != 12 || tmat_(3,4) != 10 ) {
1966 std::ostringstream oss;
1967 oss << " Test: " << test_ << "\n"
1968 << " Error: Assignment failed\n"
1969 << " Details:\n"
1970 << " Result:\n" << tmat_ << "\n"
1971 << " Expected result:\n( 0 0 -2 11 7 )\n"
1972 "( 0 13 0 0 -8 )\n"
1973 "( 0 14 -3 0 9 )\n"
1974 "( 0 0 0 12 10 )\n";
1975 throw std::runtime_error( oss.str() );
1976 }
1977 }
1978
1979 {
1980 test_ = "Column-major/column-major dense matrix assignment";
1981
1982 initialize();
1983
1984 auto cs = blaze::columns( tmat_, { 3UL, 1UL } );
1985
1986 const blaze::DynamicMatrix<int,blaze::columnMajor> mat{ { 11, 0 },
1987 { 0, 13 },
1988 { 0, 14 },
1989 { 12, 0 } };
1990
1991 cs = mat;
1992
1993 checkRows ( cs , 4UL );
1994 checkColumns ( cs , 2UL );
1995 checkNonZeros( cs , 4UL );
1996 checkRows ( tmat_, 4UL );
1997 checkColumns ( tmat_, 5UL );
1998 checkNonZeros( tmat_, 10UL );
1999
2000 if( cs(0,0) != 11 || cs(0,1) != 0 ||
2001 cs(1,0) != 0 || cs(1,1) != 13 ||
2002 cs(2,0) != 0 || cs(2,1) != 14 ||
2003 cs(3,0) != 12 || cs(3,1) != 0 ) {
2004 std::ostringstream oss;
2005 oss << " Test: " << test_ << "\n"
2006 << " Error: Assignment failed\n"
2007 << " Details:\n"
2008 << " Result:\n" << cs << "\n"
2009 << " Expected result:\n( 11 0 )\n( 0 13 )\n( 0 14 )\n( 12 0 )\n";
2010 throw std::runtime_error( oss.str() );
2011 }
2012
2013 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != -2 || tmat_(0,3) != 11 || tmat_(0,4) != 7 ||
2014 tmat_(1,0) != 0 || tmat_(1,1) != 13 || tmat_(1,2) != 0 || tmat_(1,3) != 0 || tmat_(1,4) != -8 ||
2015 tmat_(2,0) != 0 || tmat_(2,1) != 14 || tmat_(2,2) != -3 || tmat_(2,3) != 0 || tmat_(2,4) != 9 ||
2016 tmat_(3,0) != 0 || tmat_(3,1) != 0 || tmat_(3,2) != 0 || tmat_(3,3) != 12 || tmat_(3,4) != 10 ) {
2017 std::ostringstream oss;
2018 oss << " Test: " << test_ << "\n"
2019 << " Error: Assignment failed\n"
2020 << " Details:\n"
2021 << " Result:\n" << tmat_ << "\n"
2022 << " Expected result:\n( 0 0 -2 11 7 )\n"
2023 "( 0 13 0 0 -8 )\n"
2024 "( 0 14 -3 0 9 )\n"
2025 "( 0 0 0 12 10 )\n";
2026 throw std::runtime_error( oss.str() );
2027 }
2028 }
2029
2030
2031 //=====================================================================================
2032 // Column-major sparse matrix assignment
2033 //=====================================================================================
2034
2035 {
2036 test_ = "Column-major/row-major sparse matrix assignment";
2037
2038 initialize();
2039
2040 auto cs = blaze::columns( tmat_, { 3UL, 1UL } );
2041
2042 const blaze::CompressedMatrix<int,blaze::rowMajor> mat{ { 11, 0 },
2043 { 0, 13 },
2044 { 0, 14 },
2045 { 12, 0 } };
2046
2047 cs = mat;
2048
2049 checkRows ( cs , 4UL );
2050 checkColumns ( cs , 2UL );
2051 checkNonZeros( cs , 4UL );
2052 checkRows ( tmat_, 4UL );
2053 checkColumns ( tmat_, 5UL );
2054 checkNonZeros( tmat_, 10UL );
2055
2056 if( cs(0,0) != 11 || cs(0,1) != 0 ||
2057 cs(1,0) != 0 || cs(1,1) != 13 ||
2058 cs(2,0) != 0 || cs(2,1) != 14 ||
2059 cs(3,0) != 12 || cs(3,1) != 0 ) {
2060 std::ostringstream oss;
2061 oss << " Test: " << test_ << "\n"
2062 << " Error: Assignment failed\n"
2063 << " Details:\n"
2064 << " Result:\n" << cs << "\n"
2065 << " Expected result:\n( 11 0 )\n( 0 13 )\n( 0 14 )\n( 12 0 )\n";
2066 throw std::runtime_error( oss.str() );
2067 }
2068
2069 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != -2 || tmat_(0,3) != 11 || tmat_(0,4) != 7 ||
2070 tmat_(1,0) != 0 || tmat_(1,1) != 13 || tmat_(1,2) != 0 || tmat_(1,3) != 0 || tmat_(1,4) != -8 ||
2071 tmat_(2,0) != 0 || tmat_(2,1) != 14 || tmat_(2,2) != -3 || tmat_(2,3) != 0 || tmat_(2,4) != 9 ||
2072 tmat_(3,0) != 0 || tmat_(3,1) != 0 || tmat_(3,2) != 0 || tmat_(3,3) != 12 || tmat_(3,4) != 10 ) {
2073 std::ostringstream oss;
2074 oss << " Test: " << test_ << "\n"
2075 << " Error: Assignment failed\n"
2076 << " Details:\n"
2077 << " Result:\n" << tmat_ << "\n"
2078 << " Expected result:\n( 0 0 -2 11 7 )\n"
2079 "( 0 13 0 0 -8 )\n"
2080 "( 0 14 -3 0 9 )\n"
2081 "( 0 0 0 12 10 )\n";
2082 throw std::runtime_error( oss.str() );
2083 }
2084 }
2085
2086 {
2087 test_ = "Column-major/column-major sparse matrix assignment";
2088
2089 initialize();
2090
2091 auto cs = blaze::columns( tmat_, { 3UL, 1UL } );
2092
2093 const blaze::CompressedMatrix<int,blaze::columnMajor> mat{ { 11, 0 },
2094 { 0, 13 },
2095 { 0, 14 },
2096 { 12, 0 } };
2097
2098 cs = mat;
2099
2100 checkRows ( cs , 4UL );
2101 checkColumns ( cs , 2UL );
2102 checkNonZeros( cs , 4UL );
2103 checkRows ( tmat_, 4UL );
2104 checkColumns ( tmat_, 5UL );
2105 checkNonZeros( tmat_, 10UL );
2106
2107 if( cs(0,0) != 11 || cs(0,1) != 0 ||
2108 cs(1,0) != 0 || cs(1,1) != 13 ||
2109 cs(2,0) != 0 || cs(2,1) != 14 ||
2110 cs(3,0) != 12 || cs(3,1) != 0 ) {
2111 std::ostringstream oss;
2112 oss << " Test: " << test_ << "\n"
2113 << " Error: Assignment failed\n"
2114 << " Details:\n"
2115 << " Result:\n" << cs << "\n"
2116 << " Expected result:\n( 11 0 )\n( 0 13 )\n( 0 14 )\n( 12 0 )\n";
2117 throw std::runtime_error( oss.str() );
2118 }
2119
2120 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != -2 || tmat_(0,3) != 11 || tmat_(0,4) != 7 ||
2121 tmat_(1,0) != 0 || tmat_(1,1) != 13 || tmat_(1,2) != 0 || tmat_(1,3) != 0 || tmat_(1,4) != -8 ||
2122 tmat_(2,0) != 0 || tmat_(2,1) != 14 || tmat_(2,2) != -3 || tmat_(2,3) != 0 || tmat_(2,4) != 9 ||
2123 tmat_(3,0) != 0 || tmat_(3,1) != 0 || tmat_(3,2) != 0 || tmat_(3,3) != 12 || tmat_(3,4) != 10 ) {
2124 std::ostringstream oss;
2125 oss << " Test: " << test_ << "\n"
2126 << " Error: Assignment failed\n"
2127 << " Details:\n"
2128 << " Result:\n" << tmat_ << "\n"
2129 << " Expected result:\n( 0 0 -2 11 7 )\n"
2130 "( 0 13 0 0 -8 )\n"
2131 "( 0 14 -3 0 9 )\n"
2132 "( 0 0 0 12 10 )\n";
2133 throw std::runtime_error( oss.str() );
2134 }
2135 }
2136 }
2137 //*************************************************************************************************
2138
2139
2140 //*************************************************************************************************
2141 /*!\brief Test of the Columns addition assignment operators.
2142 //
2143 // \return void
2144 // \exception std::runtime_error Error detected.
2145 //
2146 // This function performs a test of the addition assignment operators of the Columns specialization.
2147 // In case an error is detected, a \a std::runtime_error exception is thrown.
2148 */
testAddAssign()2149 void SparseGeneralTest::testAddAssign()
2150 {
2151 //=====================================================================================
2152 // Row-major Columns addition assignment
2153 //=====================================================================================
2154
2155 {
2156 test_ = "Row-major Columns addition assignment (no aliasing)";
2157
2158 initialize();
2159
2160 MT mat{ { 0, 11, 0, 13, 0 },
2161 { 0, 0, 0, 14, 0 },
2162 { 0, 12, 0, 15, 0 },
2163 { 0, 0, 0, 16, 0 } };
2164
2165 auto cs = blaze::columns( mat, { 3UL, 1UL } );
2166 cs += blaze::columns( mat_, { 3UL, 1UL } );
2167
2168 checkRows ( cs , 4UL );
2169 checkColumns ( cs , 2UL );
2170 checkNonZeros( cs , 7UL );
2171 checkRows ( mat, 4UL );
2172 checkColumns ( mat, 5UL );
2173 checkNonZeros( mat, 7UL );
2174
2175 if( cs(0,0) != 13 || cs(0,1) != 11 ||
2176 cs(1,0) != 18 || cs(1,1) != 1 ||
2177 cs(2,0) != 20 || cs(2,1) != 12 ||
2178 cs(3,0) != 10 || cs(3,1) != 0 ) {
2179 std::ostringstream oss;
2180 oss << " Test: " << test_ << "\n"
2181 << " Error: Addition assignment failed\n"
2182 << " Details:\n"
2183 << " Result:\n" << cs << "\n"
2184 << " Expected result:\n( 13 11 )\n( 18 1 )\n( 20 12 )\n( 10 0 )\n";
2185 throw std::runtime_error( oss.str() );
2186 }
2187
2188 if( mat(0,0) != 0 || mat(0,1) != 11 || mat(0,2) != 0 || mat(0,3) != 13 || mat(0,4) != 0 ||
2189 mat(1,0) != 0 || mat(1,1) != 1 || mat(1,2) != 0 || mat(1,3) != 18 || mat(1,4) != 0 ||
2190 mat(2,0) != 0 || mat(2,1) != 12 || mat(2,2) != 0 || mat(2,3) != 20 || mat(2,4) != 0 ||
2191 mat(3,0) != 0 || mat(3,1) != 0 || mat(3,2) != 0 || mat(3,3) != 10 || mat(3,4) != 0 ) {
2192 std::ostringstream oss;
2193 oss << " Test: " << test_ << "\n"
2194 << " Error: Addition assignment failed\n"
2195 << " Details:\n"
2196 << " Result:\n" << mat << "\n"
2197 << " Expected result:\n( 0 11 0 13 0 )\n"
2198 "( 0 1 0 18 0 )\n"
2199 "( 0 12 0 20 0 )\n"
2200 "( 0 0 0 10 0 )\n";
2201 throw std::runtime_error( oss.str() );
2202 }
2203 }
2204
2205 {
2206 test_ = "Row-major Columns addition assignment (aliasing)";
2207
2208 initialize();
2209
2210 auto cs = blaze::columns( mat_, { 3UL, 4UL } );
2211 cs += blaze::columns( mat_, { 2UL, 3UL } );
2212
2213 checkRows ( cs , 4UL );
2214 checkColumns ( cs , 2UL );
2215 checkNonZeros( cs , 8UL );
2216 checkRows ( mat_, 4UL );
2217 checkColumns ( mat_, 5UL );
2218 checkNonZeros( mat_, 11UL );
2219
2220 if( cs(0,0) != -2 || cs(0,1) != 7 ||
2221 cs(1,0) != 4 || cs(1,1) != -4 ||
2222 cs(2,0) != 2 || cs(2,1) != 14 ||
2223 cs(3,0) != -6 || cs(3,1) != 4 ) {
2224 std::ostringstream oss;
2225 oss << " Test: " << test_ << "\n"
2226 << " Error: Addition assignment failed\n"
2227 << " Details:\n"
2228 << " Result:\n" << cs << "\n"
2229 << " Expected result:\n( -2 7 )\n( 4 -4 )\n( 2 14 )\n( -6 4 )\n";
2230 throw std::runtime_error( oss.str() );
2231 }
2232
2233 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != -2 || mat_(0,3) != -2 || mat_(0,4) != 7 ||
2234 mat_(1,0) != 0 || mat_(1,1) != 1 || mat_(1,2) != 0 || mat_(1,3) != 4 || mat_(1,4) != -4 ||
2235 mat_(2,0) != 0 || mat_(2,1) != 0 || mat_(2,2) != -3 || mat_(2,3) != 2 || mat_(2,4) != 14 ||
2236 mat_(3,0) != 0 || mat_(3,1) != 0 || mat_(3,2) != 0 || mat_(3,3) != -6 || mat_(3,4) != 4 ) {
2237 std::ostringstream oss;
2238 oss << " Test: " << test_ << "\n"
2239 << " Error: Addition assignment failed\n"
2240 << " Details:\n"
2241 << " Result:\n" << mat_ << "\n"
2242 << " Expected result:\n( 0 0 -2 -2 7 )\n"
2243 "( 0 1 0 4 -4 )\n"
2244 "( 0 0 -3 2 14 )\n"
2245 "( 0 0 0 -6 4 )\n";
2246 throw std::runtime_error( oss.str() );
2247 }
2248 }
2249
2250
2251 //=====================================================================================
2252 // Row-major dense matrix addition assignment
2253 //=====================================================================================
2254
2255 {
2256 test_ = "Row-major/row-major dense matrix addition assignment";
2257
2258 initialize();
2259
2260 auto cs = blaze::columns( mat_, { 3UL, 1UL } );
2261
2262 const blaze::DynamicMatrix<int,blaze::rowMajor> mat{ { 11, 0 },
2263 { 0, 13 },
2264 { 0, 14 },
2265 { 12, 0 } };
2266
2267 cs += mat;
2268
2269 checkRows ( cs , 4UL );
2270 checkColumns ( cs , 2UL );
2271 checkNonZeros( cs , 6UL );
2272 checkRows ( mat_, 4UL );
2273 checkColumns ( mat_, 5UL );
2274 checkNonZeros( mat_, 12UL );
2275
2276 if( cs(0,0) != 11 || cs(0,1) != 0 ||
2277 cs(1,0) != 4 || cs(1,1) != 14 ||
2278 cs(2,0) != 5 || cs(2,1) != 14 ||
2279 cs(3,0) != 6 || cs(3,1) != 0 ) {
2280 std::ostringstream oss;
2281 oss << " Test: " << test_ << "\n"
2282 << " Error: Addition assignment failed\n"
2283 << " Details:\n"
2284 << " Result:\n" << cs << "\n"
2285 << " Expected result:\n( 11 0 )\n( 0 13 )\n( 0 14 )\n( 12 0 )\n";
2286 throw std::runtime_error( oss.str() );
2287 }
2288
2289 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != -2 || mat_(0,3) != 11 || mat_(0,4) != 7 ||
2290 mat_(1,0) != 0 || mat_(1,1) != 14 || mat_(1,2) != 0 || mat_(1,3) != 4 || mat_(1,4) != -8 ||
2291 mat_(2,0) != 0 || mat_(2,1) != 14 || mat_(2,2) != -3 || mat_(2,3) != 5 || mat_(2,4) != 9 ||
2292 mat_(3,0) != 0 || mat_(3,1) != 0 || mat_(3,2) != 0 || mat_(3,3) != 6 || mat_(3,4) != 10 ) {
2293 std::ostringstream oss;
2294 oss << " Test: " << test_ << "\n"
2295 << " Error: Addition assignment failed\n"
2296 << " Details:\n"
2297 << " Result:\n" << mat_ << "\n"
2298 << " Expected result:\n( 0 0 -2 11 7 )\n"
2299 "( 0 14 0 4 -8 )\n"
2300 "( 0 14 -3 5 9 )\n"
2301 "( 0 0 0 6 10 )\n";
2302 throw std::runtime_error( oss.str() );
2303 }
2304 }
2305
2306 {
2307 test_ = "Row-major/column-major dense matrix addition assignment";
2308
2309 initialize();
2310
2311 auto cs = blaze::columns( mat_, { 3UL, 1UL } );
2312
2313 const blaze::DynamicMatrix<int,blaze::columnMajor> mat{ { 11, 0 },
2314 { 0, 13 },
2315 { 0, 14 },
2316 { 12, 0 } };
2317
2318 cs += mat;
2319
2320 checkRows ( cs , 4UL );
2321 checkColumns ( cs , 2UL );
2322 checkNonZeros( cs , 6UL );
2323 checkRows ( mat_, 4UL );
2324 checkColumns ( mat_, 5UL );
2325 checkNonZeros( mat_, 12UL );
2326
2327 if( cs(0,0) != 11 || cs(0,1) != 0 ||
2328 cs(1,0) != 4 || cs(1,1) != 14 ||
2329 cs(2,0) != 5 || cs(2,1) != 14 ||
2330 cs(3,0) != 6 || cs(3,1) != 0 ) {
2331 std::ostringstream oss;
2332 oss << " Test: " << test_ << "\n"
2333 << " Error: Addition assignment failed\n"
2334 << " Details:\n"
2335 << " Result:\n" << cs << "\n"
2336 << " Expected result:\n( 11 0 )\n( 0 13 )\n( 0 14 )\n( 12 0 )\n";
2337 throw std::runtime_error( oss.str() );
2338 }
2339
2340 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != -2 || mat_(0,3) != 11 || mat_(0,4) != 7 ||
2341 mat_(1,0) != 0 || mat_(1,1) != 14 || mat_(1,2) != 0 || mat_(1,3) != 4 || mat_(1,4) != -8 ||
2342 mat_(2,0) != 0 || mat_(2,1) != 14 || mat_(2,2) != -3 || mat_(2,3) != 5 || mat_(2,4) != 9 ||
2343 mat_(3,0) != 0 || mat_(3,1) != 0 || mat_(3,2) != 0 || mat_(3,3) != 6 || mat_(3,4) != 10 ) {
2344 std::ostringstream oss;
2345 oss << " Test: " << test_ << "\n"
2346 << " Error: Addition assignment failed\n"
2347 << " Details:\n"
2348 << " Result:\n" << mat_ << "\n"
2349 << " Expected result:\n( 0 0 -2 11 7 )\n"
2350 "( 0 14 0 4 -8 )\n"
2351 "( 0 14 -3 5 9 )\n"
2352 "( 0 0 0 6 10 )\n";
2353 throw std::runtime_error( oss.str() );
2354 }
2355 }
2356
2357
2358 //=====================================================================================
2359 // Row-major sparse matrix addition assignment
2360 //=====================================================================================
2361
2362 {
2363 test_ = "Row-major/row-major sparse matrix addition assignment";
2364
2365 initialize();
2366
2367 auto cs = blaze::columns( mat_, { 3UL, 1UL } );
2368
2369 const blaze::CompressedMatrix<int,blaze::rowMajor> mat{ { 11, 0 },
2370 { 0, 13 },
2371 { 0, 14 },
2372 { 12, 0 } };
2373
2374 cs += mat;
2375
2376 checkRows ( cs , 4UL );
2377 checkColumns ( cs , 2UL );
2378 checkNonZeros( cs , 6UL );
2379 checkRows ( mat_, 4UL );
2380 checkColumns ( mat_, 5UL );
2381 checkNonZeros( mat_, 12UL );
2382
2383 if( cs(0,0) != 11 || cs(0,1) != 0 ||
2384 cs(1,0) != 4 || cs(1,1) != 14 ||
2385 cs(2,0) != 5 || cs(2,1) != 14 ||
2386 cs(3,0) != 6 || cs(3,1) != 0 ) {
2387 std::ostringstream oss;
2388 oss << " Test: " << test_ << "\n"
2389 << " Error: Addition assignment failed\n"
2390 << " Details:\n"
2391 << " Result:\n" << cs << "\n"
2392 << " Expected result:\n( 11 0 )\n( 0 13 )\n( 0 14 )\n( 12 0 )\n";
2393 throw std::runtime_error( oss.str() );
2394 }
2395
2396 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != -2 || mat_(0,3) != 11 || mat_(0,4) != 7 ||
2397 mat_(1,0) != 0 || mat_(1,1) != 14 || mat_(1,2) != 0 || mat_(1,3) != 4 || mat_(1,4) != -8 ||
2398 mat_(2,0) != 0 || mat_(2,1) != 14 || mat_(2,2) != -3 || mat_(2,3) != 5 || mat_(2,4) != 9 ||
2399 mat_(3,0) != 0 || mat_(3,1) != 0 || mat_(3,2) != 0 || mat_(3,3) != 6 || mat_(3,4) != 10 ) {
2400 std::ostringstream oss;
2401 oss << " Test: " << test_ << "\n"
2402 << " Error: Addition assignment failed\n"
2403 << " Details:\n"
2404 << " Result:\n" << mat_ << "\n"
2405 << " Expected result:\n( 0 0 -2 11 7 )\n"
2406 "( 0 14 0 4 -8 )\n"
2407 "( 0 14 -3 5 9 )\n"
2408 "( 0 0 0 6 10 )\n";
2409 throw std::runtime_error( oss.str() );
2410 }
2411 }
2412
2413 {
2414 test_ = "Row-major/column-major sparse matrix addition assignment";
2415
2416 initialize();
2417
2418 auto cs = blaze::columns( mat_, { 3UL, 1UL } );
2419
2420 const blaze::CompressedMatrix<int,blaze::columnMajor> mat{ { 11, 0 },
2421 { 0, 13 },
2422 { 0, 14 },
2423 { 12, 0 } };
2424
2425 cs += mat;
2426
2427 checkRows ( cs , 4UL );
2428 checkColumns ( cs , 2UL );
2429 checkNonZeros( cs , 6UL );
2430 checkRows ( mat_, 4UL );
2431 checkColumns ( mat_, 5UL );
2432 checkNonZeros( mat_, 12UL );
2433
2434 if( cs(0,0) != 11 || cs(0,1) != 0 ||
2435 cs(1,0) != 4 || cs(1,1) != 14 ||
2436 cs(2,0) != 5 || cs(2,1) != 14 ||
2437 cs(3,0) != 6 || cs(3,1) != 0 ) {
2438 std::ostringstream oss;
2439 oss << " Test: " << test_ << "\n"
2440 << " Error: Addition assignment failed\n"
2441 << " Details:\n"
2442 << " Result:\n" << cs << "\n"
2443 << " Expected result:\n( 11 0 )\n( 0 13 )\n( 0 14 )\n( 12 0 )\n";
2444 throw std::runtime_error( oss.str() );
2445 }
2446
2447 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != -2 || mat_(0,3) != 11 || mat_(0,4) != 7 ||
2448 mat_(1,0) != 0 || mat_(1,1) != 14 || mat_(1,2) != 0 || mat_(1,3) != 4 || mat_(1,4) != -8 ||
2449 mat_(2,0) != 0 || mat_(2,1) != 14 || mat_(2,2) != -3 || mat_(2,3) != 5 || mat_(2,4) != 9 ||
2450 mat_(3,0) != 0 || mat_(3,1) != 0 || mat_(3,2) != 0 || mat_(3,3) != 6 || mat_(3,4) != 10 ) {
2451 std::ostringstream oss;
2452 oss << " Test: " << test_ << "\n"
2453 << " Error: Addition assignment failed\n"
2454 << " Details:\n"
2455 << " Result:\n" << mat_ << "\n"
2456 << " Expected result:\n( 0 0 -2 11 7 )\n"
2457 "( 0 14 0 4 -8 )\n"
2458 "( 0 14 -3 5 9 )\n"
2459 "( 0 0 0 6 10 )\n";
2460 throw std::runtime_error( oss.str() );
2461 }
2462 }
2463
2464
2465 //=====================================================================================
2466 // Column-major Columns addition assignment
2467 //=====================================================================================
2468
2469 {
2470 test_ = "Column-major Columns addition assignment (no aliasing)";
2471
2472 initialize();
2473
2474 OMT mat{ { 0, 11, 0, 13, 0 },
2475 { 0, 0, 0, 14, 0 },
2476 { 0, 12, 0, 15, 0 },
2477 { 0, 0, 0, 16, 0 } };
2478
2479 auto cs = blaze::columns( mat, { 3UL, 1UL } );
2480 cs += blaze::columns( tmat_, { 3UL, 1UL } );
2481
2482 checkRows ( cs , 4UL );
2483 checkColumns ( cs , 2UL );
2484 checkNonZeros( cs , 7UL );
2485 checkRows ( mat, 4UL );
2486 checkColumns ( mat, 5UL );
2487 checkNonZeros( mat, 7UL );
2488
2489 if( cs(0,0) != 13 || cs(0,1) != 11 ||
2490 cs(1,0) != 18 || cs(1,1) != 1 ||
2491 cs(2,0) != 20 || cs(2,1) != 12 ||
2492 cs(3,0) != 10 || cs(3,1) != 0 ) {
2493 std::ostringstream oss;
2494 oss << " Test: " << test_ << "\n"
2495 << " Error: Addition assignment failed\n"
2496 << " Details:\n"
2497 << " Result:\n" << cs << "\n"
2498 << " Expected result:\n( 13 11 )\n( 18 1 )\n( 20 12 )\n( 10 0 )\n";
2499 throw std::runtime_error( oss.str() );
2500 }
2501
2502 if( mat(0,0) != 0 || mat(0,1) != 11 || mat(0,2) != 0 || mat(0,3) != 13 || mat(0,4) != 0 ||
2503 mat(1,0) != 0 || mat(1,1) != 1 || mat(1,2) != 0 || mat(1,3) != 18 || mat(1,4) != 0 ||
2504 mat(2,0) != 0 || mat(2,1) != 12 || mat(2,2) != 0 || mat(2,3) != 20 || mat(2,4) != 0 ||
2505 mat(3,0) != 0 || mat(3,1) != 0 || mat(3,2) != 0 || mat(3,3) != 10 || mat(3,4) != 0 ) {
2506 std::ostringstream oss;
2507 oss << " Test: " << test_ << "\n"
2508 << " Error: Addition assignment failed\n"
2509 << " Details:\n"
2510 << " Result:\n" << mat << "\n"
2511 << " Expected result:\n( 0 11 0 13 0 )\n"
2512 "( 0 1 0 18 0 )\n"
2513 "( 0 12 0 20 0 )\n"
2514 "( 0 0 0 10 0 )\n";
2515 throw std::runtime_error( oss.str() );
2516 }
2517 }
2518
2519 {
2520 test_ = "Column-major Columns addition assignment (aliasing)";
2521
2522 initialize();
2523
2524 auto cs = blaze::columns( tmat_, { 3UL, 4UL } );
2525 cs += blaze::columns( tmat_, { 2UL, 3UL } );
2526
2527 checkRows ( cs , 4UL );
2528 checkColumns ( cs , 2UL );
2529 checkNonZeros( cs , 8UL );
2530 checkRows ( tmat_, 4UL );
2531 checkColumns ( tmat_, 5UL );
2532 checkNonZeros( tmat_, 11UL );
2533
2534 if( cs(0,0) != -2 || cs(0,1) != 7 ||
2535 cs(1,0) != 4 || cs(1,1) != -4 ||
2536 cs(2,0) != 2 || cs(2,1) != 14 ||
2537 cs(3,0) != -6 || cs(3,1) != 4 ) {
2538 std::ostringstream oss;
2539 oss << " Test: " << test_ << "\n"
2540 << " Error: Addition assignment failed\n"
2541 << " Details:\n"
2542 << " Result:\n" << cs << "\n"
2543 << " Expected result:\n( -2 7 )\n( 4 -4 )\n( 2 14 )\n( -6 4 )\n";
2544 throw std::runtime_error( oss.str() );
2545 }
2546
2547 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != -2 || tmat_(0,3) != -2 || tmat_(0,4) != 7 ||
2548 tmat_(1,0) != 0 || tmat_(1,1) != 1 || tmat_(1,2) != 0 || tmat_(1,3) != 4 || tmat_(1,4) != -4 ||
2549 tmat_(2,0) != 0 || tmat_(2,1) != 0 || tmat_(2,2) != -3 || tmat_(2,3) != 2 || tmat_(2,4) != 14 ||
2550 tmat_(3,0) != 0 || tmat_(3,1) != 0 || tmat_(3,2) != 0 || tmat_(3,3) != -6 || tmat_(3,4) != 4 ) {
2551 std::ostringstream oss;
2552 oss << " Test: " << test_ << "\n"
2553 << " Error: Addition assignment failed\n"
2554 << " Details:\n"
2555 << " Result:\n" << tmat_ << "\n"
2556 << " Expected result:\n( 0 0 -2 -2 7 )\n"
2557 "( 0 1 0 4 -4 )\n"
2558 "( 0 0 -3 2 14 )\n"
2559 "( 0 0 0 -6 4 )\n";
2560 throw std::runtime_error( oss.str() );
2561 }
2562 }
2563
2564
2565 //=====================================================================================
2566 // Column-major dense matrix addition assignment
2567 //=====================================================================================
2568
2569 {
2570 test_ = "Column-major/row-major dense matrix addition assignment";
2571
2572 initialize();
2573
2574 auto cs = blaze::columns( tmat_, { 3UL, 1UL } );
2575
2576 const blaze::DynamicMatrix<int,blaze::rowMajor> mat{ { 11, 0 },
2577 { 0, 13 },
2578 { 0, 14 },
2579 { 12, 0 } };
2580
2581 cs += mat;
2582
2583 checkRows ( cs , 4UL );
2584 checkColumns ( cs , 2UL );
2585 checkNonZeros( cs , 6UL );
2586 checkRows ( tmat_, 4UL );
2587 checkColumns ( tmat_, 5UL );
2588 checkNonZeros( tmat_, 12UL );
2589
2590 if( cs(0,0) != 11 || cs(0,1) != 0 ||
2591 cs(1,0) != 4 || cs(1,1) != 14 ||
2592 cs(2,0) != 5 || cs(2,1) != 14 ||
2593 cs(3,0) != 6 || cs(3,1) != 0 ) {
2594 std::ostringstream oss;
2595 oss << " Test: " << test_ << "\n"
2596 << " Error: Addition assignment failed\n"
2597 << " Details:\n"
2598 << " Result:\n" << cs << "\n"
2599 << " Expected result:\n( 11 0 )\n( 0 13 )\n( 0 14 )\n( 12 0 )\n";
2600 throw std::runtime_error( oss.str() );
2601 }
2602
2603 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != -2 || tmat_(0,3) != 11 || tmat_(0,4) != 7 ||
2604 tmat_(1,0) != 0 || tmat_(1,1) != 14 || tmat_(1,2) != 0 || tmat_(1,3) != 4 || tmat_(1,4) != -8 ||
2605 tmat_(2,0) != 0 || tmat_(2,1) != 14 || tmat_(2,2) != -3 || tmat_(2,3) != 5 || tmat_(2,4) != 9 ||
2606 tmat_(3,0) != 0 || tmat_(3,1) != 0 || tmat_(3,2) != 0 || tmat_(3,3) != 6 || tmat_(3,4) != 10 ) {
2607 std::ostringstream oss;
2608 oss << " Test: " << test_ << "\n"
2609 << " Error: Addition assignment failed\n"
2610 << " Details:\n"
2611 << " Result:\n" << tmat_ << "\n"
2612 << " Expected result:\n( 0 0 -2 11 7 )\n"
2613 "( 0 14 0 4 -8 )\n"
2614 "( 0 14 -3 5 9 )\n"
2615 "( 0 0 0 6 10 )\n";
2616 throw std::runtime_error( oss.str() );
2617 }
2618 }
2619
2620 {
2621 test_ = "Column-major/column-major dense matrix addition assignment";
2622
2623 initialize();
2624
2625 auto cs = blaze::columns( tmat_, { 3UL, 1UL } );
2626
2627 const blaze::DynamicMatrix<int,blaze::columnMajor> mat{ { 11, 0 },
2628 { 0, 13 },
2629 { 0, 14 },
2630 { 12, 0 } };
2631
2632 cs += mat;
2633
2634 checkRows ( cs , 4UL );
2635 checkColumns ( cs , 2UL );
2636 checkNonZeros( cs , 6UL );
2637 checkRows ( tmat_, 4UL );
2638 checkColumns ( tmat_, 5UL );
2639 checkNonZeros( tmat_, 12UL );
2640
2641 if( cs(0,0) != 11 || cs(0,1) != 0 ||
2642 cs(1,0) != 4 || cs(1,1) != 14 ||
2643 cs(2,0) != 5 || cs(2,1) != 14 ||
2644 cs(3,0) != 6 || cs(3,1) != 0 ) {
2645 std::ostringstream oss;
2646 oss << " Test: " << test_ << "\n"
2647 << " Error: Addition assignment failed\n"
2648 << " Details:\n"
2649 << " Result:\n" << cs << "\n"
2650 << " Expected result:\n( 11 0 )\n( 0 13 )\n( 0 14 )\n( 12 0 )\n";
2651 throw std::runtime_error( oss.str() );
2652 }
2653
2654 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != -2 || tmat_(0,3) != 11 || tmat_(0,4) != 7 ||
2655 tmat_(1,0) != 0 || tmat_(1,1) != 14 || tmat_(1,2) != 0 || tmat_(1,3) != 4 || tmat_(1,4) != -8 ||
2656 tmat_(2,0) != 0 || tmat_(2,1) != 14 || tmat_(2,2) != -3 || tmat_(2,3) != 5 || tmat_(2,4) != 9 ||
2657 tmat_(3,0) != 0 || tmat_(3,1) != 0 || tmat_(3,2) != 0 || tmat_(3,3) != 6 || tmat_(3,4) != 10 ) {
2658 std::ostringstream oss;
2659 oss << " Test: " << test_ << "\n"
2660 << " Error: Addition assignment failed\n"
2661 << " Details:\n"
2662 << " Result:\n" << tmat_ << "\n"
2663 << " Expected result:\n( 0 0 -2 11 7 )\n"
2664 "( 0 14 0 4 -8 )\n"
2665 "( 0 14 -3 5 9 )\n"
2666 "( 0 0 0 6 10 )\n";
2667 throw std::runtime_error( oss.str() );
2668 }
2669 }
2670
2671
2672 //=====================================================================================
2673 // Column-major sparse matrix addition assignment
2674 //=====================================================================================
2675
2676 {
2677 test_ = "Column-major/row-major sparse matrix addition assignment";
2678
2679 initialize();
2680
2681 auto cs = blaze::columns( tmat_, { 3UL, 1UL } );
2682
2683 const blaze::CompressedMatrix<int,blaze::rowMajor> mat{ { 11, 0 },
2684 { 0, 13 },
2685 { 0, 14 },
2686 { 12, 0 } };
2687
2688 cs += mat;
2689
2690 checkRows ( cs , 4UL );
2691 checkColumns ( cs , 2UL );
2692 checkNonZeros( cs , 6UL );
2693 checkRows ( tmat_, 4UL );
2694 checkColumns ( tmat_, 5UL );
2695 checkNonZeros( tmat_, 12UL );
2696
2697 if( cs(0,0) != 11 || cs(0,1) != 0 ||
2698 cs(1,0) != 4 || cs(1,1) != 14 ||
2699 cs(2,0) != 5 || cs(2,1) != 14 ||
2700 cs(3,0) != 6 || cs(3,1) != 0 ) {
2701 std::ostringstream oss;
2702 oss << " Test: " << test_ << "\n"
2703 << " Error: Addition assignment failed\n"
2704 << " Details:\n"
2705 << " Result:\n" << cs << "\n"
2706 << " Expected result:\n( 11 0 )\n( 0 13 )\n( 0 14 )\n( 12 0 )\n";
2707 throw std::runtime_error( oss.str() );
2708 }
2709
2710 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != -2 || tmat_(0,3) != 11 || tmat_(0,4) != 7 ||
2711 tmat_(1,0) != 0 || tmat_(1,1) != 14 || tmat_(1,2) != 0 || tmat_(1,3) != 4 || tmat_(1,4) != -8 ||
2712 tmat_(2,0) != 0 || tmat_(2,1) != 14 || tmat_(2,2) != -3 || tmat_(2,3) != 5 || tmat_(2,4) != 9 ||
2713 tmat_(3,0) != 0 || tmat_(3,1) != 0 || tmat_(3,2) != 0 || tmat_(3,3) != 6 || tmat_(3,4) != 10 ) {
2714 std::ostringstream oss;
2715 oss << " Test: " << test_ << "\n"
2716 << " Error: Addition assignment failed\n"
2717 << " Details:\n"
2718 << " Result:\n" << tmat_ << "\n"
2719 << " Expected result:\n( 0 0 -2 11 7 )\n"
2720 "( 0 14 0 4 -8 )\n"
2721 "( 0 14 -3 5 9 )\n"
2722 "( 0 0 0 6 10 )\n";
2723 throw std::runtime_error( oss.str() );
2724 }
2725 }
2726
2727 {
2728 test_ = "Column-major/column-major sparse matrix addition assignment";
2729
2730 initialize();
2731
2732 auto cs = blaze::columns( tmat_, { 3UL, 1UL } );
2733
2734 const blaze::CompressedMatrix<int,blaze::columnMajor> mat{ { 11, 0 },
2735 { 0, 13 },
2736 { 0, 14 },
2737 { 12, 0 } };
2738
2739 cs += mat;
2740
2741 checkRows ( cs , 4UL );
2742 checkColumns ( cs , 2UL );
2743 checkNonZeros( cs , 6UL );
2744 checkRows ( tmat_, 4UL );
2745 checkColumns ( tmat_, 5UL );
2746 checkNonZeros( tmat_, 12UL );
2747
2748 if( cs(0,0) != 11 || cs(0,1) != 0 ||
2749 cs(1,0) != 4 || cs(1,1) != 14 ||
2750 cs(2,0) != 5 || cs(2,1) != 14 ||
2751 cs(3,0) != 6 || cs(3,1) != 0 ) {
2752 std::ostringstream oss;
2753 oss << " Test: " << test_ << "\n"
2754 << " Error: Addition assignment failed\n"
2755 << " Details:\n"
2756 << " Result:\n" << cs << "\n"
2757 << " Expected result:\n( 11 0 )\n( 0 13 )\n( 0 14 )\n( 12 0 )\n";
2758 throw std::runtime_error( oss.str() );
2759 }
2760
2761 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != -2 || tmat_(0,3) != 11 || tmat_(0,4) != 7 ||
2762 tmat_(1,0) != 0 || tmat_(1,1) != 14 || tmat_(1,2) != 0 || tmat_(1,3) != 4 || tmat_(1,4) != -8 ||
2763 tmat_(2,0) != 0 || tmat_(2,1) != 14 || tmat_(2,2) != -3 || tmat_(2,3) != 5 || tmat_(2,4) != 9 ||
2764 tmat_(3,0) != 0 || tmat_(3,1) != 0 || tmat_(3,2) != 0 || tmat_(3,3) != 6 || tmat_(3,4) != 10 ) {
2765 std::ostringstream oss;
2766 oss << " Test: " << test_ << "\n"
2767 << " Error: Addition assignment failed\n"
2768 << " Details:\n"
2769 << " Result:\n" << tmat_ << "\n"
2770 << " Expected result:\n( 0 0 -2 11 7 )\n"
2771 "( 0 14 0 4 -8 )\n"
2772 "( 0 14 -3 5 9 )\n"
2773 "( 0 0 0 6 10 )\n";
2774 throw std::runtime_error( oss.str() );
2775 }
2776 }
2777 }
2778 //*************************************************************************************************
2779
2780
2781 //*************************************************************************************************
2782 /*!\brief Test of the Columns subtraction assignment operators.
2783 //
2784 // \return void
2785 // \exception std::runtime_error Error detected.
2786 //
2787 // This function performs a test of the subtraction assignment operators of the Columns
2788 // specialization. In case an error is detected, a \a std::runtime_error exception is thrown.
2789 */
testSubAssign()2790 void SparseGeneralTest::testSubAssign()
2791 {
2792 //=====================================================================================
2793 // Row-major Columns subtraction assignment
2794 //=====================================================================================
2795
2796 {
2797 test_ = "Row-major Columns subtraction assignment (no aliasing)";
2798
2799 initialize();
2800
2801 MT mat{ { 0, 11, 0, 13, 0 },
2802 { 0, 0, 0, 14, 0 },
2803 { 0, 12, 0, 15, 0 },
2804 { 0, 0, 0, 16, 0 } };
2805
2806 auto cs = blaze::columns( mat, { 3UL, 1UL } );
2807 cs -= blaze::columns( mat_, { 3UL, 1UL } );
2808
2809 checkRows ( cs , 4UL );
2810 checkColumns ( cs , 2UL );
2811 checkNonZeros( cs , 7UL );
2812 checkRows ( mat, 4UL );
2813 checkColumns ( mat, 5UL );
2814 checkNonZeros( mat, 7UL );
2815
2816 if( cs(0,0) != 13 || cs(0,1) != 11 ||
2817 cs(1,0) != 10 || cs(1,1) != -1 ||
2818 cs(2,0) != 10 || cs(2,1) != 12 ||
2819 cs(3,0) != 22 || cs(3,1) != 0 ) {
2820 std::ostringstream oss;
2821 oss << " Test: " << test_ << "\n"
2822 << " Error: Subtraction assignment failed\n"
2823 << " Details:\n"
2824 << " Result:\n" << cs << "\n"
2825 << " Expected result:\n( 13 11 )\n( 10 -1 )\n( 10 12 )\n( 22 0 )\n";
2826 throw std::runtime_error( oss.str() );
2827 }
2828
2829 if( mat(0,0) != 0 || mat(0,1) != 11 || mat(0,2) != 0 || mat(0,3) != 13 || mat(0,4) != 0 ||
2830 mat(1,0) != 0 || mat(1,1) != -1 || mat(1,2) != 0 || mat(1,3) != 10 || mat(1,4) != 0 ||
2831 mat(2,0) != 0 || mat(2,1) != 12 || mat(2,2) != 0 || mat(2,3) != 10 || mat(2,4) != 0 ||
2832 mat(3,0) != 0 || mat(3,1) != 0 || mat(3,2) != 0 || mat(3,3) != 22 || mat(3,4) != 0 ) {
2833 std::ostringstream oss;
2834 oss << " Test: " << test_ << "\n"
2835 << " Error: Subtraction assignment failed\n"
2836 << " Details:\n"
2837 << " Result:\n" << mat << "\n"
2838 << " Expected result:\n( 0 11 0 13 0 )\n"
2839 "( 0 -1 0 10 0 )\n"
2840 "( 0 12 0 10 0 )\n"
2841 "( 0 0 0 22 0 )\n";
2842 throw std::runtime_error( oss.str() );
2843 }
2844 }
2845
2846 {
2847 test_ = "Row-major Columns subtraction assignment (aliasing)";
2848
2849 initialize();
2850
2851 auto cs = blaze::columns( mat_, { 3UL, 4UL } );
2852 cs -= blaze::columns( mat_, { 2UL, 3UL } );
2853
2854 checkRows ( cs , 4UL );
2855 checkColumns ( cs , 2UL );
2856 checkNonZeros( cs , 8UL );
2857 checkRows ( mat_, 4UL );
2858 checkColumns ( mat_, 5UL );
2859 checkNonZeros( mat_, 11UL );
2860
2861 if( cs(0,0) != 2 || cs(0,1) != 7 ||
2862 cs(1,0) != 4 || cs(1,1) != -12 ||
2863 cs(2,0) != 8 || cs(2,1) != 4 ||
2864 cs(3,0) != -6 || cs(3,1) != 16 ) {
2865 std::ostringstream oss;
2866 oss << " Test: " << test_ << "\n"
2867 << " Error: Subtraction assignment failed\n"
2868 << " Details:\n"
2869 << " Result:\n" << cs << "\n"
2870 << " Expected result:\n( 13 11 )\n( 10 -1 )\n( 10 12 )\n( 22 0 )\n";
2871 throw std::runtime_error( oss.str() );
2872 }
2873
2874 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != -2 || mat_(0,3) != 2 || mat_(0,4) != 7 ||
2875 mat_(1,0) != 0 || mat_(1,1) != 1 || mat_(1,2) != 0 || mat_(1,3) != 4 || mat_(1,4) != -12 ||
2876 mat_(2,0) != 0 || mat_(2,1) != 0 || mat_(2,2) != -3 || mat_(2,3) != 8 || mat_(2,4) != 4 ||
2877 mat_(3,0) != 0 || mat_(3,1) != 0 || mat_(3,2) != 0 || mat_(3,3) != -6 || mat_(3,4) != 16 ) {
2878 std::ostringstream oss;
2879 oss << " Test: " << test_ << "\n"
2880 << " Error: Subtraction assignment failed\n"
2881 << " Details:\n"
2882 << " Result:\n" << mat_ << "\n"
2883 << " Expected result:\n( 0 0 -2 2 7 )\n"
2884 "( 0 1 0 4 -12 )\n"
2885 "( 0 0 -3 8 4 )\n"
2886 "( 0 0 0 -6 16 )\n";
2887 throw std::runtime_error( oss.str() );
2888 }
2889 }
2890
2891
2892 //=====================================================================================
2893 // Row-major dense matrix subtraction assignment
2894 //=====================================================================================
2895
2896 {
2897 test_ = "Row-major/row-major dense matrix subtraction assignment";
2898
2899 initialize();
2900
2901 auto cs = blaze::columns( mat_, { 3UL, 1UL } );
2902
2903 const blaze::DynamicMatrix<int,blaze::rowMajor> mat{ { 11, 0 },
2904 { 0, 13 },
2905 { 0, 14 },
2906 { 12, 0 } };
2907
2908 cs -= mat;
2909
2910 checkRows ( cs , 4UL );
2911 checkColumns ( cs , 2UL );
2912 checkNonZeros( cs , 6UL );
2913 checkRows ( mat_, 4UL );
2914 checkColumns ( mat_, 5UL );
2915 checkNonZeros( mat_, 12UL );
2916
2917 if( cs(0,0) != -11 || cs(0,1) != 0 ||
2918 cs(1,0) != 4 || cs(1,1) != -12 ||
2919 cs(2,0) != 5 || cs(2,1) != -14 ||
2920 cs(3,0) != -18 || cs(3,1) != 0 ) {
2921 std::ostringstream oss;
2922 oss << " Test: " << test_ << "\n"
2923 << " Error: Subtraction assignment failed\n"
2924 << " Details:\n"
2925 << " Result:\n" << cs << "\n"
2926 << " Expected result:\n( -11 0 )\n( 4 -12 )\n( 5 -14 )\n( -18 0 )\n";
2927 throw std::runtime_error( oss.str() );
2928 }
2929
2930 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != -2 || mat_(0,3) != -11 || mat_(0,4) != 7 ||
2931 mat_(1,0) != 0 || mat_(1,1) != -12 || mat_(1,2) != 0 || mat_(1,3) != 4 || mat_(1,4) != -8 ||
2932 mat_(2,0) != 0 || mat_(2,1) != -14 || mat_(2,2) != -3 || mat_(2,3) != 5 || mat_(2,4) != 9 ||
2933 mat_(3,0) != 0 || mat_(3,1) != 0 || mat_(3,2) != 0 || mat_(3,3) != -18 || mat_(3,4) != 10 ) {
2934 std::ostringstream oss;
2935 oss << " Test: " << test_ << "\n"
2936 << " Error: Subtraction assignment failed\n"
2937 << " Details:\n"
2938 << " Result:\n" << mat_ << "\n"
2939 << " Expected result:\n( 0 0 -2 -11 7 )\n"
2940 "( 0 -12 0 4 -8 )\n"
2941 "( 0 -14 -3 5 9 )\n"
2942 "( 0 0 0 -18 10 )\n";
2943 throw std::runtime_error( oss.str() );
2944 }
2945 }
2946
2947 {
2948 test_ = "Row-major/column-major dense matrix subtraction assignment";
2949
2950 initialize();
2951
2952 auto cs = blaze::columns( mat_, { 3UL, 1UL } );
2953
2954 const blaze::DynamicMatrix<int,blaze::columnMajor> mat{ { 11, 0 },
2955 { 0, 13 },
2956 { 0, 14 },
2957 { 12, 0 } };
2958
2959 cs -= mat;
2960
2961 checkRows ( cs , 4UL );
2962 checkColumns ( cs , 2UL );
2963 checkNonZeros( cs , 6UL );
2964 checkRows ( mat_, 4UL );
2965 checkColumns ( mat_, 5UL );
2966 checkNonZeros( mat_, 12UL );
2967
2968 if( cs(0,0) != -11 || cs(0,1) != 0 ||
2969 cs(1,0) != 4 || cs(1,1) != -12 ||
2970 cs(2,0) != 5 || cs(2,1) != -14 ||
2971 cs(3,0) != -18 || cs(3,1) != 0 ) {
2972 std::ostringstream oss;
2973 oss << " Test: " << test_ << "\n"
2974 << " Error: Subtraction assignment failed\n"
2975 << " Details:\n"
2976 << " Result:\n" << cs << "\n"
2977 << " Expected result:\n( -11 0 )\n( 4 -12 )\n( 5 -14 )\n( -18 0 )\n";
2978 throw std::runtime_error( oss.str() );
2979 }
2980
2981 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != -2 || mat_(0,3) != -11 || mat_(0,4) != 7 ||
2982 mat_(1,0) != 0 || mat_(1,1) != -12 || mat_(1,2) != 0 || mat_(1,3) != 4 || mat_(1,4) != -8 ||
2983 mat_(2,0) != 0 || mat_(2,1) != -14 || mat_(2,2) != -3 || mat_(2,3) != 5 || mat_(2,4) != 9 ||
2984 mat_(3,0) != 0 || mat_(3,1) != 0 || mat_(3,2) != 0 || mat_(3,3) != -18 || mat_(3,4) != 10 ) {
2985 std::ostringstream oss;
2986 oss << " Test: " << test_ << "\n"
2987 << " Error: Subtraction assignment failed\n"
2988 << " Details:\n"
2989 << " Result:\n" << mat_ << "\n"
2990 << " Expected result:\n( 0 0 -2 -11 7 )\n"
2991 "( 0 -12 0 4 -8 )\n"
2992 "( 0 -14 -3 5 9 )\n"
2993 "( 0 0 0 -18 10 )\n";
2994 throw std::runtime_error( oss.str() );
2995 }
2996 }
2997
2998
2999 //=====================================================================================
3000 // Row-major sparse matrix subtraction assignment
3001 //=====================================================================================
3002
3003 {
3004 test_ = "Row-major/row-major sparse matrix subtraction assignment";
3005
3006 initialize();
3007
3008 auto cs = blaze::columns( mat_, { 3UL, 1UL } );
3009
3010 const blaze::CompressedMatrix<int,blaze::rowMajor> mat{ { 11, 0 },
3011 { 0, 13 },
3012 { 0, 14 },
3013 { 12, 0 } };
3014
3015 cs -= mat;
3016
3017 checkRows ( cs , 4UL );
3018 checkColumns ( cs , 2UL );
3019 checkNonZeros( cs , 6UL );
3020 checkRows ( mat_, 4UL );
3021 checkColumns ( mat_, 5UL );
3022 checkNonZeros( mat_, 12UL );
3023
3024 if( cs(0,0) != -11 || cs(0,1) != 0 ||
3025 cs(1,0) != 4 || cs(1,1) != -12 ||
3026 cs(2,0) != 5 || cs(2,1) != -14 ||
3027 cs(3,0) != -18 || cs(3,1) != 0 ) {
3028 std::ostringstream oss;
3029 oss << " Test: " << test_ << "\n"
3030 << " Error: Subtraction assignment failed\n"
3031 << " Details:\n"
3032 << " Result:\n" << cs << "\n"
3033 << " Expected result:\n( -11 0 )\n( 4 -12 )\n( 5 -14 )\n( -18 0 )\n";
3034 throw std::runtime_error( oss.str() );
3035 }
3036
3037 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != -2 || mat_(0,3) != -11 || mat_(0,4) != 7 ||
3038 mat_(1,0) != 0 || mat_(1,1) != -12 || mat_(1,2) != 0 || mat_(1,3) != 4 || mat_(1,4) != -8 ||
3039 mat_(2,0) != 0 || mat_(2,1) != -14 || mat_(2,2) != -3 || mat_(2,3) != 5 || mat_(2,4) != 9 ||
3040 mat_(3,0) != 0 || mat_(3,1) != 0 || mat_(3,2) != 0 || mat_(3,3) != -18 || mat_(3,4) != 10 ) {
3041 std::ostringstream oss;
3042 oss << " Test: " << test_ << "\n"
3043 << " Error: Subtraction assignment failed\n"
3044 << " Details:\n"
3045 << " Result:\n" << mat_ << "\n"
3046 << " Expected result:\n( 0 0 -2 -11 7 )\n"
3047 "( 0 -12 0 4 -8 )\n"
3048 "( 0 -14 -3 5 9 )\n"
3049 "( 0 0 0 -18 10 )\n";
3050 throw std::runtime_error( oss.str() );
3051 }
3052 }
3053
3054 {
3055 test_ = "Row-major/column-major sparse matrix subtraction assignment";
3056
3057 initialize();
3058
3059 auto cs = blaze::columns( mat_, { 3UL, 1UL } );
3060
3061 const blaze::CompressedMatrix<int,blaze::columnMajor> mat{ { 11, 0 },
3062 { 0, 13 },
3063 { 0, 14 },
3064 { 12, 0 } };
3065
3066 cs -= mat;
3067
3068 checkRows ( cs , 4UL );
3069 checkColumns ( cs , 2UL );
3070 checkNonZeros( cs , 6UL );
3071 checkRows ( mat_, 4UL );
3072 checkColumns ( mat_, 5UL );
3073 checkNonZeros( mat_, 12UL );
3074
3075 if( cs(0,0) != -11 || cs(0,1) != 0 ||
3076 cs(1,0) != 4 || cs(1,1) != -12 ||
3077 cs(2,0) != 5 || cs(2,1) != -14 ||
3078 cs(3,0) != -18 || cs(3,1) != 0 ) {
3079 std::ostringstream oss;
3080 oss << " Test: " << test_ << "\n"
3081 << " Error: Subtraction assignment failed\n"
3082 << " Details:\n"
3083 << " Result:\n" << cs << "\n"
3084 << " Expected result:\n( -11 0 )\n( 4 -12 )\n( 5 -14 )\n( -18 0 )\n";
3085 throw std::runtime_error( oss.str() );
3086 }
3087
3088 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != -2 || mat_(0,3) != -11 || mat_(0,4) != 7 ||
3089 mat_(1,0) != 0 || mat_(1,1) != -12 || mat_(1,2) != 0 || mat_(1,3) != 4 || mat_(1,4) != -8 ||
3090 mat_(2,0) != 0 || mat_(2,1) != -14 || mat_(2,2) != -3 || mat_(2,3) != 5 || mat_(2,4) != 9 ||
3091 mat_(3,0) != 0 || mat_(3,1) != 0 || mat_(3,2) != 0 || mat_(3,3) != -18 || mat_(3,4) != 10 ) {
3092 std::ostringstream oss;
3093 oss << " Test: " << test_ << "\n"
3094 << " Error: Subtraction assignment failed\n"
3095 << " Details:\n"
3096 << " Result:\n" << mat_ << "\n"
3097 << " Expected result:\n( 0 0 -2 -11 7 )\n"
3098 "( 0 -12 0 4 -8 )\n"
3099 "( 0 -14 -3 5 9 )\n"
3100 "( 0 0 0 -18 10 )\n";
3101 throw std::runtime_error( oss.str() );
3102 }
3103 }
3104
3105
3106 //=====================================================================================
3107 // Column-major Columns subtraction assignment
3108 //=====================================================================================
3109
3110 {
3111 test_ = "Column-major Columns subtraction assignment (no aliasing)";
3112
3113 initialize();
3114
3115 OMT mat{ { 0, 11, 0, 13, 0 },
3116 { 0, 0, 0, 14, 0 },
3117 { 0, 12, 0, 15, 0 },
3118 { 0, 0, 0, 16, 0 } };
3119
3120 auto cs = blaze::columns( mat, { 3UL, 1UL } );
3121 cs -= blaze::columns( mat_, { 3UL, 1UL } );
3122
3123 checkRows ( cs , 4UL );
3124 checkColumns ( cs , 2UL );
3125 checkNonZeros( cs , 7UL );
3126 checkRows ( mat, 4UL );
3127 checkColumns ( mat, 5UL );
3128 checkNonZeros( mat, 7UL );
3129
3130 if( cs(0,0) != 13 || cs(0,1) != 11 ||
3131 cs(1,0) != 10 || cs(1,1) != -1 ||
3132 cs(2,0) != 10 || cs(2,1) != 12 ||
3133 cs(3,0) != 22 || cs(3,1) != 0 ) {
3134 std::ostringstream oss;
3135 oss << " Test: " << test_ << "\n"
3136 << " Error: Subtraction assignment failed\n"
3137 << " Details:\n"
3138 << " Result:\n" << cs << "\n"
3139 << " Expected result:\n( 13 11 )\n( 10 -1 )\n( 10 12 )\n( 22 0 )\n";
3140 throw std::runtime_error( oss.str() );
3141 }
3142
3143 if( mat(0,0) != 0 || mat(0,1) != 11 || mat(0,2) != 0 || mat(0,3) != 13 || mat(0,4) != 0 ||
3144 mat(1,0) != 0 || mat(1,1) != -1 || mat(1,2) != 0 || mat(1,3) != 10 || mat(1,4) != 0 ||
3145 mat(2,0) != 0 || mat(2,1) != 12 || mat(2,2) != 0 || mat(2,3) != 10 || mat(2,4) != 0 ||
3146 mat(3,0) != 0 || mat(3,1) != 0 || mat(3,2) != 0 || mat(3,3) != 22 || mat(3,4) != 0 ) {
3147 std::ostringstream oss;
3148 oss << " Test: " << test_ << "\n"
3149 << " Error: Subtraction assignment failed\n"
3150 << " Details:\n"
3151 << " Result:\n" << mat << "\n"
3152 << " Expected result:\n( 0 11 0 13 0 )\n"
3153 "( 0 -1 0 10 0 )\n"
3154 "( 0 12 0 10 0 )\n"
3155 "( 0 0 0 22 0 )\n";
3156 throw std::runtime_error( oss.str() );
3157 }
3158 }
3159
3160 {
3161 test_ = "Column-major Columns subtraction assignment (aliasing)";
3162
3163 initialize();
3164
3165 auto cs = blaze::columns( tmat_, { 3UL, 4UL } );
3166 cs -= blaze::columns( tmat_, { 2UL, 3UL } );
3167
3168 checkRows ( cs , 4UL );
3169 checkColumns ( cs , 2UL );
3170 checkNonZeros( cs , 8UL );
3171 checkRows ( tmat_, 4UL );
3172 checkColumns ( tmat_, 5UL );
3173 checkNonZeros( tmat_, 11UL );
3174
3175 if( cs(0,0) != 2 || cs(0,1) != 7 ||
3176 cs(1,0) != 4 || cs(1,1) != -12 ||
3177 cs(2,0) != 8 || cs(2,1) != 4 ||
3178 cs(3,0) != -6 || cs(3,1) != 16 ) {
3179 std::ostringstream oss;
3180 oss << " Test: " << test_ << "\n"
3181 << " Error: Subtraction assignment failed\n"
3182 << " Details:\n"
3183 << " Result:\n" << cs << "\n"
3184 << " Expected result:\n( 13 11 )\n( 10 -1 )\n( 10 12 )\n( 22 0 )\n";
3185 throw std::runtime_error( oss.str() );
3186 }
3187
3188 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != -2 || tmat_(0,3) != 2 || tmat_(0,4) != 7 ||
3189 tmat_(1,0) != 0 || tmat_(1,1) != 1 || tmat_(1,2) != 0 || tmat_(1,3) != 4 || tmat_(1,4) != -12 ||
3190 tmat_(2,0) != 0 || tmat_(2,1) != 0 || tmat_(2,2) != -3 || tmat_(2,3) != 8 || tmat_(2,4) != 4 ||
3191 tmat_(3,0) != 0 || tmat_(3,1) != 0 || tmat_(3,2) != 0 || tmat_(3,3) != -6 || tmat_(3,4) != 16 ) {
3192 std::ostringstream oss;
3193 oss << " Test: " << test_ << "\n"
3194 << " Error: Subtraction assignment failed\n"
3195 << " Details:\n"
3196 << " Result:\n" << tmat_ << "\n"
3197 << " Expected result:\n( 0 0 -2 2 7 )\n"
3198 "( 0 1 0 4 -12 )\n"
3199 "( 0 0 -3 8 4 )\n"
3200 "( 0 0 0 -6 16 )\n";
3201 throw std::runtime_error( oss.str() );
3202 }
3203 }
3204
3205
3206 //=====================================================================================
3207 // Column-major dense matrix subtraction assignment
3208 //=====================================================================================
3209
3210 {
3211 test_ = "Column-major/row-major dense matrix subtraction assignment";
3212
3213 initialize();
3214
3215 auto cs = blaze::columns( tmat_, { 3UL, 1UL } );
3216
3217 const blaze::DynamicMatrix<int,blaze::rowMajor> mat{ { 11, 0 },
3218 { 0, 13 },
3219 { 0, 14 },
3220 { 12, 0 } };
3221
3222 cs -= mat;
3223
3224 checkRows ( cs , 4UL );
3225 checkColumns ( cs , 2UL );
3226 checkNonZeros( cs , 6UL );
3227 checkRows ( tmat_, 4UL );
3228 checkColumns ( tmat_, 5UL );
3229 checkNonZeros( tmat_, 12UL );
3230
3231 if( cs(0,0) != -11 || cs(0,1) != 0 ||
3232 cs(1,0) != 4 || cs(1,1) != -12 ||
3233 cs(2,0) != 5 || cs(2,1) != -14 ||
3234 cs(3,0) != -18 || cs(3,1) != 0 ) {
3235 std::ostringstream oss;
3236 oss << " Test: " << test_ << "\n"
3237 << " Error: Subtraction assignment failed\n"
3238 << " Details:\n"
3239 << " Result:\n" << cs << "\n"
3240 << " Expected result:\n( -11 0 )\n( 4 -12 )\n( 5 -14 )\n( -18 0 )\n";
3241 throw std::runtime_error( oss.str() );
3242 }
3243
3244 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != -2 || tmat_(0,3) != -11 || tmat_(0,4) != 7 ||
3245 tmat_(1,0) != 0 || tmat_(1,1) != -12 || tmat_(1,2) != 0 || tmat_(1,3) != 4 || tmat_(1,4) != -8 ||
3246 tmat_(2,0) != 0 || tmat_(2,1) != -14 || tmat_(2,2) != -3 || tmat_(2,3) != 5 || tmat_(2,4) != 9 ||
3247 tmat_(3,0) != 0 || tmat_(3,1) != 0 || tmat_(3,2) != 0 || tmat_(3,3) != -18 || tmat_(3,4) != 10 ) {
3248 std::ostringstream oss;
3249 oss << " Test: " << test_ << "\n"
3250 << " Error: Subtraction assignment failed\n"
3251 << " Details:\n"
3252 << " Result:\n" << tmat_ << "\n"
3253 << " Expected result:\n( 0 0 -2 -11 7 )\n"
3254 "( 0 -12 0 4 -8 )\n"
3255 "( 0 -14 -3 5 9 )\n"
3256 "( 0 0 0 -18 10 )\n";
3257 throw std::runtime_error( oss.str() );
3258 }
3259 }
3260
3261 {
3262 test_ = "Column-major/column-major dense matrix subtraction assignment";
3263
3264 initialize();
3265
3266 auto cs = blaze::columns( tmat_, { 3UL, 1UL } );
3267
3268 const blaze::DynamicMatrix<int,blaze::columnMajor> mat{ { 11, 0 },
3269 { 0, 13 },
3270 { 0, 14 },
3271 { 12, 0 } };
3272
3273 cs -= mat;
3274
3275 checkRows ( cs , 4UL );
3276 checkColumns ( cs , 2UL );
3277 checkNonZeros( cs , 6UL );
3278 checkRows ( tmat_, 4UL );
3279 checkColumns ( tmat_, 5UL );
3280 checkNonZeros( tmat_, 12UL );
3281
3282 if( cs(0,0) != -11 || cs(0,1) != 0 ||
3283 cs(1,0) != 4 || cs(1,1) != -12 ||
3284 cs(2,0) != 5 || cs(2,1) != -14 ||
3285 cs(3,0) != -18 || cs(3,1) != 0 ) {
3286 std::ostringstream oss;
3287 oss << " Test: " << test_ << "\n"
3288 << " Error: Subtraction assignment failed\n"
3289 << " Details:\n"
3290 << " Result:\n" << cs << "\n"
3291 << " Expected result:\n( -11 0 )\n( 4 -12 )\n( 5 -14 )\n( -18 0 )\n";
3292 throw std::runtime_error( oss.str() );
3293 }
3294
3295 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != -2 || tmat_(0,3) != -11 || tmat_(0,4) != 7 ||
3296 tmat_(1,0) != 0 || tmat_(1,1) != -12 || tmat_(1,2) != 0 || tmat_(1,3) != 4 || tmat_(1,4) != -8 ||
3297 tmat_(2,0) != 0 || tmat_(2,1) != -14 || tmat_(2,2) != -3 || tmat_(2,3) != 5 || tmat_(2,4) != 9 ||
3298 tmat_(3,0) != 0 || tmat_(3,1) != 0 || tmat_(3,2) != 0 || tmat_(3,3) != -18 || tmat_(3,4) != 10 ) {
3299 std::ostringstream oss;
3300 oss << " Test: " << test_ << "\n"
3301 << " Error: Subtraction assignment failed\n"
3302 << " Details:\n"
3303 << " Result:\n" << tmat_ << "\n"
3304 << " Expected result:\n( 0 0 -2 -11 7 )\n"
3305 "( 0 -12 0 4 -8 )\n"
3306 "( 0 -14 -3 5 9 )\n"
3307 "( 0 0 0 -18 10 )\n";
3308 throw std::runtime_error( oss.str() );
3309 }
3310 }
3311
3312
3313 //=====================================================================================
3314 // Column-major sparse matrix subtraction assignment
3315 //=====================================================================================
3316
3317 {
3318 test_ = "Column-major/row-major sparse matrix subtraction assignment";
3319
3320 initialize();
3321
3322 auto cs = blaze::columns( tmat_, { 3UL, 1UL } );
3323
3324 const blaze::CompressedMatrix<int,blaze::rowMajor> mat{ { 11, 0 },
3325 { 0, 13 },
3326 { 0, 14 },
3327 { 12, 0 } };
3328
3329 cs -= mat;
3330
3331 checkRows ( cs , 4UL );
3332 checkColumns ( cs , 2UL );
3333 checkNonZeros( cs , 6UL );
3334 checkRows ( tmat_, 4UL );
3335 checkColumns ( tmat_, 5UL );
3336 checkNonZeros( tmat_, 12UL );
3337
3338 if( cs(0,0) != -11 || cs(0,1) != 0 ||
3339 cs(1,0) != 4 || cs(1,1) != -12 ||
3340 cs(2,0) != 5 || cs(2,1) != -14 ||
3341 cs(3,0) != -18 || cs(3,1) != 0 ) {
3342 std::ostringstream oss;
3343 oss << " Test: " << test_ << "\n"
3344 << " Error: Subtraction assignment failed\n"
3345 << " Details:\n"
3346 << " Result:\n" << cs << "\n"
3347 << " Expected result:\n( -11 0 )\n( 4 -12 )\n( 5 -14 )\n( -18 0 )\n";
3348 throw std::runtime_error( oss.str() );
3349 }
3350
3351 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != -2 || tmat_(0,3) != -11 || tmat_(0,4) != 7 ||
3352 tmat_(1,0) != 0 || tmat_(1,1) != -12 || tmat_(1,2) != 0 || tmat_(1,3) != 4 || tmat_(1,4) != -8 ||
3353 tmat_(2,0) != 0 || tmat_(2,1) != -14 || tmat_(2,2) != -3 || tmat_(2,3) != 5 || tmat_(2,4) != 9 ||
3354 tmat_(3,0) != 0 || tmat_(3,1) != 0 || tmat_(3,2) != 0 || tmat_(3,3) != -18 || tmat_(3,4) != 10 ) {
3355 std::ostringstream oss;
3356 oss << " Test: " << test_ << "\n"
3357 << " Error: Subtraction assignment failed\n"
3358 << " Details:\n"
3359 << " Result:\n" << tmat_ << "\n"
3360 << " Expected result:\n( 0 0 -2 -11 7 )\n"
3361 "( 0 -12 0 4 -8 )\n"
3362 "( 0 -14 -3 5 9 )\n"
3363 "( 0 0 0 -18 10 )\n";
3364 throw std::runtime_error( oss.str() );
3365 }
3366 }
3367
3368 {
3369 test_ = "Column-major/column-major sparse matrix subtraction assignment";
3370
3371 initialize();
3372
3373 auto cs = blaze::columns( tmat_, { 3UL, 1UL } );
3374
3375 const blaze::CompressedMatrix<int,blaze::columnMajor> mat{ { 11, 0 },
3376 { 0, 13 },
3377 { 0, 14 },
3378 { 12, 0 } };
3379
3380 cs -= mat;
3381
3382 checkRows ( cs , 4UL );
3383 checkColumns ( cs , 2UL );
3384 checkNonZeros( cs , 6UL );
3385 checkRows ( tmat_, 4UL );
3386 checkColumns ( tmat_, 5UL );
3387 checkNonZeros( tmat_, 12UL );
3388
3389 if( cs(0,0) != -11 || cs(0,1) != 0 ||
3390 cs(1,0) != 4 || cs(1,1) != -12 ||
3391 cs(2,0) != 5 || cs(2,1) != -14 ||
3392 cs(3,0) != -18 || cs(3,1) != 0 ) {
3393 std::ostringstream oss;
3394 oss << " Test: " << test_ << "\n"
3395 << " Error: Subtraction assignment failed\n"
3396 << " Details:\n"
3397 << " Result:\n" << cs << "\n"
3398 << " Expected result:\n( -11 0 )\n( 4 -12 )\n( 5 -14 )\n( -18 0 )\n";
3399 throw std::runtime_error( oss.str() );
3400 }
3401
3402 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != -2 || tmat_(0,3) != -11 || tmat_(0,4) != 7 ||
3403 tmat_(1,0) != 0 || tmat_(1,1) != -12 || tmat_(1,2) != 0 || tmat_(1,3) != 4 || tmat_(1,4) != -8 ||
3404 tmat_(2,0) != 0 || tmat_(2,1) != -14 || tmat_(2,2) != -3 || tmat_(2,3) != 5 || tmat_(2,4) != 9 ||
3405 tmat_(3,0) != 0 || tmat_(3,1) != 0 || tmat_(3,2) != 0 || tmat_(3,3) != -18 || tmat_(3,4) != 10 ) {
3406 std::ostringstream oss;
3407 oss << " Test: " << test_ << "\n"
3408 << " Error: Subtraction assignment failed\n"
3409 << " Details:\n"
3410 << " Result:\n" << tmat_ << "\n"
3411 << " Expected result:\n( 0 0 -2 -11 7 )\n"
3412 "( 0 -12 0 4 -8 )\n"
3413 "( 0 -14 -3 5 9 )\n"
3414 "( 0 0 0 -18 10 )\n";
3415 throw std::runtime_error( oss.str() );
3416 }
3417 }
3418 }
3419 //*************************************************************************************************
3420
3421
3422 //*************************************************************************************************
3423 /*!\brief Test of the Columns Schur product assignment operators.
3424 //
3425 // \return void
3426 // \exception std::runtime_error Error detected.
3427 //
3428 // This function performs a test of the Schur product assignment operators of the Columns
3429 // specialization. In case an error is detected, a \a std::runtime_error exception is thrown.
3430 */
testSchurAssign()3431 void SparseGeneralTest::testSchurAssign()
3432 {
3433 //=====================================================================================
3434 // Row-major Columns Schur product assignment
3435 //=====================================================================================
3436
3437 {
3438 test_ = "Row-major Columns Schur product assignment (no aliasing)";
3439
3440 initialize();
3441
3442 MT mat{ { 0, 1, 0, 4, 0 },
3443 { 0, 2, 0, 3, 0 },
3444 { 0, 3, 0, 2, 0 },
3445 { 0, 0, 0, 1, 0 } };
3446
3447 auto cs = blaze::columns( mat, { 3UL, 1UL } );
3448 cs %= blaze::columns( mat_, { 3UL, 1UL } );
3449
3450 checkRows ( cs , 4UL );
3451 checkColumns ( cs , 2UL );
3452 checkNonZeros( cs , 4UL );
3453 checkRows ( mat, 4UL );
3454 checkColumns ( mat, 5UL );
3455 checkNonZeros( mat, 4UL );
3456
3457 if( cs(0,0) != 0 || cs(0,1) != 0 ||
3458 cs(1,0) != 12 || cs(1,1) != 2 ||
3459 cs(2,0) != 10 || cs(2,1) != 0 ||
3460 cs(3,0) != -6 || cs(3,1) != 0 ) {
3461 std::ostringstream oss;
3462 oss << " Test: " << test_ << "\n"
3463 << " Error: Schur product assignment failed\n"
3464 << " Details:\n"
3465 << " Result:\n" << cs << "\n"
3466 << " Expected result:\n( 0 0 )\n( 12 2 )\n( 10 0 )\n( -6 0 )\n";
3467 throw std::runtime_error( oss.str() );
3468 }
3469
3470 if( mat(0,0) != 0 || mat(0,1) != 0 || mat(0,2) != 0 || mat(0,3) != 0 || mat(0,4) != 0 ||
3471 mat(1,0) != 0 || mat(1,1) != 2 || mat(1,2) != 0 || mat(1,3) != 12 || mat(1,4) != 0 ||
3472 mat(2,0) != 0 || mat(2,1) != 0 || mat(2,2) != 0 || mat(2,3) != 10 || mat(2,4) != 0 ||
3473 mat(3,0) != 0 || mat(3,1) != 0 || mat(3,2) != 0 || mat(3,3) != -6 || mat(3,4) != 0 ) {
3474 std::ostringstream oss;
3475 oss << " Test: " << test_ << "\n"
3476 << " Error: Schur product assignment failed\n"
3477 << " Details:\n"
3478 << " Result:\n" << mat << "\n"
3479 << " Expected result:\n( 0 0 0 0 0 )\n"
3480 "( 0 2 0 12 0 )\n"
3481 "( 0 0 0 10 0 )\n"
3482 "( 0 0 0 -6 0 )\n";
3483 throw std::runtime_error( oss.str() );
3484 }
3485 }
3486
3487 {
3488 test_ = "Row-major Columns Schur product assignment (aliasing)";
3489
3490 initialize();
3491
3492 auto cs = blaze::columns( mat_, { 3UL, 4UL } );
3493 cs %= blaze::columns( mat_, { 2UL, 3UL } );
3494
3495 checkRows ( cs , 4UL );
3496 checkColumns ( cs , 2UL );
3497 checkNonZeros( cs , 4UL );
3498 checkRows ( mat_, 4UL );
3499 checkColumns ( mat_, 5UL );
3500 checkNonZeros( mat_, 7UL );
3501
3502 if( cs(0,0) != 0 || cs(0,1) != 0 ||
3503 cs(1,0) != 0 || cs(1,1) != -32 ||
3504 cs(2,0) != -15 || cs(2,1) != 45 ||
3505 cs(3,0) != 0 || cs(3,1) != -60 ) {
3506 std::ostringstream oss;
3507 oss << " Test: " << test_ << "\n"
3508 << " Error: Schur product assignment failed\n"
3509 << " Details:\n"
3510 << " Result:\n" << cs << "\n"
3511 << " Expected result:\n( 0 0 )\n( 0 -32 )\n( -15 45 )\n( 0 -60 )\n";
3512 throw std::runtime_error( oss.str() );
3513 }
3514
3515 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != -2 || mat_(0,3) != 0 || mat_(0,4) != 0 ||
3516 mat_(1,0) != 0 || mat_(1,1) != 1 || mat_(1,2) != 0 || mat_(1,3) != 0 || mat_(1,4) != -32 ||
3517 mat_(2,0) != 0 || mat_(2,1) != 0 || mat_(2,2) != -3 || mat_(2,3) != -15 || mat_(2,4) != 45 ||
3518 mat_(3,0) != 0 || mat_(3,1) != 0 || mat_(3,2) != 0 || mat_(3,3) != 0 || mat_(3,4) != -60 ) {
3519 std::ostringstream oss;
3520 oss << " Test: " << test_ << "\n"
3521 << " Error: Schur product assignment failed\n"
3522 << " Details:\n"
3523 << " Result:\n" << mat_ << "\n"
3524 << " Expected result:\n( 0 0 -2 0 0 )\n"
3525 "( 0 1 0 0 32 )\n"
3526 "( 0 0 -3 -15 45 )\n"
3527 "( 0 0 0 0 -60 )\n";
3528 throw std::runtime_error( oss.str() );
3529 }
3530 }
3531
3532
3533 //=====================================================================================
3534 // Row-major dense matrix Schur product assignment
3535 //=====================================================================================
3536
3537 {
3538 test_ = "Row-major/row-major dense matrix Schur product assignment";
3539
3540 initialize();
3541
3542 auto cs = blaze::columns( mat_, { 3UL, 1UL } );
3543
3544 const blaze::DynamicMatrix<int,blaze::rowMajor> mat{ { 0, 0 },
3545 { -1, 2 },
3546 { 0, 1 },
3547 { -2, 0 } };
3548
3549 cs %= mat;
3550
3551 checkRows ( cs , 4UL );
3552 checkColumns ( cs , 2UL );
3553 checkNonZeros( cs , 3UL );
3554 checkRows ( mat_, 4UL );
3555 checkColumns ( mat_, 5UL );
3556 checkNonZeros( mat_, 9UL );
3557
3558 if( cs(0,0) != 0 || cs(0,1) != 0 ||
3559 cs(1,0) != -4 || cs(1,1) != 2 ||
3560 cs(2,0) != 0 || cs(2,1) != 0 ||
3561 cs(3,0) != 12 || cs(3,1) != 0 ) {
3562 std::ostringstream oss;
3563 oss << " Test: " << test_ << "\n"
3564 << " Error: Schur product assignment failed\n"
3565 << " Details:\n"
3566 << " Result:\n" << cs << "\n"
3567 << " Expected result:\n( 0 0 )\n( -4 2 )\n( 0 0 )\n( 12 0 )\n";
3568 throw std::runtime_error( oss.str() );
3569 }
3570
3571 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != -2 || mat_(0,3) != 0 || mat_(0,4) != 7 ||
3572 mat_(1,0) != 0 || mat_(1,1) != 2 || mat_(1,2) != 0 || mat_(1,3) != -4 || mat_(1,4) != -8 ||
3573 mat_(2,0) != 0 || mat_(2,1) != 0 || mat_(2,2) != -3 || mat_(2,3) != 0 || mat_(2,4) != 9 ||
3574 mat_(3,0) != 0 || mat_(3,1) != 0 || mat_(3,2) != 0 || mat_(3,3) != 12 || mat_(3,4) != 10 ) {
3575 std::ostringstream oss;
3576 oss << " Test: " << test_ << "\n"
3577 << " Error: Schur product assignment failed\n"
3578 << " Details:\n"
3579 << " Result:\n" << mat_ << "\n"
3580 << " Expected result:\n( 0 0 -2 0 7 )\n"
3581 "( 0 2 0 -4 -8 )\n"
3582 "( 0 0 -3 0 9 )\n"
3583 "( 0 0 0 12 10 )\n";
3584 throw std::runtime_error( oss.str() );
3585 }
3586 }
3587
3588 {
3589 test_ = "Row-major/column-major dense matrix Schur product assignment";
3590
3591 initialize();
3592
3593 auto cs = blaze::columns( mat_, { 3UL, 1UL } );
3594
3595 const blaze::DynamicMatrix<int,blaze::columnMajor> mat{ { 0, 0 },
3596 { -1, 2 },
3597 { 0, 1 },
3598 { -2, 0 } };
3599
3600 cs %= mat;
3601
3602 checkRows ( cs , 4UL );
3603 checkColumns ( cs , 2UL );
3604 checkNonZeros( cs , 3UL );
3605 checkRows ( mat_, 4UL );
3606 checkColumns ( mat_, 5UL );
3607 checkNonZeros( mat_, 9UL );
3608
3609 if( cs(0,0) != 0 || cs(0,1) != 0 ||
3610 cs(1,0) != -4 || cs(1,1) != 2 ||
3611 cs(2,0) != 0 || cs(2,1) != 0 ||
3612 cs(3,0) != 12 || cs(3,1) != 0 ) {
3613 std::ostringstream oss;
3614 oss << " Test: " << test_ << "\n"
3615 << " Error: Schur product assignment failed\n"
3616 << " Details:\n"
3617 << " Result:\n" << cs << "\n"
3618 << " Expected result:\n( 0 0 )\n( -4 2 )\n( 0 0 )\n( 12 0 )\n";
3619 throw std::runtime_error( oss.str() );
3620 }
3621
3622 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != -2 || mat_(0,3) != 0 || mat_(0,4) != 7 ||
3623 mat_(1,0) != 0 || mat_(1,1) != 2 || mat_(1,2) != 0 || mat_(1,3) != -4 || mat_(1,4) != -8 ||
3624 mat_(2,0) != 0 || mat_(2,1) != 0 || mat_(2,2) != -3 || mat_(2,3) != 0 || mat_(2,4) != 9 ||
3625 mat_(3,0) != 0 || mat_(3,1) != 0 || mat_(3,2) != 0 || mat_(3,3) != 12 || mat_(3,4) != 10 ) {
3626 std::ostringstream oss;
3627 oss << " Test: " << test_ << "\n"
3628 << " Error: Schur product assignment failed\n"
3629 << " Details:\n"
3630 << " Result:\n" << mat_ << "\n"
3631 << " Expected result:\n( 0 0 -2 0 7 )\n"
3632 "( 0 2 0 -4 -8 )\n"
3633 "( 0 0 -3 0 9 )\n"
3634 "( 0 0 0 12 10 )\n";
3635 throw std::runtime_error( oss.str() );
3636 }
3637 }
3638
3639
3640 //=====================================================================================
3641 // Row-major sparse matrix Schur product assignment
3642 //=====================================================================================
3643
3644 {
3645 test_ = "Row-major/row-major sparse matrix Schur product assignment";
3646
3647 initialize();
3648
3649 auto cs = blaze::columns( mat_, { 3UL, 1UL } );
3650
3651 const blaze::CompressedMatrix<int,blaze::rowMajor> mat{ { 0, 0 },
3652 { -1, 2 },
3653 { 0, 1 },
3654 { -2, 0 } };
3655
3656 cs %= mat;
3657
3658 checkRows ( cs , 4UL );
3659 checkColumns ( cs , 2UL );
3660 checkNonZeros( cs , 3UL );
3661 checkRows ( mat_, 4UL );
3662 checkColumns ( mat_, 5UL );
3663 checkNonZeros( mat_, 9UL );
3664
3665 if( cs(0,0) != 0 || cs(0,1) != 0 ||
3666 cs(1,0) != -4 || cs(1,1) != 2 ||
3667 cs(2,0) != 0 || cs(2,1) != 0 ||
3668 cs(3,0) != 12 || cs(3,1) != 0 ) {
3669 std::ostringstream oss;
3670 oss << " Test: " << test_ << "\n"
3671 << " Error: Schur product assignment failed\n"
3672 << " Details:\n"
3673 << " Result:\n" << cs << "\n"
3674 << " Expected result:\n( 0 0 )\n( -4 2 )\n( 0 0 )\n( 12 0 )\n";
3675 throw std::runtime_error( oss.str() );
3676 }
3677
3678 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != -2 || mat_(0,3) != 0 || mat_(0,4) != 7 ||
3679 mat_(1,0) != 0 || mat_(1,1) != 2 || mat_(1,2) != 0 || mat_(1,3) != -4 || mat_(1,4) != -8 ||
3680 mat_(2,0) != 0 || mat_(2,1) != 0 || mat_(2,2) != -3 || mat_(2,3) != 0 || mat_(2,4) != 9 ||
3681 mat_(3,0) != 0 || mat_(3,1) != 0 || mat_(3,2) != 0 || mat_(3,3) != 12 || mat_(3,4) != 10 ) {
3682 std::ostringstream oss;
3683 oss << " Test: " << test_ << "\n"
3684 << " Error: Schur product assignment failed\n"
3685 << " Details:\n"
3686 << " Result:\n" << mat_ << "\n"
3687 << " Expected result:\n( 0 0 -2 0 7 )\n"
3688 "( 0 2 0 -4 -8 )\n"
3689 "( 0 0 -3 0 9 )\n"
3690 "( 0 0 0 12 10 )\n";
3691 throw std::runtime_error( oss.str() );
3692 }
3693 }
3694
3695 {
3696 test_ = "Row-major/column-major sparse matrix Schur product assignment";
3697
3698 initialize();
3699
3700 auto cs = blaze::columns( mat_, { 3UL, 1UL } );
3701
3702 const blaze::CompressedMatrix<int,blaze::columnMajor> mat{ { 0, 0 },
3703 { -1, 2 },
3704 { 0, 1 },
3705 { -2, 0 } };
3706
3707 cs %= mat;
3708
3709 checkRows ( cs , 4UL );
3710 checkColumns ( cs , 2UL );
3711 checkNonZeros( cs , 3UL );
3712 checkRows ( mat_, 4UL );
3713 checkColumns ( mat_, 5UL );
3714 checkNonZeros( mat_, 9UL );
3715
3716 if( cs(0,0) != 0 || cs(0,1) != 0 ||
3717 cs(1,0) != -4 || cs(1,1) != 2 ||
3718 cs(2,0) != 0 || cs(2,1) != 0 ||
3719 cs(3,0) != 12 || cs(3,1) != 0 ) {
3720 std::ostringstream oss;
3721 oss << " Test: " << test_ << "\n"
3722 << " Error: Schur product assignment failed\n"
3723 << " Details:\n"
3724 << " Result:\n" << cs << "\n"
3725 << " Expected result:\n( 0 0 )\n( -4 2 )\n( 0 0 )\n( 12 0 )\n";
3726 throw std::runtime_error( oss.str() );
3727 }
3728
3729 if( mat_(0,0) != 0 || mat_(0,1) != 0 || mat_(0,2) != -2 || mat_(0,3) != 0 || mat_(0,4) != 7 ||
3730 mat_(1,0) != 0 || mat_(1,1) != 2 || mat_(1,2) != 0 || mat_(1,3) != -4 || mat_(1,4) != -8 ||
3731 mat_(2,0) != 0 || mat_(2,1) != 0 || mat_(2,2) != -3 || mat_(2,3) != 0 || mat_(2,4) != 9 ||
3732 mat_(3,0) != 0 || mat_(3,1) != 0 || mat_(3,2) != 0 || mat_(3,3) != 12 || mat_(3,4) != 10 ) {
3733 std::ostringstream oss;
3734 oss << " Test: " << test_ << "\n"
3735 << " Error: Schur product assignment failed\n"
3736 << " Details:\n"
3737 << " Result:\n" << mat_ << "\n"
3738 << " Expected result:\n( 0 0 -2 0 7 )\n"
3739 "( 0 2 0 -4 -8 )\n"
3740 "( 0 0 -3 0 9 )\n"
3741 "( 0 0 0 12 10 )\n";
3742 throw std::runtime_error( oss.str() );
3743 }
3744 }
3745
3746
3747 //=====================================================================================
3748 // Column-major Columns Schur product assignment
3749 //=====================================================================================
3750
3751 {
3752 test_ = "Column-major Columns Schur product assignment (no aliasing)";
3753
3754 initialize();
3755
3756 OMT mat{ { 0, 1, 0, 4, 0 },
3757 { 0, 2, 0, 3, 0 },
3758 { 0, 3, 0, 2, 0 },
3759 { 0, 0, 0, 1, 0 } };
3760
3761 auto cs = blaze::columns( mat, { 3UL, 1UL } );
3762 cs %= blaze::columns( tmat_, { 3UL, 1UL } );
3763
3764 checkRows ( cs , 4UL );
3765 checkColumns ( cs , 2UL );
3766 checkNonZeros( cs , 4UL );
3767 checkRows ( mat, 4UL );
3768 checkColumns ( mat, 5UL );
3769 checkNonZeros( mat, 4UL );
3770
3771 if( cs(0,0) != 0 || cs(0,1) != 0 ||
3772 cs(1,0) != 12 || cs(1,1) != 2 ||
3773 cs(2,0) != 10 || cs(2,1) != 0 ||
3774 cs(3,0) != -6 || cs(3,1) != 0 ) {
3775 std::ostringstream oss;
3776 oss << " Test: " << test_ << "\n"
3777 << " Error: Schur product assignment failed\n"
3778 << " Details:\n"
3779 << " Result:\n" << cs << "\n"
3780 << " Expected result:\n( 0 0 )\n( 12 2 )\n( 10 0 )\n( -6 0 )\n";
3781 throw std::runtime_error( oss.str() );
3782 }
3783
3784 if( mat(0,0) != 0 || mat(0,1) != 0 || mat(0,2) != 0 || mat(0,3) != 0 || mat(0,4) != 0 ||
3785 mat(1,0) != 0 || mat(1,1) != 2 || mat(1,2) != 0 || mat(1,3) != 12 || mat(1,4) != 0 ||
3786 mat(2,0) != 0 || mat(2,1) != 0 || mat(2,2) != 0 || mat(2,3) != 10 || mat(2,4) != 0 ||
3787 mat(3,0) != 0 || mat(3,1) != 0 || mat(3,2) != 0 || mat(3,3) != -6 || mat(3,4) != 0 ) {
3788 std::ostringstream oss;
3789 oss << " Test: " << test_ << "\n"
3790 << " Error: Schur product assignment failed\n"
3791 << " Details:\n"
3792 << " Result:\n" << mat << "\n"
3793 << " Expected result:\n( 0 0 0 0 0 )\n"
3794 "( 0 2 0 12 0 )\n"
3795 "( 0 0 0 10 0 )\n"
3796 "( 0 0 0 -6 0 )\n";
3797 throw std::runtime_error( oss.str() );
3798 }
3799 }
3800
3801 {
3802 test_ = "Column-major Columns Schur product assignment (aliasing)";
3803
3804 initialize();
3805
3806 auto cs = blaze::columns( tmat_, { 3UL, 4UL } );
3807 cs %= blaze::columns( tmat_, { 2UL, 3UL } );
3808
3809 checkRows ( cs , 4UL );
3810 checkColumns ( cs , 2UL );
3811 checkNonZeros( cs , 4UL );
3812 checkRows ( tmat_, 4UL );
3813 checkColumns ( tmat_, 5UL );
3814 checkNonZeros( tmat_, 7UL );
3815
3816 if( cs(0,0) != 0 || cs(0,1) != 0 ||
3817 cs(1,0) != 0 || cs(1,1) != -32 ||
3818 cs(2,0) != -15 || cs(2,1) != 45 ||
3819 cs(3,0) != 0 || cs(3,1) != -60 ) {
3820 std::ostringstream oss;
3821 oss << " Test: " << test_ << "\n"
3822 << " Error: Schur product assignment failed\n"
3823 << " Details:\n"
3824 << " Result:\n" << cs << "\n"
3825 << " Expected result:\n( 0 0 )\n( 0 -32 )\n( -15 45 )\n( 0 -60 )\n";
3826 throw std::runtime_error( oss.str() );
3827 }
3828
3829 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != -2 || tmat_(0,3) != 0 || tmat_(0,4) != 0 ||
3830 tmat_(1,0) != 0 || tmat_(1,1) != 1 || tmat_(1,2) != 0 || tmat_(1,3) != 0 || tmat_(1,4) != -32 ||
3831 tmat_(2,0) != 0 || tmat_(2,1) != 0 || tmat_(2,2) != -3 || tmat_(2,3) != -15 || tmat_(2,4) != 45 ||
3832 tmat_(3,0) != 0 || tmat_(3,1) != 0 || tmat_(3,2) != 0 || tmat_(3,3) != 0 || tmat_(3,4) != -60 ) {
3833 std::ostringstream oss;
3834 oss << " Test: " << test_ << "\n"
3835 << " Error: Schur product assignment failed\n"
3836 << " Details:\n"
3837 << " Result:\n" << tmat_ << "\n"
3838 << " Expected result:\n( 0 0 -2 0 0 )\n"
3839 "( 0 1 0 0 32 )\n"
3840 "( 0 0 -3 -15 45 )\n"
3841 "( 0 0 0 0 -60 )\n";
3842 throw std::runtime_error( oss.str() );
3843 }
3844 }
3845
3846
3847 //=====================================================================================
3848 // Column-major dense matrix Schur product assignment
3849 //=====================================================================================
3850
3851 {
3852 test_ = "Column-major/row-major dense matrix Schur product assignment";
3853
3854 initialize();
3855
3856 auto cs = blaze::columns( tmat_, { 3UL, 1UL } );
3857
3858 const blaze::DynamicMatrix<int,blaze::rowMajor> mat{ { 0, 0 },
3859 { -1, 2 },
3860 { 0, 1 },
3861 { -2, 0 } };
3862
3863 cs %= mat;
3864
3865 checkRows ( cs , 4UL );
3866 checkColumns ( cs , 2UL );
3867 checkNonZeros( cs , 3UL );
3868 checkRows ( tmat_, 4UL );
3869 checkColumns ( tmat_, 5UL );
3870 checkNonZeros( tmat_, 9UL );
3871
3872 if( cs(0,0) != 0 || cs(0,1) != 0 ||
3873 cs(1,0) != -4 || cs(1,1) != 2 ||
3874 cs(2,0) != 0 || cs(2,1) != 0 ||
3875 cs(3,0) != 12 || cs(3,1) != 0 ) {
3876 std::ostringstream oss;
3877 oss << " Test: " << test_ << "\n"
3878 << " Error: Schur product assignment failed\n"
3879 << " Details:\n"
3880 << " Result:\n" << cs << "\n"
3881 << " Expected result:\n( 0 0 )\n( -4 2 )\n( 0 0 )\n( 12 0 )\n";
3882 throw std::runtime_error( oss.str() );
3883 }
3884
3885 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != -2 || tmat_(0,3) != 0 || tmat_(0,4) != 7 ||
3886 tmat_(1,0) != 0 || tmat_(1,1) != 2 || tmat_(1,2) != 0 || tmat_(1,3) != -4 || tmat_(1,4) != -8 ||
3887 tmat_(2,0) != 0 || tmat_(2,1) != 0 || tmat_(2,2) != -3 || tmat_(2,3) != 0 || tmat_(2,4) != 9 ||
3888 tmat_(3,0) != 0 || tmat_(3,1) != 0 || tmat_(3,2) != 0 || tmat_(3,3) != 12 || tmat_(3,4) != 10 ) {
3889 std::ostringstream oss;
3890 oss << " Test: " << test_ << "\n"
3891 << " Error: Schur product assignment failed\n"
3892 << " Details:\n"
3893 << " Result:\n" << tmat_ << "\n"
3894 << " Expected result:\n( 0 0 -2 0 7 )\n"
3895 "( 0 2 0 -4 -8 )\n"
3896 "( 0 0 -3 0 9 )\n"
3897 "( 0 0 0 12 10 )\n";
3898 throw std::runtime_error( oss.str() );
3899 }
3900 }
3901
3902 {
3903 test_ = "Column-major/column-major dense matrix Schur product assignment";
3904
3905 initialize();
3906
3907 auto cs = blaze::columns( tmat_, { 3UL, 1UL } );
3908
3909 const blaze::DynamicMatrix<int,blaze::columnMajor> mat{ { 0, 0 },
3910 { -1, 2 },
3911 { 0, 1 },
3912 { -2, 0 } };
3913
3914 cs %= mat;
3915
3916 checkRows ( cs , 4UL );
3917 checkColumns ( cs , 2UL );
3918 checkNonZeros( cs , 3UL );
3919 checkRows ( tmat_, 4UL );
3920 checkColumns ( tmat_, 5UL );
3921 checkNonZeros( tmat_, 9UL );
3922
3923 if( cs(0,0) != 0 || cs(0,1) != 0 ||
3924 cs(1,0) != -4 || cs(1,1) != 2 ||
3925 cs(2,0) != 0 || cs(2,1) != 0 ||
3926 cs(3,0) != 12 || cs(3,1) != 0 ) {
3927 std::ostringstream oss;
3928 oss << " Test: " << test_ << "\n"
3929 << " Error: Schur product assignment failed\n"
3930 << " Details:\n"
3931 << " Result:\n" << cs << "\n"
3932 << " Expected result:\n( 0 0 )\n( -4 2 )\n( 0 0 )\n( 12 0 )\n";
3933 throw std::runtime_error( oss.str() );
3934 }
3935
3936 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != -2 || tmat_(0,3) != 0 || tmat_(0,4) != 7 ||
3937 tmat_(1,0) != 0 || tmat_(1,1) != 2 || tmat_(1,2) != 0 || tmat_(1,3) != -4 || tmat_(1,4) != -8 ||
3938 tmat_(2,0) != 0 || tmat_(2,1) != 0 || tmat_(2,2) != -3 || tmat_(2,3) != 0 || tmat_(2,4) != 9 ||
3939 tmat_(3,0) != 0 || tmat_(3,1) != 0 || tmat_(3,2) != 0 || tmat_(3,3) != 12 || tmat_(3,4) != 10 ) {
3940 std::ostringstream oss;
3941 oss << " Test: " << test_ << "\n"
3942 << " Error: Schur product assignment failed\n"
3943 << " Details:\n"
3944 << " Result:\n" << tmat_ << "\n"
3945 << " Expected result:\n( 0 0 -2 0 7 )\n"
3946 "( 0 2 0 -4 -8 )\n"
3947 "( 0 0 -3 0 9 )\n"
3948 "( 0 0 0 12 10 )\n";
3949 throw std::runtime_error( oss.str() );
3950 }
3951 }
3952
3953
3954 //=====================================================================================
3955 // Column-major sparse matrix Schur product assignment
3956 //=====================================================================================
3957
3958 {
3959 test_ = "Column-major/row-major sparse matrix Schur product assignment";
3960
3961 initialize();
3962
3963 auto cs = blaze::columns( tmat_, { 3UL, 1UL } );
3964
3965 const blaze::CompressedMatrix<int,blaze::rowMajor> mat{ { 0, 0 },
3966 { -1, 2 },
3967 { 0, 1 },
3968 { -2, 0 } };
3969
3970 cs %= mat;
3971
3972 checkRows ( cs , 4UL );
3973 checkColumns ( cs , 2UL );
3974 checkNonZeros( cs , 3UL );
3975 checkRows ( tmat_, 4UL );
3976 checkColumns ( tmat_, 5UL );
3977 checkNonZeros( tmat_, 9UL );
3978
3979 if( cs(0,0) != 0 || cs(0,1) != 0 ||
3980 cs(1,0) != -4 || cs(1,1) != 2 ||
3981 cs(2,0) != 0 || cs(2,1) != 0 ||
3982 cs(3,0) != 12 || cs(3,1) != 0 ) {
3983 std::ostringstream oss;
3984 oss << " Test: " << test_ << "\n"
3985 << " Error: Schur product assignment failed\n"
3986 << " Details:\n"
3987 << " Result:\n" << cs << "\n"
3988 << " Expected result:\n( 0 0 )\n( -4 2 )\n( 0 0 )\n( 12 0 )\n";
3989 throw std::runtime_error( oss.str() );
3990 }
3991
3992 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != -2 || tmat_(0,3) != 0 || tmat_(0,4) != 7 ||
3993 tmat_(1,0) != 0 || tmat_(1,1) != 2 || tmat_(1,2) != 0 || tmat_(1,3) != -4 || tmat_(1,4) != -8 ||
3994 tmat_(2,0) != 0 || tmat_(2,1) != 0 || tmat_(2,2) != -3 || tmat_(2,3) != 0 || tmat_(2,4) != 9 ||
3995 tmat_(3,0) != 0 || tmat_(3,1) != 0 || tmat_(3,2) != 0 || tmat_(3,3) != 12 || tmat_(3,4) != 10 ) {
3996 std::ostringstream oss;
3997 oss << " Test: " << test_ << "\n"
3998 << " Error: Schur product assignment failed\n"
3999 << " Details:\n"
4000 << " Result:\n" << tmat_ << "\n"
4001 << " Expected result:\n( 0 0 -2 0 7 )\n"
4002 "( 0 2 0 -4 -8 )\n"
4003 "( 0 0 -3 0 9 )\n"
4004 "( 0 0 0 12 10 )\n";
4005 throw std::runtime_error( oss.str() );
4006 }
4007 }
4008
4009 {
4010 test_ = "Column-major/column-major sparse matrix Schur product assignment";
4011
4012 initialize();
4013
4014 auto cs = blaze::columns( tmat_, { 3UL, 1UL } );
4015
4016 const blaze::CompressedMatrix<int,blaze::columnMajor> mat{ { 0, 0 },
4017 { -1, 2 },
4018 { 0, 1 },
4019 { -2, 0 } };
4020
4021 cs %= mat;
4022
4023 checkRows ( cs , 4UL );
4024 checkColumns ( cs , 2UL );
4025 checkNonZeros( cs , 3UL );
4026 checkRows ( tmat_, 4UL );
4027 checkColumns ( tmat_, 5UL );
4028 checkNonZeros( tmat_, 9UL );
4029
4030 if( cs(0,0) != 0 || cs(0,1) != 0 ||
4031 cs(1,0) != -4 || cs(1,1) != 2 ||
4032 cs(2,0) != 0 || cs(2,1) != 0 ||
4033 cs(3,0) != 12 || cs(3,1) != 0 ) {
4034 std::ostringstream oss;
4035 oss << " Test: " << test_ << "\n"
4036 << " Error: Schur product assignment failed\n"
4037 << " Details:\n"
4038 << " Result:\n" << cs << "\n"
4039 << " Expected result:\n( 0 0 )\n( -4 2 )\n( 0 0 )\n( 12 0 )\n";
4040 throw std::runtime_error( oss.str() );
4041 }
4042
4043 if( tmat_(0,0) != 0 || tmat_(0,1) != 0 || tmat_(0,2) != -2 || tmat_(0,3) != 0 || tmat_(0,4) != 7 ||
4044 tmat_(1,0) != 0 || tmat_(1,1) != 2 || tmat_(1,2) != 0 || tmat_(1,3) != -4 || tmat_(1,4) != -8 ||
4045 tmat_(2,0) != 0 || tmat_(2,1) != 0 || tmat_(2,2) != -3 || tmat_(2,3) != 0 || tmat_(2,4) != 9 ||
4046 tmat_(3,0) != 0 || tmat_(3,1) != 0 || tmat_(3,2) != 0 || tmat_(3,3) != 12 || tmat_(3,4) != 10 ) {
4047 std::ostringstream oss;
4048 oss << " Test: " << test_ << "\n"
4049 << " Error: Schur product assignment failed\n"
4050 << " Details:\n"
4051 << " Result:\n" << tmat_ << "\n"
4052 << " Expected result:\n( 0 0 -2 0 7 )\n"
4053 "( 0 2 0 -4 -8 )\n"
4054 "( 0 0 -3 0 9 )\n"
4055 "( 0 0 0 12 10 )\n";
4056 throw std::runtime_error( oss.str() );
4057 }
4058 }
4059 }
4060 //*************************************************************************************************
4061
4062
4063 //*************************************************************************************************
4064 /*!\brief Test of the Columns multiplication assignment operators.
4065 //
4066 // \return void
4067 // \exception std::runtime_error Error detected.
4068 //
4069 // This function performs a test of the multiplication assignment operators of the Columns
4070 // specialization. In case an error is detected, a \a std::runtime_error exception is thrown.
4071 */
testMultAssign()4072 void SparseGeneralTest::testMultAssign()
4073 {
4074 //=====================================================================================
4075 // Row-major Columns multiplication assignment
4076 //=====================================================================================
4077
4078 {
4079 test_ = "Row-major Columns multiplication assignment (no aliasing)";
4080
4081 initialize();
4082
4083 MT mat{ { 0, 0, -2, 0, 7 },
4084 { 0, 1, 0, 4, -8 },
4085 { 0, 0, -3, 5, 9 },
4086 { 0, 0, 0, -6, 10 } };
4087
4088 auto cs = blaze::columns( mat, { 2UL, 0UL, 3UL, 1UL } );
4089 cs *= blaze::columns( mat_, { 1UL, 2UL, 2UL, 1UL } );
4090
4091 checkRows ( cs , 4UL );
4092 checkColumns ( cs , 4UL );
4093 checkNonZeros( cs , 8UL );
4094 checkRows ( mat, 4UL );
4095 checkColumns ( mat, 5UL );
4096 checkNonZeros( mat, 12UL );
4097
4098 if( cs(0,0) != 0 || cs(0,1) != 4 || cs(0,2) != 4 || cs(0,3) != 0 ||
4099 cs(1,0) != 0 || cs(1,1) != -12 || cs(1,2) != -12 || cs(1,3) != 0 ||
4100 cs(2,0) != 0 || cs(2,1) != -9 || cs(2,2) != -9 || cs(2,3) != 0 ||
4101 cs(3,0) != 0 || cs(3,1) != 18 || cs(3,2) != 18 || cs(3,3) != 0 ) {
4102 std::ostringstream oss;
4103 oss << " Test: " << test_ << "\n"
4104 << " Error: Multiplication assignment failed\n"
4105 << " Details:\n"
4106 << " Result:\n" << cs << "\n"
4107 << " Expected result:\n( 0 4 4 0 )\n"
4108 "( 0 -12 -12 0 )\n"
4109 "( 0 -9 -9 0 )\n"
4110 "( 0 18 18 0 )\n";
4111 throw std::runtime_error( oss.str() );
4112 }
4113
4114 if( mat(0,0) != 4 || mat(0,1) != 0 || mat(0,2) != 0 || mat(0,3) != 4 || mat(0,4) != 7 ||
4115 mat(1,0) != -12 || mat(1,1) != 0 || mat(1,2) != 0 || mat(1,3) != -12 || mat(1,4) != -8 ||
4116 mat(2,0) != -9 || mat(2,1) != 0 || mat(2,2) != 0 || mat(2,3) != -9 || mat(2,4) != 9 ||
4117 mat(3,0) != 18 || mat(3,1) != 0 || mat(3,2) != 0 || mat(3,3) != 18 || mat(3,4) != 10 ) {
4118 std::ostringstream oss;
4119 oss << " Test: " << test_ << "\n"
4120 << " Error: Multiplication assignment failed\n"
4121 << " Details:\n"
4122 << " Result:\n" << mat << "\n"
4123 << " Expected result:\n( 4 0 0 4 7 )\n"
4124 "( -12 0 0 -12 -8 )\n"
4125 "( -9 0 0 -9 9 )\n"
4126 "( 18 0 0 18 10 )\n";
4127 throw std::runtime_error( oss.str() );
4128 }
4129 }
4130
4131 {
4132 test_ = "Row-major Columns multiplication assignment (aliasing)";
4133
4134 initialize();
4135
4136 auto cs = blaze::columns( mat_, { 2UL, 0UL, 3UL, 1UL } );
4137 cs *= blaze::columns( mat_, { 1UL, 2UL, 2UL, 1UL } );
4138
4139 checkRows ( cs , 4UL );
4140 checkColumns ( cs , 4UL );
4141 checkNonZeros( cs , 8UL );
4142 checkRows ( mat_, 4UL );
4143 checkColumns ( mat_, 5UL );
4144 checkNonZeros( mat_, 12UL );
4145
4146 if( cs(0,0) != 0 || cs(0,1) != 4 || cs(0,2) != 4 || cs(0,3) != 0 ||
4147 cs(1,0) != 0 || cs(1,1) != -12 || cs(1,2) != -12 || cs(1,3) != 0 ||
4148 cs(2,0) != 0 || cs(2,1) != -9 || cs(2,2) != -9 || cs(2,3) != 0 ||
4149 cs(3,0) != 0 || cs(3,1) != 18 || cs(3,2) != 18 || cs(3,3) != 0 ) {
4150 std::ostringstream oss;
4151 oss << " Test: " << test_ << "\n"
4152 << " Error: Multiplication assignment failed\n"
4153 << " Details:\n"
4154 << " Result:\n" << cs << "\n"
4155 << " Expected result:\n( 0 4 4 0 )\n"
4156 "( 0 -12 -12 0 )\n"
4157 "( 0 -9 -9 0 )\n"
4158 "( 0 18 18 0 )\n";
4159 throw std::runtime_error( oss.str() );
4160 }
4161
4162 if( mat_(0,0) != 4 || mat_(0,1) != 0 || mat_(0,2) != 0 || mat_(0,3) != 4 || mat_(0,4) != 7 ||
4163 mat_(1,0) != -12 || mat_(1,1) != 0 || mat_(1,2) != 0 || mat_(1,3) != -12 || mat_(1,4) != -8 ||
4164 mat_(2,0) != -9 || mat_(2,1) != 0 || mat_(2,2) != 0 || mat_(2,3) != -9 || mat_(2,4) != 9 ||
4165 mat_(3,0) != 18 || mat_(3,1) != 0 || mat_(3,2) != 0 || mat_(3,3) != 18 || mat_(3,4) != 10 ) {
4166 std::ostringstream oss;
4167 oss << " Test: " << test_ << "\n"
4168 << " Error: Multiplication assignment failed\n"
4169 << " Details:\n"
4170 << " Result:\n" << mat_ << "\n"
4171 << " Expected result:\n( 4 0 0 4 7 )\n"
4172 "( -12 0 0 -12 -8 )\n"
4173 "( -9 0 0 -9 9 )\n"
4174 "( 18 0 0 18 10 )\n";
4175 throw std::runtime_error( oss.str() );
4176 }
4177 }
4178
4179
4180 //=====================================================================================
4181 // Row-major dense matrix multiplication assignment
4182 //=====================================================================================
4183
4184 {
4185 test_ = "Row-major/row-major dense matrix multiplication assignment";
4186
4187 initialize();
4188
4189 auto cs = blaze::columns( mat_, { 2UL, 0UL, 3UL, 1UL } );
4190
4191 const blaze::DynamicMatrix<int,blaze::rowMajor> mat{ { 0, 1, 0, 0 },
4192 { -2, 0, -3, 0 },
4193 { -2, 0, -3, 0 },
4194 { 0, 1, 0, 0 } };
4195
4196 cs *= mat;
4197
4198 checkRows ( cs , 4UL );
4199 checkColumns ( cs , 4UL );
4200 checkNonZeros( cs , 9UL );
4201 checkRows ( mat_, 4UL );
4202 checkColumns ( mat_, 5UL );
4203 checkNonZeros( mat_, 13UL );
4204
4205 if( cs(0,0) != 0 || cs(0,1) != -2 || cs(0,2) != 0 || cs(0,3) != 0 ||
4206 cs(1,0) != -8 || cs(1,1) != 1 || cs(1,2) != -12 || cs(1,3) != 0 ||
4207 cs(2,0) != -10 || cs(2,1) != -3 || cs(2,2) != -15 || cs(2,3) != 0 ||
4208 cs(3,0) != 12 || cs(3,1) != 0 || cs(3,2) != 18 || cs(3,3) != 0 ) {
4209 std::ostringstream oss;
4210 oss << " Test: " << test_ << "\n"
4211 << " Error: Multiplication assignment failed\n"
4212 << " Details:\n"
4213 << " Result:\n" << cs << "\n"
4214 << " Expected result:\n( 0 -2 0 0 )\n"
4215 "( -8 1 -12 0 )\n"
4216 "( -10 -3 -15 0 )\n"
4217 "( 12 0 18 0 )\n";
4218 throw std::runtime_error( oss.str() );
4219 }
4220
4221 if( mat_(0,0) != -2 || mat_(0,1) != 0 || mat_(0,2) != 0 || mat_(0,3) != 0 || mat_(0,4) != 7 ||
4222 mat_(1,0) != 1 || mat_(1,1) != 0 || mat_(1,2) != -8 || mat_(1,3) != -12 || mat_(1,4) != -8 ||
4223 mat_(2,0) != -3 || mat_(2,1) != 0 || mat_(2,2) != -10 || mat_(2,3) != -15 || mat_(2,4) != 9 ||
4224 mat_(3,0) != 0 || mat_(3,1) != 0 || mat_(3,2) != 12 || mat_(3,3) != 18 || mat_(3,4) != 10 ) {
4225 std::ostringstream oss;
4226 oss << " Test: " << test_ << "\n"
4227 << " Error: Multiplication assignment failed\n"
4228 << " Details:\n"
4229 << " Result:\n" << mat_ << "\n"
4230 << " Expected result:\n( -2 0 0 0 7 )\n"
4231 "( 1 0 -8 -12 -8 )\n"
4232 "( -3 0 -10 -15 9 )\n"
4233 "( 0 0 12 18 10 )\n";
4234 throw std::runtime_error( oss.str() );
4235 }
4236 }
4237
4238 {
4239 test_ = "Row-major/column-major dense matrix multiplication assignment";
4240
4241 initialize();
4242
4243 auto cs = blaze::columns( mat_, { 2UL, 0UL, 3UL, 1UL } );
4244
4245 const blaze::DynamicMatrix<int,blaze::columnMajor> mat{ { 0, 1, 0, 0 },
4246 { -2, 0, -3, 0 },
4247 { -2, 0, -3, 0 },
4248 { 0, 1, 0, 0 } };
4249
4250 cs *= mat;
4251
4252 checkRows ( cs , 4UL );
4253 checkColumns ( cs , 4UL );
4254 checkNonZeros( cs , 9UL );
4255 checkRows ( mat_, 4UL );
4256 checkColumns ( mat_, 5UL );
4257 checkNonZeros( mat_, 13UL );
4258
4259 if( cs(0,0) != 0 || cs(0,1) != -2 || cs(0,2) != 0 || cs(0,3) != 0 ||
4260 cs(1,0) != -8 || cs(1,1) != 1 || cs(1,2) != -12 || cs(1,3) != 0 ||
4261 cs(2,0) != -10 || cs(2,1) != -3 || cs(2,2) != -15 || cs(2,3) != 0 ||
4262 cs(3,0) != 12 || cs(3,1) != 0 || cs(3,2) != 18 || cs(3,3) != 0 ) {
4263 std::ostringstream oss;
4264 oss << " Test: " << test_ << "\n"
4265 << " Error: Multiplication assignment failed\n"
4266 << " Details:\n"
4267 << " Result:\n" << cs << "\n"
4268 << " Expected result:\n( 0 -2 0 0 )\n"
4269 "( -8 1 -12 0 )\n"
4270 "( -10 -3 -15 0 )\n"
4271 "( 12 0 18 0 )\n";
4272 throw std::runtime_error( oss.str() );
4273 }
4274
4275 if( mat_(0,0) != -2 || mat_(0,1) != 0 || mat_(0,2) != 0 || mat_(0,3) != 0 || mat_(0,4) != 7 ||
4276 mat_(1,0) != 1 || mat_(1,1) != 0 || mat_(1,2) != -8 || mat_(1,3) != -12 || mat_(1,4) != -8 ||
4277 mat_(2,0) != -3 || mat_(2,1) != 0 || mat_(2,2) != -10 || mat_(2,3) != -15 || mat_(2,4) != 9 ||
4278 mat_(3,0) != 0 || mat_(3,1) != 0 || mat_(3,2) != 12 || mat_(3,3) != 18 || mat_(3,4) != 10 ) {
4279 std::ostringstream oss;
4280 oss << " Test: " << test_ << "\n"
4281 << " Error: Multiplication assignment failed\n"
4282 << " Details:\n"
4283 << " Result:\n" << mat_ << "\n"
4284 << " Expected result:\n( -2 0 0 0 7 )\n"
4285 "( 1 0 -8 -12 -8 )\n"
4286 "( -3 0 -10 -15 9 )\n"
4287 "( 0 0 12 18 10 )\n";
4288 throw std::runtime_error( oss.str() );
4289 }
4290 }
4291
4292
4293 //=====================================================================================
4294 // Row-major sparse matrix multiplication assignment
4295 //=====================================================================================
4296
4297 {
4298 test_ = "Row-major/row-major sparse matrix multiplication assignment";
4299
4300 initialize();
4301
4302 auto cs = blaze::columns( mat_, { 2UL, 0UL, 3UL, 1UL } );
4303
4304 const blaze::CompressedMatrix<int,blaze::rowMajor> mat{ { 0, 1, 0, 0 },
4305 { -2, 0, -3, 0 },
4306 { -2, 0, -3, 0 },
4307 { 0, 1, 0, 0 } };
4308
4309 cs *= mat;
4310
4311 checkRows ( cs , 4UL );
4312 checkColumns ( cs , 4UL );
4313 checkNonZeros( cs , 9UL );
4314 checkRows ( mat_, 4UL );
4315 checkColumns ( mat_, 5UL );
4316 checkNonZeros( mat_, 13UL );
4317
4318 if( cs(0,0) != 0 || cs(0,1) != -2 || cs(0,2) != 0 || cs(0,3) != 0 ||
4319 cs(1,0) != -8 || cs(1,1) != 1 || cs(1,2) != -12 || cs(1,3) != 0 ||
4320 cs(2,0) != -10 || cs(2,1) != -3 || cs(2,2) != -15 || cs(2,3) != 0 ||
4321 cs(3,0) != 12 || cs(3,1) != 0 || cs(3,2) != 18 || cs(3,3) != 0 ) {
4322 std::ostringstream oss;
4323 oss << " Test: " << test_ << "\n"
4324 << " Error: Multiplication assignment failed\n"
4325 << " Details:\n"
4326 << " Result:\n" << cs << "\n"
4327 << " Expected result:\n( 0 -2 0 0 )\n"
4328 "( -8 1 -12 0 )\n"
4329 "( -10 -3 -15 0 )\n"
4330 "( 12 0 18 0 )\n";
4331 throw std::runtime_error( oss.str() );
4332 }
4333
4334 if( mat_(0,0) != -2 || mat_(0,1) != 0 || mat_(0,2) != 0 || mat_(0,3) != 0 || mat_(0,4) != 7 ||
4335 mat_(1,0) != 1 || mat_(1,1) != 0 || mat_(1,2) != -8 || mat_(1,3) != -12 || mat_(1,4) != -8 ||
4336 mat_(2,0) != -3 || mat_(2,1) != 0 || mat_(2,2) != -10 || mat_(2,3) != -15 || mat_(2,4) != 9 ||
4337 mat_(3,0) != 0 || mat_(3,1) != 0 || mat_(3,2) != 12 || mat_(3,3) != 18 || mat_(3,4) != 10 ) {
4338 std::ostringstream oss;
4339 oss << " Test: " << test_ << "\n"
4340 << " Error: Multiplication assignment failed\n"
4341 << " Details:\n"
4342 << " Result:\n" << mat_ << "\n"
4343 << " Expected result:\n( -2 0 0 0 7 )\n"
4344 "( 1 0 -8 -12 -8 )\n"
4345 "( -3 0 -10 -15 9 )\n"
4346 "( 0 0 12 18 10 )\n";
4347 throw std::runtime_error( oss.str() );
4348 }
4349 }
4350
4351 {
4352 test_ = "Row-major/column-major sparse matrix multiplication assignment";
4353
4354 initialize();
4355
4356 auto cs = blaze::columns( mat_, { 2UL, 0UL, 3UL, 1UL } );
4357
4358 const blaze::CompressedMatrix<int,blaze::columnMajor> mat{ { 0, 1, 0, 0 },
4359 { -2, 0, -3, 0 },
4360 { -2, 0, -3, 0 },
4361 { 0, 1, 0, 0 } };
4362
4363 cs *= mat;
4364
4365 checkRows ( cs , 4UL );
4366 checkColumns ( cs , 4UL );
4367 checkNonZeros( cs , 9UL );
4368 checkRows ( mat_, 4UL );
4369 checkColumns ( mat_, 5UL );
4370 checkNonZeros( mat_, 13UL );
4371
4372 if( cs(0,0) != 0 || cs(0,1) != -2 || cs(0,2) != 0 || cs(0,3) != 0 ||
4373 cs(1,0) != -8 || cs(1,1) != 1 || cs(1,2) != -12 || cs(1,3) != 0 ||
4374 cs(2,0) != -10 || cs(2,1) != -3 || cs(2,2) != -15 || cs(2,3) != 0 ||
4375 cs(3,0) != 12 || cs(3,1) != 0 || cs(3,2) != 18 || cs(3,3) != 0 ) {
4376 std::ostringstream oss;
4377 oss << " Test: " << test_ << "\n"
4378 << " Error: Multiplication assignment failed\n"
4379 << " Details:\n"
4380 << " Result:\n" << cs << "\n"
4381 << " Expected result:\n( 0 -2 0 0 )\n"
4382 "( -8 1 -12 0 )\n"
4383 "( -10 -3 -15 0 )\n"
4384 "( 12 0 18 0 )\n";
4385 throw std::runtime_error( oss.str() );
4386 }
4387
4388 if( mat_(0,0) != -2 || mat_(0,1) != 0 || mat_(0,2) != 0 || mat_(0,3) != 0 || mat_(0,4) != 7 ||
4389 mat_(1,0) != 1 || mat_(1,1) != 0 || mat_(1,2) != -8 || mat_(1,3) != -12 || mat_(1,4) != -8 ||
4390 mat_(2,0) != -3 || mat_(2,1) != 0 || mat_(2,2) != -10 || mat_(2,3) != -15 || mat_(2,4) != 9 ||
4391 mat_(3,0) != 0 || mat_(3,1) != 0 || mat_(3,2) != 12 || mat_(3,3) != 18 || mat_(3,4) != 10 ) {
4392 std::ostringstream oss;
4393 oss << " Test: " << test_ << "\n"
4394 << " Error: Multiplication assignment failed\n"
4395 << " Details:\n"
4396 << " Result:\n" << mat_ << "\n"
4397 << " Expected result:\n( -2 0 0 0 7 )\n"
4398 "( 1 0 -8 -12 -8 )\n"
4399 "( -3 0 -10 -15 9 )\n"
4400 "( 0 0 12 18 10 )\n";
4401 throw std::runtime_error( oss.str() );
4402 }
4403 }
4404
4405
4406 //=====================================================================================
4407 // Column-major Columns multiplication assignment
4408 //=====================================================================================
4409
4410 {
4411 test_ = "Column-major Columns multiplication assignment (no aliasing)";
4412
4413 initialize();
4414
4415 OMT mat{ { 0, 0, -2, 0, 7 },
4416 { 0, 1, 0, 4, -8 },
4417 { 0, 0, -3, 5, 9 },
4418 { 0, 0, 0, -6, 10 } };
4419
4420 auto cs = blaze::columns( mat, { 2UL, 0UL, 3UL, 1UL } );
4421 cs *= blaze::columns( tmat_, { 1UL, 2UL, 2UL, 1UL } );
4422
4423 checkRows ( cs , 4UL );
4424 checkColumns ( cs , 4UL );
4425 checkNonZeros( cs , 8UL );
4426 checkRows ( mat, 4UL );
4427 checkColumns ( mat, 5UL );
4428 checkNonZeros( mat, 12UL );
4429
4430 if( cs(0,0) != 0 || cs(0,1) != 4 || cs(0,2) != 4 || cs(0,3) != 0 ||
4431 cs(1,0) != 0 || cs(1,1) != -12 || cs(1,2) != -12 || cs(1,3) != 0 ||
4432 cs(2,0) != 0 || cs(2,1) != -9 || cs(2,2) != -9 || cs(2,3) != 0 ||
4433 cs(3,0) != 0 || cs(3,1) != 18 || cs(3,2) != 18 || cs(3,3) != 0 ) {
4434 std::ostringstream oss;
4435 oss << " Test: " << test_ << "\n"
4436 << " Error: Multiplication assignment failed\n"
4437 << " Details:\n"
4438 << " Result:\n" << cs << "\n"
4439 << " Expected result:\n( 0 4 4 0 )\n"
4440 "( 0 -12 -12 0 )\n"
4441 "( 0 -9 -9 0 )\n"
4442 "( 0 18 18 0 )\n";
4443 throw std::runtime_error( oss.str() );
4444 }
4445
4446 if( mat(0,0) != 4 || mat(0,1) != 0 || mat(0,2) != 0 || mat(0,3) != 4 || mat(0,4) != 7 ||
4447 mat(1,0) != -12 || mat(1,1) != 0 || mat(1,2) != 0 || mat(1,3) != -12 || mat(1,4) != -8 ||
4448 mat(2,0) != -9 || mat(2,1) != 0 || mat(2,2) != 0 || mat(2,3) != -9 || mat(2,4) != 9 ||
4449 mat(3,0) != 18 || mat(3,1) != 0 || mat(3,2) != 0 || mat(3,3) != 18 || mat(3,4) != 10 ) {
4450 std::ostringstream oss;
4451 oss << " Test: " << test_ << "\n"
4452 << " Error: Multiplication assignment failed\n"
4453 << " Details:\n"
4454 << " Result:\n" << mat << "\n"
4455 << " Expected result:\n( 4 0 0 4 7 )\n"
4456 "( -12 0 0 -12 -8 )\n"
4457 "( -9 0 0 -9 9 )\n"
4458 "( 18 0 0 18 10 )\n";
4459 throw std::runtime_error( oss.str() );
4460 }
4461 }
4462
4463 {
4464 test_ = "Column-major Columns multiplication assignment (aliasing)";
4465
4466 initialize();
4467
4468 auto cs = blaze::columns( tmat_, { 2UL, 0UL, 3UL, 1UL } );
4469 cs *= blaze::columns( tmat_, { 1UL, 2UL, 2UL, 1UL } );
4470
4471 checkRows ( cs , 4UL );
4472 checkColumns ( cs , 4UL );
4473 checkNonZeros( cs , 8UL );
4474 checkRows ( tmat_, 4UL );
4475 checkColumns ( tmat_, 5UL );
4476 checkNonZeros( tmat_, 12UL );
4477
4478 if( cs(0,0) != 0 || cs(0,1) != 4 || cs(0,2) != 4 || cs(0,3) != 0 ||
4479 cs(1,0) != 0 || cs(1,1) != -12 || cs(1,2) != -12 || cs(1,3) != 0 ||
4480 cs(2,0) != 0 || cs(2,1) != -9 || cs(2,2) != -9 || cs(2,3) != 0 ||
4481 cs(3,0) != 0 || cs(3,1) != 18 || cs(3,2) != 18 || cs(3,3) != 0 ) {
4482 std::ostringstream oss;
4483 oss << " Test: " << test_ << "\n"
4484 << " Error: Multiplication assignment failed\n"
4485 << " Details:\n"
4486 << " Result:\n" << cs << "\n"
4487 << " Expected result:\n( 0 4 4 0 )\n"
4488 "( 0 -12 -12 0 )\n"
4489 "( 0 -9 -9 0 )\n"
4490 "( 0 18 18 0 )\n";
4491 throw std::runtime_error( oss.str() );
4492 }
4493
4494 if( tmat_(0,0) != 4 || tmat_(0,1) != 0 || tmat_(0,2) != 0 || tmat_(0,3) != 4 || tmat_(0,4) != 7 ||
4495 tmat_(1,0) != -12 || tmat_(1,1) != 0 || tmat_(1,2) != 0 || tmat_(1,3) != -12 || tmat_(1,4) != -8 ||
4496 tmat_(2,0) != -9 || tmat_(2,1) != 0 || tmat_(2,2) != 0 || tmat_(2,3) != -9 || tmat_(2,4) != 9 ||
4497 tmat_(3,0) != 18 || tmat_(3,1) != 0 || tmat_(3,2) != 0 || tmat_(3,3) != 18 || tmat_(3,4) != 10 ) {
4498 std::ostringstream oss;
4499 oss << " Test: " << test_ << "\n"
4500 << " Error: Multiplication assignment failed\n"
4501 << " Details:\n"
4502 << " Result:\n" << tmat_ << "\n"
4503 << " Expected result:\n( 4 0 0 4 7 )\n"
4504 "( -12 0 0 -12 -8 )\n"
4505 "( -9 0 0 -9 9 )\n"
4506 "( 18 0 0 18 10 )\n";
4507 throw std::runtime_error( oss.str() );
4508 }
4509 }
4510
4511
4512 //=====================================================================================
4513 // Column-major dense matrix multiplication assignment
4514 //=====================================================================================
4515
4516 {
4517 test_ = "Column-major/row-major dense matrix multiplication assignment";
4518
4519 initialize();
4520
4521 auto cs = blaze::columns( tmat_, { 2UL, 0UL, 3UL, 1UL } );
4522
4523 const blaze::DynamicMatrix<int,blaze::rowMajor> mat{ { 0, 1, 0, 0 },
4524 { -2, 0, -3, 0 },
4525 { -2, 0, -3, 0 },
4526 { 0, 1, 0, 0 } };
4527
4528 cs *= mat;
4529
4530 checkRows ( cs , 4UL );
4531 checkColumns ( cs , 4UL );
4532 checkNonZeros( cs , 9UL );
4533 checkRows ( tmat_, 4UL );
4534 checkColumns ( tmat_, 5UL );
4535 checkNonZeros( tmat_, 13UL );
4536
4537 if( cs(0,0) != 0 || cs(0,1) != -2 || cs(0,2) != 0 || cs(0,3) != 0 ||
4538 cs(1,0) != -8 || cs(1,1) != 1 || cs(1,2) != -12 || cs(1,3) != 0 ||
4539 cs(2,0) != -10 || cs(2,1) != -3 || cs(2,2) != -15 || cs(2,3) != 0 ||
4540 cs(3,0) != 12 || cs(3,1) != 0 || cs(3,2) != 18 || cs(3,3) != 0 ) {
4541 std::ostringstream oss;
4542 oss << " Test: " << test_ << "\n"
4543 << " Error: Multiplication assignment failed\n"
4544 << " Details:\n"
4545 << " Result:\n" << cs << "\n"
4546 << " Expected result:\n( 0 -2 0 0 )\n"
4547 "( -8 1 -12 0 )\n"
4548 "( -10 -3 -15 0 )\n"
4549 "( 12 0 18 0 )\n";
4550 throw std::runtime_error( oss.str() );
4551 }
4552
4553 if( tmat_(0,0) != -2 || tmat_(0,1) != 0 || tmat_(0,2) != 0 || tmat_(0,3) != 0 || tmat_(0,4) != 7 ||
4554 tmat_(1,0) != 1 || tmat_(1,1) != 0 || tmat_(1,2) != -8 || tmat_(1,3) != -12 || tmat_(1,4) != -8 ||
4555 tmat_(2,0) != -3 || tmat_(2,1) != 0 || tmat_(2,2) != -10 || tmat_(2,3) != -15 || tmat_(2,4) != 9 ||
4556 tmat_(3,0) != 0 || tmat_(3,1) != 0 || tmat_(3,2) != 12 || tmat_(3,3) != 18 || tmat_(3,4) != 10 ) {
4557 std::ostringstream oss;
4558 oss << " Test: " << test_ << "\n"
4559 << " Error: Multiplication assignment failed\n"
4560 << " Details:\n"
4561 << " Result:\n" << tmat_ << "\n"
4562 << " Expected result:\n( -2 0 0 0 7 )\n"
4563 "( 1 0 -8 -12 -8 )\n"
4564 "( -3 0 -10 -15 9 )\n"
4565 "( 0 0 12 18 10 )\n";
4566 throw std::runtime_error( oss.str() );
4567 }
4568 }
4569
4570 {
4571 test_ = "Column-major/column-major dense matrix multiplication assignment";
4572
4573 initialize();
4574
4575 auto cs = blaze::columns( tmat_, { 2UL, 0UL, 3UL, 1UL } );
4576
4577 const blaze::DynamicMatrix<int,blaze::columnMajor> mat{ { 0, 1, 0, 0 },
4578 { -2, 0, -3, 0 },
4579 { -2, 0, -3, 0 },
4580 { 0, 1, 0, 0 } };
4581
4582 cs *= mat;
4583
4584 checkRows ( cs , 4UL );
4585 checkColumns ( cs , 4UL );
4586 checkNonZeros( cs , 9UL );
4587 checkRows ( tmat_, 4UL );
4588 checkColumns ( tmat_, 5UL );
4589 checkNonZeros( tmat_, 13UL );
4590
4591 if( cs(0,0) != 0 || cs(0,1) != -2 || cs(0,2) != 0 || cs(0,3) != 0 ||
4592 cs(1,0) != -8 || cs(1,1) != 1 || cs(1,2) != -12 || cs(1,3) != 0 ||
4593 cs(2,0) != -10 || cs(2,1) != -3 || cs(2,2) != -15 || cs(2,3) != 0 ||
4594 cs(3,0) != 12 || cs(3,1) != 0 || cs(3,2) != 18 || cs(3,3) != 0 ) {
4595 std::ostringstream oss;
4596 oss << " Test: " << test_ << "\n"
4597 << " Error: Multiplication assignment failed\n"
4598 << " Details:\n"
4599 << " Result:\n" << cs << "\n"
4600 << " Expected result:\n( 0 -2 0 0 )\n"
4601 "( -8 1 -12 0 )\n"
4602 "( -10 -3 -15 0 )\n"
4603 "( 12 0 18 0 )\n";
4604 throw std::runtime_error( oss.str() );
4605 }
4606
4607 if( tmat_(0,0) != -2 || tmat_(0,1) != 0 || tmat_(0,2) != 0 || tmat_(0,3) != 0 || tmat_(0,4) != 7 ||
4608 tmat_(1,0) != 1 || tmat_(1,1) != 0 || tmat_(1,2) != -8 || tmat_(1,3) != -12 || tmat_(1,4) != -8 ||
4609 tmat_(2,0) != -3 || tmat_(2,1) != 0 || tmat_(2,2) != -10 || tmat_(2,3) != -15 || tmat_(2,4) != 9 ||
4610 tmat_(3,0) != 0 || tmat_(3,1) != 0 || tmat_(3,2) != 12 || tmat_(3,3) != 18 || tmat_(3,4) != 10 ) {
4611 std::ostringstream oss;
4612 oss << " Test: " << test_ << "\n"
4613 << " Error: Multiplication assignment failed\n"
4614 << " Details:\n"
4615 << " Result:\n" << tmat_ << "\n"
4616 << " Expected result:\n( -2 0 0 0 7 )\n"
4617 "( 1 0 -8 -12 -8 )\n"
4618 "( -3 0 -10 -15 9 )\n"
4619 "( 0 0 12 18 10 )\n";
4620 throw std::runtime_error( oss.str() );
4621 }
4622 }
4623
4624
4625 //=====================================================================================
4626 // Column-major sparse matrix multiplication assignment
4627 //=====================================================================================
4628
4629 {
4630 test_ = "Column-major/row-major sparse matrix multiplication assignment";
4631
4632 initialize();
4633
4634 auto cs = blaze::columns( tmat_, { 2UL, 0UL, 3UL, 1UL } );
4635
4636 const blaze::CompressedMatrix<int,blaze::rowMajor> mat{ { 0, 1, 0, 0 },
4637 { -2, 0, -3, 0 },
4638 { -2, 0, -3, 0 },
4639 { 0, 1, 0, 0 } };
4640
4641 cs *= mat;
4642
4643 checkRows ( cs , 4UL );
4644 checkColumns ( cs , 4UL );
4645 checkNonZeros( cs , 9UL );
4646 checkRows ( tmat_, 4UL );
4647 checkColumns ( tmat_, 5UL );
4648 checkNonZeros( tmat_, 13UL );
4649
4650 if( cs(0,0) != 0 || cs(0,1) != -2 || cs(0,2) != 0 || cs(0,3) != 0 ||
4651 cs(1,0) != -8 || cs(1,1) != 1 || cs(1,2) != -12 || cs(1,3) != 0 ||
4652 cs(2,0) != -10 || cs(2,1) != -3 || cs(2,2) != -15 || cs(2,3) != 0 ||
4653 cs(3,0) != 12 || cs(3,1) != 0 || cs(3,2) != 18 || cs(3,3) != 0 ) {
4654 std::ostringstream oss;
4655 oss << " Test: " << test_ << "\n"
4656 << " Error: Multiplication assignment failed\n"
4657 << " Details:\n"
4658 << " Result:\n" << cs << "\n"
4659 << " Expected result:\n( 0 -2 0 0 )\n"
4660 "( -8 1 -12 0 )\n"
4661 "( -10 -3 -15 0 )\n"
4662 "( 12 0 18 0 )\n";
4663 throw std::runtime_error( oss.str() );
4664 }
4665
4666 if( tmat_(0,0) != -2 || tmat_(0,1) != 0 || tmat_(0,2) != 0 || tmat_(0,3) != 0 || tmat_(0,4) != 7 ||
4667 tmat_(1,0) != 1 || tmat_(1,1) != 0 || tmat_(1,2) != -8 || tmat_(1,3) != -12 || tmat_(1,4) != -8 ||
4668 tmat_(2,0) != -3 || tmat_(2,1) != 0 || tmat_(2,2) != -10 || tmat_(2,3) != -15 || tmat_(2,4) != 9 ||
4669 tmat_(3,0) != 0 || tmat_(3,1) != 0 || tmat_(3,2) != 12 || tmat_(3,3) != 18 || tmat_(3,4) != 10 ) {
4670 std::ostringstream oss;
4671 oss << " Test: " << test_ << "\n"
4672 << " Error: Multiplication assignment failed\n"
4673 << " Details:\n"
4674 << " Result:\n" << tmat_ << "\n"
4675 << " Expected result:\n( -2 0 0 0 7 )\n"
4676 "( 1 0 -8 -12 -8 )\n"
4677 "( -3 0 -10 -15 9 )\n"
4678 "( 0 0 12 18 10 )\n";
4679 throw std::runtime_error( oss.str() );
4680 }
4681 }
4682
4683 {
4684 test_ = "Column-major/column-major sparse matrix multiplication assignment";
4685
4686 initialize();
4687
4688 auto cs = blaze::columns( tmat_, { 2UL, 0UL, 3UL, 1UL } );
4689
4690 const blaze::CompressedMatrix<int,blaze::columnMajor> mat{ { 0, 1, 0, 0 },
4691 { -2, 0, -3, 0 },
4692 { -2, 0, -3, 0 },
4693 { 0, 1, 0, 0 } };
4694
4695 cs *= mat;
4696
4697 checkRows ( cs , 4UL );
4698 checkColumns ( cs , 4UL );
4699 checkNonZeros( cs , 9UL );
4700 checkRows ( tmat_, 4UL );
4701 checkColumns ( tmat_, 5UL );
4702 checkNonZeros( tmat_, 13UL );
4703
4704 if( cs(0,0) != 0 || cs(0,1) != -2 || cs(0,2) != 0 || cs(0,3) != 0 ||
4705 cs(1,0) != -8 || cs(1,1) != 1 || cs(1,2) != -12 || cs(1,3) != 0 ||
4706 cs(2,0) != -10 || cs(2,1) != -3 || cs(2,2) != -15 || cs(2,3) != 0 ||
4707 cs(3,0) != 12 || cs(3,1) != 0 || cs(3,2) != 18 || cs(3,3) != 0 ) {
4708 std::ostringstream oss;
4709 oss << " Test: " << test_ << "\n"
4710 << " Error: Multiplication assignment failed\n"
4711 << " Details:\n"
4712 << " Result:\n" << cs << "\n"
4713 << " Expected result:\n( 0 -2 0 0 )\n"
4714 "( -8 1 -12 0 )\n"
4715 "( -10 -3 -15 0 )\n"
4716 "( 12 0 18 0 )\n";
4717 throw std::runtime_error( oss.str() );
4718 }
4719
4720 if( tmat_(0,0) != -2 || tmat_(0,1) != 0 || tmat_(0,2) != 0 || tmat_(0,3) != 0 || tmat_(0,4) != 7 ||
4721 tmat_(1,0) != 1 || tmat_(1,1) != 0 || tmat_(1,2) != -8 || tmat_(1,3) != -12 || tmat_(1,4) != -8 ||
4722 tmat_(2,0) != -3 || tmat_(2,1) != 0 || tmat_(2,2) != -10 || tmat_(2,3) != -15 || tmat_(2,4) != 9 ||
4723 tmat_(3,0) != 0 || tmat_(3,1) != 0 || tmat_(3,2) != 12 || tmat_(3,3) != 18 || tmat_(3,4) != 10 ) {
4724 std::ostringstream oss;
4725 oss << " Test: " << test_ << "\n"
4726 << " Error: Multiplication assignment failed\n"
4727 << " Details:\n"
4728 << " Result:\n" << tmat_ << "\n"
4729 << " Expected result:\n( -2 0 0 0 7 )\n"
4730 "( 1 0 -8 -12 -8 )\n"
4731 "( -3 0 -10 -15 9 )\n"
4732 "( 0 0 12 18 10 )\n";
4733 throw std::runtime_error( oss.str() );
4734 }
4735 }
4736 }
4737 //*************************************************************************************************
4738
4739
4740
4741
4742 //=================================================================================================
4743 //
4744 // UTILITY FUNCTIONS
4745 //
4746 //=================================================================================================
4747
4748 //*************************************************************************************************
4749 /*!\brief Initialization of all member matrices.
4750 //
4751 // \return void
4752 // \exception std::runtime_error Error detected.
4753 //
4754 // This function initializes all member matrices to specific predetermined values.
4755 */
initialize()4756 void SparseGeneralTest::initialize()
4757 {
4758 // Initializing the row-major compressed matrix
4759 mat_.reset();
4760 mat_(1,1) = 1;
4761 mat_(0,2) = -2;
4762 mat_(2,2) = -3;
4763 mat_(1,3) = 4;
4764 mat_(2,3) = 5;
4765 mat_(3,3) = -6;
4766 mat_(0,4) = 7;
4767 mat_(1,4) = -8;
4768 mat_(2,4) = 9;
4769 mat_(3,4) = 10;
4770
4771 // Initializing the column-major compressed matrix
4772 tmat_.reset();
4773 tmat_(1,1) = 1;
4774 tmat_(0,2) = -2;
4775 tmat_(2,2) = -3;
4776 tmat_(1,3) = 4;
4777 tmat_(2,3) = 5;
4778 tmat_(3,3) = -6;
4779 tmat_(0,4) = 7;
4780 tmat_(1,4) = -8;
4781 tmat_(2,4) = 9;
4782 tmat_(3,4) = 10;
4783 }
4784 //*************************************************************************************************
4785
4786 } // namespace columns
4787
4788 } // namespace views
4789
4790 } // namespace mathtest
4791
4792 } // namespace blazetest
4793
4794
4795
4796
4797 //=================================================================================================
4798 //
4799 // MAIN FUNCTION
4800 //
4801 //=================================================================================================
4802
4803 //*************************************************************************************************
main()4804 int main()
4805 {
4806 std::cout << " Running Columns sparse general test (part 1)..." << std::endl;
4807
4808 try
4809 {
4810 RUN_COLUMNS_SPARSEGENERAL_TEST;
4811 }
4812 catch( std::exception& ex ) {
4813 std::cerr << "\n\n ERROR DETECTED during Columns sparse general test (part 1):\n"
4814 << ex.what() << "\n";
4815 return EXIT_FAILURE;
4816 }
4817
4818 return EXIT_SUCCESS;
4819 }
4820 //*************************************************************************************************
4821