1 //=================================================================================================
2 /*!
3 //  \file blazetest/mathtest/adaptors/strictlyuppermatrix/ColumnTest.h
4 //  \brief Header file for the StrictlyUpperMatrix column test
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 #ifndef _BLAZETEST_MATHTEST_ADAPTORS_STRICTLYUPPERMATRIX_COLUMNTEST_H_
36 #define _BLAZETEST_MATHTEST_ADAPTORS_STRICTLYUPPERMATRIX_COLUMNTEST_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <sstream>
44 #include <stdexcept>
45 #include <string>
46 #include <blaze/math/CompressedMatrix.h>
47 #include <blaze/math/CompressedVector.h>
48 #include <blaze/math/Column.h>
49 #include <blaze/math/DynamicMatrix.h>
50 #include <blaze/math/DynamicVector.h>
51 #include <blaze/math/StrictlyUpperMatrix.h>
52 #include <blaze/math/typetraits/IsRowMajorMatrix.h>
53 #include <blazetest/system/Types.h>
54 
55 
56 namespace blazetest {
57 
58 namespace mathtest {
59 
60 namespace adaptors {
61 
62 namespace strictlyuppermatrix {
63 
64 //=================================================================================================
65 //
66 //  CLASS DEFINITION
67 //
68 //=================================================================================================
69 
70 //*************************************************************************************************
71 /*!\brief Auxiliary class for assignment tests to a single column of a StrictlyUpperMatrix.
72 //
73 // This class performs assignment tests to a single column of a StrictlyUpperMatrix. It performs a
74 // series of both compile time as well as runtime tests.
75 */
76 class ColumnTest
77 {
78  private:
79    //**Type definitions****************************************************************************
80    //! Type of the dense strictly upper triangular matrix.
81    using DUT = blaze::StrictlyUpperMatrix< blaze::DynamicMatrix<int,blaze::rowMajor> >;
82 
83    //! Opposite dense strictly upper triangular matrix type.
84    using DOUT = DUT::OppositeType;
85 
86    //! Type of the sparse strictly upper triangular matrix.
87    using SUT = blaze::StrictlyUpperMatrix< blaze::CompressedMatrix<int,blaze::rowMajor> >;
88 
89    //! Opposite sparse strictly upper triangular matrix type.
90    using SOUT = SUT::OppositeType;
91    //**********************************************************************************************
92 
93  public:
94    //**Constructors********************************************************************************
95    /*!\name Constructors */
96    //@{
97    explicit ColumnTest();
98    // No explicitly declared copy constructor.
99    //@}
100    //**********************************************************************************************
101 
102    //**Destructor**********************************************************************************
103    // No explicitly declared destructor.
104    //**********************************************************************************************
105 
106  private:
107    //**Test functions******************************************************************************
108    /*!\name Test functions */
109    //@{
110    template< typename UT > void testAssignment();
111    template< typename UT > void testAddAssign ();
112    template< typename UT > void testSubAssign ();
113    template< typename UT > void testMultAssign();
114 
115    template< typename Type >
116    void checkRows( const Type& matrix, size_t expectedRows ) const;
117 
118    template< typename Type >
119    void checkColumns( const Type& matrix, size_t expectedColumns ) const;
120 
121    template< typename Type >
122    void checkNonZeros( const Type& matrix, size_t expectedNonZeros ) const;
123    //@}
124    //**********************************************************************************************
125 
126    //**Utility functions***************************************************************************
127    /*!\name Utility functions */
128    //@{
129    template< typename UT > void init( UT& upper );
130    //@}
131    //**********************************************************************************************
132 
133    //**Member variables****************************************************************************
134    /*!\name Member variables */
135    //@{
136    std::string test_;  //!< Label of the currently performed test.
137    //@}
138    //**********************************************************************************************
139 };
140 //*************************************************************************************************
141 
142 
143 
144 
145 //=================================================================================================
146 //
147 //  TEST FUNCTIONS
148 //
149 //=================================================================================================
150 
151 //*************************************************************************************************
152 /*!\brief Test of the assignment to columns of a StrictlyUpperMatrix.
153 //
154 // \return void
155 // \exception std::runtime_error Error detected.
156 //
157 // This function performs a test of the assignment to a single column of a StrictlyUpperMatrix. In
158 // case an error is detected, a \a std::runtime_error exception is thrown.
159 */
160 template< typename UT >  // Type of the strictly upper matrix
testAssignment()161 void ColumnTest::testAssignment()
162 {
163    //=====================================================================================
164    // Dense vector assignment
165    //=====================================================================================
166 
167    // ( 0 -4  7 )      ( 0 -2  7 )
168    // ( 0  0  0 )  =>  ( 0  0  0 )
169    // ( 0  0  0 )      ( 0  0  0 )
170    {
171       test_ = "Dense vector assignment test 1";
172 
173       blaze::DynamicVector<int,blaze::columnVector> vec( 3UL, 0 );
174       vec[0] = -2;
175 
176       UT upper;
177       init( upper );
178 
179       auto col1 = column( upper, 1UL );
180       col1 = vec;
181 
182       checkRows    ( upper, 3UL );
183       checkColumns ( upper, 3UL );
184       checkNonZeros( upper, 2UL );
185 
186       if( col1[0] != -2 || col1[1] != 0 || col1[2] != 0 ) {
187          std::ostringstream oss;
188          oss << " Test: " << test_ << "\n"
189              << " Error: Assignment to column failed\n"
190              << " Details:\n"
191              << "   Result:\n" << col1 << "\n"
192              << "   Expected result:\n( -2 0 0 )\n";
193          throw std::runtime_error( oss.str() );
194       }
195 
196       if( upper(0,0) != 0 || upper(0,1) != -2 || upper(0,2) != 7 ||
197           upper(1,0) != 0 || upper(1,1) !=  0 || upper(1,2) != 0 ||
198           upper(2,0) != 0 || upper(2,1) !=  0 || upper(2,2) != 0 ) {
199          std::ostringstream oss;
200          oss << " Test: " << test_ << "\n"
201              << " Error: Assignment to column failed\n"
202              << " Details:\n"
203              << "   Result:\n" << upper << "\n"
204              << "   Expected result:\n( 0 -2  7 )\n( 0  0  0 )\n( 0  0  0 )\n";
205          throw std::runtime_error( oss.str() );
206       }
207    }
208 
209    // ( 0 -4  7 )      ( 0 -2  7 )
210    // ( 0  0  0 )  =>  ( 0  1  0 )
211    // ( 0  0  0 )      ( 0  0  0 )
212    {
213       test_ = "Dense vector assignment test 2";
214 
215       blaze::DynamicVector<int,blaze::columnVector> vec( 3UL, 0 );
216       vec[0] = -2;
217       vec[1] =  1;
218 
219       UT upper;
220       init( upper );
221 
222       auto col1 = column( upper, 1UL );
223 
224       try {
225          col1 = vec;
226 
227          std::ostringstream oss;
228          oss << " Test: " << test_ << "\n"
229              << " Error: Assignment of invalid vector succeeded\n"
230              << " Details:\n"
231              << "   Result:\n" << upper << "\n";
232          throw std::runtime_error( oss.str() );
233       }
234       catch( std::invalid_argument& ) {}
235    }
236 
237    // ( 0 -4  7 )      ( 0 -2  7 )
238    // ( 0  0  0 )  =>  ( 0  0  0 )
239    // ( 0  0  0 )      ( 0  9  0 )
240    {
241       test_ = "Dense vector assignment test 3";
242 
243       blaze::DynamicVector<int,blaze::columnVector> vec( 3UL, 0 );
244       vec[0] = -2;
245       vec[2] =  9;
246 
247       UT upper;
248       init( upper );
249 
250       auto col1 = column( upper, 1UL );
251 
252       try {
253          col1 = vec;
254 
255          std::ostringstream oss;
256          oss << " Test: " << test_ << "\n"
257              << " Error: Assignment of invalid vector succeeded\n"
258              << " Details:\n"
259              << "   Result:\n" << upper << "\n";
260          throw std::runtime_error( oss.str() );
261       }
262       catch( std::invalid_argument& ) {}
263    }
264 
265 
266    //=====================================================================================
267    // Sparse vector assignment
268    //=====================================================================================
269 
270    // ( 0 -4  7 )      ( 0 -2  7 )
271    // ( 0  0  0 )  =>  ( 0  0  0 )
272    // ( 0  0  0 )      ( 0  0  0 )
273    {
274       test_ = "Sparse vector assignment test 1";
275 
276       blaze::CompressedVector<int,blaze::columnVector> vec( 3UL, 2UL );
277       vec[0] = -2;
278       vec.insert( 2UL, 0 );
279 
280       UT upper;
281       init( upper );
282 
283       auto col1 = column( upper, 1UL );
284       col1 = vec;
285 
286       checkRows    ( upper, 3UL );
287       checkColumns ( upper, 3UL );
288       checkNonZeros( upper, 2UL );
289 
290       if( col1[0] != -2 || col1[1] != 0 || col1[2] != 0 ) {
291          std::ostringstream oss;
292          oss << " Test: " << test_ << "\n"
293              << " Error: Assignment to column failed\n"
294              << " Details:\n"
295              << "   Result:\n" << col1 << "\n"
296              << "   Expected result:\n( -2 0 0 )\n";
297          throw std::runtime_error( oss.str() );
298       }
299 
300       if( upper(0,0) != 0 || upper(0,1) != -2 || upper(0,2) != 7 ||
301           upper(1,0) != 0 || upper(1,1) !=  0 || upper(1,2) != 0 ||
302           upper(2,0) != 0 || upper(2,1) !=  0 || upper(2,2) != 0 ) {
303          std::ostringstream oss;
304          oss << " Test: " << test_ << "\n"
305              << " Error: Assignment to column failed\n"
306              << " Details:\n"
307              << "   Result:\n" << upper << "\n"
308              << "   Expected result:\n( 0 -2  7 )\n( 0  0  0 )\n( 0  0  0 )\n";
309          throw std::runtime_error( oss.str() );
310       }
311    }
312 
313    // ( 0 -4  7 )      ( 0 -2  7 )
314    // ( 0  0  0 )  =>  ( 0  1  0 )
315    // ( 0  0  0 )      ( 0  0  0 )
316    {
317       test_ = "Sparse vector assignment test 2";
318 
319       blaze::CompressedVector<int,blaze::columnVector> vec( 3UL, 2UL );
320       vec[0] = -2;
321       vec[1] =  1;
322 
323       UT upper;
324       init( upper );
325 
326       auto col1 = column( upper, 1UL );
327 
328       try {
329          col1 = vec;
330 
331          std::ostringstream oss;
332          oss << " Test: " << test_ << "\n"
333              << " Error: Assignment of invalid vector succeeded\n"
334              << " Details:\n"
335              << "   Result:\n" << upper << "\n";
336          throw std::runtime_error( oss.str() );
337       }
338       catch( std::invalid_argument& ) {}
339    }
340 
341    // ( 0 -4  7 )      ( 0 -2  7 )
342    // ( 0  0  0 )  =>  ( 0  0  0 )
343    // ( 0  0  0 )      ( 0  9  0 )
344    {
345       test_ = "Sparse vector assignment test 3";
346 
347       blaze::CompressedVector<int,blaze::columnVector> vec( 3UL, 2UL );
348       vec[0] = -2;
349       vec[2] =  9;
350 
351       UT upper;
352       init( upper );
353 
354       auto col1 = column( upper, 1UL );
355 
356       try {
357          col1 = vec;
358 
359          std::ostringstream oss;
360          oss << " Test: " << test_ << "\n"
361              << " Error: Assignment of invalid vector succeeded\n"
362              << " Details:\n"
363              << "   Result:\n" << upper << "\n";
364          throw std::runtime_error( oss.str() );
365       }
366       catch( std::invalid_argument& ) {}
367    }
368 }
369 //*************************************************************************************************
370 
371 
372 //*************************************************************************************************
373 /*!\brief Test of the addition assignment to columns of a StrictlyUpperMatrix.
374 //
375 // \return void
376 // \exception std::runtime_error Error detected.
377 //
378 // This function performs a test of the addition assignment to a single column of a StrictlyUpperMatrix.
379 // In case an error is detected, a \a std::runtime_error exception is thrown.
380 */
381 template< typename UT >  // Type of the strictly upper matrix
testAddAssign()382 void ColumnTest::testAddAssign()
383 {
384    //=====================================================================================
385    // Dense vector addition assignment
386    //=====================================================================================
387 
388    // ( 0 -4  7 )      ( 0 -6  7 )
389    // ( 0  0  0 )  =>  ( 0  0  0 )
390    // ( 0  0  0 )      ( 0  0  0 )
391    {
392       test_ = "Dense vector addition assignment test 1";
393 
394       blaze::DynamicVector<int,blaze::columnVector> vec( 3UL, 0 );
395       vec[0] = -2;
396 
397       UT upper;
398       init( upper );
399 
400       auto col1 = column( upper, 1UL );
401       col1 += vec;
402 
403       checkRows    ( upper, 3UL );
404       checkColumns ( upper, 3UL );
405       checkNonZeros( upper, 2UL );
406 
407       if( col1[0] != -6 || col1[1] != 0 || col1[2] != 0 ) {
408          std::ostringstream oss;
409          oss << " Test: " << test_ << "\n"
410              << " Error: Assignment to column failed\n"
411              << " Details:\n"
412              << "   Result:\n" << col1 << "\n"
413              << "   Expected result:\n( -6 0 0 )\n";
414          throw std::runtime_error( oss.str() );
415       }
416 
417       if( upper(0,0) != 0 || upper(0,1) != -6 || upper(0,2) != 7 ||
418           upper(1,0) != 0 || upper(1,1) !=  0 || upper(1,2) != 0 ||
419           upper(2,0) != 0 || upper(2,1) !=  0 || upper(2,2) != 0 ) {
420          std::ostringstream oss;
421          oss << " Test: " << test_ << "\n"
422              << " Error: Assignment to column failed\n"
423              << " Details:\n"
424              << "   Result:\n" << upper << "\n"
425              << "   Expected result:\n( 0 -6  7 )\n( 0  0  0 )\n( 0  0  0 )\n";
426          throw std::runtime_error( oss.str() );
427       }
428    }
429 
430    // ( 0 -4  7 )      ( 0 -6  7 )
431    // ( 0  0  0 )  =>  ( 0  1  0 )
432    // ( 0  0  0 )      ( 0  0  0 )
433    {
434       test_ = "Dense vector addition assignment test 2";
435 
436       blaze::DynamicVector<int,blaze::columnVector> vec( 3UL, 0 );
437       vec[0] = -2;
438       vec[1] =  1;
439 
440       UT upper;
441       init( upper );
442 
443       auto col1 = column( upper, 1UL );
444 
445       try {
446          col1 += vec;
447 
448          std::ostringstream oss;
449          oss << " Test: " << test_ << "\n"
450              << " Error: Assignment of invalid vector succeeded\n"
451              << " Details:\n"
452              << "   Result:\n" << upper << "\n";
453          throw std::runtime_error( oss.str() );
454       }
455       catch( std::invalid_argument& ) {}
456    }
457 
458    // ( 0 -4  7 )      ( 0 -6  7 )
459    // ( 0  0  0 )  =>  ( 0  0  0 )
460    // ( 0  0  0 )      ( 0  9  0 )
461    {
462       test_ = "Dense vector addition assignment test 3";
463 
464       blaze::DynamicVector<int,blaze::columnVector> vec( 3UL, 0 );
465       vec[0] = -2;
466       vec[2] =  9;
467 
468       UT upper;
469       init( upper );
470 
471       auto col1 = column( upper, 1UL );
472 
473       try {
474          col1 += vec;
475 
476          std::ostringstream oss;
477          oss << " Test: " << test_ << "\n"
478              << " Error: Assignment of invalid vector succeeded\n"
479              << " Details:\n"
480              << "   Result:\n" << upper << "\n";
481          throw std::runtime_error( oss.str() );
482       }
483       catch( std::invalid_argument& ) {}
484    }
485 
486 
487    //=====================================================================================
488    // Sparse vector addition assignment
489    //=====================================================================================
490 
491    // ( 0 -4  7 )      ( 0 -6  7 )
492    // ( 0  0  0 )  =>  ( 0  0  0 )
493    // ( 0  0  0 )      ( 0  0  0 )
494    {
495       test_ = "Sparse vector addition assignment test 1";
496 
497       blaze::CompressedVector<int,blaze::columnVector> vec( 3UL, 2UL );
498       vec[0] = -2;
499       vec.insert( 2UL, 0 );
500 
501       UT upper;
502       init( upper );
503 
504       auto col1 = column( upper, 1UL );
505       col1 += vec;
506 
507       checkRows    ( upper, 3UL );
508       checkColumns ( upper, 3UL );
509       checkNonZeros( upper, 2UL );
510 
511       if( col1[0] != -6 || col1[1] != 0 || col1[2] != 0 ) {
512          std::ostringstream oss;
513          oss << " Test: " << test_ << "\n"
514              << " Error: Assignment to column failed\n"
515              << " Details:\n"
516              << "   Result:\n" << col1 << "\n"
517              << "   Expected result:\n( -6 0 0 )\n";
518          throw std::runtime_error( oss.str() );
519       }
520 
521       if( upper(0,0) != 0 || upper(0,1) != -6 || upper(0,2) != 7 ||
522           upper(1,0) != 0 || upper(1,1) !=  0 || upper(1,2) != 0 ||
523           upper(2,0) != 0 || upper(2,1) !=  0 || upper(2,2) != 0 ) {
524          std::ostringstream oss;
525          oss << " Test: " << test_ << "\n"
526              << " Error: Assignment to column failed\n"
527              << " Details:\n"
528              << "   Result:\n" << upper << "\n"
529              << "   Expected result:\n( 0 -6  7 )\n( 0  0  0 )\n( 0  0  0 )\n";
530          throw std::runtime_error( oss.str() );
531       }
532    }
533 
534    // ( 0 -4  7 )      ( 0 -6  7 )
535    // ( 0  0  0 )  =>  ( 0  1  0 )
536    // ( 0  0  0 )      ( 0  0  0 )
537    {
538       test_ = "Sparse vector addition assignment test 2";
539 
540       blaze::CompressedVector<int,blaze::columnVector> vec( 3UL, 2UL );
541       vec[0] = -2;
542       vec[1] =  1;
543 
544       UT upper;
545       init( upper );
546 
547       auto col1 = column( upper, 1UL );
548 
549       try {
550          col1 += vec;
551 
552          std::ostringstream oss;
553          oss << " Test: " << test_ << "\n"
554              << " Error: Assignment of invalid vector succeeded\n"
555              << " Details:\n"
556              << "   Result:\n" << upper << "\n";
557          throw std::runtime_error( oss.str() );
558       }
559       catch( std::invalid_argument& ) {}
560    }
561 
562    // ( 0 -4  7 )      ( 0 -6  7 )
563    // ( 0  0  0 )  =>  ( 0  0  0 )
564    // ( 0  0  0 )      ( 0  9  0 )
565    {
566       test_ = "Sparse vector addition assignment test 3";
567 
568       blaze::CompressedVector<int,blaze::columnVector> vec( 3UL, 2UL );
569       vec[0] = -2;
570       vec[2] =  9;
571 
572       UT upper;
573       init( upper );
574 
575       auto col1 = column( upper, 1UL );
576 
577       try {
578          col1 += vec;
579 
580          std::ostringstream oss;
581          oss << " Test: " << test_ << "\n"
582              << " Error: Assignment of invalid vector succeeded\n"
583              << " Details:\n"
584              << "   Result:\n" << upper << "\n";
585          throw std::runtime_error( oss.str() );
586       }
587       catch( std::invalid_argument& ) {}
588    }
589 }
590 //*************************************************************************************************
591 
592 
593 //*************************************************************************************************
594 /*!\brief Test of the subtraction assignment to columns of a StrictlyUpperMatrix.
595 //
596 // \return void
597 // \exception std::runtime_error Error detected.
598 //
599 // This function performs a test of the subtraction assignment to a single column of a
600 // StrictlyUpperMatrix. In case an error is detected, a \a std::runtime_error exception is thrown.
601 */
602 template< typename UT >  // Type of the strictly upper matrix
testSubAssign()603 void ColumnTest::testSubAssign()
604 {
605    //=====================================================================================
606    // Dense vector subtraction assignment
607    //=====================================================================================
608 
609    // ( 0 -4  7 )      ( 0 -2  7 )
610    // ( 0  0  0 )  =>  ( 0  0  0 )
611    // ( 0  0  0 )      ( 0  0  0 )
612    {
613       test_ = "Dense vector subtraction assignment test 1";
614 
615       blaze::DynamicVector<int,blaze::columnVector> vec( 3UL, 0 );
616       vec[0] = -2;
617 
618       UT upper;
619       init( upper );
620 
621       auto col1 = column( upper, 1UL );
622       col1 -= vec;
623 
624       checkRows    ( upper, 3UL );
625       checkColumns ( upper, 3UL );
626       checkNonZeros( upper, 2UL );
627 
628       if( col1[0] != -2 || col1[1] != 0 || col1[2] != 0 ) {
629          std::ostringstream oss;
630          oss << " Test: " << test_ << "\n"
631              << " Error: Assignment to column failed\n"
632              << " Details:\n"
633              << "   Result:\n" << col1 << "\n"
634              << "   Expected result:\n( -2 0 0 )\n";
635          throw std::runtime_error( oss.str() );
636       }
637 
638       if( upper(0,0) != 0 || upper(0,1) != -2 || upper(0,2) != 7 ||
639           upper(1,0) != 0 || upper(1,1) !=  0 || upper(1,2) != 0 ||
640           upper(2,0) != 0 || upper(2,1) !=  0 || upper(2,2) != 0 ) {
641          std::ostringstream oss;
642          oss << " Test: " << test_ << "\n"
643              << " Error: Assignment to column failed\n"
644              << " Details:\n"
645              << "   Result:\n" << upper << "\n"
646              << "   Expected result:\n( 0 -2  7 )\n( 0  0  0 )\n( 0  0  0 )\n";
647          throw std::runtime_error( oss.str() );
648       }
649    }
650 
651    // ( 0 -4  7 )      ( 0 -2  7 )
652    // ( 0  0  0 )  =>  ( 0 -1  0 )
653    // ( 0  0  0 )      ( 0  0  0 )
654    {
655       test_ = "Dense vector subtraction assignment test 2";
656 
657       blaze::DynamicVector<int,blaze::columnVector> vec( 3UL, 0 );
658       vec[0] = -2;
659       vec[1] =  1;
660 
661       UT upper;
662       init( upper );
663 
664       auto col1 = column( upper, 1UL );
665 
666       try {
667          col1 -= vec;
668 
669          std::ostringstream oss;
670          oss << " Test: " << test_ << "\n"
671              << " Error: Assignment of invalid vector succeeded\n"
672              << " Details:\n"
673              << "   Result:\n" << upper << "\n";
674          throw std::runtime_error( oss.str() );
675       }
676       catch( std::invalid_argument& ) {}
677    }
678 
679    // ( 0 -4  7 )      ( 0 -2  7 )
680    // ( 0  0  0 )  =>  ( 0  0  0 )
681    // ( 0  0  0 )      ( 0 -9  0 )
682    {
683       test_ = "Dense vector subtraction assignment test 3";
684 
685       blaze::DynamicVector<int,blaze::columnVector> vec( 3UL, 0 );
686       vec[0] = -2;
687       vec[2] =  9;
688 
689       UT upper;
690       init( upper );
691 
692       auto col1 = column( upper, 1UL );
693 
694       try {
695          col1 -= vec;
696 
697          std::ostringstream oss;
698          oss << " Test: " << test_ << "\n"
699              << " Error: Assignment of invalid vector succeeded\n"
700              << " Details:\n"
701              << "   Result:\n" << upper << "\n";
702          throw std::runtime_error( oss.str() );
703       }
704       catch( std::invalid_argument& ) {}
705    }
706 
707 
708    //=====================================================================================
709    // Sparse vector subtraction assignment
710    //=====================================================================================
711 
712    // ( 0 -4  7 )      ( 0 -2  7 )
713    // ( 0  0  0 )  =>  ( 0  0  0 )
714    // ( 0  0  0 )      ( 0  0  0 )
715    {
716       test_ = "Sparse vector subtraction assignment test 1";
717 
718       blaze::CompressedVector<int,blaze::columnVector> vec( 3UL, 2UL );
719       vec[0] = -2;
720       vec.insert( 2UL, 0 );
721 
722       UT upper;
723       init( upper );
724 
725       auto col1 = column( upper, 1UL );
726       col1 -= vec;
727 
728       checkRows    ( upper, 3UL );
729       checkColumns ( upper, 3UL );
730       checkNonZeros( upper, 2UL );
731 
732       if( col1[0] != -2 || col1[1] != 0 || col1[2] != 0 ) {
733          std::ostringstream oss;
734          oss << " Test: " << test_ << "\n"
735              << " Error: Assignment to column failed\n"
736              << " Details:\n"
737              << "   Result:\n" << col1 << "\n"
738              << "   Expected result:\n( -2 0 0 )\n";
739          throw std::runtime_error( oss.str() );
740       }
741 
742       if( upper(0,0) != 0 || upper(0,1) != -2 || upper(0,2) != 7 ||
743           upper(1,0) != 0 || upper(1,1) !=  0 || upper(1,2) != 0 ||
744           upper(2,0) != 0 || upper(2,1) !=  0 || upper(2,2) != 0 ) {
745          std::ostringstream oss;
746          oss << " Test: " << test_ << "\n"
747              << " Error: Assignment to column failed\n"
748              << " Details:\n"
749              << "   Result:\n" << upper << "\n"
750              << "   Expected result:\n( 0 -2  7 )\n( 0  0  0 )\n( 0  0  0 )\n";
751          throw std::runtime_error( oss.str() );
752       }
753    }
754 
755    // ( 0 -4  7 )      ( 0 -2  7 )
756    // ( 0  0  0 )  =>  ( 0 -1  0 )
757    // ( 0  0  0 )      ( 0  0  0 )
758    {
759       test_ = "Sparse vector subtraction assignment test 2";
760 
761       blaze::CompressedVector<int,blaze::columnVector> vec( 3UL, 2UL );
762       vec[0] = -2;
763       vec[1] =  1;
764 
765       UT upper;
766       init( upper );
767 
768       auto col1 = column( upper, 1UL );
769 
770       try {
771          col1 -= vec;
772 
773          std::ostringstream oss;
774          oss << " Test: " << test_ << "\n"
775              << " Error: Assignment of invalid vector succeeded\n"
776              << " Details:\n"
777              << "   Result:\n" << upper << "\n";
778          throw std::runtime_error( oss.str() );
779       }
780       catch( std::invalid_argument& ) {}
781    }
782 
783    // ( 0 -4  7 )      ( 0 -2  7 )
784    // ( 0  0  0 )  =>  ( 0  0  0 )
785    // ( 0  0  0 )      ( 0 -9  0 )
786    {
787       test_ = "Sparse vector subtraction assignment test 3";
788 
789       blaze::CompressedVector<int,blaze::columnVector> vec( 3UL, 2UL );
790       vec[0] = -2;
791       vec[2] =  9;
792 
793       UT upper;
794       init( upper );
795 
796       auto col1 = column( upper, 1UL );
797 
798       try {
799          col1 -= vec;
800 
801          std::ostringstream oss;
802          oss << " Test: " << test_ << "\n"
803              << " Error: Assignment of invalid vector succeeded\n"
804              << " Details:\n"
805              << "   Result:\n" << upper << "\n";
806          throw std::runtime_error( oss.str() );
807       }
808       catch( std::invalid_argument& ) {}
809    }
810 }
811 //*************************************************************************************************
812 
813 
814 //*************************************************************************************************
815 /*!\brief Test of the multiplication assignment to columns of a StrictlyUpperMatrix.
816 //
817 // \return void
818 // \exception std::runtime_error Error detected.
819 //
820 // This function performs a test of the multiplication assignment to a single column of a
821 // StrictlyUpperMatrix. In case an error is detected, a \a std::runtime_error exception is thrown.
822 */
823 template< typename UT >  // Type of the strictly upper matrix
testMultAssign()824 void ColumnTest::testMultAssign()
825 {
826    //=====================================================================================
827    // Dense vector multiplication assignment
828    //=====================================================================================
829 
830    // ( 0 -4  7 )      ( 0  8  7 )
831    // ( 0  0  0 )  =>  ( 0  0  0 )
832    // ( 0  0  0 )      ( 0  0  0 )
833    {
834       test_ = "Dense vector multiplication assignment test";
835 
836       blaze::DynamicVector<int,blaze::columnVector> vec( 3UL );
837       vec[0] = -2;
838       vec[1] =  8;
839       vec[2] =  9;
840 
841       UT upper;
842       init( upper );
843 
844       auto col1 = column( upper, 1UL );
845       col1 *= vec;
846 
847       checkRows    ( upper, 3UL );
848       checkColumns ( upper, 3UL );
849       checkNonZeros( upper, 2UL );
850 
851       if( col1[0] != 8 || col1[1] != 0 || col1[2] != 0 ) {
852          std::ostringstream oss;
853          oss << " Test: " << test_ << "\n"
854              << " Error: Assignment to column failed\n"
855              << " Details:\n"
856              << "   Result:\n" << col1 << "\n"
857              << "   Expected result:\n( 8 0 0 )\n";
858          throw std::runtime_error( oss.str() );
859       }
860 
861       if( upper(0,0) != 0 || upper(0,1) != 8 || upper(0,2) != 7 ||
862           upper(1,0) != 0 || upper(1,1) != 0 || upper(1,2) != 0 ||
863           upper(2,0) != 0 || upper(2,1) != 0 || upper(2,2) != 0 ) {
864          std::ostringstream oss;
865          oss << " Test: " << test_ << "\n"
866              << " Error: Assignment to column failed\n"
867              << " Details:\n"
868              << "   Result:\n" << upper << "\n"
869              << "   Expected result:\n( 0 8 7 )\n( 0 0 0 )\n( 0 0 0 )\n";
870          throw std::runtime_error( oss.str() );
871       }
872    }
873 
874 
875    //=====================================================================================
876    // Sparse vector multiplication assignment
877    //=====================================================================================
878 
879    // ( 0 -4  7 )      ( 0  8  7 )
880    // ( 0  0  0 )  =>  ( 0  0  0 )
881    // ( 0  0  0 )      ( 0  0  0 )
882    {
883       test_ = "Sparse vector multiplication assignment test";
884 
885       blaze::CompressedVector<int,blaze::columnVector> vec( 3UL, 3UL );
886       vec[0] = -2;
887       vec[1] =  8;
888       vec[2] =  9;
889 
890       UT upper;
891       init( upper );
892 
893       auto col1 = column( upper, 1UL );
894       col1 *= vec;
895 
896       checkRows    ( upper, 3UL );
897       checkColumns ( upper, 3UL );
898       checkNonZeros( upper, 2UL );
899 
900       if( col1[0] != 8 || col1[1] != 0 || col1[2] != 0 ) {
901          std::ostringstream oss;
902          oss << " Test: " << test_ << "\n"
903              << " Error: Assignment to column failed\n"
904              << " Details:\n"
905              << "   Result:\n" << col1 << "\n"
906              << "   Expected result:\n( 8 0 0 )\n";
907          throw std::runtime_error( oss.str() );
908       }
909 
910       if( upper(0,0) != 0 || upper(0,1) != 8 || upper(0,2) != 7 ||
911           upper(1,0) != 0 || upper(1,1) != 0 || upper(1,2) != 0 ||
912           upper(2,0) != 0 || upper(2,1) != 0 || upper(2,2) != 0 ) {
913          std::ostringstream oss;
914          oss << " Test: " << test_ << "\n"
915              << " Error: Assignment to column failed\n"
916              << " Details:\n"
917              << "   Result:\n" << upper << "\n"
918              << "   Expected result:\n( 0 8 7 )\n( 0 0 0 )\n( 0 0 0 )\n";
919          throw std::runtime_error( oss.str() );
920       }
921    }
922 }
923 //*************************************************************************************************
924 
925 
926 //*************************************************************************************************
927 /*!\brief Checking the number of rows of the given matrix.
928 //
929 // \param matrix The matrix to be checked.
930 // \param expectedRows The expected number of rows of the matrix.
931 // \return void
932 // \exception std::runtime_error Error detected.
933 //
934 // This function checks the number of rows of the given matrix. In case the actual number of
935 // rows does not correspond to the given expected number of rows, a \a std::runtime_error
936 // exception is thrown.
937 */
938 template< typename Type >  // Type of the matrix
checkRows(const Type & matrix,size_t expectedRows)939 void ColumnTest::checkRows( const Type& matrix, size_t expectedRows ) const
940 {
941    if( matrix.rows() != expectedRows ) {
942       std::ostringstream oss;
943       oss << " Test: " << test_ << "\n"
944           << " Error: Invalid number of rows detected\n"
945           << " Details:\n"
946           << "   Number of rows         : " << matrix.rows() << "\n"
947           << "   Expected number of rows: " << expectedRows << "\n";
948       throw std::runtime_error( oss.str() );
949    }
950 }
951 //*************************************************************************************************
952 
953 
954 //*************************************************************************************************
955 /*!\brief Checking the number of columns of the given matrix.
956 //
957 // \param matrix The matrix to be checked.
958 // \param expectedColumns The expected number of columns of the matrix.
959 // \return void
960 // \exception std::runtime_error Error detected.
961 //
962 // This function checks the number of columns of the given matrix. In case the actual number of
963 // columns does not correspond to the given expected number of columns, a \a std::runtime_error
964 // exception is thrown.
965 */
966 template< typename Type >  // Type of the matrix
checkColumns(const Type & matrix,size_t expectedColumns)967 void ColumnTest::checkColumns( const Type& matrix, size_t expectedColumns ) const
968 {
969    if( matrix.columns() != expectedColumns ) {
970       std::ostringstream oss;
971       oss << " Test: " << test_ << "\n"
972           << " Error: Invalid number of columns detected\n"
973           << " Details:\n"
974           << "   Number of columns         : " << matrix.columns() << "\n"
975           << "   Expected number of columns: " << expectedColumns << "\n";
976       throw std::runtime_error( oss.str() );
977    }
978 }
979 //*************************************************************************************************
980 
981 
982 //*************************************************************************************************
983 /*!\brief Checking the number of non-zero elements of the given matrix.
984 //
985 // \param matrix The matrix to be checked.
986 // \param expectedNonZeros The expected number of non-zero elements of the matrix.
987 // \return void
988 // \exception std::runtime_error Error detected.
989 //
990 // This function checks the number of non-zero elements of the given matrix. In case the
991 // actual number of non-zero elements does not correspond to the given expected number,
992 // a \a std::runtime_error exception is thrown.
993 */
994 template< typename Type >  // Type of the matrix
checkNonZeros(const Type & matrix,size_t expectedNonZeros)995 void ColumnTest::checkNonZeros( const Type& matrix, size_t expectedNonZeros ) const
996 {
997    if( nonZeros( matrix ) != expectedNonZeros ) {
998       std::ostringstream oss;
999       oss << " Test: " << test_ << "\n"
1000           << " Error: Invalid number of non-zero elements\n"
1001           << " Details:\n"
1002           << "   Number of non-zeros         : " << nonZeros( matrix ) << "\n"
1003           << "   Expected number of non-zeros: " << expectedNonZeros << "\n";
1004       throw std::runtime_error( oss.str() );
1005    }
1006 
1007    if( capacity( matrix ) < nonZeros( matrix ) ) {
1008       std::ostringstream oss;
1009       oss << " Test: " << test_ << "\n"
1010           << " Error: Invalid capacity detected\n"
1011           << " Details:\n"
1012           << "   Number of non-zeros: " << nonZeros( matrix ) << "\n"
1013           << "   Capacity           : " << capacity( matrix ) << "\n";
1014       throw std::runtime_error( oss.str() );
1015    }
1016 }
1017 //*************************************************************************************************
1018 
1019 
1020 
1021 
1022 //=================================================================================================
1023 //
1024 //  UTILITY FUNCTIONS
1025 //
1026 //=================================================================================================
1027 
1028 //*************************************************************************************************
1029 /*!\brief Initializing the given strictly upper triangular matrix.
1030 //
1031 // \return void
1032 //
1033 // This function is called before each test case to initialize the given strictly upper triangular
1034 // matrix.
1035 */
1036 template< typename UT >
init(UT & upper)1037 void ColumnTest::init( UT& upper )
1038 {
1039    upper.resize( 3UL );
1040    upper(0,1) = -4;
1041    upper(0,2) =  7;
1042    upper(1,2) =  0;
1043 }
1044 //*************************************************************************************************
1045 
1046 
1047 
1048 
1049 //=================================================================================================
1050 //
1051 //  GLOBAL TEST FUNCTIONS
1052 //
1053 //=================================================================================================
1054 
1055 //*************************************************************************************************
1056 /*!\brief Testing the assignment to a single column of a StrictlyUpperMatrix.
1057 //
1058 // \return void
1059 */
runTest()1060 void runTest()
1061 {
1062    ColumnTest();
1063 }
1064 //*************************************************************************************************
1065 
1066 
1067 
1068 
1069 //=================================================================================================
1070 //
1071 //  MACRO DEFINITIONS
1072 //
1073 //=================================================================================================
1074 
1075 //*************************************************************************************************
1076 /*! \cond BLAZE_INTERNAL */
1077 /*!\brief Macro for the execution of the StrictlyUpperMatrix column test.
1078 */
1079 #define RUN_STRICTLYUPPERMATRIX_COLUMN_TEST \
1080    blazetest::mathtest::adaptors::strictlyuppermatrix::runTest()
1081 /*! \endcond */
1082 //*************************************************************************************************
1083 
1084 } // namespace strictlyuppermatrix
1085 
1086 } // namespace adaptors
1087 
1088 } // namespace mathtest
1089 
1090 } // namespace blazetest
1091 
1092 #endif
1093