1 //=================================================================================================
2 /*!
3 //  \file src/mathtest/vectors/customvector/AlignedPaddedTest.cpp
4 //  \brief Source file for the aligned/padded 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 
36 //*************************************************************************************************
37 // Includes
38 //*************************************************************************************************
39 
40 #include <array>
41 #include <cstdlib>
42 #include <iostream>
43 #include <memory>
44 #include <blaze/math/CompressedVector.h>
45 #include <blaze/math/shims/Equal.h>
46 #include <blaze/util/Complex.h>
47 #include <blaze/util/Memory.h>
48 #include <blaze/util/policies/Deallocate.h>
49 #include <blaze/util/Random.h>
50 #include <blaze/util/typetraits/AlignmentOf.h>
51 #include <blaze/util/typetraits/IsVectorizable.h>
52 #include <blazetest/mathtest/RandomMaximum.h>
53 #include <blazetest/mathtest/RandomMinimum.h>
54 #include <blazetest/mathtest/vectors/customvector/AlignedPaddedTest.h>
55 
56 #ifdef BLAZE_USE_HPX_THREADS
57 #  include <hpx/hpx_main.hpp>
58 #endif
59 
60 
61 namespace blazetest {
62 
63 namespace mathtest {
64 
65 namespace vectors {
66 
67 namespace customvector {
68 
69 //=================================================================================================
70 //
71 //  CONSTRUCTORS
72 //
73 //=================================================================================================
74 
75 //*************************************************************************************************
76 /*!\brief Constructor for the aligned/padded CustomVector class test.
77 //
78 // \exception std::runtime_error Operation error detected.
79 */
AlignedPaddedTest()80 AlignedPaddedTest::AlignedPaddedTest()
81 {
82    testConstructors();
83    testAssignment();
84    testAddAssign();
85    testSubAssign();
86    testMultAssign();
87    testDivAssign();
88    testCrossAssign();
89    testScaling();
90    testSubscript();
91    testAt();
92    testIterator();
93    testNonZeros();
94    testReset();
95    testClear();
96    testSwap();
97    testIsDefault();
98 }
99 //*************************************************************************************************
100 
101 
102 
103 
104 //=================================================================================================
105 //
106 //  TEST FUNCTIONS
107 //
108 //=================================================================================================
109 
110 //*************************************************************************************************
111 /*!\brief Test of the CustomVector constructors.
112 //
113 // \return void
114 // \exception std::runtime_error Error detected.
115 //
116 // This function performs a test of all constructors of the CustomVector class template.
117 // In case an error is detected, a \a std::runtime_error exception is thrown.
118 */
testConstructors()119 void AlignedPaddedTest::testConstructors()
120 {
121    //=====================================================================================
122    // Default constructor
123    //=====================================================================================
124 
125    {
126       test_ = "CustomVector default constructor";
127 
128       VT vec;
129 
130       checkSize    ( vec, 0UL );
131       checkNonZeros( vec, 0UL );
132    }
133 
134 
135    //=====================================================================================
136    // Constructor ( Type*, size_t, size_t )
137    //=====================================================================================
138 
139    {
140       test_ = "CustomVector constructor ( Type*, size_t, size_t )";
141 
142       // Constructing a custom vector of size 10
143       {
144          std::unique_ptr<int[],blaze::Deallocate> memory( blaze::allocate<int>( 16UL ) );
145          VT vec( memory.get(), 10UL, 16UL );
146 
147          checkSize    ( vec, 10UL );
148          checkCapacity( vec, 16UL );
149       }
150 
151       // Trying to construct a custom vector with invalid array of elements
152       try {
153          VT vec( nullptr, 0UL, 0UL );
154 
155          std::ostringstream oss;
156          oss << " Test: " << test_ << "\n"
157              << " Error: Constructing a custom vector with a nullptr succeeded\n";
158          throw std::runtime_error( oss.str() );
159       }
160       catch( std::invalid_argument& ) {}
161 
162       // Trying to construct a custom vector with invalid alignment
163       if( blaze::AlignmentOf<int>::value > sizeof(int) )
164       {
165          try {
166             std::unique_ptr<int[],blaze::Deallocate> memory( blaze::allocate<int>( 17UL ) );
167             VT vec( memory.get()+1UL, 4UL, 16UL );
168 
169             std::ostringstream oss;
170             oss << " Test: " << test_ << "\n"
171                 << " Error: Constructing a custom vector with invalid alignment succeeded\n"
172                 << " Details:\n"
173                 << "   Result:\n" << vec << "\n";
174             throw std::runtime_error( oss.str() );
175          }
176          catch( std::invalid_argument& ) {}
177       }
178 
179       // Trying to construct a custom vector with invalid padding
180       if( blaze::IsVectorizable<int>::value )
181       {
182          try {
183             std::unique_ptr<int[],blaze::Deallocate> memory( blaze::allocate<int>( 3UL ) );
184             VT vec( memory.get(), 2UL, 3UL );
185 
186             std::ostringstream oss;
187             oss << " Test: " << test_ << "\n"
188                 << " Error: Constructing a custom vector with invalid padding succeeded\n"
189                 << " Details:\n"
190                 << "   Result:\n" << vec << "\n";
191             throw std::runtime_error( oss.str() );
192          }
193          catch( std::invalid_argument& ) {}
194       }
195    }
196 
197 
198    //=====================================================================================
199    // Copy constructor
200    //=====================================================================================
201 
202    {
203       test_ = "CustomVector copy constructor (size 0)";
204 
205       VT vec1;
206       VT vec2( vec1 );
207 
208       checkSize    ( vec2, 0UL );
209       checkNonZeros( vec2, 0UL );
210    }
211 
212    {
213       test_ = "CustomVector copy constructor (size 5)";
214 
215       std::unique_ptr<int[],blaze::Deallocate> memory( blaze::allocate<int>( 16UL ) );
216       VT vec1( memory.get(), 5UL, 16UL );
217       vec1[0] = 1;
218       vec1[1] = 2;
219       vec1[2] = 3;
220       vec1[3] = 4;
221       vec1[4] = 5;
222 
223       VT vec2( vec1 );
224 
225       checkSize    ( vec2, 5UL );
226       checkCapacity( vec2, 5UL );
227       checkNonZeros( vec2, 5UL );
228 
229       if( vec1.data() != vec2.data() ||
230           vec2[0] != 1 || vec2[1] != 2 || vec2[2] != 3 || vec2[3] != 4 || vec2[4] != 5 ) {
231          std::ostringstream oss;
232          oss << " Test: " << test_ << "\n"
233              << " Error: Construction failed\n"
234              << " Details:\n"
235              << "   Result:\n" << vec2 << "\n"
236              << "   Expected result:\n( 1 2 3 4 5 )\n";
237          throw std::runtime_error( oss.str() );
238       }
239    }
240 
241 
242    //=====================================================================================
243    // Move constructor
244    //=====================================================================================
245 
246    {
247       test_ = "CustomVector move constructor (size 0)";
248 
249       VT vec1;
250       VT vec2( std::move( vec1 ) );
251 
252       checkSize    ( vec2, 0UL );
253       checkNonZeros( vec2, 0UL );
254    }
255 
256    {
257       test_ = "CustomVector copy constructor (size 5)";
258 
259       std::unique_ptr<int[],blaze::Deallocate> memory( blaze::allocate<int>( 16UL ) );
260       VT vec1( memory.get(), 5UL, 16UL );
261       vec1[0] = 1;
262       vec1[1] = 2;
263       vec1[2] = 3;
264       vec1[3] = 4;
265       vec1[4] = 5;
266 
267       VT vec2( std::move( vec1 ) );
268 
269       checkSize    ( vec2, 5UL );
270       checkCapacity( vec2, 5UL );
271       checkNonZeros( vec2, 5UL );
272 
273       if( vec2[0] != 1 || vec2[1] != 2 || vec2[2] != 3 || vec2[3] != 4 || vec2[4] != 5 ) {
274          std::ostringstream oss;
275          oss << " Test: " << test_ << "\n"
276              << " Error: Construction failed\n"
277              << " Details:\n"
278              << "   Result:\n" << vec2 << "\n"
279              << "   Expected result:\n( 1 2 3 4 5 )\n";
280          throw std::runtime_error( oss.str() );
281       }
282    }
283 }
284 //*************************************************************************************************
285 
286 
287 //*************************************************************************************************
288 /*!\brief Test of the CustomVector assignment operators.
289 //
290 // \return void
291 // \exception std::runtime_error Error detected.
292 //
293 // This function performs a test of all assignment operators of the CustomVector class template.
294 // In case an error is detected, a \a std::runtime_error exception is thrown.
295 */
testAssignment()296 void AlignedPaddedTest::testAssignment()
297 {
298    //=====================================================================================
299    // Homogeneous assignment
300    //=====================================================================================
301 
302    {
303       test_ = "CustomVector homogeneous assignment";
304 
305       std::unique_ptr<int[],blaze::Deallocate> memory( blaze::allocate<int>( 16UL ) );
306       VT vec( memory.get(), 3UL, 16UL );
307       vec = 2;
308 
309       checkSize    ( vec, 3UL );
310       checkCapacity( vec, 3UL );
311       checkNonZeros( vec, 3UL );
312 
313       if( vec[0] != 2 || vec[1] != 2 || vec[2] != 2 ) {
314          std::ostringstream oss;
315          oss << " Test: " << test_ << "\n"
316              << " Error: Assignment failed\n"
317              << " Details:\n"
318              << "   Result:\n" << vec << "\n"
319              << "   Expected result:\n( 2 2 2 )\n";
320          throw std::runtime_error( oss.str() );
321       }
322    }
323 
324 
325    //=====================================================================================
326    // List assignment
327    //=====================================================================================
328 
329    {
330       test_ = "CustomVector initializer list assignment (complete list)";
331 
332       std::unique_ptr<int[],blaze::Deallocate> memory( blaze::allocate<int>( 16UL ) );
333       VT vec( memory.get(), 4UL, 16UL );
334       vec = { 1, 2, 3, 4 };
335 
336       checkSize    ( vec, 4UL );
337       checkCapacity( vec, 4UL );
338       checkNonZeros( vec, 4UL );
339 
340       if( vec[0] != 1 || vec[1] != 2 || vec[2] != 3 || vec[3] != 4 ) {
341          std::ostringstream oss;
342          oss << " Test: " << test_ << "\n"
343              << " Error: Assignment failed\n"
344              << " Details:\n"
345              << "   Result:\n" << vec << "\n"
346              << "   Expected result:\n( 1 2 3 4 )\n";
347          throw std::runtime_error( oss.str() );
348       }
349    }
350 
351    {
352       test_ = "CustomVector initializer list assignment (incomplete list)";
353 
354       std::unique_ptr<int[],blaze::Deallocate> memory( blaze::allocate<int>( 16UL ) );
355       VT vec( memory.get(), 4UL, 16UL );
356       vec = { 1, 2 };
357 
358       checkSize    ( vec, 4UL );
359       checkCapacity( vec, 4UL );
360       checkNonZeros( vec, 2UL );
361 
362       if( vec[0] != 1 || vec[1] != 2 || vec[2] != 0 || vec[3] != 0 ) {
363          std::ostringstream oss;
364          oss << " Test: " << test_ << "\n"
365              << " Error: Assignment failed\n"
366              << " Details:\n"
367              << "   Result:\n" << vec << "\n"
368              << "   Expected result:\n( 1 2 0 0 )\n";
369          throw std::runtime_error( oss.str() );
370       }
371    }
372 
373 
374    //=====================================================================================
375    // Array assignment
376    //=====================================================================================
377 
378    {
379       test_ = "CustomVector static array assignment";
380 
381       const int array[4] = { 1, 2, 3, 4 };
382       std::unique_ptr<int[],blaze::Deallocate> memory( blaze::allocate<int>( 16UL ) );
383       VT vec( memory.get(), 4UL, 16UL );
384       vec = array;
385 
386       checkSize    ( vec, 4UL );
387       checkCapacity( vec, 4UL );
388       checkNonZeros( vec, 4UL );
389 
390       if( vec[0] != 1 || vec[1] != 2 || vec[2] != 3 || vec[3] != 4 ) {
391          std::ostringstream oss;
392          oss << " Test: " << test_ << "\n"
393              << " Error: Assignment failed\n"
394              << " Details:\n"
395              << "   Result:\n" << vec << "\n"
396              << "   Expected result:\n( 1 2 3 4 )\n";
397          throw std::runtime_error( oss.str() );
398       }
399    }
400 
401    {
402       test_ = "CustomVector std::array assignment";
403 
404       const std::array<int,4UL> array{ 1, 2, 3, 4 };
405       std::unique_ptr<int[],blaze::Deallocate> memory( blaze::allocate<int>( 16UL ) );
406       VT vec( memory.get(), 4UL, 16UL );
407       vec = array;
408 
409       checkSize    ( vec, 4UL );
410       checkCapacity( vec, 4UL );
411       checkNonZeros( vec, 4UL );
412 
413       if( vec[0] != 1 || vec[1] != 2 || vec[2] != 3 || vec[3] != 4 ) {
414          std::ostringstream oss;
415          oss << " Test: " << test_ << "\n"
416              << " Error: Assignment failed\n"
417              << " Details:\n"
418              << "   Result:\n" << vec << "\n"
419              << "   Expected result:\n( 1 2 3 4 )\n";
420          throw std::runtime_error( oss.str() );
421       }
422    }
423 
424 
425    //=====================================================================================
426    // Copy assignment
427    //=====================================================================================
428 
429    {
430       test_ = "CustomVector copy assignment";
431 
432       std::unique_ptr<int[],blaze::Deallocate> memory1( blaze::allocate<int>( 16UL ) );
433       VT vec1( memory1.get(), 5UL, 16UL );
434       vec1[0] = 1;
435       vec1[1] = 2;
436       vec1[2] = 3;
437       vec1[3] = 4;
438       vec1[4] = 5;
439 
440       std::unique_ptr<int[],blaze::Deallocate> memory2( blaze::allocate<int>( 16UL ) );
441       VT vec2( memory2.get(), 5UL, 16UL );
442       vec2 = vec1;
443 
444       checkSize    ( vec2, 5UL );
445       checkCapacity( vec2, 5UL );
446       checkNonZeros( vec2, 5UL );
447 
448       if( vec2[0] != 1 || vec2[1] != 2 || vec2[2] != 3 || vec2[3] != 4 || vec2[4] != 5 ) {
449          std::ostringstream oss;
450          oss << " Test: " << test_ << "\n"
451              << " Error: Assignment failed\n"
452              << " Details:\n"
453              << "   Result:\n" << vec2 << "\n"
454              << "   Expected result:\n( 1 2 3 4 5 )\n";
455          throw std::runtime_error( oss.str() );
456       }
457    }
458 
459 
460    //=====================================================================================
461    // Move assignment
462    //=====================================================================================
463 
464    {
465       test_ = "CustomVector move assignment";
466 
467       std::unique_ptr<int[],blaze::Deallocate> memory1( blaze::allocate<int>( 16UL ) );
468       VT vec1( memory1.get(), 5UL, 16UL );
469       vec1[0] = 1;
470       vec1[1] = 2;
471       vec1[2] = 3;
472       vec1[3] = 4;
473       vec1[4] = 5;
474 
475       std::unique_ptr<int[],blaze::Deallocate> memory2( blaze::allocate<int>( 16UL ) );
476       VT vec2( memory2.get(), 5UL, 16UL );
477       vec2 = std::move( vec1 );
478 
479       checkSize    ( vec2, 5UL );
480       checkCapacity( vec2, 5UL );
481       checkNonZeros( vec2, 5UL );
482 
483       if( vec2[0] != 1 || vec2[1] != 2 || vec2[2] != 3 || vec2[3] != 4 || vec2[4] != 5 ) {
484          std::ostringstream oss;
485          oss << " Test: " << test_ << "\n"
486              << " Error: Assignment failed\n"
487              << " Details:\n"
488              << "   Result:\n" << vec2 << "\n"
489              << "   Expected result:\n( 1 2 3 4 5 )\n";
490          throw std::runtime_error( oss.str() );
491       }
492    }
493 
494 
495    //=====================================================================================
496    // Dense vector assignment
497    //=====================================================================================
498 
499    {
500       test_ = "CustomVector dense vector assignment (mixed type)";
501 
502       using blaze::aligned;
503       using blaze::padded;
504       using blaze::rowVector;
505 
506       using AlignedPadded = blaze::CustomVector<short,aligned,padded,rowVector>;
507       std::unique_ptr<short[],blaze::Deallocate> memory1( blaze::allocate<short>( 32UL ) );
508       AlignedPadded vec1( memory1.get(), 5UL, 32UL );
509       vec1[0] = 1;
510       vec1[1] = 2;
511       vec1[2] = 3;
512       vec1[3] = 4;
513       vec1[4] = 5;
514 
515       std::unique_ptr<int[],blaze::Deallocate> memory2( blaze::allocate<int>( 16UL ) );
516       VT vec2( memory2.get(), 5UL, 16UL );
517       vec2 = vec1;
518 
519       checkSize    ( vec2, 5UL );
520       checkCapacity( vec2, 5UL );
521       checkNonZeros( vec2, 5UL );
522 
523       if( vec2[0] != 1 || vec2[1] != 2 || vec2[2] != 3 || vec2[3] != 4 || vec2[4] != 5 ) {
524          std::ostringstream oss;
525          oss << " Test: " << test_ << "\n"
526              << " Error: Assignment failed\n"
527              << " Details:\n"
528              << "   Result:\n" << vec2 << "\n"
529              << "   Expected result:\n( 1 2 3 4 5 )\n";
530          throw std::runtime_error( oss.str() );
531       }
532    }
533 
534    {
535       test_ = "CustomVector dense vector assignment (aligned/padded)";
536 
537       using blaze::aligned;
538       using blaze::padded;
539       using blaze::rowVector;
540 
541       using AlignedPadded = blaze::CustomVector<unsigned int,aligned,padded,rowVector>;
542       std::unique_ptr<unsigned int[],blaze::Deallocate> memory1( blaze::allocate<unsigned int>( 16UL ) );
543       AlignedPadded vec1( memory1.get(), 5UL, 16UL );
544       vec1[0] = 1U;
545       vec1[1] = 2U;
546       vec1[2] = 3U;
547       vec1[3] = 4U;
548       vec1[4] = 5U;
549 
550       std::unique_ptr<int[],blaze::Deallocate> memory2( blaze::allocate<int>( 16UL ) );
551       VT vec2( memory2.get(), 5UL, 16UL );
552       vec2 = vec1;
553 
554       checkSize    ( vec2, 5UL );
555       checkCapacity( vec2, 5UL );
556       checkNonZeros( vec2, 5UL );
557 
558       if( vec2[0] != 1 || vec2[1] != 2 || vec2[2] != 3 || vec2[3] != 4 || vec2[4] != 5 ) {
559          std::ostringstream oss;
560          oss << " Test: " << test_ << "\n"
561              << " Error: Assignment failed\n"
562              << " Details:\n"
563              << "   Result:\n" << vec2 << "\n"
564              << "   Expected result:\n( 1 2 3 4 5 )\n";
565          throw std::runtime_error( oss.str() );
566       }
567    }
568 
569    {
570       test_ = "CustomVector dense vector assignment (unaligned/unpadded)";
571 
572       using blaze::unaligned;
573       using blaze::unpadded;
574       using blaze::rowVector;
575 
576       using UnalignedUnpadded = blaze::CustomVector<int,unaligned,unpadded,rowVector>;
577       std::unique_ptr<int[]> memory1( new int[6UL] );
578       UnalignedUnpadded vec1( memory1.get()+1UL, 5UL );
579       vec1[0] = 1;
580       vec1[1] = 2;
581       vec1[2] = 3;
582       vec1[3] = 4;
583       vec1[4] = 5;
584 
585       std::unique_ptr<int[],blaze::Deallocate> memory2( blaze::allocate<int>( 16UL ) );
586       VT vec2( memory2.get(), 5UL, 16UL );
587       vec2 = vec1;
588 
589       checkSize    ( vec2, 5UL );
590       checkCapacity( vec2, 5UL );
591       checkNonZeros( vec2, 5UL );
592 
593       if( vec2[0] != 1 || vec2[1] != 2 || vec2[2] != 3 || vec2[3] != 4 || vec2[4] != 5 ) {
594          std::ostringstream oss;
595          oss << " Test: " << test_ << "\n"
596              << " Error: Assignment failed\n"
597              << " Details:\n"
598              << "   Result:\n" << vec2 << "\n"
599              << "   Expected result:\n( 1 2 3 4 5 )\n";
600          throw std::runtime_error( oss.str() );
601       }
602    }
603 
604 
605    //=====================================================================================
606    // Sparse vector assignment
607    //=====================================================================================
608 
609    {
610       test_ = "CustomVector sparse vector assignment";
611 
612       blaze::CompressedVector<int,blaze::rowVector> vec1( 5UL );
613       vec1[0] = 1;
614       vec1[2] = 2;
615       vec1[3] = 3;
616 
617       std::unique_ptr<int[],blaze::Deallocate> memory( blaze::allocate<int>( 16UL ) );
618       VT vec2( memory.get(), 5UL, 16UL );
619       vec2 = vec1;
620 
621       checkSize    ( vec2, 5UL );
622       checkCapacity( vec2, 5UL );
623       checkNonZeros( vec2, 3UL );
624 
625       if( vec2[0] != 1 || vec2[1] != 0 || vec2[2] != 2 || vec2[3] != 3 || vec2[4] != 0 ) {
626          std::ostringstream oss;
627          oss << " Test: " << test_ << "\n"
628              << " Error: Assignment failed\n"
629              << " Details:\n"
630              << "   Result:\n" << vec2 << "\n"
631              << "   Expected result:\n( 1 0 2 3 0 )\n";
632          throw std::runtime_error( oss.str() );
633       }
634    }
635 }
636 //*************************************************************************************************
637 
638 
639 //*************************************************************************************************
640 /*!\brief Test of the CustomVector addition assignment operators.
641 //
642 // \return void
643 // \exception std::runtime_error Error detected.
644 //
645 // This function performs a test of the addition assignment operators of the CustomVector class
646 // template. In case an error is detected, a \a std::runtime_error exception is thrown.
647 */
testAddAssign()648 void AlignedPaddedTest::testAddAssign()
649 {
650    //=====================================================================================
651    // Dense vector addition assignment
652    //=====================================================================================
653 
654    {
655       test_ = "CustomVector dense vector addition assignment (mixed type)";
656 
657       using blaze::aligned;
658       using blaze::padded;
659       using blaze::rowVector;
660 
661       using AlignedPadded = blaze::CustomVector<short,aligned,padded,rowVector>;
662       std::unique_ptr<short[],blaze::Deallocate> memory1( blaze::allocate<short>( 32UL ) );
663       AlignedPadded vec1( memory1.get(), 5UL, 32UL );
664       vec1[0] =  1;
665       vec1[1] =  0;
666       vec1[2] = -2;
667       vec1[3] =  3;
668       vec1[4] =  0;
669 
670       std::unique_ptr<int[],blaze::Deallocate> memory2( blaze::allocate<int>( 16UL ) );
671       VT vec2( memory2.get(), 5UL, 16UL );
672       vec2[0] =  0;
673       vec2[1] =  4;
674       vec2[2] =  2;
675       vec2[3] = -6;
676       vec2[4] =  7;
677 
678       vec2 += vec1;
679 
680       checkSize    ( vec2, 5UL );
681       checkCapacity( vec2, 5UL );
682       checkNonZeros( vec2, 4UL );
683 
684       if( vec2[0] != 1 || vec2[1] != 4 || vec2[2] != 0 || vec2[3] != -3 || vec2[4] != 7 ) {
685          std::ostringstream oss;
686          oss << " Test: " << test_ << "\n"
687              << " Error: Addition assignment failed\n"
688              << " Details:\n"
689              << "   Result:\n" << vec2 << "\n"
690              << "   Expected result:\n( 1 4 0 -3 7 )\n";
691          throw std::runtime_error( oss.str() );
692       }
693    }
694 
695    {
696       test_ = "CustomVector dense vector addition assignment (aligned/padded)";
697 
698       using blaze::aligned;
699       using blaze::padded;
700       using blaze::rowVector;
701 
702       using AlignedPadded = blaze::CustomVector<int,aligned,padded,rowVector>;
703       std::unique_ptr<int[],blaze::Deallocate> memory1( blaze::allocate<int>( 16UL ) );
704       AlignedPadded vec1( memory1.get(), 5UL, 16UL );
705       vec1[0] =  1;
706       vec1[1] =  0;
707       vec1[2] = -2;
708       vec1[3] =  3;
709       vec1[4] =  0;
710 
711       std::unique_ptr<int[],blaze::Deallocate> memory2( blaze::allocate<int>( 16UL ) );
712       VT vec2( memory2.get(), 5UL, 16UL );
713       vec2[0] =  0;
714       vec2[1] =  4;
715       vec2[2] =  2;
716       vec2[3] = -6;
717       vec2[4] =  7;
718 
719       vec2 += vec1;
720 
721       checkSize    ( vec2, 5UL );
722       checkCapacity( vec2, 5UL );
723       checkNonZeros( vec2, 4UL );
724 
725       if( vec2[0] != 1 || vec2[1] != 4 || vec2[2] != 0 || vec2[3] != -3 || vec2[4] != 7 ) {
726          std::ostringstream oss;
727          oss << " Test: " << test_ << "\n"
728              << " Error: Addition assignment failed\n"
729              << " Details:\n"
730              << "   Result:\n" << vec2 << "\n"
731              << "   Expected result:\n( 1 4 0 -3 7 )\n";
732          throw std::runtime_error( oss.str() );
733       }
734    }
735 
736    {
737       test_ = "CustomVector dense vector addition assignment (unaligned/unpadded)";
738 
739       using blaze::unaligned;
740       using blaze::unpadded;
741       using blaze::rowVector;
742 
743       using UnalignedUnpadded = blaze::CustomVector<int,unaligned,unpadded,rowVector>;
744       std::unique_ptr<int[]> memory1( new int[6UL] );
745       UnalignedUnpadded vec1( memory1.get()+1UL, 5UL );
746       vec1[0] =  1;
747       vec1[1] =  0;
748       vec1[2] = -2;
749       vec1[3] =  3;
750       vec1[4] =  0;
751 
752       std::unique_ptr<int[],blaze::Deallocate> memory2( blaze::allocate<int>( 16UL ) );
753       VT vec2( memory2.get(), 5UL, 16UL );
754       vec2[0] =  0;
755       vec2[1] =  4;
756       vec2[2] =  2;
757       vec2[3] = -6;
758       vec2[4] =  7;
759 
760       vec2 += vec1;
761 
762       checkSize    ( vec2, 5UL );
763       checkCapacity( vec2, 5UL );
764       checkNonZeros( vec2, 4UL );
765 
766       if( vec2[0] != 1 || vec2[1] != 4 || vec2[2] != 0 || vec2[3] != -3 || vec2[4] != 7 ) {
767          std::ostringstream oss;
768          oss << " Test: " << test_ << "\n"
769              << " Error: Addition assignment failed\n"
770              << " Details:\n"
771              << "   Result:\n" << vec2 << "\n"
772              << "   Expected result:\n( 1 4 0 -3 7 )\n";
773          throw std::runtime_error( oss.str() );
774       }
775    }
776 
777 
778    //=====================================================================================
779    // Sparse vector addition assignment
780    //=====================================================================================
781 
782    {
783       test_ = "CustomVector sparse vector addition assignment";
784 
785       blaze::CompressedVector<int,blaze::rowVector> vec1( 5UL, 3UL );
786       vec1[0] =  1;
787       vec1[2] = -2;
788       vec1[3] =  3;
789 
790       std::unique_ptr<int[],blaze::Deallocate> memory( blaze::allocate<int>( 16UL ) );
791       VT vec2( memory.get(), 5UL, 16UL );
792       vec2[0] =  0;
793       vec2[1] =  4;
794       vec2[2] =  2;
795       vec2[3] = -6;
796       vec2[4] =  7;
797 
798       vec2 += vec1;
799 
800       checkSize    ( vec2, 5UL );
801       checkCapacity( vec2, 5UL );
802       checkNonZeros( vec2, 4UL );
803 
804       if( vec2[0] != 1 || vec2[1] != 4 || vec2[2] != 0 || vec2[3] != -3 || vec2[4] != 7 ) {
805          std::ostringstream oss;
806          oss << " Test: " << test_ << "\n"
807              << " Error: Addition assignment failed\n"
808              << " Details:\n"
809              << "   Result:\n" << vec2 << "\n"
810              << "   Expected result:\n( 1 4 0 -3 7 )\n";
811          throw std::runtime_error( oss.str() );
812       }
813    }
814 }
815 //*************************************************************************************************
816 
817 
818 //*************************************************************************************************
819 /*!\brief Test of the CustomVector subtraction assignment operators.
820 //
821 // \return void
822 // \exception std::runtime_error Error detected.
823 //
824 // This function performs a test of the subtraction assignment operators of the CustomVector class
825 // template. In case an error is detected, a \a std::runtime_error exception is thrown.
826 */
testSubAssign()827 void AlignedPaddedTest::testSubAssign()
828 {
829    //=====================================================================================
830    // Dense vector subtraction assignment
831    //=====================================================================================
832 
833    {
834       test_ = "CustomVector dense vector subtraction assignment (mixed type)";
835 
836       using blaze::aligned;
837       using blaze::padded;
838       using blaze::rowVector;
839 
840       using AlignedPadded = blaze::CustomVector<short,aligned,padded,rowVector>;
841       std::unique_ptr<short[],blaze::Deallocate> memory1( blaze::allocate<short>( 32UL ) );
842       AlignedPadded vec1( memory1.get(), 5UL, 32UL );
843       vec1[0] = -1;
844       vec1[1] =  0;
845       vec1[2] =  2;
846       vec1[3] = -3;
847       vec1[4] =  0;
848 
849       std::unique_ptr<int[],blaze::Deallocate> memory2( blaze::allocate<int>( 16UL ) );
850       VT vec2( memory2.get(), 5UL, 16UL );
851       vec2[0] =  0;
852       vec2[1] =  4;
853       vec2[2] =  2;
854       vec2[3] = -6;
855       vec2[4] =  7;
856 
857       vec2 -= vec1;
858 
859       checkSize    ( vec2, 5UL );
860       checkCapacity( vec2, 5UL );
861       checkNonZeros( vec2, 4UL );
862 
863       if( vec2[0] != 1 || vec2[1] != 4 || vec2[2] != 0 || vec2[3] != -3 || vec2[4] != 7 ) {
864          std::ostringstream oss;
865          oss << " Test: " << test_ << "\n"
866              << " Error: Subtraction assignment failed\n"
867              << " Details:\n"
868              << "   Result:\n" << vec2 << "\n"
869              << "   Expected result:\n( 1 4 0 -3 7 )\n";
870          throw std::runtime_error( oss.str() );
871       }
872    }
873 
874    {
875       test_ = "CustomVector dense vector subtraction assignment (aligned/padded)";
876 
877       using blaze::aligned;
878       using blaze::padded;
879       using blaze::rowVector;
880 
881       using AlignedPadded = blaze::CustomVector<int,aligned,padded,rowVector>;
882       std::unique_ptr<int[],blaze::Deallocate> memory1( blaze::allocate<int>( 16UL ) );
883       AlignedPadded vec1( memory1.get(), 5UL, 16UL );
884       vec1[0] = -1;
885       vec1[1] =  0;
886       vec1[2] =  2;
887       vec1[3] = -3;
888       vec1[4] =  0;
889 
890       std::unique_ptr<int[],blaze::Deallocate> memory2( blaze::allocate<int>( 16UL ) );
891       VT vec2( memory2.get(), 5UL, 16UL );
892       vec2[0] =  0;
893       vec2[1] =  4;
894       vec2[2] =  2;
895       vec2[3] = -6;
896       vec2[4] =  7;
897 
898       vec2 -= vec1;
899 
900       checkSize    ( vec2, 5UL );
901       checkCapacity( vec2, 5UL );
902       checkNonZeros( vec2, 4UL );
903 
904       if( vec2[0] != 1 || vec2[1] != 4 || vec2[2] != 0 || vec2[3] != -3 || vec2[4] != 7 ) {
905          std::ostringstream oss;
906          oss << " Test: " << test_ << "\n"
907              << " Error: Subtraction assignment failed\n"
908              << " Details:\n"
909              << "   Result:\n" << vec2 << "\n"
910              << "   Expected result:\n( 1 4 0 -3 7 )\n";
911          throw std::runtime_error( oss.str() );
912       }
913    }
914 
915    {
916       test_ = "CustomVector dense vector subtraction assignment (unaligned/unpadded)";
917 
918       using blaze::unaligned;
919       using blaze::unpadded;
920       using blaze::rowVector;
921 
922       using UnalignedUnpadded = blaze::CustomVector<int,unaligned,unpadded,rowVector>;
923       std::unique_ptr<int[]> memory1( new int[6UL] );
924       UnalignedUnpadded vec1( memory1.get()+1UL, 5UL );
925       vec1[0] = -1;
926       vec1[1] =  0;
927       vec1[2] =  2;
928       vec1[3] = -3;
929       vec1[4] =  0;
930 
931       std::unique_ptr<int[],blaze::Deallocate> memory2( blaze::allocate<int>( 16UL ) );
932       VT vec2( memory2.get(), 5UL, 16UL );
933       vec2[0] =  0;
934       vec2[1] =  4;
935       vec2[2] =  2;
936       vec2[3] = -6;
937       vec2[4] =  7;
938 
939       vec2 -= vec1;
940 
941       checkSize    ( vec2, 5UL );
942       checkCapacity( vec2, 5UL );
943       checkNonZeros( vec2, 4UL );
944 
945       if( vec2[0] != 1 || vec2[1] != 4 || vec2[2] != 0 || vec2[3] != -3 || vec2[4] != 7 ) {
946          std::ostringstream oss;
947          oss << " Test: " << test_ << "\n"
948              << " Error: Subtraction assignment failed\n"
949              << " Details:\n"
950              << "   Result:\n" << vec2 << "\n"
951              << "   Expected result:\n( 1 4 0 -3 7 )\n";
952          throw std::runtime_error( oss.str() );
953       }
954    }
955 
956 
957    //=====================================================================================
958    // Sparse vector subtraction assignment
959    //=====================================================================================
960 
961    {
962       test_ = "CustomVector sparse vector subtraction assignment";
963 
964       blaze::CompressedVector<int,blaze::rowVector> vec1( 5UL, 3UL );
965       vec1[0] = -1;
966       vec1[2] =  2;
967       vec1[3] = -3;
968 
969       std::unique_ptr<int[],blaze::Deallocate> memory( blaze::allocate<int>( 16UL ) );
970       VT vec2( memory.get(), 5UL, 16UL );
971       vec2[0] =  0;
972       vec2[1] =  4;
973       vec2[2] =  2;
974       vec2[3] = -6;
975       vec2[4] =  7;
976 
977       vec2 -= vec1;
978 
979       checkSize    ( vec2, 5UL );
980       checkCapacity( vec2, 5UL );
981       checkNonZeros( vec2, 4UL );
982 
983       if( vec2[0] != 1 || vec2[1] != 4 || vec2[2] != 0 || vec2[3] != -3 || vec2[4] != 7 ) {
984          std::ostringstream oss;
985          oss << " Test: " << test_ << "\n"
986              << " Error: Subtraction assignment failed\n"
987              << " Details:\n"
988              << "   Result:\n" << vec2 << "\n"
989              << "   Expected result:\n( 1 4 0 -3 7 )\n";
990          throw std::runtime_error( oss.str() );
991       }
992    }
993 }
994 //*************************************************************************************************
995 
996 
997 //*************************************************************************************************
998 /*!\brief Test of the CustomVector multiplication assignment operators.
999 //
1000 // \return void
1001 // \exception std::runtime_error Error detected.
1002 //
1003 // This function performs a test of the multiplication assignment operators of the CustomVector
1004 // class template. In case an error is detected, a \a std::runtime_error exception is thrown.
1005 */
testMultAssign()1006 void AlignedPaddedTest::testMultAssign()
1007 {
1008    //=====================================================================================
1009    // Dense vector multiplication assignment
1010    //=====================================================================================
1011 
1012    {
1013       test_ = "CustomVector dense vector multiplication assignment (mixed type)";
1014 
1015       using blaze::aligned;
1016       using blaze::padded;
1017       using blaze::rowVector;
1018 
1019       using AlignedPadded = blaze::CustomVector<short,aligned,padded,rowVector>;
1020       std::unique_ptr<short[],blaze::Deallocate> memory1( blaze::allocate<short>( 32UL ) );
1021       AlignedPadded vec1( memory1.get(), 5UL, 32UL );
1022       vec1[0] =  1;
1023       vec1[1] =  0;
1024       vec1[2] = -2;
1025       vec1[3] =  3;
1026       vec1[4] =  0;
1027 
1028       std::unique_ptr<int[],blaze::Deallocate> memory2( blaze::allocate<int>( 16UL ) );
1029       VT vec2( memory2.get(), 5UL, 16UL );
1030       vec2[0] =  0;
1031       vec2[1] =  4;
1032       vec2[2] =  2;
1033       vec2[3] = -6;
1034       vec2[4] =  7;
1035 
1036       vec2 *= vec1;
1037 
1038       checkSize    ( vec2, 5UL );
1039       checkCapacity( vec2, 5UL );
1040       checkNonZeros( vec2, 2UL );
1041 
1042       if( vec2[0] != 0 || vec2[1] != 0 || vec2[2] != -4 || vec2[3] != -18 || vec2[4] != 0 ) {
1043          std::ostringstream oss;
1044          oss << " Test: " << test_ << "\n"
1045              << " Error: Multiplication assignment failed\n"
1046              << " Details:\n"
1047              << "   Result:\n" << vec2 << "\n"
1048              << "   Expected result:\n( 0 0 -4 -18 0 )\n";
1049          throw std::runtime_error( oss.str() );
1050       }
1051    }
1052 
1053    {
1054       test_ = "CustomVector dense vector multiplication assignment (aligned/padded)";
1055 
1056       using blaze::aligned;
1057       using blaze::padded;
1058       using blaze::rowVector;
1059 
1060       using AlignedPadded = blaze::CustomVector<int,aligned,padded,rowVector>;
1061       std::unique_ptr<int[],blaze::Deallocate> memory1( blaze::allocate<int>( 16UL ) );
1062       AlignedPadded vec1( memory1.get(), 5UL, 16UL );
1063       vec1[0] =  1;
1064       vec1[1] =  0;
1065       vec1[2] = -2;
1066       vec1[3] =  3;
1067       vec1[4] =  0;
1068 
1069       std::unique_ptr<int[],blaze::Deallocate> memory2( blaze::allocate<int>( 16UL ) );
1070       VT vec2( memory2.get(), 5UL, 16UL );
1071       vec2[0] =  0;
1072       vec2[1] =  4;
1073       vec2[2] =  2;
1074       vec2[3] = -6;
1075       vec2[4] =  7;
1076 
1077       vec2 *= vec1;
1078 
1079       checkSize    ( vec2, 5UL );
1080       checkCapacity( vec2, 5UL );
1081       checkNonZeros( vec2, 2UL );
1082 
1083       if( vec2[0] != 0 || vec2[1] != 0 || vec2[2] != -4 || vec2[3] != -18 || vec2[4] != 0 ) {
1084          std::ostringstream oss;
1085          oss << " Test: " << test_ << "\n"
1086              << " Error: Multiplication assignment failed\n"
1087              << " Details:\n"
1088              << "   Result:\n" << vec2 << "\n"
1089              << "   Expected result:\n( 0 0 -4 -18 0 )\n";
1090          throw std::runtime_error( oss.str() );
1091       }
1092    }
1093 
1094    {
1095       test_ = "CustomVector dense vector multiplication assignment (unaligned/unpadded)";
1096 
1097       using blaze::unaligned;
1098       using blaze::unpadded;
1099       using blaze::rowVector;
1100 
1101       using UnalignedUnpadded = blaze::CustomVector<int,unaligned,unpadded,rowVector>;
1102       std::unique_ptr<int[]> memory1( new int[6UL] );
1103       UnalignedUnpadded vec1( memory1.get()+1UL, 5UL );
1104       vec1[0] =  1;
1105       vec1[1] =  0;
1106       vec1[2] = -2;
1107       vec1[3] =  3;
1108       vec1[4] =  0;
1109 
1110       std::unique_ptr<int[],blaze::Deallocate> memory2( blaze::allocate<int>( 16UL ) );
1111       VT vec2( memory2.get(), 5UL, 16UL );
1112       vec2[0] =  0;
1113       vec2[1] =  4;
1114       vec2[2] =  2;
1115       vec2[3] = -6;
1116       vec2[4] =  7;
1117 
1118       vec2 *= vec1;
1119 
1120       checkSize    ( vec2, 5UL );
1121       checkCapacity( vec2, 5UL );
1122       checkNonZeros( vec2, 2UL );
1123 
1124       if( vec2[0] != 0 || vec2[1] != 0 || vec2[2] != -4 || vec2[3] != -18 || vec2[4] != 0 ) {
1125          std::ostringstream oss;
1126          oss << " Test: " << test_ << "\n"
1127              << " Error: Multiplication assignment failed\n"
1128              << " Details:\n"
1129              << "   Result:\n" << vec2 << "\n"
1130              << "   Expected result:\n( 0 0 -4 -18 0 )\n";
1131          throw std::runtime_error( oss.str() );
1132       }
1133    }
1134 
1135 
1136    //=====================================================================================
1137    // Sparse vector multiplication assignment
1138    //=====================================================================================
1139 
1140    {
1141       test_ = "CustomVector sparse vector multiplication assignment";
1142 
1143       blaze::CompressedVector<int,blaze::rowVector> vec1( 5UL, 3UL );
1144       vec1[0] =  1;
1145       vec1[2] = -2;
1146       vec1[3] =  3;
1147 
1148       std::unique_ptr<int[],blaze::Deallocate> memory( blaze::allocate<int>( 16UL ) );
1149       VT vec2( memory.get(), 5UL, 16UL );
1150       vec2[0] =  0;
1151       vec2[1] =  4;
1152       vec2[2] =  2;
1153       vec2[3] = -6;
1154       vec2[4] =  7;
1155 
1156       vec2 *= vec1;
1157 
1158       checkSize    ( vec2, 5UL );
1159       checkCapacity( vec2, 5UL );
1160       checkNonZeros( vec2, 2UL );
1161 
1162       if( vec2[0] != 0 || vec2[1] != 0 || vec2[2] != -4 || vec2[3] != -18 || vec2[4] != 0 ) {
1163          std::ostringstream oss;
1164          oss << " Test: " << test_ << "\n"
1165              << " Error: Multiplication assignment failed\n"
1166              << " Details:\n"
1167              << "   Result:\n" << vec2 << "\n"
1168              << "   Expected result:\n( 0 0 -4 -18 0 )\n";
1169          throw std::runtime_error( oss.str() );
1170       }
1171    }
1172 }
1173 //*************************************************************************************************
1174 
1175 
1176 //*************************************************************************************************
1177 /*!\brief Test of the CustomVector division assignment operators.
1178 //
1179 // \return void
1180 // \exception std::runtime_error Error detected.
1181 //
1182 // This function performs a test of the division assignment operators of the CustomVector
1183 // class template. In case an error is detected, a \a std::runtime_error exception is thrown.
1184 */
testDivAssign()1185 void AlignedPaddedTest::testDivAssign()
1186 {
1187    //=====================================================================================
1188    // Dense vector division assignment
1189    //=====================================================================================
1190 
1191    {
1192       test_ = "CustomVector dense vector division assignment (mixed type)";
1193 
1194       using blaze::aligned;
1195       using blaze::padded;
1196       using blaze::rowVector;
1197 
1198       using AlignedPadded = blaze::CustomVector<short,aligned,padded,rowVector>;
1199       std::unique_ptr<short[],blaze::Deallocate> memory1( blaze::allocate<short>( 32UL ) );
1200       AlignedPadded vec1( memory1.get(), 5UL, 32UL );
1201       vec1[0] =  1;
1202       vec1[1] =  2;
1203       vec1[2] = -3;
1204       vec1[3] =  4;
1205       vec1[4] =  1;
1206 
1207       std::unique_ptr<int[],blaze::Deallocate> memory2( blaze::allocate<int>( 16UL ) );
1208       VT vec2( memory2.get(), 5UL, 16UL );
1209       vec2[0] =  2;
1210       vec2[1] =  0;
1211       vec2[2] = -3;
1212       vec2[3] =  8;
1213       vec2[4] =  0;
1214 
1215       vec2 /= vec1;
1216 
1217       checkSize    ( vec2, 5UL );
1218       checkCapacity( vec2, 5UL );
1219       checkNonZeros( vec2, 3UL );
1220 
1221       if( vec2[0] != 2 || vec2[1] != 0 || vec2[2] != 1 || vec2[3] != 2 || vec2[4] != 0 ) {
1222          std::ostringstream oss;
1223          oss << " Test: " << test_ << "\n"
1224              << " Error: Division assignment failed\n"
1225              << " Details:\n"
1226              << "   Result:\n" << vec2 << "\n"
1227              << "   Expected result:\n( 2 0 1 2 0 )\n";
1228          throw std::runtime_error( oss.str() );
1229       }
1230    }
1231 
1232    {
1233       test_ = "CustomVector dense vector division assignment (aligned/padded)";
1234 
1235       using blaze::aligned;
1236       using blaze::padded;
1237       using blaze::rowVector;
1238 
1239       using AlignedPadded = blaze::CustomVector<int,aligned,padded,rowVector>;
1240       std::unique_ptr<int[],blaze::Deallocate> memory1( blaze::allocate<int>( 16UL ) );
1241       AlignedPadded vec1( memory1.get(), 5UL, 16UL );
1242       vec1[0] =  1;
1243       vec1[1] =  2;
1244       vec1[2] = -3;
1245       vec1[3] =  4;
1246       vec1[4] =  1;
1247 
1248       std::unique_ptr<int[],blaze::Deallocate> memory2( blaze::allocate<int>( 16UL ) );
1249       VT vec2( memory2.get(), 5UL, 16UL );
1250       vec2[0] =  2;
1251       vec2[1] =  0;
1252       vec2[2] = -3;
1253       vec2[3] =  8;
1254       vec2[4] =  0;
1255 
1256       vec2 /= vec1;
1257 
1258       checkSize    ( vec2, 5UL );
1259       checkCapacity( vec2, 5UL );
1260       checkNonZeros( vec2, 3UL );
1261 
1262       if( vec2[0] != 2 || vec2[1] != 0 || vec2[2] != 1 || vec2[3] != 2 || vec2[4] != 0 ) {
1263          std::ostringstream oss;
1264          oss << " Test: " << test_ << "\n"
1265              << " Error: Division assignment failed\n"
1266              << " Details:\n"
1267              << "   Result:\n" << vec2 << "\n"
1268              << "   Expected result:\n( 2 0 1 2 0 )\n";
1269          throw std::runtime_error( oss.str() );
1270       }
1271    }
1272 
1273    {
1274       test_ = "CustomVector dense vector division assignment (unaligned/unpadded)";
1275 
1276       using blaze::unaligned;
1277       using blaze::unpadded;
1278       using blaze::rowVector;
1279 
1280       using UnalignedUnpadded = blaze::CustomVector<int,unaligned,unpadded,rowVector>;
1281       std::unique_ptr<int[]> memory1( new int[6UL] );
1282       UnalignedUnpadded vec1( memory1.get()+1UL, 5UL );
1283       vec1[0] =  1;
1284       vec1[1] =  2;
1285       vec1[2] = -3;
1286       vec1[3] =  4;
1287       vec1[4] =  1;
1288 
1289       std::unique_ptr<int[],blaze::Deallocate> memory2( blaze::allocate<int>( 16UL ) );
1290       VT vec2( memory2.get(), 5UL, 16UL );
1291       vec2[0] =  2;
1292       vec2[1] =  0;
1293       vec2[2] = -3;
1294       vec2[3] =  8;
1295       vec2[4] =  0;
1296 
1297       vec2 /= vec1;
1298 
1299       checkSize    ( vec2, 5UL );
1300       checkCapacity( vec2, 5UL );
1301       checkNonZeros( vec2, 3UL );
1302 
1303       if( vec2[0] != 2 || vec2[1] != 0 || vec2[2] != 1 || vec2[3] != 2 || vec2[4] != 0 ) {
1304          std::ostringstream oss;
1305          oss << " Test: " << test_ << "\n"
1306              << " Error: Division assignment failed\n"
1307              << " Details:\n"
1308              << "   Result:\n" << vec2 << "\n"
1309              << "   Expected result:\n( 2 0 1 2 0 )\n";
1310          throw std::runtime_error( oss.str() );
1311       }
1312    }
1313 }
1314 //*************************************************************************************************
1315 
1316 
1317 //*************************************************************************************************
1318 /*!\brief Test of the CustomVector cross product assignment operators.
1319 //
1320 // \return void
1321 // \exception std::runtime_error Error detected.
1322 //
1323 // This function performs a test of the cross product assignment operators of the CustomVector
1324 // class template. In case an error is detected, a \a std::runtime_error exception is thrown.
1325 */
testCrossAssign()1326 void AlignedPaddedTest::testCrossAssign()
1327 {
1328    //=====================================================================================
1329    // Dense vector cross product assignment
1330    //=====================================================================================
1331 
1332    {
1333       test_ = "CustomVector dense vector cross product assignment (mixed type)";
1334 
1335       using blaze::aligned;
1336       using blaze::padded;
1337       using blaze::rowVector;
1338 
1339       using AlignedPadded = blaze::CustomVector<short,aligned,padded,rowVector>;
1340       std::unique_ptr<short[],blaze::Deallocate> memory1( blaze::allocate<short>( 32UL ) );
1341       AlignedPadded vec1( memory1.get(), 3UL, 32UL );
1342       vec1[0] =  1;
1343       vec1[1] =  0;
1344       vec1[2] = -2;
1345 
1346       std::unique_ptr<int[],blaze::Deallocate> memory2( blaze::allocate<int>( 16UL ) );
1347       VT vec2( memory2.get(), 3UL, 16UL );
1348       vec2[0] =  2;
1349       vec2[1] =  0;
1350       vec2[2] = -1;
1351 
1352       vec2 %= vec1;
1353 
1354       checkSize    ( vec2, 3UL );
1355       checkCapacity( vec2, 3UL );
1356       checkNonZeros( vec2, 1UL );
1357 
1358       if( vec2[0] != 0 || vec2[1] != 3 || vec2[2] != 0 ) {
1359          std::ostringstream oss;
1360          oss << " Test: " << test_ << "\n"
1361              << " Error: Cross product assignment failed\n"
1362              << " Details:\n"
1363              << "   Result:\n" << vec2 << "\n"
1364              << "   Expected result:\n( 0 3 0 )\n";
1365          throw std::runtime_error( oss.str() );
1366       }
1367    }
1368 
1369    {
1370       test_ = "CustomVector dense vector cross product assignment (aligned/padded)";
1371 
1372       using blaze::aligned;
1373       using blaze::padded;
1374       using blaze::rowVector;
1375 
1376       using AlignedPadded = blaze::CustomVector<int,aligned,padded,rowVector>;
1377       std::unique_ptr<int[],blaze::Deallocate> memory1( blaze::allocate<int>( 16UL ) );
1378       AlignedPadded vec1( memory1.get(), 3UL, 16UL );
1379       vec1[0] =  1;
1380       vec1[1] =  0;
1381       vec1[2] = -2;
1382 
1383       std::unique_ptr<int[],blaze::Deallocate> memory2( blaze::allocate<int>( 16UL ) );
1384       VT vec2( memory2.get(), 3UL, 16UL );
1385       vec2[0] =  2;
1386       vec2[1] =  0;
1387       vec2[2] = -1;
1388 
1389       vec2 %= vec1;
1390 
1391       checkSize    ( vec2, 3UL );
1392       checkCapacity( vec2, 3UL );
1393       checkNonZeros( vec2, 1UL );
1394 
1395       if( vec2[0] != 0 || vec2[1] != 3 || vec2[2] != 0 ) {
1396          std::ostringstream oss;
1397          oss << " Test: " << test_ << "\n"
1398              << " Error: Cross product assignment failed\n"
1399              << " Details:\n"
1400              << "   Result:\n" << vec2 << "\n"
1401              << "   Expected result:\n( 0 3 0 )\n";
1402          throw std::runtime_error( oss.str() );
1403       }
1404    }
1405 
1406    {
1407       test_ = "CustomVector dense vector cross product assignment (unaligned/unpadded)";
1408 
1409       using blaze::unaligned;
1410       using blaze::unpadded;
1411       using blaze::rowVector;
1412 
1413       using UnalignedUnpadded = blaze::CustomVector<int,unaligned,unpadded,rowVector>;
1414       std::unique_ptr<int[]> memory1( new int[4UL] );
1415       UnalignedUnpadded vec1( memory1.get()+1UL, 3UL );
1416       vec1[0] =  1;
1417       vec1[1] =  0;
1418       vec1[2] = -2;
1419 
1420       std::unique_ptr<int[],blaze::Deallocate> memory2( blaze::allocate<int>( 16UL ) );
1421       VT vec2( memory2.get(), 3UL, 16UL );
1422       vec2[0] =  2;
1423       vec2[1] =  0;
1424       vec2[2] = -1;
1425 
1426       vec2 %= vec1;
1427 
1428       checkSize    ( vec2, 3UL );
1429       checkCapacity( vec2, 3UL );
1430       checkNonZeros( vec2, 1UL );
1431 
1432       if( vec2[0] != 0 || vec2[1] != 3 || vec2[2] != 0 ) {
1433          std::ostringstream oss;
1434          oss << " Test: " << test_ << "\n"
1435              << " Error: Cross product assignment failed\n"
1436              << " Details:\n"
1437              << "   Result:\n" << vec2 << "\n"
1438              << "   Expected result:\n( 0 3 0 )\n";
1439          throw std::runtime_error( oss.str() );
1440       }
1441    }
1442 
1443 
1444    //=====================================================================================
1445    // Sparse vector cross product assignment
1446    //=====================================================================================
1447 
1448    {
1449       test_ = "CustomVector sparse vector cross product assignment";
1450 
1451       blaze::CompressedVector<int,blaze::rowVector> vec1( 3UL, 2UL );
1452       vec1[0] =  1;
1453       vec1[2] = -2;
1454 
1455       std::unique_ptr<int[],blaze::Deallocate> memory( blaze::allocate<int>( 16UL ) );
1456       VT vec2( memory.get(), 3UL, 16UL );
1457       vec2[0] =  2;
1458       vec2[1] =  0;
1459       vec2[2] = -1;
1460 
1461       vec2 %= vec1;
1462 
1463       checkSize    ( vec2, 3UL );
1464       checkCapacity( vec2, 3UL );
1465       checkNonZeros( vec2, 1UL );
1466 
1467       if( vec2[0] != 0 || vec2[1] != 3 || vec2[2] != 0 ) {
1468          std::ostringstream oss;
1469          oss << " Test: " << test_ << "\n"
1470              << " Error: Cross product assignment failed\n"
1471              << " Details:\n"
1472              << "   Result:\n" << vec2 << "\n"
1473              << "   Expected result:\n( 0 3 0 )\n";
1474          throw std::runtime_error( oss.str() );
1475       }
1476    }
1477 }
1478 //*************************************************************************************************
1479 
1480 
1481 //*************************************************************************************************
1482 /*!\brief Test of all CustomVector (self-)scaling operations.
1483 //
1484 // \return void
1485 // \exception std::runtime_error Error detected.
1486 //
1487 // This function performs a test of all available ways to scale an instance of the CustomVector
1488 // class template. In case an error is detected, a \a std::runtime_error exception is thrown.
1489 */
testScaling()1490 void AlignedPaddedTest::testScaling()
1491 {
1492    //=====================================================================================
1493    // Self-scaling (v*=s)
1494    //=====================================================================================
1495 
1496    {
1497       test_ = "CustomVector self-scaling (v*=s)";
1498 
1499       std::unique_ptr<int[],blaze::Deallocate> memory( blaze::allocate<int>( 16UL ) );
1500       VT vec( memory.get(), 5UL, 16UL );
1501       vec[0] =  1;
1502       vec[1] =  0;
1503       vec[2] = -2;
1504       vec[3] =  3;
1505       vec[4] =  0;
1506 
1507       vec *= 2;
1508 
1509       checkSize    ( vec, 5UL );
1510       checkCapacity( vec, 5UL );
1511       checkNonZeros( vec, 3UL );
1512 
1513       if( vec[0] != 2 || vec[1] != 0 || vec[2] != -4 || vec[3] != 6 || vec[4] != 0 ) {
1514          std::ostringstream oss;
1515          oss << " Test: " << test_ << "\n"
1516              << " Error: Failed self-scaling operation\n"
1517              << " Details:\n"
1518              << "   Result:\n" << vec << "\n"
1519              << "   Expected result:\n( 2 0 -4 6 0 )\n";
1520          throw std::runtime_error( oss.str() );
1521       }
1522    }
1523 
1524 
1525    //=====================================================================================
1526    // Self-scaling (v=v*s)
1527    //=====================================================================================
1528 
1529    {
1530       test_ = "CustomVector self-scaling (v=v*s)";
1531 
1532       std::unique_ptr<int[],blaze::Deallocate> memory( blaze::allocate<int>( 16UL ) );
1533       VT vec( memory.get(), 5UL, 16UL );
1534       vec[0] =  1;
1535       vec[1] =  0;
1536       vec[2] = -2;
1537       vec[3] =  3;
1538       vec[4] =  0;
1539 
1540       vec = vec * 2;
1541 
1542       checkSize    ( vec, 5UL );
1543       checkCapacity( vec, 5UL );
1544       checkNonZeros( vec, 3UL );
1545 
1546       if( vec[0] != 2 || vec[1] != 0 || vec[2] != -4 || vec[3] != 6 || vec[4] != 0 ) {
1547          std::ostringstream oss;
1548          oss << " Test: " << test_ << "\n"
1549              << " Error: Failed self-scaling operation\n"
1550              << " Details:\n"
1551              << "   Result:\n" << vec << "\n"
1552              << "   Expected result:\n( 2 0 -4 6 0 )\n";
1553          throw std::runtime_error( oss.str() );
1554       }
1555    }
1556 
1557 
1558    //=====================================================================================
1559    // Self-scaling (v=s*v)
1560    //=====================================================================================
1561 
1562    {
1563       test_ = "CustomVector self-scaling (v=s*v)";
1564 
1565       std::unique_ptr<int[],blaze::Deallocate> memory( blaze::allocate<int>( 16UL ) );
1566       VT vec( memory.get(), 5UL, 16UL );
1567       vec[0] =  1;
1568       vec[1] =  0;
1569       vec[2] = -2;
1570       vec[3] =  3;
1571       vec[4] =  0;
1572 
1573       vec = 2 * vec;
1574 
1575       checkSize    ( vec, 5UL );
1576       checkCapacity( vec, 5UL );
1577       checkNonZeros( vec, 3UL );
1578 
1579       if( vec[0] != 2 || vec[1] != 0 || vec[2] != -4 || vec[3] != 6 || vec[4] != 0 ) {
1580          std::ostringstream oss;
1581          oss << " Test: " << test_ << "\n"
1582              << " Error: Failed self-scaling operation\n"
1583              << " Details:\n"
1584              << "   Result:\n" << vec << "\n"
1585              << "   Expected result:\n( 2 0 -4 6 0 )\n";
1586          throw std::runtime_error( oss.str() );
1587       }
1588    }
1589 
1590 
1591    //=====================================================================================
1592    // Self-scaling (v/=s)
1593    //=====================================================================================
1594 
1595    {
1596       test_ = "CustomVector self-scaling (v/=s)";
1597 
1598       std::unique_ptr<int[],blaze::Deallocate> memory( blaze::allocate<int>( 16UL ) );
1599       VT vec( memory.get(), 5UL, 16UL );
1600       vec[0] =  2;
1601       vec[1] =  0;
1602       vec[2] = -4;
1603       vec[3] =  6;
1604       vec[4] =  0;
1605 
1606       vec /= 2;
1607 
1608       checkSize    ( vec, 5UL );
1609       checkCapacity( vec, 5UL );
1610       checkNonZeros( vec, 3UL );
1611 
1612       if( vec[0] != 1 || vec[1] != 0 || vec[2] != -2 || vec[3] != 3 || vec[4] != 0 ) {
1613          std::ostringstream oss;
1614          oss << " Test: " << test_ << "\n"
1615              << " Error: Failed self-scaling operation\n"
1616              << " Details:\n"
1617              << "   Result:\n" << vec << "\n"
1618              << "   Expected result:\n( 1 0 -2 3 0 )\n";
1619          throw std::runtime_error( oss.str() );
1620       }
1621    }
1622 
1623 
1624    //=====================================================================================
1625    // Self-scaling (v=v/s)
1626    //=====================================================================================
1627 
1628    {
1629       test_ = "CustomVector self-scaling (v=v/s)";
1630 
1631       std::unique_ptr<int[],blaze::Deallocate> memory( blaze::allocate<int>( 16UL ) );
1632       VT vec( memory.get(), 5UL, 16UL );
1633       vec[0] =  2;
1634       vec[1] =  0;
1635       vec[2] = -4;
1636       vec[3] =  6;
1637       vec[4] =  0;
1638 
1639       vec = vec / 2;
1640 
1641       checkSize    ( vec, 5UL );
1642       checkCapacity( vec, 5UL );
1643       checkNonZeros( vec, 3UL );
1644 
1645       if( vec[0] != 1 || vec[1] != 0 || vec[2] != -2 || vec[3] != 3 || vec[4] != 0 ) {
1646          std::ostringstream oss;
1647          oss << " Test: " << test_ << "\n"
1648              << " Error: Failed self-scaling operation\n"
1649              << " Details:\n"
1650              << "   Result:\n" << vec << "\n"
1651              << "   Expected result:\n( 1 0 -2 3 0 )\n";
1652          throw std::runtime_error( oss.str() );
1653       }
1654    }
1655 
1656 
1657    //=====================================================================================
1658    // CustomVector::scale()
1659    //=====================================================================================
1660 
1661    {
1662       test_ = "CustomVector::scale() (int)";
1663 
1664       // Initialization check
1665       std::unique_ptr<int[],blaze::Deallocate> memory( blaze::allocate<int>( 16UL ) );
1666       VT vec( memory.get(), 4UL, 16UL );
1667       vec[0] = 1;
1668       vec[1] = 2;
1669       vec[2] = 3;
1670       vec[3] = 4;
1671 
1672       checkSize    ( vec, 4UL );
1673       checkCapacity( vec, 4UL );
1674       checkNonZeros( vec, 4UL );
1675 
1676       if( vec[0] != 1 || vec[1] != 2 || vec[2] != 3 || vec[3] != 4 ) {
1677          std::ostringstream oss;
1678          oss << " Test: " << test_ << "\n"
1679              << " Error: Initialization failed\n"
1680              << " Details:\n"
1681              << "   Result:\n" << vec << "\n"
1682              << "   Expected result:\n( 1 2 3 4 )\n";
1683          throw std::runtime_error( oss.str() );
1684       }
1685 
1686       // Integral scaling of the vector
1687       vec.scale( 2 );
1688 
1689       checkSize    ( vec, 4UL );
1690       checkCapacity( vec, 4UL );
1691       checkNonZeros( vec, 4UL );
1692 
1693       if( vec[0] != 2 || vec[1] != 4 || vec[2] != 6 || vec[3] != 8 ) {
1694          std::ostringstream oss;
1695          oss << " Test: " << test_ << "\n"
1696              << " Error: Scale operation failed\n"
1697              << " Details:\n"
1698              << "   Result:\n" << vec << "\n"
1699              << "   Expected result:\n( 2 4 6 8 )\n";
1700          throw std::runtime_error( oss.str() );
1701       }
1702 
1703       // Floating point scaling of the vector
1704       vec.scale( 0.5 );
1705 
1706       checkSize    ( vec, 4UL );
1707       checkCapacity( vec, 4UL );
1708       checkNonZeros( vec, 4UL );
1709 
1710       if( vec[0] != 1 || vec[1] != 2 || vec[2] != 3 || vec[3] != 4 ) {
1711          std::ostringstream oss;
1712          oss << " Test: " << test_ << "\n"
1713              << " Error: Scale operation failed\n"
1714              << " Details:\n"
1715              << "   Result:\n" << vec << "\n"
1716              << "   Expected result:\n( 1 2 3 4 )\n";
1717          throw std::runtime_error( oss.str() );
1718       }
1719    }
1720 
1721    {
1722       test_ = "CustomVector::scale() (complex)";
1723 
1724       using blaze::complex;
1725       using blaze::aligned;
1726       using blaze::padded;
1727       using blaze::rowVector;
1728 
1729       using cplx = complex<float>;
1730       using AlignedPadded = blaze::CustomVector<cplx,aligned,padded,rowVector>;
1731       std::unique_ptr<cplx[],blaze::Deallocate> memory( blaze::allocate<cplx>( 8UL ) );
1732       AlignedPadded vec( memory.get(), 2UL, 8UL );
1733       vec[0] = cplx( 1.0F, 0.0F );
1734       vec[1] = cplx( 2.0F, 0.0F );
1735       vec.scale( cplx( 3.0F, 0.0F ) );
1736 
1737       checkSize    ( vec, 2UL );
1738       checkCapacity( vec, 2UL );
1739       checkNonZeros( vec, 2UL );
1740 
1741       if( vec[0] != cplx( 3.0F, 0.0F ) || vec[1] != cplx( 6.0F, 0.0F ) ) {
1742          std::ostringstream oss;
1743          oss << " Test: " << test_ << "\n"
1744              << " Error: Scale operation failed\n"
1745              << " Details:\n"
1746              << "   Result:\n" << vec << "\n"
1747              << "   Expected result:\n( (3,0) (6,0) )\n";
1748          throw std::runtime_error( oss.str() );
1749       }
1750    }
1751 }
1752 //*************************************************************************************************
1753 
1754 
1755 //*************************************************************************************************
1756 /*!\brief Test of the CustomVector subscript operator.
1757 //
1758 // \return void
1759 // \exception std::runtime_error Error detected.
1760 //
1761 // This function performs a test of adding and accessing elements via the subscript operator
1762 // of the CustomVector class template. In case an error is detected, a \a std::runtime_error
1763 // exception is thrown.
1764 */
testSubscript()1765 void AlignedPaddedTest::testSubscript()
1766 {
1767    test_ = "CustomVector::operator[]";
1768 
1769    // Assignment to the element at index 2
1770    std::unique_ptr<int[],blaze::Deallocate> memory( blaze::allocate<int>( 16UL ) );
1771    VT vec( memory.get(), 7UL, 16UL );
1772    reset( vec );
1773    vec[2] = 1;
1774 
1775    checkSize    ( vec, 7UL );
1776    checkCapacity( vec, 7UL );
1777    checkNonZeros( vec, 1UL );
1778 
1779    if( vec[2] != 1 ) {
1780       std::ostringstream oss;
1781       oss << " Test: " << test_ << "\n"
1782           << " Error: Subscript operator failed\n"
1783           << " Details:\n"
1784           << "   Result:\n" << vec << "\n"
1785           << "   Expected result:\n( 0 0 1 0 0 0 0 )\n";
1786       throw std::runtime_error( oss.str() );
1787    }
1788 
1789    // Assignment to the element at index 5
1790    vec[5] = 2;
1791 
1792    checkSize    ( vec, 7UL );
1793    checkCapacity( vec, 7UL );
1794    checkNonZeros( vec, 2UL );
1795 
1796    if( vec[2] != 1 || vec[5] != 2 ) {
1797       std::ostringstream oss;
1798       oss << " Test: " << test_ << "\n"
1799           << " Error: Subscript operator failed\n"
1800           << " Details:\n"
1801           << "   Result:\n" << vec << "\n"
1802           << "   Expected result:\n( 0 0 1 0 0 2 0 )\n";
1803       throw std::runtime_error( oss.str() );
1804    }
1805 
1806    // Assignment to the element at index 3
1807    vec[3] = 3;
1808 
1809    checkSize    ( vec, 7UL );
1810    checkCapacity( vec, 7UL );
1811    checkNonZeros( vec, 3UL );
1812 
1813    if( vec[2] != 1 || vec[3] != 3 || vec[5] != 2 ) {
1814       std::ostringstream oss;
1815       oss << " Test: " << test_ << "\n"
1816           << " Error: Subscript operator failed\n"
1817           << " Details:\n"
1818           << "   Result:\n" << vec << "\n"
1819           << "   Expected result:\n( 0 0 1 3 0 2 0 )\n";
1820       throw std::runtime_error( oss.str() );
1821    }
1822 
1823    // Assignment to the element at index 0
1824    vec[0] = 4;
1825 
1826    checkSize    ( vec, 7UL );
1827    checkCapacity( vec, 7UL );
1828    checkNonZeros( vec, 4UL );
1829 
1830    if( vec[0] != 4 || vec[2] != 1 || vec[3] != 3 || vec[5] != 2 ) {
1831       std::ostringstream oss;
1832       oss << " Test: " << test_ << "\n"
1833           << " Error: Subscript operator failed\n"
1834           << " Details:\n"
1835           << "   Result:\n" << vec << "\n"
1836           << "   Expected result:\n( 4 0 1 3 0 2 0 )\n";
1837       throw std::runtime_error( oss.str() );
1838    }
1839 
1840    // Addition assignment to the element at index 2
1841    vec[2] += vec[3];
1842 
1843    checkSize    ( vec, 7UL );
1844    checkCapacity( vec, 7UL );
1845    checkNonZeros( vec, 4UL );
1846 
1847    if( vec[0] != 4 || vec[2] != 4 || vec[3] != 3 || vec[5] != 2 ) {
1848       std::ostringstream oss;
1849       oss << " Test: " << test_ << "\n"
1850           << " Error: Subscript operator failed\n"
1851           << " Details:\n"
1852           << "   Result:\n" << vec << "\n"
1853           << "   Expected result:\n( 4 0 4 3 0 2 0 )\n";
1854       throw std::runtime_error( oss.str() );
1855    }
1856 
1857    // Subtraction assignment to the element at index 1
1858    vec[1] -= vec[5];
1859 
1860    checkSize    ( vec, 7UL );
1861    checkCapacity( vec, 7UL );
1862    checkNonZeros( vec, 5UL );
1863 
1864    if( vec[0] != 4 || vec[1] != -2 || vec[2] != 4 || vec[3] != 3 || vec[5] != 2 ) {
1865       std::ostringstream oss;
1866       oss << " Test: " << test_ << "\n"
1867           << " Error: Subscript operator failed\n"
1868           << " Details:\n"
1869           << "   Result:\n" << vec << "\n"
1870           << "   Expected result:\n( 4 -2 4 3 0 2 0 )\n";
1871       throw std::runtime_error( oss.str() );
1872    }
1873 
1874    // Multiplication assignment to the element at index 3
1875    vec[3] *= -3;
1876 
1877    checkSize    ( vec, 7UL );
1878    checkCapacity( vec, 7UL );
1879    checkNonZeros( vec, 5UL );
1880 
1881    if( vec[0] != 4 || vec[1] != -2 || vec[2] != 4 || vec[3] != -9 || vec[5] != 2 ) {
1882       std::ostringstream oss;
1883       oss << " Test: " << test_ << "\n"
1884           << " Error: Subscript operator failed\n"
1885           << " Details:\n"
1886           << "   Result:\n" << vec << "\n"
1887           << "   Expected result:\n( 4 -2 4 -9 0 2 0 )\n";
1888       throw std::runtime_error( oss.str() );
1889    }
1890 
1891    // Division assignment to the element at index 2
1892    vec[2] /= 2;
1893 
1894    checkSize    ( vec, 7UL );
1895    checkCapacity( vec, 7UL );
1896    checkNonZeros( vec, 5UL );
1897 
1898    if( vec[0] != 4 || vec[1] != -2 || vec[2] != 2 || vec[3] != -9 || vec[5] != 2 ) {
1899       std::ostringstream oss;
1900       oss << " Test: " << test_ << "\n"
1901           << " Error: Subscript operator failed\n"
1902           << " Details:\n"
1903           << "   Result:\n" << vec << "\n"
1904           << "   Expected result:\n( 4 -2 2 -9 0 2 0 )\n";
1905       throw std::runtime_error( oss.str() );
1906    }
1907 }
1908 //*************************************************************************************************
1909 
1910 
1911 //*************************************************************************************************
1912 /*!\brief Test of the \c at() member function of the CustomVector class template.
1913 //
1914 // \return void
1915 // \exception std::runtime_error Error detected.
1916 //
1917 // This function performs a test of adding and accessing elements via the \c at() member function
1918 // of the CustomVector class template. In case an error is detected, a \a std::runtime_error
1919 // exception is thrown.
1920 */
testAt()1921 void AlignedPaddedTest::testAt()
1922 {
1923    test_ = "CustomVector::at()";
1924 
1925    // Assignment to the element at index 2
1926    std::unique_ptr<int[],blaze::Deallocate> memory( blaze::allocate<int>( 16UL ) );
1927    VT vec( memory.get(), 7UL, 16UL );
1928    reset( vec );
1929    vec.at(2) = 1;
1930 
1931    checkSize    ( vec, 7UL );
1932    checkCapacity( vec, 7UL );
1933    checkNonZeros( vec, 1UL );
1934 
1935    if( vec.at(2) != 1 ) {
1936       std::ostringstream oss;
1937       oss << " Test: " << test_ << "\n"
1938           << " Error: Access via at() function failed\n"
1939           << " Details:\n"
1940           << "   Result:\n" << vec << "\n"
1941           << "   Expected result:\n( 0 0 1 0 0 0 0 )\n";
1942       throw std::runtime_error( oss.str() );
1943    }
1944 
1945    // Assignment to the element at index 5
1946    vec.at(5) = 2;
1947 
1948    checkSize    ( vec, 7UL );
1949    checkCapacity( vec, 7UL );
1950    checkNonZeros( vec, 2UL );
1951 
1952    if( vec.at(2) != 1 || vec.at(5) != 2 ) {
1953       std::ostringstream oss;
1954       oss << " Test: " << test_ << "\n"
1955           << " Error: Access via at() function failed\n"
1956           << " Details:\n"
1957           << "   Result:\n" << vec << "\n"
1958           << "   Expected result:\n( 0 0 1 0 0 2 0 )\n";
1959       throw std::runtime_error( oss.str() );
1960    }
1961 
1962    // Assignment to the element at index 3
1963    vec.at(3) = 3;
1964 
1965    checkSize    ( vec, 7UL );
1966    checkCapacity( vec, 7UL );
1967    checkNonZeros( vec, 3UL );
1968 
1969    if( vec.at(2) != 1 || vec.at(3) != 3 || vec.at(5) != 2 ) {
1970       std::ostringstream oss;
1971       oss << " Test: " << test_ << "\n"
1972           << " Error: Access via at() function failed\n"
1973           << " Details:\n"
1974           << "   Result:\n" << vec << "\n"
1975           << "   Expected result:\n( 0 0 1 3 0 2 0 )\n";
1976       throw std::runtime_error( oss.str() );
1977    }
1978 
1979    // Assignment to the element at index 0
1980    vec.at(0) = 4;
1981 
1982    checkSize    ( vec, 7UL );
1983    checkCapacity( vec, 7UL );
1984    checkNonZeros( vec, 4UL );
1985 
1986    if( vec.at(0) != 4 || vec.at(2) != 1 || vec.at(3) != 3 || vec.at(5) != 2 ) {
1987       std::ostringstream oss;
1988       oss << " Test: " << test_ << "\n"
1989           << " Error: Access via at() function failed\n"
1990           << " Details:\n"
1991           << "   Result:\n" << vec << "\n"
1992           << "   Expected result:\n( 4 0 1 3 0 2 0 )\n";
1993       throw std::runtime_error( oss.str() );
1994    }
1995 
1996    // Addition assignment to the element at index 2
1997    vec.at(2) += vec.at(3);
1998 
1999    checkSize    ( vec, 7UL );
2000    checkCapacity( vec, 7UL );
2001    checkNonZeros( vec, 4UL );
2002 
2003    if( vec.at(0) != 4 || vec.at(2) != 4 || vec.at(3) != 3 || vec.at(5) != 2 ) {
2004       std::ostringstream oss;
2005       oss << " Test: " << test_ << "\n"
2006           << " Error: Access via at() function failed\n"
2007           << " Details:\n"
2008           << "   Result:\n" << vec << "\n"
2009           << "   Expected result:\n( 4 0 4 3 0 2 0 )\n";
2010       throw std::runtime_error( oss.str() );
2011    }
2012 
2013    // Subtraction assignment to the element at index 1
2014    vec.at(1) -= vec.at(5);
2015 
2016    checkSize    ( vec, 7UL );
2017    checkCapacity( vec, 7UL );
2018    checkNonZeros( vec, 5UL );
2019 
2020    if( vec.at(0) != 4 || vec.at(1) != -2 || vec.at(2) != 4 || vec.at(3) != 3 || vec.at(5) != 2 ) {
2021       std::ostringstream oss;
2022       oss << " Test: " << test_ << "\n"
2023           << " Error: Access via at() function failed\n"
2024           << " Details:\n"
2025           << "   Result:\n" << vec << "\n"
2026           << "   Expected result:\n( 4 -2 4 3 0 2 0 )\n";
2027       throw std::runtime_error( oss.str() );
2028    }
2029 
2030    // Multiplication assignment to the element at index 3
2031    vec.at(3) *= -3;
2032 
2033    checkSize    ( vec, 7UL );
2034    checkCapacity( vec, 7UL );
2035    checkNonZeros( vec, 5UL );
2036 
2037    if( vec.at(0) != 4 || vec.at(1) != -2 || vec.at(2) != 4 || vec.at(3) != -9 || vec.at(5) != 2 ) {
2038       std::ostringstream oss;
2039       oss << " Test: " << test_ << "\n"
2040           << " Error: Access via at() function failed\n"
2041           << " Details:\n"
2042           << "   Result:\n" << vec << "\n"
2043           << "   Expected result:\n( 4 -2 4 -9 0 2 0 )\n";
2044       throw std::runtime_error( oss.str() );
2045    }
2046 
2047    // Division assignment to the element at index 2
2048    vec.at(2) /= 2;
2049 
2050    checkSize    ( vec, 7UL );
2051    checkCapacity( vec, 7UL );
2052    checkNonZeros( vec, 5UL );
2053 
2054    if( vec.at(0) != 4 || vec.at(1) != -2 || vec.at(2) != 2 || vec.at(3) != -9 || vec.at(5) != 2 ) {
2055       std::ostringstream oss;
2056       oss << " Test: " << test_ << "\n"
2057           << " Error: Access via at() function failed\n"
2058           << " Details:\n"
2059           << "   Result:\n" << vec << "\n"
2060           << "   Expected result:\n( 4 -2 2 -9 0 2 0 )\n";
2061       throw std::runtime_error( oss.str() );
2062    }
2063 
2064    // Attempt to assign to the element at index 7
2065    try {
2066       vec.at(7) = 2;
2067 
2068       std::ostringstream oss;
2069       oss << " Test: " << test_ << "\n"
2070           << " Error: Out-of-bound access succeeded\n"
2071           << " Details:\n"
2072           << "   Result:\n" << vec << "\n"
2073           << "   Expected result:\n( 4 -2 2 -9 0 2 0 )\n";
2074       throw std::runtime_error( oss.str() );
2075    }
2076    catch( std::out_of_range& ) {}
2077 }
2078 //*************************************************************************************************
2079 
2080 
2081 //*************************************************************************************************
2082 /*!\brief Test of the CustomVector iterator implementation.
2083 //
2084 // \return void
2085 // \exception std::runtime_error Error detected.
2086 //
2087 // This function performs a test of the iterator implementation of the CustomVector class
2088 // template. In case an error is detected, a \a std::runtime_error exception is thrown.
2089 */
testIterator()2090 void AlignedPaddedTest::testIterator()
2091 {
2092    using Iterator      = VT::Iterator;
2093    using ConstIterator = VT::ConstIterator;
2094 
2095    std::unique_ptr<int[],blaze::Deallocate> memory( blaze::allocate<int>( 16UL ) );
2096    VT vec( memory.get(), 4UL, 16UL );
2097    vec[0] =  1;
2098    vec[1] =  0;
2099    vec[2] = -2;
2100    vec[3] = -3;
2101 
2102    // Testing the Iterator default constructor
2103    {
2104       test_ = "Iterator default constructor";
2105 
2106       Iterator it{};
2107 
2108       if( it != Iterator() ) {
2109          std::ostringstream oss;
2110          oss << " Test: " << test_ << "\n"
2111              << " Error: Failed iterator default constructor\n";
2112          throw std::runtime_error( oss.str() );
2113       }
2114    }
2115 
2116    // Testing the ConstIterator default constructor
2117    {
2118       test_ = "ConstIterator default constructor";
2119 
2120       ConstIterator it{};
2121 
2122       if( it != ConstIterator() ) {
2123          std::ostringstream oss;
2124          oss << " Test: " << test_ << "\n"
2125              << " Error: Failed iterator default constructor\n";
2126          throw std::runtime_error( oss.str() );
2127       }
2128    }
2129 
2130    // Testing conversion from Iterator to ConstIterator
2131    {
2132       test_ = "Iterator/ConstIterator conversion";
2133 
2134       ConstIterator it( begin( vec ) );
2135 
2136       if( it == end( vec ) || *it != 1 ) {
2137          std::ostringstream oss;
2138          oss << " Test: " << test_ << "\n"
2139              << " Error: Failed iterator conversion detected\n";
2140          throw std::runtime_error( oss.str() );
2141       }
2142    }
2143 
2144    // Counting the number of elements via Iterator (end-begin)
2145    {
2146       test_ = "Iterator subtraction (end-begin)";
2147 
2148       const ptrdiff_t number( end( vec ) - begin( vec ) );
2149 
2150       if( number != 4L ) {
2151          std::ostringstream oss;
2152          oss << " Test: " << test_ << "\n"
2153              << " Error: Invalid number of elements detected\n"
2154              << " Details:\n"
2155              << "   Number of elements         : " << number << "\n"
2156              << "   Expected number of elements: 4\n";
2157          throw std::runtime_error( oss.str() );
2158       }
2159    }
2160 
2161    // Counting the number of elements via Iterator (begin-end)
2162    {
2163       test_ = "Iterator subtraction (begin-end)";
2164 
2165       const ptrdiff_t number( begin( vec ) - end( vec ) );
2166 
2167       if( number != -4L ) {
2168          std::ostringstream oss;
2169          oss << " Test: " << test_ << "\n"
2170              << " Error: Invalid number of elements detected\n"
2171              << " Details:\n"
2172              << "   Number of elements         : " << number << "\n"
2173              << "   Expected number of elements: -4\n";
2174          throw std::runtime_error( oss.str() );
2175       }
2176    }
2177 
2178    // Counting the number of elements via ConstIterator (end-begin)
2179    {
2180       test_ = "ConstIterator subtraction (end-begin)";
2181 
2182       const ptrdiff_t number( cend( vec ) - cbegin( vec ) );
2183 
2184       if( number != 4L ) {
2185          std::ostringstream oss;
2186          oss << " Test: " << test_ << "\n"
2187              << " Error: Invalid number of elements detected\n"
2188              << " Details:\n"
2189              << "   Number of elements         : " << number << "\n"
2190              << "   Expected number of elements: 4\n";
2191          throw std::runtime_error( oss.str() );
2192       }
2193    }
2194 
2195    // Counting the number of elements via ConstIterator (begin-end)
2196    {
2197       test_ = "ConstIterator subtraction (begin-end)";
2198 
2199       const ptrdiff_t number( cbegin( vec ) - cend( vec ) );
2200 
2201       if( number != -4L ) {
2202          std::ostringstream oss;
2203          oss << " Test: " << test_ << "\n"
2204              << " Error: Invalid number of elements detected\n"
2205              << " Details:\n"
2206              << "   Number of elements         : " << number << "\n"
2207              << "   Expected number of elements: -4\n";
2208          throw std::runtime_error( oss.str() );
2209       }
2210    }
2211 
2212    // Testing read-only access via ConstIterator
2213    {
2214       test_ = "Read-only access via ConstIterator";
2215 
2216       ConstIterator it ( cbegin( vec ) );
2217       ConstIterator end( cend( vec ) );
2218 
2219       if( it == end || *it != 1 ) {
2220          std::ostringstream oss;
2221          oss << " Test: " << test_ << "\n"
2222              << " Error: Invalid initial iterator detected\n";
2223          throw std::runtime_error( oss.str() );
2224       }
2225 
2226       ++it;
2227 
2228       if( it == end || *it != 0 ) {
2229          std::ostringstream oss;
2230          oss << " Test: " << test_ << "\n"
2231              << " Error: Iterator pre-increment failed\n";
2232          throw std::runtime_error( oss.str() );
2233       }
2234 
2235       --it;
2236 
2237       if( it == end || *it != 1 ) {
2238          std::ostringstream oss;
2239          oss << " Test: " << test_ << "\n"
2240              << " Error: Iterator pre-decrement failed\n";
2241          throw std::runtime_error( oss.str() );
2242       }
2243 
2244       it++;
2245 
2246       if( it == end || *it != 0 ) {
2247          std::ostringstream oss;
2248          oss << " Test: " << test_ << "\n"
2249              << " Error: Iterator post-increment failed\n";
2250          throw std::runtime_error( oss.str() );
2251       }
2252 
2253       it--;
2254 
2255       if( it == end || *it != 1 ) {
2256          std::ostringstream oss;
2257          oss << " Test: " << test_ << "\n"
2258              << " Error: Iterator post-decrement failed\n";
2259          throw std::runtime_error( oss.str() );
2260       }
2261 
2262       it += 2UL;
2263 
2264       if( it == end || *it != -2 ) {
2265          std::ostringstream oss;
2266          oss << " Test: " << test_ << "\n"
2267              << " Error: Iterator addition assignment failed\n";
2268          throw std::runtime_error( oss.str() );
2269       }
2270 
2271       it -= 2UL;
2272 
2273       if( it == end || *it != 1 ) {
2274          std::ostringstream oss;
2275          oss << " Test: " << test_ << "\n"
2276              << " Error: Iterator subtraction assignment failed\n";
2277          throw std::runtime_error( oss.str() );
2278       }
2279 
2280       it = it + 3UL;
2281 
2282       if( it == end || *it != -3 ) {
2283          std::ostringstream oss;
2284          oss << " Test: " << test_ << "\n"
2285              << " Error: Iterator/scalar addition failed\n";
2286          throw std::runtime_error( oss.str() );
2287       }
2288 
2289       it = it - 3UL;
2290 
2291       if( it == end || *it != 1 ) {
2292          std::ostringstream oss;
2293          oss << " Test: " << test_ << "\n"
2294              << " Error: Iterator/scalar subtraction failed\n";
2295          throw std::runtime_error( oss.str() );
2296       }
2297 
2298       it = 4UL + it;
2299 
2300       if( it != end ) {
2301          std::ostringstream oss;
2302          oss << " Test: " << test_ << "\n"
2303              << " Error: Scalar/iterator addition failed\n";
2304          throw std::runtime_error( oss.str() );
2305       }
2306    }
2307 
2308    // Testing assignment via Iterator
2309    {
2310       test_ = "Assignment via Iterator";
2311 
2312       int value = 6;
2313 
2314       for( Iterator it=begin( vec ); it!=end( vec ); ++it ) {
2315          *it = value++;
2316       }
2317 
2318       if( vec[0] != 6 || vec[1] != 7 || vec[2] != 8 || vec[3] != 9 ) {
2319          std::ostringstream oss;
2320          oss << " Test: " << test_ << "\n"
2321              << " Error: Assignment via iterator failed\n"
2322              << " Details:\n"
2323              << "   Result:\n" << vec << "\n"
2324              << "   Expected result:\n( 6 7 8 9 )\n";
2325          throw std::runtime_error( oss.str() );
2326       }
2327    }
2328 
2329    // Testing addition assignment via Iterator
2330    {
2331       test_ = "Addition assignment via Iterator";
2332 
2333       int value = 2;
2334 
2335       for( Iterator it=begin( vec ); it!=end( vec ); ++it ) {
2336          *it += value++;
2337       }
2338 
2339       if( vec[0] != 8 || vec[1] != 10 || vec[2] != 12 || vec[3] != 14 ) {
2340          std::ostringstream oss;
2341          oss << " Test: " << test_ << "\n"
2342              << " Error: Addition assignment via iterator failed\n"
2343              << " Details:\n"
2344              << "   Result:\n" << vec << "\n"
2345              << "   Expected result:\n( 8 10 12 14 )\n";
2346          throw std::runtime_error( oss.str() );
2347       }
2348    }
2349 
2350    // Testing subtraction assignment via Iterator
2351    {
2352       test_ = "Subtraction assignment via Iterator";
2353 
2354       int value = 2;
2355 
2356       for( Iterator it=begin( vec ); it!=end( vec ); ++it ) {
2357          *it -= value++;
2358       }
2359 
2360       if( vec[0] != 6 || vec[1] != 7 || vec[2] != 8 || vec[3] != 9 ) {
2361          std::ostringstream oss;
2362          oss << " Test: " << test_ << "\n"
2363              << " Error: Subtraction assignment via iterator failed\n"
2364              << " Details:\n"
2365              << "   Result:\n" << vec << "\n"
2366              << "   Expected result:\n( 6 7 8 9 )\n";
2367          throw std::runtime_error( oss.str() );
2368       }
2369    }
2370 
2371    // Testing multiplication assignment via Iterator
2372    {
2373       test_ = "Multiplication assignment via Iterator";
2374 
2375       int value = 1;
2376 
2377       for( Iterator it=begin( vec ); it!=end( vec ); ++it ) {
2378          *it *= value++;
2379       }
2380 
2381       if( vec[0] != 6 || vec[1] != 14 || vec[2] != 24 || vec[3] != 36 ) {
2382          std::ostringstream oss;
2383          oss << " Test: " << test_ << "\n"
2384              << " Error: Multiplication assignment via iterator failed\n"
2385              << " Details:\n"
2386              << "   Result:\n" << vec << "\n"
2387              << "   Expected result:\n( 6 14 24 36 )\n";
2388          throw std::runtime_error( oss.str() );
2389       }
2390    }
2391 
2392    // Testing division assignment via Iterator
2393    {
2394       test_ = "Division assignment via Iterator";
2395 
2396       for( Iterator it=begin( vec ); it!=end( vec ); ++it ) {
2397          *it /= 2;
2398       }
2399 
2400       if( vec[0] != 3 || vec[1] != 7 || vec[2] != 12 || vec[3] != 18 ) {
2401          std::ostringstream oss;
2402          oss << " Test: " << test_ << "\n"
2403              << " Error: Division assignment via iterator failed\n"
2404              << " Details:\n"
2405              << "   Result:\n" << vec << "\n"
2406              << "   Expected result:\n( 3 7 12 18 )\n";
2407          throw std::runtime_error( oss.str() );
2408       }
2409    }
2410 }
2411 //*************************************************************************************************
2412 
2413 
2414 //*************************************************************************************************
2415 /*!\brief Test of the \c nonZeros() member function of the CustomVector class template.
2416 //
2417 // \return void
2418 // \exception std::runtime_error Error detected.
2419 //
2420 // This function performs a test of the \c nonZeros() member function of the CustomVector class
2421 // template. In case an error is detected, a \a std::runtime_error exception is thrown.
2422 */
testNonZeros()2423 void AlignedPaddedTest::testNonZeros()
2424 {
2425    test_ = "CustomVector::nonZeros()";
2426 
2427    {
2428       std::unique_ptr<int[],blaze::Deallocate> memory( blaze::allocate<int>( 16UL ) );
2429       VT vec( memory.get(), 4UL, 16UL );
2430       reset( vec );
2431 
2432       checkSize    ( vec, 4UL );
2433       checkCapacity( vec, 4UL );
2434       checkNonZeros( vec, 0UL );
2435 
2436       if( vec[0] != 0 || vec[1] != 0 || vec[2] != 0 || vec[3] != 0 ) {
2437          std::ostringstream oss;
2438          oss << " Test: " << test_ << "\n"
2439              << " Error: Initialization failed\n"
2440              << " Details:\n"
2441              << "   Result:\n" << vec << "\n"
2442              << "   Expected result:\n( 0 0 0 0 )\n";
2443          throw std::runtime_error( oss.str() );
2444       }
2445    }
2446 
2447    {
2448       std::unique_ptr<int[],blaze::Deallocate> memory( blaze::allocate<int>( 16UL ) );
2449       VT vec( memory.get(), 4UL, 16UL );
2450       vec[0] = 1;
2451       vec[1] = 2;
2452       vec[2] = 0;
2453       vec[3] = 3;
2454 
2455       checkSize    ( vec, 4UL );
2456       checkCapacity( vec, 4UL );
2457       checkNonZeros( vec, 3UL );
2458 
2459       if( vec[0] != 1 || vec[1] != 2 || vec[2] != 0 || vec[3] != 3 ) {
2460          std::ostringstream oss;
2461          oss << " Test: " << test_ << "\n"
2462              << " Error: Initialization failed\n"
2463              << " Details:\n"
2464              << "   Result:\n" << vec << "\n"
2465              << "   Expected result:\n( 1 2 0 3 )\n";
2466          throw std::runtime_error( oss.str() );
2467       }
2468    }
2469 }
2470 //*************************************************************************************************
2471 
2472 
2473 //*************************************************************************************************
2474 /*!\brief Test of the \c reset() member function of the CustomVector class template.
2475 //
2476 // \return void
2477 // \exception std::runtime_error Error detected.
2478 //
2479 // This function performs a test of the \c reset() member function of the CustomVector class
2480 // template. In case an error is detected, a \a std::runtime_error exception is thrown.
2481 */
testReset()2482 void AlignedPaddedTest::testReset()
2483 {
2484    using blaze::reset;
2485 
2486 
2487    //=====================================================================================
2488    // CustomVector::reset()
2489    //=====================================================================================
2490 
2491    {
2492       test_ = "CustomVector::reset()";
2493 
2494       // Initialization check
2495       std::unique_ptr<int[],blaze::Deallocate> memory( blaze::allocate<int>( 16UL ) );
2496       VT vec( memory.get(), 4UL, 16UL );
2497       vec[0] = 1;
2498       vec[1] = 2;
2499       vec[2] = 3;
2500       vec[3] = 4;
2501 
2502       checkSize    ( vec, 4UL );
2503       checkCapacity( vec, 4UL );
2504       checkNonZeros( vec, 4UL );
2505 
2506       if( vec[0] != 1 || vec[1] != 2 || vec[2] != 3 || vec[3] != 4 ) {
2507          std::ostringstream oss;
2508          oss << " Test: " << test_ << "\n"
2509              << " Error: Initialization failed\n"
2510              << " Details:\n"
2511              << "   Result:\n" << vec << "\n"
2512              << "   Expected result:\n( 1 2 3 4 )\n";
2513          throw std::runtime_error( oss.str() );
2514       }
2515 
2516       // Resetting a single element
2517       reset( vec[2] );
2518 
2519       checkSize    ( vec, 4UL );
2520       checkCapacity( vec, 4UL );
2521       checkNonZeros( vec, 3UL );
2522 
2523       if( vec[0] != 1 || vec[1] != 2 || vec[2] != 0 || vec[3] != 4 ) {
2524          std::ostringstream oss;
2525          oss << " Test: " << test_ << "\n"
2526              << " Error: Reset operation failed\n"
2527              << " Details:\n"
2528              << "   Result:\n" << vec << "\n"
2529              << "   Expected result:\n( 1 2 0 4 )\n";
2530          throw std::runtime_error( oss.str() );
2531       }
2532 
2533       // Resetting the vector
2534       reset( vec );
2535 
2536       checkSize    ( vec, 4UL );
2537       checkCapacity( vec, 4UL );
2538       checkNonZeros( vec, 0UL );
2539 
2540       if( vec[0] != 0 || vec[1] != 0 || vec[2] != 0 || vec[3] != 0 ) {
2541          std::ostringstream oss;
2542          oss << " Test: " << test_ << "\n"
2543              << " Error: Reset operation failed\n"
2544              << " Details:\n"
2545              << "   Result:\n" << vec << "\n"
2546              << "   Expected result:\n( 0 0 0 0 )\n";
2547          throw std::runtime_error( oss.str() );
2548       }
2549    }
2550 
2551 
2552    //=====================================================================================
2553    // CustomVector::reset( Type*, size_t, size_t )
2554    //=====================================================================================
2555 
2556    {
2557       test_ = "CustomVector::reset( Type*, size_t, size_t )";
2558 
2559       std::unique_ptr<int[],blaze::Deallocate> memory1( blaze::allocate<int>( 16UL ) );
2560       VT vec( memory1.get(), 4UL, 16UL );
2561       vec[0] = 1;
2562       vec[1] = 2;
2563       vec[2] = 3;
2564       vec[3] = 4;
2565 
2566       std::unique_ptr<int[],blaze::Deallocate> memory2( blaze::allocate<int>( 32UL ) );
2567       vec.reset( memory2.get(), 27UL, 32UL );
2568 
2569       checkSize    ( vec, 27UL );
2570       checkCapacity( vec, 32UL );
2571    }
2572 }
2573 //*************************************************************************************************
2574 
2575 
2576 //*************************************************************************************************
2577 /*!\brief Test of the \c clear() member function of the CustomVector class template.
2578 //
2579 // \return void
2580 // \exception std::runtime_error Error detected.
2581 //
2582 // This function performs a test of the \c clear() member function of the CustomVector class
2583 // template. In case an error is detected, a \a std::runtime_error exception is thrown.
2584 */
testClear()2585 void AlignedPaddedTest::testClear()
2586 {
2587    using blaze::clear;
2588 
2589    test_ = "CustomVector::clear()";
2590 
2591    // Initialization check
2592    std::unique_ptr<int[],blaze::Deallocate> memory( blaze::allocate<int>( 16UL ) );
2593    VT vec( memory.get(), 4UL, 16UL );
2594    vec[0] = 1;
2595    vec[1] = 2;
2596    vec[2] = 3;
2597    vec[3] = 4;
2598 
2599    checkSize    ( vec, 4UL );
2600    checkCapacity( vec, 4UL );
2601    checkNonZeros( vec, 4UL );
2602 
2603    if( vec[0] != 1 || vec[1] != 2 || vec[2] != 3 || vec[3] != 4 ) {
2604       std::ostringstream oss;
2605       oss << " Test: " << test_ << "\n"
2606           << " Error: Initialization failed\n"
2607           << " Details:\n"
2608           << "   Result:\n" << vec << "\n"
2609           << "   Expected result:\n( 1 2 3 4 )\n";
2610       throw std::runtime_error( oss.str() );
2611    }
2612 
2613    // Clearing a single element
2614    clear( vec[2] );
2615 
2616    checkSize    ( vec, 4UL );
2617    checkCapacity( vec, 4UL );
2618    checkNonZeros( vec, 3UL );
2619 
2620    if( vec[0] != 1 || vec[1] != 2 || vec[2] != 0 || vec[3] != 4 ) {
2621       std::ostringstream oss;
2622       oss << " Test: " << test_ << "\n"
2623           << " Error: Clear operation failed\n"
2624           << " Details:\n"
2625           << "   Result:\n" << vec << "\n"
2626           << "   Expected result:\n( 1 2 0 4 )\n";
2627       throw std::runtime_error( oss.str() );
2628    }
2629 
2630    // Clearing the vector
2631    clear( vec );
2632 
2633    checkSize    ( vec, 0UL );
2634    checkNonZeros( vec, 0UL );
2635 }
2636 //*************************************************************************************************
2637 
2638 
2639 //*************************************************************************************************
2640 /*!\brief Test of the \c swap() functionality of the CustomVector class template.
2641 //
2642 // \return void
2643 // \exception std::runtime_error Error detected.
2644 //
2645 // This function performs a test of the \c swap() function of the CustomVector class template.
2646 // In case an error is detected, a \a std::runtime_error exception is thrown.
2647 */
testSwap()2648 void AlignedPaddedTest::testSwap()
2649 {
2650    test_ = "CustomVector swap";
2651 
2652    std::unique_ptr<int[],blaze::Deallocate> memory1( blaze::allocate<int>( 16UL ) );
2653    VT vec1( memory1.get(), 3UL, 16UL );
2654    vec1[0] = 1;
2655    vec1[1] = 2;
2656    vec1[2] = 3;
2657 
2658    std::unique_ptr<int[],blaze::Deallocate> memory2( blaze::allocate<int>( 16UL ) );
2659    VT vec2( memory2.get(), 4UL, 16UL );
2660    vec2[0] = 4;
2661    vec2[1] = 3;
2662    vec2[2] = 2;
2663    vec2[3] = 1;
2664 
2665    swap( vec1, vec2 );
2666 
2667    checkSize    ( vec1, 4UL );
2668    checkCapacity( vec1, 4UL );
2669    checkNonZeros( vec1, 4UL );
2670 
2671    if( vec1[0] != 4 || vec1[1] != 3 || vec1[2] != 2 || vec1[3] != 1 ) {
2672       std::ostringstream oss;
2673       oss << " Test: " << test_ << "\n"
2674           << " Error: Swapping the first vector failed\n"
2675           << " Details:\n"
2676           << "   Result:\n" << vec1 << "\n"
2677           << "   Expected result:\n( 4 3 2 1 )\n";
2678       throw std::runtime_error( oss.str() );
2679    }
2680 
2681    checkSize    ( vec2, 3UL );
2682    checkCapacity( vec2, 3UL );
2683    checkNonZeros( vec2, 3UL );
2684 
2685    if( vec2[0] != 1 || vec2[1] != 2 || vec2[2] != 3 ) {
2686       std::ostringstream oss;
2687       oss << " Test: " << test_ << "\n"
2688           << " Error: Swapping the second vector failed\n"
2689           << " Details:\n"
2690           << "   Result:\n" << vec1 << "\n"
2691           << "   Expected result:\n( 1 2 3 )\n";
2692       throw std::runtime_error( oss.str() );
2693    }
2694 }
2695 //*************************************************************************************************
2696 
2697 
2698 //*************************************************************************************************
2699 /*!\brief Test of the \c isDefault() function with the CustomVector class template.
2700 //
2701 // \return void
2702 // \exception std::runtime_error Error detected.
2703 //
2704 // This function performs a test of the \c isDefault() function with the CustomVector class
2705 // template. In case an error is detected, a \a std::runtime_error exception is thrown.
2706 */
testIsDefault()2707 void AlignedPaddedTest::testIsDefault()
2708 {
2709    using blaze::isDefault;
2710 
2711    test_ = "isDefault() function";
2712 
2713    // isDefault with vector of size 0
2714    {
2715       VT vec;
2716 
2717       if( isDefault( vec ) != true ) {
2718          std::ostringstream oss;
2719          oss << " Test: " << test_ << "\n"
2720              << " Error: Invalid isDefault evaluation\n"
2721              << " Details:\n"
2722              << "   Vector:\n" << vec << "\n";
2723          throw std::runtime_error( oss.str() );
2724       }
2725    }
2726 
2727    // isDefault with default vector
2728    {
2729       std::unique_ptr<int[],blaze::Deallocate> memory( blaze::allocate<int>( 16UL ) );
2730       VT vec( memory.get(), 3UL, 16UL );
2731       reset( vec );
2732 
2733       if( isDefault( vec[1] ) != true ) {
2734          std::ostringstream oss;
2735          oss << " Test: " << test_ << "\n"
2736              << " Error: Invalid isDefault evaluation\n"
2737              << " Details:\n"
2738              << "   Vector element: " << vec[1] << "\n";
2739          throw std::runtime_error( oss.str() );
2740       }
2741 
2742       if( isDefault( vec ) != false ) {
2743          std::ostringstream oss;
2744          oss << " Test: " << test_ << "\n"
2745              << " Error: Invalid isDefault evaluation\n"
2746              << " Details:\n"
2747              << "   Vector:\n" << vec << "\n";
2748          throw std::runtime_error( oss.str() );
2749       }
2750    }
2751 
2752    // isDefault with non-default vector
2753    {
2754       std::unique_ptr<int[],blaze::Deallocate> memory( blaze::allocate<int>( 16UL ) );
2755       VT vec( memory.get(), 3UL, 16UL );
2756       reset( vec );
2757       vec[1] = 1;
2758 
2759       if( isDefault( vec[1] ) != false ) {
2760          std::ostringstream oss;
2761          oss << " Test: " << test_ << "\n"
2762              << " Error: Invalid isDefault evaluation\n"
2763              << " Details:\n"
2764              << "   Vector element: " << vec[1] << "\n";
2765          throw std::runtime_error( oss.str() );
2766       }
2767 
2768       if( isDefault( vec ) != false ) {
2769          std::ostringstream oss;
2770          oss << " Test: " << test_ << "\n"
2771              << " Error: Invalid isDefault evaluation\n"
2772              << " Details:\n"
2773              << "   Vector:\n" << vec << "\n";
2774          throw std::runtime_error( oss.str() );
2775       }
2776    }
2777 }
2778 //*************************************************************************************************
2779 
2780 } // namespace customvector
2781 
2782 } // namespace vectors
2783 
2784 } // namespace mathtest
2785 
2786 } // namespace blazetest
2787 
2788 
2789 
2790 
2791 //=================================================================================================
2792 //
2793 //  MAIN FUNCTION
2794 //
2795 //=================================================================================================
2796 
2797 //*************************************************************************************************
main()2798 int main()
2799 {
2800    std::cout << "   Running aligned/padded CustomVector class test..." << std::endl;
2801 
2802    try
2803    {
2804       RUN_CUSTOMVECTOR_ALIGNED_PADDED_TEST;
2805    }
2806    catch( std::exception& ex ) {
2807       std::cerr << "\n\n ERROR DETECTED during aligned/padded CustomVector class test:\n"
2808                 << ex.what() << "\n";
2809       return EXIT_FAILURE;
2810    }
2811 
2812    return EXIT_SUCCESS;
2813 }
2814 //*************************************************************************************************
2815