1 //=================================================================================================
2 /*!
3 // \file blazetest/mathtest/vectors/customvector/UnalignedUnpaddedTest.h
4 // \brief Header file for the unaligned/unpadded CustomVector class 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_VECTORS_CUSTOMVECTOR_UNALIGNEDUNPADDEDTEST_H_
36 #define _BLAZETEST_MATHTEST_VECTORS_CUSTOMVECTOR_UNALIGNEDUNPADDEDTEST_H_
37
38
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42
43 #include <sstream>
44 #include <stdexcept>
45 #include <string>
46 #include <blaze/math/constraints/ColumnVector.h>
47 #include <blaze/math/constraints/DenseVector.h>
48 #include <blaze/math/constraints/RequiresEvaluation.h>
49 #include <blaze/math/constraints/RowVector.h>
50 #include <blaze/math/CustomVector.h>
51 #include <blaze/util/constraints/SameType.h>
52 #include <blazetest/system/Types.h>
53
54
55 namespace blazetest {
56
57 namespace mathtest {
58
59 namespace vectors {
60
61 namespace customvector {
62
63 //=================================================================================================
64 //
65 // CLASS DEFINITION
66 //
67 //=================================================================================================
68
69 //*************************************************************************************************
70 /*!\brief Auxiliary class for all tests of the unaligned/unpadded CustomVector class template.
71 //
72 // This class represents a test suite for the specialization of the blaze::CustomVector class
73 // template for unaligned and unpadded custom vectors. It performs a series of both compile time
74 // as well as runtime tests.
75 */
76 class UnalignedUnpaddedTest
77 {
78 public:
79 //**Constructors********************************************************************************
80 /*!\name Constructors */
81 //@{
82 explicit UnalignedUnpaddedTest();
83 // No explicitly declared copy constructor.
84 //@}
85 //**********************************************************************************************
86
87 //**Destructor**********************************************************************************
88 // No explicitly declared destructor.
89 //**********************************************************************************************
90
91 private:
92 //**Test functions******************************************************************************
93 /*!\name Test functions */
94 //@{
95 void testConstructors();
96 void testAssignment ();
97 void testAddAssign ();
98 void testSubAssign ();
99 void testMultAssign ();
100 void testDivAssign ();
101 void testCrossAssign ();
102 void testScaling ();
103 void testSubscript ();
104 void testAt ();
105 void testIterator ();
106 void testNonZeros ();
107 void testReset ();
108 void testClear ();
109 void testSwap ();
110 void testIsDefault ();
111
112 template< typename Type >
113 void checkSize( const Type& vector, size_t expectedSize ) const;
114
115 template< typename Type >
116 void checkCapacity( const Type& vector, size_t minCapacity ) const;
117
118 template< typename Type >
119 void checkNonZeros( const Type& vector, size_t nonzeros ) const;
120 //@}
121 //**********************************************************************************************
122
123 //**Member variables****************************************************************************
124 /*!\name Member variables */
125 //@{
126 std::string test_; //!< Label of the currently performed test.
127 //@}
128 //**********************************************************************************************
129
130 //**Type definitions****************************************************************************
131 //! Type of the custom row vector.
132 using VT = blaze::CustomVector<int,blaze::unaligned,blaze::unpadded,blaze::rowVector>;
133
134 //! Type of the custom column vector.
135 using TVT = blaze::CustomVector<int,blaze::unaligned,blaze::unpadded,blaze::columnVector>;
136
137 using RVT = VT::Rebind<const double>::Other; //!< Rebound custom row vector type.
138 using TRVT = TVT::Rebind<const double>::Other; //!< Rebound custom column vector type.
139 //**********************************************************************************************
140
141 //**Compile time checks*************************************************************************
142 /*! \cond BLAZE_INTERNAL */
143 BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE( VT );
144 BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE( VT::ResultType );
145 BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE( VT::TransposeType );
146 BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE( TVT );
147 BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE( TVT::ResultType );
148 BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE( TVT::TransposeType );
149 BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE( RVT );
150 BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE( RVT::ResultType );
151 BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE( RVT::TransposeType );
152 BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE( TRVT );
153 BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE( TRVT::ResultType );
154 BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE( TRVT::TransposeType );
155
156 BLAZE_CONSTRAINT_MUST_BE_ROW_VECTOR_TYPE ( VT );
157 BLAZE_CONSTRAINT_MUST_BE_ROW_VECTOR_TYPE ( VT::ResultType );
158 BLAZE_CONSTRAINT_MUST_BE_COLUMN_VECTOR_TYPE( VT::TransposeType );
159 BLAZE_CONSTRAINT_MUST_BE_COLUMN_VECTOR_TYPE( TVT );
160 BLAZE_CONSTRAINT_MUST_BE_COLUMN_VECTOR_TYPE( TVT::ResultType );
161 BLAZE_CONSTRAINT_MUST_BE_ROW_VECTOR_TYPE ( TVT::TransposeType );
162 BLAZE_CONSTRAINT_MUST_BE_ROW_VECTOR_TYPE ( RVT );
163 BLAZE_CONSTRAINT_MUST_BE_ROW_VECTOR_TYPE ( RVT::ResultType );
164 BLAZE_CONSTRAINT_MUST_BE_COLUMN_VECTOR_TYPE( RVT::TransposeType );
165 BLAZE_CONSTRAINT_MUST_BE_COLUMN_VECTOR_TYPE( TRVT );
166 BLAZE_CONSTRAINT_MUST_BE_COLUMN_VECTOR_TYPE( TRVT::ResultType );
167 BLAZE_CONSTRAINT_MUST_BE_ROW_VECTOR_TYPE ( TRVT::TransposeType );
168
169 BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION( VT::ResultType );
170 BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION( VT::TransposeType );
171 BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION( TVT::ResultType );
172 BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION( TVT::TransposeType );
173 BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION( RVT::ResultType );
174 BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION( RVT::TransposeType );
175 BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION( TRVT::ResultType );
176 BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION( TRVT::TransposeType );
177
178 BLAZE_CONSTRAINT_MUST_BE_SAME_TYPE( VT::ElementType, VT::ResultType::ElementType );
179 BLAZE_CONSTRAINT_MUST_BE_SAME_TYPE( VT::ElementType, VT::TransposeType::ElementType );
180 BLAZE_CONSTRAINT_MUST_BE_SAME_TYPE( TVT::ElementType, TVT::ResultType::ElementType );
181 BLAZE_CONSTRAINT_MUST_BE_SAME_TYPE( TVT::ElementType, TVT::TransposeType::ElementType );
182 BLAZE_CONSTRAINT_MUST_BE_SAME_TYPE( RVT::ElementType, RVT::ResultType::ElementType );
183 BLAZE_CONSTRAINT_MUST_BE_SAME_TYPE( RVT::ElementType, RVT::TransposeType::ElementType );
184 BLAZE_CONSTRAINT_MUST_BE_SAME_TYPE( TRVT::ElementType, TRVT::ResultType::ElementType );
185 BLAZE_CONSTRAINT_MUST_BE_SAME_TYPE( TRVT::ElementType, TRVT::TransposeType::ElementType );
186 /*! \endcond */
187 //**********************************************************************************************
188 };
189 //*************************************************************************************************
190
191
192
193
194 //=================================================================================================
195 //
196 // TEST FUNCTIONS
197 //
198 //=================================================================================================
199
200 //*************************************************************************************************
201 /*!\brief Checking the size of the given custom vector.
202 //
203 // \param vector The custom vector to be checked.
204 // \param expectedSize The expected size of the custom vector.
205 // \return void
206 // \exception std::runtime_error Error detected.
207 //
208 // This function checks the size of the given custom vector. In case the actual size
209 // does not correspond to the given expected size, a \a std::runtime_error exception is
210 // thrown.
211 */
212 template< typename Type > // Type of the custom vector
checkSize(const Type & vector,size_t expectedSize)213 void UnalignedUnpaddedTest::checkSize( const Type& vector, size_t expectedSize ) const
214 {
215 if( size( vector ) != expectedSize ) {
216 std::ostringstream oss;
217 oss << " Test: " << test_ << "\n"
218 << " Error: Invalid size detected\n"
219 << " Details:\n"
220 << " Size : " << size( vector ) << "\n"
221 << " Expected size: " << expectedSize << "\n";
222 throw std::runtime_error( oss.str() );
223 }
224 }
225 //*************************************************************************************************
226
227
228 //*************************************************************************************************
229 /*!\brief Checking the capacity of the given custom vector.
230 //
231 // \param vector The custom vector to be checked.
232 // \param minCapacity The expected minimum capacity of the custom vector.
233 // \return void
234 // \exception std::runtime_error Error detected.
235 //
236 // This function checks the capacity of the given custom vector. In case the actual capacity
237 // is smaller than the given expected minimum capacity, a \a std::runtime_error exception is
238 // thrown.
239 */
240 template< typename Type > // Type of the custom vector
checkCapacity(const Type & vector,size_t minCapacity)241 void UnalignedUnpaddedTest::checkCapacity( const Type& vector, size_t minCapacity ) const
242 {
243 if( capacity( vector ) < minCapacity ) {
244 std::ostringstream oss;
245 oss << " Test: " << test_ << "\n"
246 << " Error: Invalid capacity detected\n"
247 << " Details:\n"
248 << " Capacity : " << capacity( vector ) << "\n"
249 << " Expected minimum capacity: " << minCapacity << "\n";
250 throw std::runtime_error( oss.str() );
251 }
252 }
253 //*************************************************************************************************
254
255
256 //*************************************************************************************************
257 /*!\brief Checking the number of non-zero elements of the given custom vector.
258 //
259 // \param vector The custom vector to be checked.
260 // \param expectedNonZeros The expected number of non-zero elements of the custom vector.
261 // \return void
262 // \exception std::runtime_error Error detected.
263 //
264 // This function checks the number of non-zero elements of the given custom vector. In
265 // case the actual number of non-zero elements does not correspond to the given expected
266 // number, a \a std::runtime_error exception is thrown.
267 */
268 template< typename Type > // Type of the custom vector
checkNonZeros(const Type & vector,size_t expectedNonZeros)269 void UnalignedUnpaddedTest::checkNonZeros( const Type& vector, size_t expectedNonZeros ) const
270 {
271 if( nonZeros( vector ) != expectedNonZeros ) {
272 std::ostringstream oss;
273 oss << " Test: " << test_ << "\n"
274 << " Error: Invalid number of non-zero elements\n"
275 << " Details:\n"
276 << " Number of non-zeros : " << nonZeros( vector ) << "\n"
277 << " Expected number of non-zeros: " << expectedNonZeros << "\n";
278 throw std::runtime_error( oss.str() );
279 }
280 }
281 //*************************************************************************************************
282
283
284
285
286 //=================================================================================================
287 //
288 // GLOBAL TEST FUNCTIONS
289 //
290 //=================================================================================================
291
292 //*************************************************************************************************
293 /*!\brief Testing the functionality of the unaligned/unpadded CustomVector class template.
294 //
295 // \return void
296 */
runTest()297 void runTest()
298 {
299 UnalignedUnpaddedTest();
300 }
301 //*************************************************************************************************
302
303
304
305
306 //=================================================================================================
307 //
308 // MACRO DEFINITIONS
309 //
310 //=================================================================================================
311
312 //*************************************************************************************************
313 /*! \cond BLAZE_INTERNAL */
314 /*!\brief Macro for the execution of the unaligned/unpadded CustomVector class test.
315 */
316 #define RUN_CUSTOMVECTOR_UNALIGNED_UNPADDED_TEST \
317 blazetest::mathtest::vectors::customvector::runTest()
318 /*! \endcond */
319 //*************************************************************************************************
320
321 } // namespace customvector
322
323 } // namespace vectors
324
325 } // namespace mathtest
326
327 } // namespace blazetest
328
329 #endif
330