32 #include <boost/numeric/ublas/io.hpp>
33 #include <boost/numeric/ublas/vector.hpp>
34 #include <boost/numeric/ublas/vector_proxy.hpp>
40 #define VIENNACL_WITH_UBLAS 1
51 using namespace boost::numeric;
57 template<
typename ScalarType>
66 template<
typename ScalarType>
75 template<
typename ScalarType>
84 template<
typename ScalarType,
typename VCLVectorType>
87 ublas::vector<ScalarType> v2_cpu(v2.size());
91 for (
unsigned int i=0;i<v1.size(); ++i)
93 if (v2_cpu[i] != v1[i])
100 template<
typename T1,
typename T2>
101 int check(T1
const & t1, T2
const & t2)
103 int retval = EXIT_SUCCESS;
105 if (
diff(t1, t2) != 0)
107 std::cout <<
"# Error! Difference: " << std::abs(
diff(t1, t2)) << std::endl;
108 retval = EXIT_FAILURE;
117 template<
typename NumericT,
typename UblasVectorType,
typename ViennaCLVectorType1,
typename ViennaCLVectorType2 >
118 int test(UblasVectorType & ublas_v1, UblasVectorType & ublas_v2,
119 ViennaCLVectorType1 & vcl_v1, ViennaCLVectorType2 & vcl_v2)
121 int retval = EXIT_SUCCESS;
123 NumericT cpu_result = 42;
129 std::cout <<
"Checking for zero_vector initializer..." << std::endl;
131 for (std::size_t i=0; i<ublas_v1.size(); ++i)
134 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
137 std::cout <<
"Checking for scalar_vector initializer..." << std::endl;
139 for (std::size_t i=0; i<ublas_v1.size(); ++i)
140 ublas_v1[i] = cpu_result;
142 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
146 for (std::size_t i=0; i<ublas_v1.size(); ++i)
147 ublas_v1[i] = cpu_result + 1;
149 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
152 std::cout <<
"Checking for unit_vector initializer..." << std::endl;
154 for (std::size_t i=0; i<ublas_v1.size(); ++i)
155 ublas_v1[i] = (i == 5) ? 1 : 0;
157 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
160 for (std::size_t i=0; i<ublas_v1.size(); ++i)
162 ublas_v1[i] = NumericT(i);
163 ublas_v2[i] = NumericT(i+42);
169 std::cout <<
"Checking for successful copy..." << std::endl;
170 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
172 if (
check(ublas_v2, vcl_v2) != EXIT_SUCCESS)
180 std::cout <<
"Testing inner_prod..." << std::endl;
185 if (
check(cpu_result, cpu_result2) != EXIT_SUCCESS)
187 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
190 cpu_result =
inner_prod(ublas_v1 + ublas_v2, ublas_v2 - ublas_v1);
194 if (
check(cpu_result, cpu_result3) != EXIT_SUCCESS)
196 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
200 std::cout <<
"Testing norm_1..." << std::endl;
204 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
207 gpu_result = 2 * cpu_result;
211 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
217 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
221 std::cout <<
"Testing norm_inf..." << std::endl;
225 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
228 gpu_result = 2 * cpu_result;
232 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
238 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
242 std::cout <<
"Testing index_norm_inf..." << std::endl;
246 if (
check(static_cast<NumericT>(cpu_index), static_cast<NumericT>(gpu_index)) != EXIT_SUCCESS)
252 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
258 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
262 std::cout <<
"Testing max..." << std::endl;
263 cpu_result = ublas_v1[0];
264 for (std::size_t i=0; i<ublas_v1.size(); ++i)
265 cpu_result = std::max<NumericT>(cpu_result, ublas_v1[i]);
268 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
271 cpu_result = ublas_v1[0];
272 for (std::size_t i=0; i<ublas_v1.size(); ++i)
273 cpu_result = std::max<NumericT>(cpu_result, ublas_v1[i]);
274 gpu_result = cpu_result;
278 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
281 cpu_result = ublas_v1[0] + ublas_v2[0];
282 for (std::size_t i=0; i<ublas_v1.size(); ++i)
283 cpu_result = std::max<NumericT>(cpu_result, ublas_v1[i] + ublas_v2[i]);
284 gpu_result = cpu_result;
288 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
293 std::cout <<
"Testing min..." << std::endl;
294 cpu_result = ublas_v1[0];
295 for (std::size_t i=0; i<ublas_v1.size(); ++i)
296 cpu_result = std::min<NumericT>(cpu_result, ublas_v1[i]);
299 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
302 cpu_result = ublas_v1[0];
303 for (std::size_t i=0; i<ublas_v1.size(); ++i)
304 cpu_result = std::min<NumericT>(cpu_result, ublas_v1[i]);
305 gpu_result = cpu_result;
309 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
312 cpu_result = ublas_v1[0] + ublas_v2[0];
313 for (std::size_t i=0; i<ublas_v1.size(); ++i)
314 cpu_result = std::min<NumericT>(cpu_result, ublas_v1[i] + ublas_v2[i]);
315 gpu_result = cpu_result;
319 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
330 ublas::vector<NumericT> x = ublas_v1;
331 ublas::vector<NumericT> y = ublas_v2;
332 ublas::vector<NumericT> t = ublas_v1;
333 t.assign ( NumericT(1) * x + NumericT(2) * y),
334 y.assign (- NumericT(2) * x + NumericT(1) * y),
339 if (
check(x, vcl_v1) != EXIT_SUCCESS)
341 if (
check(y, vcl_v2) != EXIT_SUCCESS)
346 std::cout <<
"Testing assignments..." << std::endl;
347 NumericT val =
static_cast<NumericT
>(1);
348 for (
size_t i=0; i < ublas_v1.size(); ++i)
351 for (
size_t i=0; i < vcl_v1.size(); ++i)
354 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
361 std::cout <<
"Testing scaling with CPU scalar..." << std::endl;
362 NumericT alpha =
static_cast<NumericT
>(3);
368 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
371 std::cout <<
"Testing scaling with GPU scalar..." << std::endl;
375 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
378 NumericT beta =
static_cast<NumericT
>(2);
381 std::cout <<
"Testing shrinking with CPU scalar..." << std::endl;
385 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
388 std::cout <<
"Testing shrinking with GPU scalar..." << std::endl;
392 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
399 for (
size_t i=0; i < ublas_v1.size(); ++i)
400 ublas_v1(i) = NumericT(i);
401 ublas_v2 = 3 * ublas_v1;
405 std::cout <<
"Testing add on vector..." << std::endl;
407 std::cout <<
"Checking for successful copy..." << std::endl;
408 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
410 if (
check(ublas_v2, vcl_v2) != EXIT_SUCCESS)
413 ublas_v1 = ublas_v1 + ublas_v2;
414 vcl_v1 = vcl_v1 + vcl_v2;
416 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
419 std::cout <<
"Testing add on vector with flipsign..." << std::endl;
420 ublas_v1 = - ublas_v1 + ublas_v2;
421 vcl_v1 = - vcl_v1 + vcl_v2;
423 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
426 std::cout <<
"Testing inplace-add on vector..." << std::endl;
427 ublas_v1 += ublas_v2;
430 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
436 std::cout <<
"Testing sub on vector..." << std::endl;
437 ublas_v2 = 3 * ublas_v1;
441 ublas_v1 = ublas_v1 - ublas_v2;
442 vcl_v1 = vcl_v1 - vcl_v2;
444 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
447 std::cout <<
"Testing inplace-sub on vector..." << std::endl;
448 ublas_v1 -= ublas_v2;
451 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
459 std::cout <<
"Testing multiply-add on vector with CPU scalar (right)..." << std::endl;
460 for (
size_t i=0; i < ublas_v1.size(); ++i)
461 ublas_v1(i) = NumericT(i);
462 ublas_v2 = 3 * ublas_v1;
466 ublas_v1 = ublas_v1 + alpha * ublas_v2;
467 vcl_v1 = vcl_v1 + alpha * vcl_v2;
469 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
472 std::cout <<
"Testing multiply-add on vector with CPU scalar (left)..." << std::endl;
473 ublas_v2 = 3 * ublas_v1;
477 ublas_v1 = alpha * ublas_v1 + ublas_v2;
478 vcl_v1 = alpha * vcl_v1 + vcl_v2;
480 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
483 std::cout <<
"Testing multiply-add on vector with CPU scalar (both)..." << std::endl;
484 ublas_v2 = 3 * ublas_v1;
488 ublas_v1 = alpha * ublas_v1 + beta * ublas_v2;
489 vcl_v1 = alpha * vcl_v1 + beta * vcl_v2;
491 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
495 std::cout <<
"Testing inplace multiply-add on vector with CPU scalar..." << std::endl;
496 ublas_v2 = 3 * ublas_v1;
500 ublas_v1 += alpha * ublas_v2;
501 vcl_v1 += alpha * vcl_v2;
503 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
507 std::cout <<
"Testing multiply-add on vector with GPU scalar (right)..." << std::endl;
508 ublas_v2 = 3 * ublas_v1;
512 ublas_v1 = ublas_v1 + alpha * ublas_v2;
513 vcl_v1 = vcl_v1 + gpu_alpha * vcl_v2;
515 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
518 std::cout <<
"Testing multiply-add on vector with GPU scalar (left)..." << std::endl;
519 ublas_v2 = 3 * ublas_v1;
523 ublas_v1 = ublas_v1 + alpha * ublas_v2;
524 vcl_v1 = vcl_v1 + gpu_alpha * vcl_v2;
526 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
529 std::cout <<
"Testing multiply-add on vector with GPU scalar (both)..." << std::endl;
530 ublas_v2 = 3 * ublas_v1;
534 ublas_v1 = alpha * ublas_v1 + beta * ublas_v2;
535 vcl_v1 = gpu_alpha * vcl_v1 + gpu_beta * vcl_v2;
537 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
541 std::cout <<
"Testing inplace multiply-add on vector with GPU scalar (both, adding)..." << std::endl;
542 ublas_v2 = 3 * ublas_v1;
546 ublas_v1 += alpha * ublas_v1 + beta * ublas_v2;
547 vcl_v1 += gpu_alpha * vcl_v1 + gpu_beta * vcl_v2;
549 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
552 std::cout <<
"Testing inplace multiply-add on vector with GPU scalar (both, subtracting)..." << std::endl;
553 ublas_v2 = 3 * ublas_v1;
557 ublas_v1 += alpha * ublas_v1 - beta * ublas_v2;
558 vcl_v1 += gpu_alpha * vcl_v1 - gpu_beta * vcl_v2;
560 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
565 std::cout <<
"Testing inplace multiply-add on vector with GPU scalar..." << std::endl;
566 ublas_v2 = 3 * ublas_v1;
570 ublas_v1 += alpha * ublas_v2;
571 vcl_v1 += gpu_alpha * vcl_v2;
573 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
580 std::cout <<
"Testing division-add on vector with CPU scalar (right)..." << std::endl;
581 for (
size_t i=0; i < ublas_v1.size(); ++i)
582 ublas_v1(i) = NumericT(i);
583 ublas_v2 = 3 * ublas_v1;
587 ublas_v1 = ublas_v1 + ublas_v2 / alpha;
588 vcl_v1 = vcl_v1 + vcl_v2 / alpha;
590 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
594 std::cout <<
"Testing division-add on vector with CPU scalar (left)..." << std::endl;
595 ublas_v2 = 3 * ublas_v1;
599 ublas_v1 = ublas_v1 / alpha + ublas_v2;
600 vcl_v1 = vcl_v1 / alpha + vcl_v2;
602 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
605 std::cout <<
"Testing division-add on vector with CPU scalar (both)..." << std::endl;
606 ublas_v2 = 3 * ublas_v1;
610 ublas_v1 = ublas_v1 / alpha + ublas_v2 / beta;
611 vcl_v1 = vcl_v1 / alpha + vcl_v2 / beta;
613 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
616 std::cout <<
"Testing division-multiply-add on vector with CPU scalar..." << std::endl;
617 ublas_v2 = 3 * ublas_v1;
621 ublas_v1 = ublas_v1 / alpha + ublas_v2 * beta;
622 vcl_v1 = vcl_v1 / alpha + vcl_v2 * beta;
624 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
628 std::cout <<
"Testing multiply-division-add on vector with CPU scalar..." << std::endl;
629 ublas_v2 = 3 * ublas_v1;
633 ublas_v1 = ublas_v1 * alpha + ublas_v2 / beta;
634 vcl_v1 = vcl_v1 * alpha + vcl_v2 / beta;
636 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
641 std::cout <<
"Testing inplace division-add on vector with CPU scalar..." << std::endl;
642 ublas_v2 = 3 * ublas_v1;
646 ublas_v1 += ublas_v2 / alpha;
647 vcl_v1 += vcl_v2 / alpha;
649 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
653 std::cout <<
"Testing division-add on vector with GPU scalar (right)..." << std::endl;
654 ublas_v2 = 3 * ublas_v1;
658 ublas_v1 = ublas_v1 + ublas_v2 / alpha;
659 vcl_v1 = vcl_v1 + vcl_v2 / gpu_alpha;
661 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
664 std::cout <<
"Testing division-add on vector with GPU scalar (left)..." << std::endl;
665 ublas_v2 = 3 * ublas_v1;
669 ublas_v1 = ublas_v1 + ublas_v2 / alpha;
670 vcl_v1 = vcl_v1 + vcl_v2 / gpu_alpha;
672 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
675 std::cout <<
"Testing division-add on vector with GPU scalar (both)..." << std::endl;
676 ublas_v2 = 3 * ublas_v1;
680 ublas_v1 = ublas_v1 / alpha + ublas_v2 / beta;
681 vcl_v1 = vcl_v1 / gpu_alpha + vcl_v2 / gpu_beta;
683 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
687 std::cout <<
"Testing inplace division-add on vector with GPU scalar (both, adding)..." << std::endl;
688 ublas_v2 = 3 * ublas_v1;
692 ublas_v1 += ublas_v1 / alpha + ublas_v2 / beta;
693 vcl_v1 += vcl_v1 / gpu_alpha + vcl_v2 / gpu_beta;
695 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
698 std::cout <<
"Testing inplace division-add on vector with GPU scalar (both, subtracting)..." << std::endl;
699 ublas_v2 = 3 * ublas_v1;
703 ublas_v1 += ublas_v1 / alpha - ublas_v2 / beta;
704 vcl_v1 += vcl_v1 / gpu_alpha - vcl_v2 / gpu_beta;
706 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
709 std::cout <<
"Testing inplace division-multiply-add on vector with GPU scalar (adding)..." << std::endl;
710 ublas_v2 = 3 * ublas_v1;
714 ublas_v1 += ublas_v1 / alpha + ublas_v2 * beta;
715 vcl_v1 += vcl_v1 / gpu_alpha + vcl_v2 * gpu_beta;
717 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
720 std::cout <<
"Testing inplace multiply-division-add on vector with GPU scalar (subtracting)..." << std::endl;
721 ublas_v2 = 3 * ublas_v1;
725 ublas_v1 += ublas_v1 * alpha - ublas_v2 / beta;
726 vcl_v1 += vcl_v1 * gpu_alpha - vcl_v2 / gpu_beta;
728 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
733 std::cout <<
"Testing inplace division-add on vector with GPU scalar..." << std::endl;
734 ublas_v2 = 3 * ublas_v1;
738 ublas_v1 += ublas_v2 * alpha;
739 vcl_v1 += vcl_v2 * gpu_alpha;
741 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
747 std::cout <<
"Testing multiply-subtract on vector with CPU scalar (right)..." << std::endl;
748 for (
size_t i=0; i < ublas_v1.size(); ++i)
749 ublas_v1(i) = NumericT(i);
750 ublas_v2 = 3 * ublas_v1;
754 ublas_v1 = ublas_v1 - alpha * ublas_v2;
755 vcl_v1 = vcl_v1 - alpha * vcl_v2;
757 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
761 std::cout <<
"Testing multiply-subtract on vector with CPU scalar (left)..." << std::endl;
762 ublas_v2 = 3 * ublas_v1;
766 ublas_v1 = alpha * ublas_v1 - ublas_v2;
767 vcl_v1 = alpha * vcl_v1 - vcl_v2;
769 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
772 std::cout <<
"Testing multiply-subtract on vector with CPU scalar (both)..." << std::endl;
773 ublas_v2 = 3 * ublas_v1;
777 ublas_v1 = alpha * ublas_v1 - beta * ublas_v2;
778 vcl_v1 = alpha * vcl_v1 - beta * vcl_v2;
780 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
784 std::cout <<
"Testing inplace multiply-subtract on vector with CPU scalar..." << std::endl;
785 ublas_v2 = 3 * ublas_v1;
789 ublas_v1 -= alpha * ublas_v2;
790 vcl_v1 -= alpha * vcl_v2;
792 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
796 std::cout <<
"Testing multiply-subtract on vector with GPU scalar (right)..." << std::endl;
797 ublas_v2 = 3 * ublas_v1;
801 ublas_v1 = ublas_v1 - alpha * ublas_v2;
802 vcl_v1 = vcl_v1 - gpu_alpha * vcl_v2;
804 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
807 std::cout <<
"Testing multiply-subtract on vector with GPU scalar (left)..." << std::endl;
808 ublas_v2 = 3 * ublas_v1;
812 ublas_v1 = ublas_v1 - alpha * ublas_v2;
813 vcl_v1 = vcl_v1 - gpu_alpha * vcl_v2;
815 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
818 std::cout <<
"Testing multiply-subtract on vector with GPU scalar (both)..." << std::endl;
819 ublas_v2 = 3 * ublas_v1;
823 ublas_v1 = alpha * ublas_v1 - beta * ublas_v2;
824 vcl_v1 = gpu_alpha * vcl_v1 - gpu_beta * vcl_v2;
826 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
829 std::cout <<
"Testing inplace multiply-subtract on vector with GPU scalar (both, adding)..." << std::endl;
830 ublas_v2 = 3 * ublas_v1;
834 ublas_v1 -= alpha * ublas_v1 + beta * ublas_v2;
835 vcl_v1 -= gpu_alpha * vcl_v1 + gpu_beta * vcl_v2;
837 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
840 std::cout <<
"Testing inplace multiply-subtract on vector with GPU scalar (both, subtracting)..." << std::endl;
841 ublas_v2 = 3 * ublas_v1;
845 ublas_v1 -= alpha * ublas_v1 - beta * ublas_v2;
846 vcl_v1 -= gpu_alpha * vcl_v1 - gpu_beta * vcl_v2;
848 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
852 std::cout <<
"Testing inplace multiply-subtract on vector with GPU scalar..." << std::endl;
853 ublas_v2 = 3 * ublas_v1;
857 ublas_v1 -= alpha * ublas_v2;
858 vcl_v1 -= gpu_alpha * vcl_v2;
860 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
868 std::cout <<
"Testing division-subtract on vector with CPU scalar (right)..." << std::endl;
869 for (
size_t i=0; i < ublas_v1.size(); ++i)
870 ublas_v1(i) = NumericT(i);
871 ublas_v2 = 3 * ublas_v1;
875 ublas_v1 = ublas_v1 - ublas_v2 / alpha;
876 vcl_v1 = vcl_v1 - vcl_v2 / alpha;
878 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
882 std::cout <<
"Testing division-subtract on vector with CPU scalar (left)..." << std::endl;
883 ublas_v2 = 3 * ublas_v1;
887 ublas_v1 = ublas_v1 / alpha - ublas_v2;
888 vcl_v1 = vcl_v1 / alpha - vcl_v2;
890 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
893 std::cout <<
"Testing division-subtract on vector with CPU scalar (both)..." << std::endl;
894 ublas_v2 = 3 * ublas_v1;
898 ublas_v1 = ublas_v1 / alpha - ublas_v2 / alpha;
899 vcl_v1 = vcl_v1 / alpha - vcl_v2 / alpha;
901 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
905 std::cout <<
"Testing inplace division-subtract on vector with CPU scalar..." << std::endl;
906 ublas_v2 = 3 * ublas_v1;
910 ublas_v1 -= ublas_v2 / alpha;
911 vcl_v1 -= vcl_v2 / alpha;
913 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
916 std::cout <<
"Testing inplace division-subtract on vector with GPU scalar..." << std::endl;
917 ublas_v2 = 3 * ublas_v1;
921 ublas_v1 -= ublas_v2 / alpha;
922 vcl_v1 -= vcl_v2 / gpu_alpha;
924 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
928 std::cout <<
"Testing division-subtract on vector with GPU scalar (right)..." << std::endl;
929 ublas_v2 = 3 * ublas_v1;
933 ublas_v1 = ublas_v1 - ublas_v2 / alpha;
934 vcl_v1 = vcl_v1 - vcl_v2 / gpu_alpha;
936 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
939 std::cout <<
"Testing division-subtract on vector with GPU scalar (left)..." << std::endl;
940 ublas_v2 = 3 * ublas_v1;
944 ublas_v1 = ublas_v1 - ublas_v2 / alpha;
945 vcl_v1 = vcl_v1 - vcl_v2 / gpu_alpha;
947 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
950 std::cout <<
"Testing division-subtract on vector with GPU scalar (both)..." << std::endl;
951 ublas_v2 = 3 * ublas_v1;
955 ublas_v1 = ublas_v1 / alpha - ublas_v2 / beta;
956 vcl_v1 = vcl_v1 / gpu_alpha - vcl_v2 / gpu_beta;
958 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
961 std::cout <<
"Testing inplace division-subtract on vector with GPU scalar (both, adding)..." << std::endl;
962 ublas_v2 = 3 * ublas_v1;
966 ublas_v1 -= ublas_v1 / alpha + ublas_v2 / beta;
967 vcl_v1 -= vcl_v1 / gpu_alpha + vcl_v2 / gpu_beta;
969 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
972 std::cout <<
"Testing inplace division-subtract on vector with GPU scalar (both, subtracting)..." << std::endl;
973 ublas_v2 = 3 * ublas_v1;
977 ublas_v1 -= ublas_v1 / alpha - ublas_v2 / beta;
978 vcl_v1 -= vcl_v1 / gpu_alpha - vcl_v2 / gpu_beta;
980 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
983 std::cout <<
"Testing multiply-division-subtract on vector with GPU scalar..." << std::endl;
984 ublas_v2 = 3 * ublas_v1;
988 ublas_v1 = ublas_v1 * alpha - ublas_v2 / beta;
989 vcl_v1 = vcl_v1 * gpu_alpha - vcl_v2 / gpu_beta;
991 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
994 std::cout <<
"Testing division-multiply-subtract on vector with GPU scalar..." << std::endl;
995 ublas_v2 = 3 * ublas_v1;
999 ublas_v1 = ublas_v1 / alpha - ublas_v2 * beta;
1000 vcl_v1 = vcl_v1 / gpu_alpha - vcl_v2 * gpu_beta;
1002 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1003 return EXIT_FAILURE;
1005 std::cout <<
"Testing inplace multiply-division-subtract on vector with GPU scalar (adding)..." << std::endl;
1006 ublas_v2 = 3 * ublas_v1;
1007 viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
1008 viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
1010 ublas_v1 -= ublas_v1 * alpha + ublas_v2 / beta;
1011 vcl_v1 -= vcl_v1 * gpu_alpha + vcl_v2 / gpu_beta;
1013 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1014 return EXIT_FAILURE;
1016 std::cout <<
"Testing inplace division-multiply-subtract on vector with GPU scalar (adding)..." << std::endl;
1017 ublas_v2 = 3 * ublas_v1;
1018 viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
1019 viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
1021 ublas_v1 -= ublas_v1 / alpha + ublas_v2 * beta;
1022 vcl_v1 -= vcl_v1 / gpu_alpha + vcl_v2 * gpu_beta;
1024 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1025 return EXIT_FAILURE;
1027 std::cout <<
"Testing inplace multiply-division-subtract on vector with GPU scalar (subtracting)..." << std::endl;
1028 ublas_v2 = 3 * ublas_v1;
1029 viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
1030 viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
1032 ublas_v1 -= ublas_v1 * alpha - ublas_v2 / beta;
1033 vcl_v1 -= vcl_v1 * gpu_alpha - vcl_v2 / gpu_beta;
1035 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1036 return EXIT_FAILURE;
1038 std::cout <<
"Testing inplace division-multiply-subtract on vector with GPU scalar (subtracting)..." << std::endl;
1039 ublas_v2 = 3 * ublas_v1;
1040 viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
1041 viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
1043 ublas_v1 -= ublas_v1 / alpha - ublas_v2 * beta;
1044 vcl_v1 -= vcl_v1 / gpu_alpha - vcl_v2 * gpu_beta;
1046 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1047 return EXIT_FAILURE;
1050 std::cout <<
"Testing inplace division-subtract on vector with GPU scalar..." << std::endl;
1051 ublas_v2 = 3 * ublas_v1;
1052 viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
1053 viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
1055 ublas_v1 -= alpha * ublas_v2;
1056 vcl_v1 -= gpu_alpha * vcl_v2;
1058 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1059 return EXIT_FAILURE;
1066 for (
size_t i=0; i < ublas_v1.size(); ++i)
1067 ublas_v1(i) = NumericT(i);
1068 ublas_v2 = 3 * ublas_v1;
1069 viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
1070 viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
1072 std::cout <<
"Testing three vector additions..." << std::endl;
1073 ublas_v1 = ublas_v2 + ublas_v1 + ublas_v2;
1074 vcl_v1 = vcl_v2 + vcl_v1 + vcl_v2;
1076 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1077 return EXIT_FAILURE;
1080 ublas_v2 = 3 * ublas_v1;
1081 viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
1082 viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
1084 std::cout <<
"Testing complicated vector expression with CPU scalar..." << std::endl;
1085 ublas_v1 = beta * (ublas_v1 - alpha * ublas_v2);
1086 vcl_v1 = beta * (vcl_v1 - alpha * vcl_v2);
1088 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1089 return EXIT_FAILURE;
1091 std::cout <<
"Testing complicated vector expression with GPU scalar..." << std::endl;
1092 ublas_v1 = beta * (ublas_v1 - alpha * ublas_v2);
1093 vcl_v1 = gpu_beta * (vcl_v1 - gpu_alpha * vcl_v2);
1095 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1096 return EXIT_FAILURE;
1099 ublas_v2 = 3 * ublas_v1;
1100 viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
1101 viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
1103 std::cout <<
"Testing swap..." << std::endl;
1104 swap(ublas_v1, ublas_v2);
1105 swap(vcl_v1, vcl_v2);
1107 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1108 return EXIT_FAILURE;
1111 for (std::size_t i=0; i<ublas_v1.size(); ++i)
1113 ublas_v1[i] = NumericT(1.0) + NumericT(i);
1114 ublas_v2[i] = NumericT(5.0) + NumericT(i);
1117 viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
1118 viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
1120 std::cout <<
"Testing unary operator-..." << std::endl;
1121 ublas_v1 = - ublas_v2;
1124 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1125 return EXIT_FAILURE;
1128 std::cout <<
"Testing elementwise multiplication..." << std::endl;
1129 std::cout <<
" v1 = element_prod(v1, v2);" << std::endl;
1133 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1134 return EXIT_FAILURE;
1136 std::cout <<
" v1 += element_prod(v1, v2);" << std::endl;
1140 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1141 return EXIT_FAILURE;
1143 std::cout <<
" v1 -= element_prod(v1, v2);" << std::endl;
1147 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1148 return EXIT_FAILURE;
1151 std::cout <<
" v1 = element_prod(v1 + v2, v2);" << std::endl;
1155 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1156 return EXIT_FAILURE;
1158 std::cout <<
" v1 += element_prod(v1 + v2, v2);" << std::endl;
1162 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1163 return EXIT_FAILURE;
1165 std::cout <<
" v1 -= element_prod(v1 + v2, v2);" << std::endl;
1169 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1170 return EXIT_FAILURE;
1173 std::cout <<
" v1 = element_prod(v1, v2 + v1);" << std::endl;
1177 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1178 return EXIT_FAILURE;
1180 std::cout <<
" v1 += element_prod(v1, v2 + v1);" << std::endl;
1184 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1185 return EXIT_FAILURE;
1187 std::cout <<
" v1 -= element_prod(v1, v2 + v1);" << std::endl;
1191 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1192 return EXIT_FAILURE;
1195 std::cout <<
" v1 = element_prod(v1 + v2, v2 + v1);" << std::endl;
1199 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1200 return EXIT_FAILURE;
1202 std::cout <<
" v1 += element_prod(v1 + v2, v2 + v1);" << std::endl;
1206 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1207 return EXIT_FAILURE;
1209 std::cout <<
" v1 -= element_prod(v1 + v2, v2 + v1);" << std::endl;
1213 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1214 return EXIT_FAILURE;
1217 std::cout <<
"Testing elementwise division..." << std::endl;
1218 for (std::size_t i=0; i<ublas_v1.size(); ++i)
1220 ublas_v1[i] = NumericT(1 + i);
1221 ublas_v2[i] = NumericT(5 + i);
1224 viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
1225 viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
1230 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1231 return EXIT_FAILURE;
1236 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1237 return EXIT_FAILURE;
1242 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1243 return EXIT_FAILURE;
1249 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1250 return EXIT_FAILURE;
1255 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1256 return EXIT_FAILURE;
1261 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1262 return EXIT_FAILURE;
1268 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1269 return EXIT_FAILURE;
1274 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1275 return EXIT_FAILURE;
1280 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1281 return EXIT_FAILURE;
1287 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1288 return EXIT_FAILURE;
1293 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1294 return EXIT_FAILURE;
1299 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1300 return EXIT_FAILURE;
1302 std::cout <<
"Testing unary elementwise operations..." << std::endl;
1304 #define GENERATE_UNARY_OP_TEST(FUNCNAME) \
1305 ublas_v2 = 3 * ublas_v1; \
1306 viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin()); \
1307 viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin()); \
1309 for (std::size_t i=0; i<ublas_v1.size(); ++i) \
1310 ublas_v1[i] = std::FUNCNAME(ublas_v2[i]); \
1311 vcl_v1 = viennacl::linalg::element_##FUNCNAME(vcl_v2); \
1313 if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS) \
1315 std::cout << "Failure at v1 = " << #FUNCNAME << "(v2)" << std::endl; \
1316 return EXIT_FAILURE; \
1319 for (std::size_t i=0; i<ublas_v1.size(); ++i) \
1320 ublas_v1[i] = std::FUNCNAME(ublas_v1[i] + ublas_v2[i]); \
1321 vcl_v1 = viennacl::linalg::element_##FUNCNAME(vcl_v1 + vcl_v2); \
1323 if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS) \
1325 std::cout << "Failure at v1 = " << #FUNCNAME << "(v1 + v2)" << std::endl; \
1326 return EXIT_FAILURE; \
1329 for (std::size_t i=0; i<ublas_v1.size(); ++i) \
1330 ublas_v1[i] += std::FUNCNAME(ublas_v1[i]); \
1331 vcl_v1 += viennacl::linalg::element_##FUNCNAME(vcl_v1); \
1333 if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS) \
1335 std::cout << "Failure at v1 += " << #FUNCNAME << "(v2)" << std::endl; \
1336 return EXIT_FAILURE; \
1339 for (std::size_t i=0; i<ublas_v1.size(); ++i) \
1340 ublas_v1[i] += std::FUNCNAME(ublas_v1[i] + ublas_v2[i]); \
1341 vcl_v1 += viennacl::linalg::element_##FUNCNAME(vcl_v1 + vcl_v2); \
1343 if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS) \
1345 std::cout << "Failure at v1 += " << #FUNCNAME << "(v1 + v2)" << std::endl; \
1346 return EXIT_FAILURE; \
1349 for (std::size_t i=0; i<ublas_v1.size(); ++i) \
1350 ublas_v1[i] -= std::FUNCNAME(ublas_v2[i]); \
1351 vcl_v1 -= viennacl::linalg::element_##FUNCNAME(vcl_v2); \
1353 if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS) \
1355 std::cout << "Failure at v1 -= " << #FUNCNAME << "(v2)" << std::endl; \
1356 return EXIT_FAILURE; \
1359 for (std::size_t i=0; i<ublas_v1.size(); ++i) \
1360 ublas_v1[i] -= std::FUNCNAME(ublas_v1[i] + ublas_v2[i]); \
1361 vcl_v1 -= viennacl::linalg::element_##FUNCNAME(vcl_v1 + vcl_v2); \
1363 if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS) \
1365 std::cout << "Failure at v1 -= " << #FUNCNAME << "(v1 + v2)" << std::endl; \
1366 return EXIT_FAILURE; \
1384 std::cout <<
"Testing lenghty sum of scaled vectors..." << std::endl;
1385 ublas_v2 = 3 * ublas_v1;
1386 viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
1387 viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
1389 ublas_v1 = ublas_v2 / alpha + beta * ublas_v1 - alpha * ublas_v2 + beta * ublas_v1 - alpha * ublas_v1;
1390 vcl_v1 = vcl_v2 / gpu_alpha + gpu_beta * vcl_v1 - alpha * vcl_v2 + beta * vcl_v1 - alpha * vcl_v1;
1392 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1393 return EXIT_FAILURE;
1400 template<
typename NumericT >
1403 int retval = EXIT_SUCCESS;
1404 std::size_t
size = 12345;
1406 std::cout <<
"Running tests for vector of size " << size << std::endl;
1411 ublas::vector<NumericT> ublas_full_vec(size);
1412 ublas::vector<NumericT> ublas_full_vec2(ublas_full_vec.size());
1414 for (std::size_t i=0; i<ublas_full_vec.size(); ++i)
1416 ublas_full_vec[i] = NumericT(1.0) + NumericT(i);
1417 ublas_full_vec2[i] = NumericT(2.0) + NumericT(i) / NumericT(2);
1420 ublas::range r1( ublas_full_vec.size() / 4, 2 * ublas_full_vec.size() / 4);
1421 ublas::range r2(2 * ublas_full_vec2.size() / 4, 3 * ublas_full_vec2.size() / 4);
1422 ublas::vector_range< ublas::vector<NumericT> > ublas_range_vec(ublas_full_vec, r1);
1423 ublas::vector_range< ublas::vector<NumericT> > ublas_range_vec2(ublas_full_vec2, r2);
1425 ublas::slice s1( ublas_full_vec.size() / 4, 3, ublas_full_vec.size() / 4);
1426 ublas::slice s2(2 * ublas_full_vec2.size() / 4, 2, ublas_full_vec2.size() / 4);
1427 ublas::vector_slice< ublas::vector<NumericT> > ublas_slice_vec(ublas_full_vec,
s1);
1428 ublas::vector_slice< ublas::vector<NumericT> > ublas_slice_vec2(ublas_full_vec2,
s2);
1437 viennacl::copy(ublas_full_vec2.begin(), ublas_full_vec2.end(), vcl_full_vec2.begin());
1439 viennacl::range vcl_r1( vcl_full_vec.size() / 4, 2 * vcl_full_vec.size() / 4);
1440 viennacl::range vcl_r2(2 * vcl_full_vec2.size() / 4, 3 * vcl_full_vec2.size() / 4);
1448 ublas::vector<NumericT> ublas_short_vec(ublas_range_vec);
1449 ublas::vector<NumericT> ublas_short_vec2(ublas_range_vec2);
1451 std::cout <<
"Testing creation of vectors from range..." << std::endl;
1452 if (
check(ublas_short_vec, vcl_short_vec) != EXIT_SUCCESS)
1453 return EXIT_FAILURE;
1454 if (
check(ublas_short_vec2, vcl_short_vec2) != EXIT_SUCCESS)
1455 return EXIT_FAILURE;
1458 viennacl::slice vcl_s1( vcl_full_vec.size() / 4, 3, vcl_full_vec.size() / 4);
1459 viennacl::slice vcl_s2(2 * vcl_full_vec2.size() / 4, 2, vcl_full_vec2.size() / 4);
1466 ublas::vector<NumericT> ublas_short_vec(ublas_slice_vec);
1467 ublas::vector<NumericT> ublas_short_vec2(ublas_slice_vec2);
1469 std::cout <<
"Testing creation of vectors from slice..." << std::endl;
1470 if (
check(ublas_short_vec, vcl_short_vec) != EXIT_SUCCESS)
1471 return EXIT_FAILURE;
1472 if (
check(ublas_short_vec2, vcl_short_vec2) != EXIT_SUCCESS)
1473 return EXIT_FAILURE;
1480 std::cout <<
" ** vcl_v1 = vector, vcl_v2 = vector **" << std::endl;
1481 retval = test<NumericT>(ublas_short_vec, ublas_short_vec2,
1482 vcl_short_vec, vcl_short_vec2);
1483 if (retval != EXIT_SUCCESS)
1484 return EXIT_FAILURE;
1486 std::cout <<
" ** vcl_v1 = vector, vcl_v2 = range **" << std::endl;
1487 retval = test<NumericT>(ublas_short_vec, ublas_short_vec2,
1488 vcl_short_vec, vcl_range_vec2);
1489 if (retval != EXIT_SUCCESS)
1490 return EXIT_FAILURE;
1492 std::cout <<
" ** vcl_v1 = vector, vcl_v2 = slice **" << std::endl;
1493 retval = test<NumericT>(ublas_short_vec, ublas_short_vec2,
1494 vcl_short_vec, vcl_slice_vec2);
1495 if (retval != EXIT_SUCCESS)
1496 return EXIT_FAILURE;
1500 std::cout <<
" ** vcl_v1 = range, vcl_v2 = vector **" << std::endl;
1501 retval = test<NumericT>(ublas_short_vec, ublas_short_vec2,
1502 vcl_range_vec, vcl_short_vec2);
1503 if (retval != EXIT_SUCCESS)
1504 return EXIT_FAILURE;
1506 std::cout <<
" ** vcl_v1 = range, vcl_v2 = range **" << std::endl;
1507 retval = test<NumericT>(ublas_short_vec, ublas_short_vec2,
1508 vcl_range_vec, vcl_range_vec2);
1509 if (retval != EXIT_SUCCESS)
1510 return EXIT_FAILURE;
1512 std::cout <<
" ** vcl_v1 = range, vcl_v2 = slice **" << std::endl;
1513 retval = test<NumericT>(ublas_short_vec, ublas_short_vec2,
1514 vcl_range_vec, vcl_slice_vec2);
1515 if (retval != EXIT_SUCCESS)
1516 return EXIT_FAILURE;
1520 std::cout <<
" ** vcl_v1 = slice, vcl_v2 = vector **" << std::endl;
1521 retval = test<NumericT>(ublas_short_vec, ublas_short_vec2,
1522 vcl_slice_vec, vcl_short_vec2);
1523 if (retval != EXIT_SUCCESS)
1524 return EXIT_FAILURE;
1526 std::cout <<
" ** vcl_v1 = slice, vcl_v2 = range **" << std::endl;
1527 retval = test<NumericT>(ublas_short_vec, ublas_short_vec2,
1528 vcl_slice_vec, vcl_range_vec2);
1529 if (retval != EXIT_SUCCESS)
1530 return EXIT_FAILURE;
1532 std::cout <<
" ** vcl_v1 = slice, vcl_v2 = slice **" << std::endl;
1533 retval = test<NumericT>(ublas_short_vec, ublas_short_vec2,
1534 vcl_slice_vec, vcl_slice_vec2);
1535 if (retval != EXIT_SUCCESS)
1536 return EXIT_FAILURE;
1538 return EXIT_SUCCESS;
1548 std::cout << std::endl;
1549 std::cout <<
"----------------------------------------------" << std::endl;
1550 std::cout <<
"----------------------------------------------" << std::endl;
1551 std::cout <<
"## Test :: Vector with Integer types" << std::endl;
1552 std::cout <<
"----------------------------------------------" << std::endl;
1553 std::cout <<
"----------------------------------------------" << std::endl;
1554 std::cout << std::endl;
1556 int retval = EXIT_SUCCESS;
1558 std::cout << std::endl;
1559 std::cout <<
"----------------------------------------------" << std::endl;
1560 std::cout << std::endl;
1562 std::cout <<
"# Testing setup:" << std::endl;
1563 std::cout <<
" numeric: int" << std::endl;
1564 retval = test<int>();
1565 if ( retval == EXIT_SUCCESS )
1566 std::cout <<
"# Test passed" << std::endl;
1570 std::cout << std::endl;
1571 std::cout <<
"----------------------------------------------" << std::endl;
1572 std::cout << std::endl;
1574 std::cout <<
"# Testing setup:" << std::endl;
1575 std::cout <<
" numeric: long" << std::endl;
1576 retval = test<long>();
1577 if ( retval == EXIT_SUCCESS )
1578 std::cout <<
"# Test passed" << std::endl;
1582 std::cout << std::endl;
1583 std::cout <<
"----------------------------------------------" << std::endl;
1584 std::cout << std::endl;
1586 std::cout << std::endl;
1587 std::cout <<
"------- Test completed --------" << std::endl;
1588 std::cout << std::endl;
int test(UblasVectorType &ublas_v1, UblasVectorType &ublas_v2, ViennaCLVectorType1 &vcl_v1, ViennaCLVectorType2 &vcl_v2)
viennacl::vector_expression< const vector_base< T >, const vector_base< T >, op_element_binary< op_div > > element_div(vector_base< T > const &v1, vector_base< T > const &v2)
vcl_size_t index_norm_inf(vector_base< T > const &vec)
Computes the index of the first entry that is equal to the supremum-norm in modulus.
This class represents a single scalar value on the GPU and behaves mostly like a built-in scalar type...
Generic interface for the l^2-norm. See viennacl/linalg/vector_operations.hpp for implementations...
void plane_rotation(vector_base< T > &vec1, vector_base< T > &vec2, T alpha, T beta)
Computes a plane rotation of two vectors.
void finish()
Synchronizes the execution. finish() will only return after all compute kernels (CUDA, OpenCL) have completed.
viennacl::enable_if< viennacl::is_stl< typename viennacl::traits::tag_of< VectorT1 >::type >::value, typename VectorT1::value_type >::type inner_prod(VectorT1 const &v1, VectorT2 const &v2)
viennacl::scalar< int > s2
viennacl::scalar< float > s1
Generic interface for the computation of inner products. See viennacl/linalg/vector_operations.hpp for implementations.
Generic interface for the l^1-norm. See viennacl/linalg/vector_operations.hpp for implementations...
#define GENERATE_UNARY_OP_TEST(FUNCNAME)
int check(T1 const &t1, T2 const &t2)
viennacl::vector< float > v1
vcl_size_t size(VectorType const &vec)
Generic routine for obtaining the size of a vector (ViennaCL, uBLAS, etc.)
Class for representing non-strided subvectors of a bigger vector x.
Class for representing strided subvectors of a bigger vector x.
ScalarType diff(ScalarType const &s1, ScalarType const &s2)
Proxy classes for vectors.
viennacl::enable_if< viennacl::is_scalar< ScalarT1 >::value &&viennacl::is_scalar< ScalarT2 >::value >::type swap(ScalarT1 &s1, ScalarT2 &s2)
Swaps the contents of two scalars, data is copied.
Represents a vector consisting of 1 at a given index and zeros otherwise.
viennacl::vector< int > v2
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
Represents a vector consisting of scalars 's' only, i.e. v[i] = s for all i. To be used as an initial...
NumericT max(std::vector< NumericT > const &v1)
T norm_inf(std::vector< T, A > const &v1)
void copy(std::vector< NumericT > &cpu_vec, circulant_matrix< NumericT, AlignmentV > &gpu_mat)
Copies a circulant matrix from the std::vector to the OpenCL device (either GPU or multi-core CPU) ...
T norm_1(std::vector< T, A > const &v1)
A range class that refers to an interval [start, stop), where 'start' is included, and 'stop' is excluded.
viennacl::vector_expression< const vector_base< T >, const vector_base< T >, op_element_binary< op_prod > > element_prod(vector_base< T > const &v1, vector_base< T > const &v2)
A slice class that refers to an interval [start, stop), where 'start' is included, and 'stop' is excluded.
A proxy class for a single element of a vector or matrix. This proxy should not be noticed by end-use...
Generic interface for the l^infty-norm. See viennacl/linalg/vector_operations.hpp for implementations...
NumericT min(std::vector< NumericT > const &v1)
void fast_copy(const const_vector_iterator< SCALARTYPE, ALIGNMENT > &gpu_begin, const const_vector_iterator< SCALARTYPE, ALIGNMENT > &gpu_end, CPU_ITERATOR cpu_begin)