1 //=================================================================================================
2 /*!
3 // \file blazetest/mathtest/adaptors/hermitianmatrix/SparseComplexTest.h
4 // \brief Header file for the HermitianMatrix sparse complex 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_HERMITIANMATRIX_SPARSECOMPLEXTEST_H_
36 #define _BLAZETEST_MATHTEST_ADAPTORS_HERMITIANMATRIX_SPARSECOMPLEXTEST_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/constraints/ColumnMajorMatrix.h>
48 #include <blaze/math/constraints/RequiresEvaluation.h>
49 #include <blaze/math/constraints/RowMajorMatrix.h>
50 #include <blaze/math/constraints/Hermitian.h>
51 #include <blaze/math/constraints/SparseMatrix.h>
52 #include <blaze/math/constraints/Symmetric.h>
53 #include <blaze/math/HermitianMatrix.h>
54 #include <blaze/math/typetraits/IsRowMajorMatrix.h>
55 #include <blaze/util/constraints/SameType.h>
56 #include <blazetest/system/Types.h>
57
58
59 namespace blazetest {
60
61 namespace mathtest {
62
63 namespace adaptors {
64
65 namespace hermitianmatrix {
66
67 //=================================================================================================
68 //
69 // CLASS DEFINITION
70 //
71 //=================================================================================================
72
73 //*************************************************************************************************
74 /*!\brief Auxiliary class for all tests of the sparse HermitianMatrix specialization.
75 //
76 // This class represents a test suite for the blaze::HermitianMatrix class template specialization
77 // for sparse matrices with complex element type. It performs a series of both compile time as well
78 // as runtime tests.
79 */
80 class SparseComplexTest
81 {
82 public:
83 //**Constructors********************************************************************************
84 /*!\name Constructors */
85 //@{
86 explicit SparseComplexTest();
87 // No explicitly declared copy constructor.
88 //@}
89 //**********************************************************************************************
90
91 //**Destructor**********************************************************************************
92 // No explicitly declared destructor.
93 //**********************************************************************************************
94
95 private:
96 //**Test functions******************************************************************************
97 /*!\name Test functions */
98 //@{
99 void testConstructors();
100 void testAssignment ();
101 void testAddAssign ();
102 void testSubAssign ();
103 void testSchurAssign ();
104 void testMultAssign ();
105 void testScaling ();
106 void testFunctionCall();
107 void testIterator ();
108 void testNonZeros ();
109 void testReset ();
110 void testClear ();
111 void testResize ();
112 void testReserve ();
113 void testTrim ();
114 void testShrinkToFit ();
115 void testSwap ();
116 void testSet ();
117 void testInsert ();
118 void testAppend ();
119 void testErase ();
120 void testFind ();
121 void testLowerBound ();
122 void testUpperBound ();
123 void testTranspose ();
124 void testCTranspose ();
125 void testIsDefault ();
126 void testSubmatrix ();
127 void testRow ();
128 void testColumn ();
129
130 template< typename Type >
131 void checkRows( const Type& matrix, size_t expectedRows ) const;
132
133 template< typename Type >
134 void checkColumns( const Type& matrix, size_t expectedColumns ) const;
135
136 template< typename Type >
137 void checkCapacity( const Type& matrix, size_t minCapacity ) const;
138
139 template< typename Type >
140 void checkCapacity( const Type& matrix, size_t index, size_t minCapacity ) const;
141
142 template< typename Type >
143 void checkNonZeros( const Type& matrix, size_t expectedNonZeros ) const;
144
145 template< typename Type >
146 void checkNonZeros( const Type& matrix, size_t index, size_t expectedNonZeros ) const;
147 //@}
148 //**********************************************************************************************
149
150 //**Member variables****************************************************************************
151 /*!\name Member variables */
152 //@{
153 std::string test_; //!< Label of the currently performed test.
154 //@}
155 //**********************************************************************************************
156
157 //**Type definitions****************************************************************************
158 //! Complex element type.
159 using cplx = blaze::complex<int>;
160
161 //! Type of the row-major Hermitian matrix.
162 using HT = blaze::HermitianMatrix< blaze::CompressedMatrix<cplx,blaze::rowMajor> >;
163
164 //! Type of the column-major Hermitian matrix.
165 using OHT = blaze::HermitianMatrix< blaze::CompressedMatrix<cplx,blaze::columnMajor> >;
166
167 using RHT = HT::Rebind< complex<double> >::Other; //!< Rebound row-major Hermitian matrix type.
168 using ORHT = OHT::Rebind< complex<double> >::Other; //!< Rebound column-major Hermitian matrix type.
169 //**********************************************************************************************
170
171 //**Compile time checks*************************************************************************
172 /*! \cond BLAZE_INTERNAL */
173 BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( HT );
174 BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( HT::ResultType );
175 BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( HT::OppositeType );
176 BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( HT::TransposeType );
177 BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( OHT );
178 BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( OHT::ResultType );
179 BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( OHT::OppositeType );
180 BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( OHT::TransposeType );
181 BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( RHT );
182 BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( RHT::ResultType );
183 BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( RHT::OppositeType );
184 BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( RHT::TransposeType );
185 BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( ORHT );
186 BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( ORHT::ResultType );
187 BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( ORHT::OppositeType );
188 BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( ORHT::TransposeType );
189
190 BLAZE_CONSTRAINT_MUST_BE_ROW_MAJOR_MATRIX_TYPE ( HT );
191 BLAZE_CONSTRAINT_MUST_BE_ROW_MAJOR_MATRIX_TYPE ( HT::ResultType );
192 BLAZE_CONSTRAINT_MUST_BE_COLUMN_MAJOR_MATRIX_TYPE( HT::OppositeType );
193 BLAZE_CONSTRAINT_MUST_BE_COLUMN_MAJOR_MATRIX_TYPE( HT::TransposeType );
194 BLAZE_CONSTRAINT_MUST_BE_COLUMN_MAJOR_MATRIX_TYPE( OHT );
195 BLAZE_CONSTRAINT_MUST_BE_COLUMN_MAJOR_MATRIX_TYPE( OHT::ResultType );
196 BLAZE_CONSTRAINT_MUST_BE_ROW_MAJOR_MATRIX_TYPE ( OHT::OppositeType );
197 BLAZE_CONSTRAINT_MUST_BE_ROW_MAJOR_MATRIX_TYPE ( OHT::TransposeType );
198 BLAZE_CONSTRAINT_MUST_BE_ROW_MAJOR_MATRIX_TYPE ( RHT );
199 BLAZE_CONSTRAINT_MUST_BE_ROW_MAJOR_MATRIX_TYPE ( RHT::ResultType );
200 BLAZE_CONSTRAINT_MUST_BE_COLUMN_MAJOR_MATRIX_TYPE( RHT::OppositeType );
201 BLAZE_CONSTRAINT_MUST_BE_COLUMN_MAJOR_MATRIX_TYPE( RHT::TransposeType );
202 BLAZE_CONSTRAINT_MUST_BE_COLUMN_MAJOR_MATRIX_TYPE( ORHT );
203 BLAZE_CONSTRAINT_MUST_BE_COLUMN_MAJOR_MATRIX_TYPE( ORHT::ResultType );
204 BLAZE_CONSTRAINT_MUST_BE_ROW_MAJOR_MATRIX_TYPE ( ORHT::OppositeType );
205 BLAZE_CONSTRAINT_MUST_BE_ROW_MAJOR_MATRIX_TYPE ( ORHT::TransposeType );
206
207 BLAZE_CONSTRAINT_MUST_BE_HERMITIAN_MATRIX_TYPE( HT );
208 BLAZE_CONSTRAINT_MUST_BE_HERMITIAN_MATRIX_TYPE( HT::ResultType );
209 BLAZE_CONSTRAINT_MUST_BE_HERMITIAN_MATRIX_TYPE( HT::OppositeType );
210 BLAZE_CONSTRAINT_MUST_BE_HERMITIAN_MATRIX_TYPE( HT::TransposeType );
211 BLAZE_CONSTRAINT_MUST_BE_HERMITIAN_MATRIX_TYPE( OHT );
212 BLAZE_CONSTRAINT_MUST_BE_HERMITIAN_MATRIX_TYPE( OHT::ResultType );
213 BLAZE_CONSTRAINT_MUST_BE_HERMITIAN_MATRIX_TYPE( OHT::OppositeType );
214 BLAZE_CONSTRAINT_MUST_BE_HERMITIAN_MATRIX_TYPE( OHT::TransposeType );
215 BLAZE_CONSTRAINT_MUST_BE_HERMITIAN_MATRIX_TYPE( RHT );
216 BLAZE_CONSTRAINT_MUST_BE_HERMITIAN_MATRIX_TYPE( RHT::ResultType );
217 BLAZE_CONSTRAINT_MUST_BE_HERMITIAN_MATRIX_TYPE( RHT::OppositeType );
218 BLAZE_CONSTRAINT_MUST_BE_HERMITIAN_MATRIX_TYPE( RHT::TransposeType );
219 BLAZE_CONSTRAINT_MUST_BE_HERMITIAN_MATRIX_TYPE( ORHT );
220 BLAZE_CONSTRAINT_MUST_BE_HERMITIAN_MATRIX_TYPE( ORHT::ResultType );
221 BLAZE_CONSTRAINT_MUST_BE_HERMITIAN_MATRIX_TYPE( ORHT::OppositeType );
222 BLAZE_CONSTRAINT_MUST_BE_HERMITIAN_MATRIX_TYPE( ORHT::TransposeType );
223
224 BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE( HT );
225 BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE( HT::ResultType );
226 BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE( HT::OppositeType );
227 BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE( HT::TransposeType );
228 BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE( OHT );
229 BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE( OHT::ResultType );
230 BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE( OHT::OppositeType );
231 BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE( OHT::TransposeType );
232 BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE( RHT );
233 BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE( RHT::ResultType );
234 BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE( RHT::OppositeType );
235 BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE( RHT::TransposeType );
236 BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE( ORHT );
237 BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE( ORHT::ResultType );
238 BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE( ORHT::OppositeType );
239 BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE( ORHT::TransposeType );
240
241 BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION( HT::ResultType );
242 BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION( HT::OppositeType );
243 BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION( HT::TransposeType );
244 BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION( OHT::ResultType );
245 BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION( OHT::OppositeType );
246 BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION( OHT::TransposeType );
247 BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION( RHT::ResultType );
248 BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION( RHT::OppositeType );
249 BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION( RHT::TransposeType );
250 BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION( ORHT::ResultType );
251 BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION( ORHT::OppositeType );
252 BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION( ORHT::TransposeType );
253
254 BLAZE_CONSTRAINT_MUST_BE_SAME_TYPE( HT::ElementType, HT::ResultType::ElementType );
255 BLAZE_CONSTRAINT_MUST_BE_SAME_TYPE( HT::ElementType, HT::OppositeType::ElementType );
256 BLAZE_CONSTRAINT_MUST_BE_SAME_TYPE( HT::ElementType, HT::TransposeType::ElementType );
257 BLAZE_CONSTRAINT_MUST_BE_SAME_TYPE( OHT::ElementType, OHT::ResultType::ElementType );
258 BLAZE_CONSTRAINT_MUST_BE_SAME_TYPE( OHT::ElementType, OHT::OppositeType::ElementType );
259 BLAZE_CONSTRAINT_MUST_BE_SAME_TYPE( OHT::ElementType, OHT::TransposeType::ElementType );
260 BLAZE_CONSTRAINT_MUST_BE_SAME_TYPE( RHT::ElementType, RHT::ResultType::ElementType );
261 BLAZE_CONSTRAINT_MUST_BE_SAME_TYPE( RHT::ElementType, RHT::OppositeType::ElementType );
262 BLAZE_CONSTRAINT_MUST_BE_SAME_TYPE( RHT::ElementType, RHT::TransposeType::ElementType );
263 BLAZE_CONSTRAINT_MUST_BE_SAME_TYPE( ORHT::ElementType, ORHT::ResultType::ElementType );
264 BLAZE_CONSTRAINT_MUST_BE_SAME_TYPE( ORHT::ElementType, ORHT::OppositeType::ElementType );
265 BLAZE_CONSTRAINT_MUST_BE_SAME_TYPE( ORHT::ElementType, ORHT::TransposeType::ElementType );
266 /*! \endcond */
267 //**********************************************************************************************
268 };
269 //*************************************************************************************************
270
271
272
273
274 //=================================================================================================
275 //
276 // TEST FUNCTIONS
277 //
278 //=================================================================================================
279
280 //*************************************************************************************************
281 /*!\brief Checking the number of rows of the given matrix.
282 //
283 // \param matrix The matrix to be checked.
284 // \param expectedRows The expected number of rows of the matrix.
285 // \return void
286 // \exception std::runtime_error Error detected.
287 //
288 // This function checks the number of rows of the given matrix. In case the actual number of
289 // rows does not correspond to the given expected number of rows, a \a std::runtime_error
290 // exception is thrown.
291 */
292 template< typename Type > // Type of the matrix
checkRows(const Type & matrix,size_t expectedRows)293 void SparseComplexTest::checkRows( const Type& matrix, size_t expectedRows ) const
294 {
295 if( matrix.rows() != expectedRows ) {
296 std::ostringstream oss;
297 oss << " Test: " << test_ << "\n"
298 << " Error: Invalid number of rows detected\n"
299 << " Details:\n"
300 << " Number of rows : " << matrix.rows() << "\n"
301 << " Expected number of rows: " << expectedRows << "\n";
302 throw std::runtime_error( oss.str() );
303 }
304 }
305 //*************************************************************************************************
306
307
308 //*************************************************************************************************
309 /*!\brief Checking the number of columns of the given matrix.
310 //
311 // \param matrix The matrix to be checked.
312 // \param expectedRows The expected number of columns of the matrix.
313 // \return void
314 // \exception std::runtime_error Error detected.
315 //
316 // This function checks the number of columns of the given matrix. In case the actual number of
317 // columns does not correspond to the given expected number of columns, a \a std::runtime_error
318 // exception is thrown.
319 */
320 template< typename Type > // Type of the matrix
checkColumns(const Type & matrix,size_t expectedColumns)321 void SparseComplexTest::checkColumns( const Type& matrix, size_t expectedColumns ) const
322 {
323 if( matrix.columns() != expectedColumns ) {
324 std::ostringstream oss;
325 oss << " Test: " << test_ << "\n"
326 << " Error: Invalid number of columns detected\n"
327 << " Details:\n"
328 << " Number of columns : " << matrix.columns() << "\n"
329 << " Expected number of columns: " << expectedColumns << "\n";
330 throw std::runtime_error( oss.str() );
331 }
332 }
333 //*************************************************************************************************
334
335
336 //*************************************************************************************************
337 /*!\brief Checking the capacity of the given matrix.
338 //
339 // \param matrix The matrix to be checked.
340 // \param minCapacity The expected minimum capacity of the matrix.
341 // \return void
342 // \exception std::runtime_error Error detected.
343 //
344 // This function checks the capacity of the given matrix. In case the actual capacity is smaller
345 // than the given expected minimum capacity, a \a std::runtime_error exception is thrown.
346 */
347 template< typename Type > // Type of the matrix
checkCapacity(const Type & matrix,size_t minCapacity)348 void SparseComplexTest::checkCapacity( const Type& matrix, size_t minCapacity ) const
349 {
350 if( capacity( matrix ) < minCapacity ) {
351 std::ostringstream oss;
352 oss << " Test: " << test_ << "\n"
353 << " Error: Invalid capacity detected\n"
354 << " Details:\n"
355 << " Capacity : " << capacity( matrix ) << "\n"
356 << " Expected minimum capacity: " << minCapacity << "\n";
357 throw std::runtime_error( oss.str() );
358 }
359 }
360 //*************************************************************************************************
361
362
363 //*************************************************************************************************
364 /*!\brief Checking the capacity of a specific row/column of the given matrix.
365 //
366 // \param matrix The matrix to be checked.
367 // \param index The row/column to be checked.
368 // \param minCapacity The expected minimum capacity of the specified row/column.
369 // \return void
370 // \exception std::runtime_error Error detected.
371 //
372 // This function checks the capacity of a specific row/column of the given matrix. In case the
373 // actual capacity is smaller than the given expected minimum capacity, a \a std::runtime_error
374 // exception is thrown.
375 */
376 template< typename Type > // Type of the matrix
checkCapacity(const Type & matrix,size_t index,size_t minCapacity)377 void SparseComplexTest::checkCapacity( const Type& matrix, size_t index, size_t minCapacity ) const
378 {
379 if( capacity( matrix, index ) < minCapacity ) {
380 std::ostringstream oss;
381 oss << " Test: " << test_ << "\n"
382 << " Error: Invalid capacity detected in "
383 << ( blaze::IsRowMajorMatrix<Type>::value ? "row " : "column " ) << index << "\n"
384 << " Details:\n"
385 << " Capacity : " << capacity( matrix, index ) << "\n"
386 << " Expected minimum capacity: " << minCapacity << "\n";
387 throw std::runtime_error( oss.str() );
388 }
389 }
390 //*************************************************************************************************
391
392
393 //*************************************************************************************************
394 /*!\brief Checking the number of non-zero elements of the given matrix.
395 //
396 // \param matrix The matrix to be checked.
397 // \param expectedNonZeros The expected number of non-zero elements of the matrix.
398 // \return void
399 // \exception std::runtime_error Error detected.
400 //
401 // This function checks the number of non-zero elements of the given matrix. In case the
402 // actual number of non-zero elements does not correspond to the given expected number,
403 // a \a std::runtime_error exception is thrown.
404 */
405 template< typename Type > // Type of the matrix
checkNonZeros(const Type & matrix,size_t expectedNonZeros)406 void SparseComplexTest::checkNonZeros( const Type& matrix, size_t expectedNonZeros ) const
407 {
408 if( nonZeros( matrix ) != expectedNonZeros ) {
409 std::ostringstream oss;
410 oss << " Test: " << test_ << "\n"
411 << " Error: Invalid number of non-zero elements\n"
412 << " Details:\n"
413 << " Number of non-zeros : " << nonZeros( matrix ) << "\n"
414 << " Expected number of non-zeros: " << expectedNonZeros << "\n";
415 throw std::runtime_error( oss.str() );
416 }
417
418 if( capacity( matrix ) < nonZeros( matrix ) ) {
419 std::ostringstream oss;
420 oss << " Test: " << test_ << "\n"
421 << " Error: Invalid capacity detected\n"
422 << " Details:\n"
423 << " Number of non-zeros: " << nonZeros( matrix ) << "\n"
424 << " Capacity : " << capacity( matrix ) << "\n";
425 throw std::runtime_error( oss.str() );
426 }
427 }
428 //*************************************************************************************************
429
430
431 //*************************************************************************************************
432 /*!\brief Checking the number of non-zero elements in a specific row/column of the given matrix.
433 //
434 // \param matrix The matrix to be checked.
435 // \param index The row/column to be checked.
436 // \param expectedNonZeros The expected number of non-zero elements in the specified row/column.
437 // \return void
438 // \exception std::runtime_error Error detected.
439 //
440 // This function checks the number of non-zero elements in the specified row/column of the
441 // given matrix. In case the actual number of non-zero elements does not correspond to the
442 // given expected number, a \a std::runtime_error exception is thrown.
443 */
444 template< typename Type > // Type of the matrix
checkNonZeros(const Type & matrix,size_t index,size_t expectedNonZeros)445 void SparseComplexTest::checkNonZeros( const Type& matrix, size_t index, size_t expectedNonZeros ) const
446 {
447 if( nonZeros( matrix, index ) != expectedNonZeros ) {
448 std::ostringstream oss;
449 oss << " Test: " << test_ << "\n"
450 << " Error: Invalid number of non-zero elements in "
451 << ( blaze::IsRowMajorMatrix<Type>::value ? "row " : "column " ) << index << "\n"
452 << " Details:\n"
453 << " Number of non-zeros : " << nonZeros( matrix, index ) << "\n"
454 << " Expected number of non-zeros: " << expectedNonZeros << "\n";
455 throw std::runtime_error( oss.str() );
456 }
457
458 if( capacity( matrix, index ) < nonZeros( matrix, index ) ) {
459 std::ostringstream oss;
460 oss << " Test: " << test_ << "\n"
461 << " Error: Invalid capacity detected in "
462 << ( blaze::IsRowMajorMatrix<Type>::value ? "row " : "column " ) << index << "\n"
463 << " Details:\n"
464 << " Number of non-zeros: " << nonZeros( matrix, index ) << "\n"
465 << " Capacity : " << capacity( matrix, index ) << "\n";
466 throw std::runtime_error( oss.str() );
467 }
468 }
469 //*************************************************************************************************
470
471
472
473
474 //=================================================================================================
475 //
476 // GLOBAL TEST FUNCTIONS
477 //
478 //=================================================================================================
479
480 //*************************************************************************************************
481 /*!\brief Testing the functionality of the sparse HermitianMatrix specialization.
482 //
483 // \return void
484 */
runTest()485 void runTest()
486 {
487 SparseComplexTest();
488 }
489 //*************************************************************************************************
490
491
492
493
494 //=================================================================================================
495 //
496 // MACRO DEFINITIONS
497 //
498 //=================================================================================================
499
500 //*************************************************************************************************
501 /*! \cond BLAZE_INTERNAL */
502 /*!\brief Macro for the execution of the HermitianMatrix sparse complex test.
503 */
504 #define RUN_HERMITIANMATRIX_SPARSECOMPLEX_TEST \
505 blazetest::mathtest::adaptors::hermitianmatrix::runTest()
506 /*! \endcond */
507 //*************************************************************************************************
508
509 } // namespace hermitianmatrix
510
511 } // namespace adaptors
512
513 } // namespace mathtest
514
515 } // namespace blazetest
516
517 #endif
518