1 //=================================================================================================
2 /*!
3 //  \file blazetest/mathtest/matrices/densematrix/StrictlyLowerTest.h
4 //  \brief Header file for the strictly lower DenseMatrix operation 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_MATRICES_DENSEMATRIX_STRICTLYLOWERTEST_H_
36 #define _BLAZETEST_MATHTEST_MATRICES_DENSEMATRIX_STRICTLYLOWERTEST_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <sstream>
44 #include <stdexcept>
45 #include <string>
46 
47 
48 namespace blazetest {
49 
50 namespace mathtest {
51 
52 namespace matrices {
53 
54 namespace densematrix {
55 
56 //=================================================================================================
57 //
58 //  CLASS DEFINITION
59 //
60 //=================================================================================================
61 
62 //*************************************************************************************************
63 /*!\brief Auxiliary class for tests of the DenseMatrix functionality.
64 //
65 // This class represents a test suite for the DenseMatrix functionality contained in the
66 // <em><blaze/math/dense/DenseMatrix.h></em> header file. It performs a series of runtime
67 // tests with strictly lower triangular matrices.
68 */
69 class StrictlyLowerTest
70 {
71  private:
72    //**Type definitions****************************************************************************
73    using cplx = blaze::complex<int>;  //!< Complex element type.
74    //**********************************************************************************************
75 
76  public:
77    //**Constructors********************************************************************************
78    /*!\name Constructors */
79    //@{
80    explicit StrictlyLowerTest();
81    // No explicitly declared copy constructor.
82    //@}
83    //**********************************************************************************************
84 
85    //**Destructor**********************************************************************************
86    // No explicitly declared destructor.
87    //**********************************************************************************************
88 
89  private:
90    //**Test functions******************************************************************************
91    /*!\name Test functions */
92    //@{
93    void testIsNan();
94    void testIsInf();
95    void testIsFinite();
96    void testIsSymmetric();
97    void testIsHermitian();
98    void testIsUniform();
99    void testIsZero();
100    void testIsLower();
101    void testIsUniLower();
102    void testIsStrictlyLower();
103    void testIsUpper();
104    void testIsUniUpper();
105    void testIsStrictlyUpper();
106    void testIsDiagonal();
107    void testIsIdentity();
108 
109    template< typename Type >
110    void checkRows( const Type& matrix, size_t expectedRows ) const;
111 
112    template< typename Type >
113    void checkColumns( const Type& matrix, size_t expectedColumns ) const;
114 
115    template< typename Type >
116    void checkCapacity( const Type& matrix, size_t minCapacity ) const;
117 
118    template< typename Type >
119    void checkNonZeros( const Type& matrix, size_t expectedNonZeros ) const;
120 
121    template< typename Type >
122    void checkNonZeros( const Type& matrix, size_t index, size_t expectedNonZeros ) const;
123    //@}
124    //**********************************************************************************************
125 
126    //**Member variables****************************************************************************
127    /*!\name Member variables */
128    //@{
129    std::string test_;  //!< Label of the currently performed test.
130    //@}
131    //**********************************************************************************************
132 };
133 //*************************************************************************************************
134 
135 
136 
137 
138 //=================================================================================================
139 //
140 //  TEST FUNCTIONS
141 //
142 //=================================================================================================
143 
144 //*************************************************************************************************
145 /*!\brief Checking the number of rows of the given dense matrix.
146 //
147 // \param matrix The dense matrix to be checked.
148 // \param expectedRows The expected number of rows of the dense matrix.
149 // \return void
150 // \exception std::runtime_error Error detected.
151 //
152 // This function checks the number of rows of the given dense matrix. In case the actual number
153 // of rows does not correspond to the given expected number of rows, a \a std::runtime_error
154 // exception is thrown.
155 */
156 template< typename Type >  // Type of the dense matrix
checkRows(const Type & matrix,size_t expectedRows)157 void StrictlyLowerTest::checkRows( const Type& matrix, size_t expectedRows ) const
158 {
159    if( matrix.rows() != expectedRows ) {
160       std::ostringstream oss;
161       oss << " Test: " << test_ << "\n"
162           << " Error: Invalid number of rows detected\n"
163           << " Details:\n"
164           << "   Number of rows         : " << matrix.rows() << "\n"
165           << "   Expected number of rows: " << expectedRows << "\n";
166       throw std::runtime_error( oss.str() );
167    }
168 }
169 //*************************************************************************************************
170 
171 
172 //*************************************************************************************************
173 /*!\brief Checking the number of columns of the given dense matrix.
174 //
175 // \param matrix The dense matrix to be checked.
176 // \param expectedRows The expected number of columns of the dense matrix.
177 // \return void
178 // \exception std::runtime_error Error detected.
179 //
180 // This function checks the number of columns of the given dense matrix. In case the
181 // actual number of columns does not correspond to the given expected number of columns,
182 // a \a std::runtime_error exception is thrown.
183 */
184 template< typename Type >  // Type of the dense matrix
checkColumns(const Type & matrix,size_t expectedColumns)185 void StrictlyLowerTest::checkColumns( const Type& matrix, size_t expectedColumns ) const
186 {
187    if( matrix.columns() != expectedColumns ) {
188       std::ostringstream oss;
189       oss << " Test: " << test_ << "\n"
190           << " Error: Invalid number of columns detected\n"
191           << " Details:\n"
192           << "   Number of columns         : " << matrix.columns() << "\n"
193           << "   Expected number of columns: " << expectedColumns << "\n";
194       throw std::runtime_error( oss.str() );
195    }
196 }
197 //*************************************************************************************************
198 
199 
200 //*************************************************************************************************
201 /*!\brief Checking the capacity of the given dense matrix.
202 //
203 // \param matrix The dense matrix to be checked.
204 // \param minCapacity The expected minimum capacity of the dense matrix.
205 // \return void
206 // \exception std::runtime_error Error detected.
207 //
208 // This function checks the capacity of the given dense matrix. In case the actual capacity
209 // is smaller than the given expected minimum capacity, a \a std::runtime_error exception is
210 // thrown.
211 */
212 template< typename Type >  // Type of the dense matrix
checkCapacity(const Type & matrix,size_t minCapacity)213 void StrictlyLowerTest::checkCapacity( const Type& matrix, size_t minCapacity ) const
214 {
215    if( matrix.capacity() < minCapacity ) {
216       std::ostringstream oss;
217       oss << " Test: " << test_ << "\n"
218           << " Error: Invalid capacity detected\n"
219           << " Details:\n"
220           << "   Capacity                 : " << matrix.capacity() << "\n"
221           << "   Expected minimum capacity: " << minCapacity << "\n";
222       throw std::runtime_error( oss.str() );
223    }
224 }
225 //*************************************************************************************************
226 
227 
228 //*************************************************************************************************
229 /*!\brief Checking the number of non-zero elements of the given dense matrix.
230 //
231 // \param matrix The dense matrix to be checked.
232 // \param expectedNonZeros The expected number of non-zero elements of the dense matrix.
233 // \return void
234 // \exception std::runtime_error Error detected.
235 //
236 // This function checks the number of non-zero elements of the given dense matrix. In
237 // case the actual number of non-zero elements does not correspond to the given expected
238 // number, a \a std::runtime_error exception is thrown.
239 */
240 template< typename Type >  // Type of the dense matrix
checkNonZeros(const Type & matrix,size_t expectedNonZeros)241 void StrictlyLowerTest::checkNonZeros( const Type& matrix, size_t expectedNonZeros ) const
242 {
243    if( matrix.nonZeros() != expectedNonZeros ) {
244       std::ostringstream oss;
245       oss << " Test: " << test_ << "\n"
246           << " Error: Invalid number of non-zero elements\n"
247           << " Details:\n"
248           << "   Number of non-zeros         : " << matrix.nonZeros() << "\n"
249           << "   Expected number of non-zeros: " << expectedNonZeros << "\n";
250       throw std::runtime_error( oss.str() );
251    }
252 
253    if( matrix.capacity() < matrix.nonZeros() ) {
254       std::ostringstream oss;
255       oss << " Test: " << test_ << "\n"
256           << " Error: Invalid capacity detected\n"
257           << " Details:\n"
258           << "   Number of non-zeros: " << matrix.nonZeros() << "\n"
259           << "   Capacity           : " << matrix.capacity() << "\n";
260       throw std::runtime_error( oss.str() );
261    }
262 }
263 //*************************************************************************************************
264 
265 
266 //*************************************************************************************************
267 /*!\brief Checking the number of non-zero elements in a specific row/column of the given dense matrix.
268 //
269 // \param matrix The dense matrix to be checked.
270 // \param index The row/column to be checked.
271 // \param expectedNonZeros The expected number of non-zero elements in the specified row/column.
272 // \return void
273 // \exception std::runtime_error Error detected.
274 //
275 // This function checks the number of non-zero elements in the specified row/column of the
276 // given dense matrix. In case the actual number of non-zero elements does not correspond
277 // to the given expected number, a \a std::runtime_error exception is thrown.
278 */
279 template< typename Type >  // Type of the dense matrix
checkNonZeros(const Type & matrix,size_t index,size_t expectedNonZeros)280 void StrictlyLowerTest::checkNonZeros( const Type& matrix, size_t index, size_t expectedNonZeros ) const
281 {
282    if( matrix.nonZeros( index ) != expectedNonZeros ) {
283       std::ostringstream oss;
284       oss << " Test: " << test_ << "\n"
285           << " Error: Invalid number of non-zero elements in "
286           << ( blaze::IsRowMajorMatrix<Type>::value ? "row " : "column " ) << index << "\n"
287           << " Details:\n"
288           << "   Number of non-zeros         : " << matrix.nonZeros( index ) << "\n"
289           << "   Expected number of non-zeros: " << expectedNonZeros << "\n";
290       throw std::runtime_error( oss.str() );
291    }
292 
293    if( matrix.capacity( index ) < matrix.nonZeros( index ) ) {
294       std::ostringstream oss;
295       oss << " Test: " << test_ << "\n"
296           << " Error: Invalid capacity detected in "
297           << ( blaze::IsRowMajorMatrix<Type>::value ? "row " : "column " ) << index << "\n"
298           << " Details:\n"
299           << "   Number of non-zeros: " << matrix.nonZeros( index ) << "\n"
300           << "   Capacity           : " << matrix.capacity( index ) << "\n";
301       throw std::runtime_error( oss.str() );
302    }
303 }
304 //*************************************************************************************************
305 
306 
307 
308 
309 //=================================================================================================
310 //
311 //  GLOBAL TEST FUNCTIONS
312 //
313 //=================================================================================================
314 
315 //*************************************************************************************************
316 /*!\brief Testing the functionality of the DenseMatrix class template.
317 //
318 // \return void
319 */
runTest()320 void runTest()
321 {
322    StrictlyLowerTest();
323 }
324 //*************************************************************************************************
325 
326 
327 
328 
329 //=================================================================================================
330 //
331 //  MACRO DEFINITIONS
332 //
333 //=================================================================================================
334 
335 //*************************************************************************************************
336 /*! \cond BLAZE_INTERNAL */
337 /*!\brief Macro for the execution of the strictly lower DenseMatrix operation test.
338 */
339 #define RUN_DENSEMATRIX_STRICTLY_LOWER_TEST \
340    blazetest::mathtest::matrices::densematrix::runTest()
341 /*! \endcond */
342 //*************************************************************************************************
343 
344 } // namespace densematrix
345 
346 } // namespace matrices
347 
348 } // namespace mathtest
349 
350 } // namespace blazetest
351 
352 #endif
353