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
56 template<
typename ScalarType>
65 template<
typename ScalarType>
74 template<
typename ScalarType>
83 template<
typename ScalarType,
typename VCLVectorType>
86 ublas::vector<ScalarType> v2_cpu(v2.size());
90 for (
unsigned int i=0;i<v1.size(); ++i)
92 if (v2_cpu[i] != v1[i])
99 template<
typename T1,
typename T2>
100 int check(T1
const & t1, T2
const & t2)
102 int retval = EXIT_SUCCESS;
104 if (
diff(t1, t2) != 0)
106 std::cout <<
"# Error! Difference: " << std::abs(
diff(t1, t2)) << std::endl;
107 retval = EXIT_FAILURE;
116 template<
typename NumericT,
typename UblasVectorType,
typename ViennaCLVectorType1,
typename ViennaCLVectorType2 >
117 int test(UblasVectorType & ublas_v1, UblasVectorType & ublas_v2,
118 ViennaCLVectorType1 & vcl_v1, ViennaCLVectorType2 & vcl_v2)
120 int retval = EXIT_SUCCESS;
128 std::cout <<
"Checking for zero_vector initializer..." << std::endl;
130 for (std::size_t i=0; i<ublas_v1.size(); ++i)
133 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
136 std::cout <<
"Checking for scalar_vector initializer..." << std::endl;
138 for (std::size_t i=0; i<ublas_v1.size(); ++i)
139 ublas_v1[i] = cpu_result;
141 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
145 for (std::size_t i=0; i<ublas_v1.size(); ++i)
146 ublas_v1[i] = cpu_result + 1;
148 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
151 std::cout <<
"Checking for unit_vector initializer..." << std::endl;
153 for (std::size_t i=0; i<ublas_v1.size(); ++i)
154 ublas_v1[i] = (i == 5) ? 1 : 0;
156 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
159 for (std::size_t i=0; i<ublas_v1.size(); ++i)
168 std::cout <<
"Checking for successful copy..." << std::endl;
169 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
171 if (
check(ublas_v2, vcl_v2) != EXIT_SUCCESS)
179 std::cout <<
"Testing inner_prod..." << std::endl;
184 if (
check(cpu_result, cpu_result2) != EXIT_SUCCESS)
186 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
189 cpu_result =
inner_prod(ublas_v1 + ublas_v2, ublas_v2 - ublas_v1);
193 if (
check(cpu_result, cpu_result3) != EXIT_SUCCESS)
195 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
199 std::cout <<
"Testing norm_1..." << std::endl;
203 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
206 gpu_result = 2 * cpu_result;
210 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
216 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
220 std::cout <<
"Testing norm_inf..." << std::endl;
224 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
227 gpu_result = 2 * cpu_result;
231 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
237 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
241 std::cout <<
"Testing index_norm_inf..." << std::endl;
245 if (
check(static_cast<NumericT>(cpu_index), static_cast<NumericT>(gpu_index)) != EXIT_SUCCESS)
251 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
257 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
261 std::cout <<
"Testing max..." << std::endl;
262 cpu_result = ublas_v1[0];
263 for (std::size_t i=0; i<ublas_v1.size(); ++i)
264 cpu_result = std::max<NumericT>(cpu_result, ublas_v1[i]);
267 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
270 cpu_result = ublas_v1[0];
271 for (std::size_t i=0; i<ublas_v1.size(); ++i)
272 cpu_result = std::max<NumericT>(cpu_result, ublas_v1[i]);
273 gpu_result = cpu_result;
277 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
280 cpu_result = ublas_v1[0] + ublas_v2[0];
281 for (std::size_t i=0; i<ublas_v1.size(); ++i)
282 cpu_result = std::max<NumericT>(cpu_result, ublas_v1[i] + ublas_v2[i]);
283 gpu_result = cpu_result;
287 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
292 std::cout <<
"Testing min..." << std::endl;
293 cpu_result = ublas_v1[0];
294 for (std::size_t i=0; i<ublas_v1.size(); ++i)
295 cpu_result = std::min<NumericT>(cpu_result, ublas_v1[i]);
298 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
301 cpu_result = ublas_v1[0];
302 for (std::size_t i=0; i<ublas_v1.size(); ++i)
303 cpu_result = std::min<NumericT>(cpu_result, ublas_v1[i]);
304 gpu_result = cpu_result;
308 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
311 cpu_result = ublas_v1[0] + ublas_v2[0];
312 for (std::size_t i=0; i<ublas_v1.size(); ++i)
313 cpu_result = std::min<NumericT>(cpu_result, ublas_v1[i] + ublas_v2[i]);
314 gpu_result = cpu_result;
318 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
322 std::cout <<
"Testing sum..." << std::endl;
324 for (std::size_t i=0; i<ublas_v1.size(); ++i)
325 cpu_result += ublas_v1[i];
329 if (
check(cpu_result, cpu_result2) != EXIT_SUCCESS)
331 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
335 for (std::size_t i=0; i<ublas_v1.size(); ++i)
336 cpu_result += ublas_v1[i] + ublas_v2[i];
340 if (
check(cpu_result, cpu_result3) != EXIT_SUCCESS)
342 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
352 ublas::vector<NumericT> x = ublas_v1;
353 ublas::vector<NumericT> y = ublas_v2;
354 ublas::vector<NumericT> t = ublas_v1;
361 if (
check(x, vcl_v1) != EXIT_SUCCESS)
363 if (
check(y, vcl_v2) != EXIT_SUCCESS)
368 std::cout <<
"Testing assignments..." << std::endl;
370 for (
size_t i=0; i < ublas_v1.size(); ++i)
373 for (
size_t i=0; i < vcl_v1.size(); ++i)
376 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
383 std::cout <<
"Testing scaling with CPU scalar..." << std::endl;
390 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
393 std::cout <<
"Testing scaling with GPU scalar..." << std::endl;
397 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
403 std::cout <<
"Testing shrinking with CPU scalar..." << std::endl;
407 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
410 std::cout <<
"Testing shrinking with GPU scalar..." << std::endl;
414 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
421 for (
size_t i=0; i < ublas_v1.size(); ++i)
423 ublas_v2 = 3 * ublas_v1;
427 std::cout <<
"Testing add on vector..." << std::endl;
429 std::cout <<
"Checking for successful copy..." << std::endl;
430 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
432 if (
check(ublas_v2, vcl_v2) != EXIT_SUCCESS)
435 ublas_v1 = ublas_v1 + ublas_v2;
436 vcl_v1 = vcl_v1 + vcl_v2;
438 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
441 std::cout <<
"Testing add on vector with flipsign..." << std::endl;
442 ublas_v1 = - ublas_v1 + ublas_v2;
443 vcl_v1 = - vcl_v1 + vcl_v2;
445 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
448 std::cout <<
"Testing inplace-add on vector..." << std::endl;
449 ublas_v1 += ublas_v2;
452 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
458 std::cout <<
"Testing sub on vector..." << std::endl;
459 ublas_v2 = 3 * ublas_v1;
463 ublas_v1 = ublas_v1 - ublas_v2;
464 vcl_v1 = vcl_v1 - vcl_v2;
466 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
469 std::cout <<
"Testing inplace-sub on vector..." << std::endl;
470 ublas_v1 -= ublas_v2;
473 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
481 std::cout <<
"Testing multiply-add on vector with CPU scalar (right)..." << std::endl;
482 for (
size_t i=0; i < ublas_v1.size(); ++i)
484 ublas_v2 = 3 * ublas_v1;
488 ublas_v1 = ublas_v1 + alpha * ublas_v2;
489 vcl_v1 = vcl_v1 + alpha * vcl_v2;
491 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
494 std::cout <<
"Testing multiply-add on vector with CPU scalar (left)..." << std::endl;
495 ublas_v2 = 3 * ublas_v1;
499 ublas_v1 = alpha * ublas_v1 + ublas_v2;
500 vcl_v1 = alpha * vcl_v1 + vcl_v2;
502 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
505 std::cout <<
"Testing multiply-add on vector with CPU scalar (both)..." << std::endl;
506 ublas_v2 = 3 * ublas_v1;
510 ublas_v1 = alpha * ublas_v1 + beta * ublas_v2;
511 vcl_v1 = alpha * vcl_v1 + beta * vcl_v2;
513 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
517 std::cout <<
"Testing inplace multiply-add on vector with CPU scalar..." << std::endl;
518 ublas_v2 = 3 * ublas_v1;
522 ublas_v1 += alpha * ublas_v2;
523 vcl_v1 += alpha * vcl_v2;
525 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
529 std::cout <<
"Testing multiply-add on vector with GPU scalar (right)..." << std::endl;
530 ublas_v2 = 3 * ublas_v1;
534 ublas_v1 = ublas_v1 + alpha * ublas_v2;
535 vcl_v1 = vcl_v1 + gpu_alpha * vcl_v2;
537 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
540 std::cout <<
"Testing multiply-add on vector with GPU scalar (left)..." << std::endl;
541 ublas_v2 = 3 * ublas_v1;
545 ublas_v1 = ublas_v1 + alpha * ublas_v2;
546 vcl_v1 = vcl_v1 + gpu_alpha * vcl_v2;
548 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
551 std::cout <<
"Testing multiply-add on vector with GPU scalar (both)..." << std::endl;
552 ublas_v2 = 3 * ublas_v1;
556 ublas_v1 = alpha * ublas_v1 + beta * ublas_v2;
557 vcl_v1 = gpu_alpha * vcl_v1 + gpu_beta * vcl_v2;
559 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
563 std::cout <<
"Testing inplace multiply-add on vector with GPU scalar (both, adding)..." << std::endl;
564 ublas_v2 = 3 * ublas_v1;
568 ublas_v1 += alpha * ublas_v1 + beta * ublas_v2;
569 vcl_v1 += gpu_alpha * vcl_v1 + gpu_beta * vcl_v2;
571 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
574 std::cout <<
"Testing inplace multiply-add on vector with GPU scalar (both, subtracting)..." << std::endl;
575 ublas_v2 = 3 * ublas_v1;
579 ublas_v1 += alpha * ublas_v1 - beta * ublas_v2;
580 vcl_v1 += gpu_alpha * vcl_v1 - gpu_beta * vcl_v2;
582 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
587 std::cout <<
"Testing inplace multiply-add on vector with GPU scalar..." << std::endl;
588 ublas_v2 = 3 * ublas_v1;
592 ublas_v1 += alpha * ublas_v2;
593 vcl_v1 += gpu_alpha * vcl_v2;
595 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
602 std::cout <<
"Testing division-add on vector with CPU scalar (right)..." << std::endl;
603 for (
size_t i=0; i < ublas_v1.size(); ++i)
605 ublas_v2 = 3 * ublas_v1;
609 ublas_v1 = ublas_v1 + ublas_v2 / alpha;
610 vcl_v1 = vcl_v1 + vcl_v2 / alpha;
612 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
616 std::cout <<
"Testing division-add on vector with CPU scalar (left)..." << std::endl;
617 ublas_v2 = 3 * ublas_v1;
621 ublas_v1 = ublas_v1 / alpha + ublas_v2;
622 vcl_v1 = vcl_v1 / alpha + vcl_v2;
624 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
627 std::cout <<
"Testing division-add on vector with CPU scalar (both)..." << std::endl;
628 ublas_v2 = 3 * ublas_v1;
632 ublas_v1 = ublas_v1 / alpha + ublas_v2 / beta;
633 vcl_v1 = vcl_v1 / alpha + vcl_v2 / beta;
635 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
638 std::cout <<
"Testing division-multiply-add on vector with CPU scalar..." << std::endl;
639 ublas_v2 = 3 * ublas_v1;
643 ublas_v1 = ublas_v1 / alpha + ublas_v2 * beta;
644 vcl_v1 = vcl_v1 / alpha + vcl_v2 * beta;
646 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
650 std::cout <<
"Testing multiply-division-add on vector with CPU scalar..." << std::endl;
651 ublas_v2 = 3 * ublas_v1;
655 ublas_v1 = ublas_v1 * alpha + ublas_v2 / beta;
656 vcl_v1 = vcl_v1 * alpha + vcl_v2 / beta;
658 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
663 std::cout <<
"Testing inplace division-add on vector with CPU scalar..." << std::endl;
664 ublas_v2 = 3 * ublas_v1;
668 ublas_v1 += ublas_v2 / alpha;
669 vcl_v1 += vcl_v2 / alpha;
671 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
675 std::cout <<
"Testing division-add on vector with GPU scalar (right)..." << std::endl;
676 ublas_v2 = 3 * ublas_v1;
680 ublas_v1 = ublas_v1 + ublas_v2 / alpha;
681 vcl_v1 = vcl_v1 + vcl_v2 / gpu_alpha;
683 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
686 std::cout <<
"Testing division-add on vector with GPU scalar (left)..." << std::endl;
687 ublas_v2 = 3 * ublas_v1;
691 ublas_v1 = ublas_v1 + ublas_v2 / alpha;
692 vcl_v1 = vcl_v1 + vcl_v2 / gpu_alpha;
694 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
697 std::cout <<
"Testing division-add on vector with GPU scalar (both)..." << std::endl;
698 ublas_v2 = 3 * ublas_v1;
702 ublas_v1 = ublas_v1 / alpha + ublas_v2 / beta;
703 vcl_v1 = vcl_v1 / gpu_alpha + vcl_v2 / gpu_beta;
705 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
709 std::cout <<
"Testing inplace division-add on vector with GPU scalar (both, 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 division-add on vector with GPU scalar (both, 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)
731 std::cout <<
"Testing inplace division-multiply-add on vector with GPU scalar (adding)..." << std::endl;
732 ublas_v2 = 3 * ublas_v1;
736 ublas_v1 += ublas_v1 / alpha + ublas_v2 * beta;
737 vcl_v1 += vcl_v1 / gpu_alpha + vcl_v2 * gpu_beta;
739 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
742 std::cout <<
"Testing inplace multiply-division-add on vector with GPU scalar (subtracting)..." << std::endl;
743 ublas_v2 = 3 * ublas_v1;
747 ublas_v1 += ublas_v1 * alpha - ublas_v2 / beta;
748 vcl_v1 += vcl_v1 * gpu_alpha - vcl_v2 / gpu_beta;
750 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
755 std::cout <<
"Testing inplace division-add on vector with GPU scalar..." << std::endl;
756 ublas_v2 = 3 * ublas_v1;
760 ublas_v1 += ublas_v2 * alpha;
761 vcl_v1 += vcl_v2 * gpu_alpha;
763 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
769 std::cout <<
"Testing multiply-subtract on vector with CPU scalar (right)..." << std::endl;
770 for (
size_t i=0; i < ublas_v1.size(); ++i)
772 ublas_v2 = 3 * ublas_v1;
776 ublas_v1 = ublas_v1 - alpha * ublas_v2;
777 vcl_v1 = vcl_v1 - alpha * vcl_v2;
779 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
783 std::cout <<
"Testing multiply-subtract on vector with CPU scalar (left)..." << std::endl;
784 ublas_v2 = 3 * ublas_v1;
788 ublas_v1 = alpha * ublas_v1 - ublas_v2;
789 vcl_v1 = alpha * vcl_v1 - vcl_v2;
791 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
794 std::cout <<
"Testing multiply-subtract on vector with CPU scalar (both)..." << std::endl;
795 ublas_v2 = 3 * ublas_v1;
799 ublas_v1 = alpha * ublas_v1 - beta * ublas_v2;
800 vcl_v1 = alpha * vcl_v1 - beta * vcl_v2;
802 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
806 std::cout <<
"Testing inplace multiply-subtract on vector with CPU scalar..." << std::endl;
807 ublas_v2 = 3 * ublas_v1;
811 ublas_v1 -= alpha * ublas_v2;
812 vcl_v1 -= alpha * vcl_v2;
814 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
818 std::cout <<
"Testing multiply-subtract on vector with GPU scalar (right)..." << std::endl;
819 ublas_v2 = 3 * ublas_v1;
823 ublas_v1 = ublas_v1 - alpha * ublas_v2;
824 vcl_v1 = vcl_v1 - gpu_alpha * vcl_v2;
826 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
829 std::cout <<
"Testing multiply-subtract on vector with GPU scalar (left)..." << std::endl;
830 ublas_v2 = 3 * ublas_v1;
834 ublas_v1 = ublas_v1 - alpha * ublas_v2;
835 vcl_v1 = vcl_v1 - gpu_alpha * vcl_v2;
837 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
840 std::cout <<
"Testing multiply-subtract on vector with GPU scalar (both)..." << 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)
851 std::cout <<
"Testing inplace multiply-subtract on vector with GPU scalar (both, adding)..." << std::endl;
852 ublas_v2 = 3 * ublas_v1;
856 ublas_v1 -= alpha * ublas_v1 + beta * ublas_v2;
857 vcl_v1 -= gpu_alpha * vcl_v1 + gpu_beta * vcl_v2;
859 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
862 std::cout <<
"Testing inplace multiply-subtract on vector with GPU scalar (both, subtracting)..." << std::endl;
863 ublas_v2 = 3 * ublas_v1;
867 ublas_v1 -= alpha * ublas_v1 - beta * ublas_v2;
868 vcl_v1 -= gpu_alpha * vcl_v1 - gpu_beta * vcl_v2;
870 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
874 std::cout <<
"Testing inplace multiply-subtract on vector with GPU scalar..." << std::endl;
875 ublas_v2 = 3 * ublas_v1;
879 ublas_v1 -= alpha * ublas_v2;
880 vcl_v1 -= gpu_alpha * vcl_v2;
882 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
890 std::cout <<
"Testing division-subtract on vector with CPU scalar (right)..." << std::endl;
891 for (
size_t i=0; i < ublas_v1.size(); ++i)
893 ublas_v2 = 3 * ublas_v1;
897 ublas_v1 = ublas_v1 - ublas_v2 / alpha;
898 vcl_v1 = vcl_v1 - vcl_v2 / alpha;
900 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
904 std::cout <<
"Testing division-subtract on vector with CPU scalar (left)..." << std::endl;
905 ublas_v2 = 3 * ublas_v1;
909 ublas_v1 = ublas_v1 / alpha - ublas_v2;
910 vcl_v1 = vcl_v1 / alpha - vcl_v2;
912 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
915 std::cout <<
"Testing division-subtract on vector with CPU scalar (both)..." << std::endl;
916 ublas_v2 = 3 * ublas_v1;
920 ublas_v1 = ublas_v1 / alpha - ublas_v2 / alpha;
921 vcl_v1 = vcl_v1 / alpha - vcl_v2 / alpha;
923 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
927 std::cout <<
"Testing inplace division-subtract on vector with CPU scalar..." << std::endl;
928 ublas_v2 = 3 * ublas_v1;
932 ublas_v1 -= ublas_v2 / alpha;
933 vcl_v1 -= vcl_v2 / alpha;
935 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
938 std::cout <<
"Testing inplace division-subtract on vector with GPU scalar..." << std::endl;
939 ublas_v2 = 3 * ublas_v1;
943 ublas_v1 -= ublas_v2 / alpha;
944 vcl_v1 -= vcl_v2 / gpu_alpha;
946 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
950 std::cout <<
"Testing division-subtract on vector with GPU scalar (right)..." << std::endl;
951 ublas_v2 = 3 * ublas_v1;
955 ublas_v1 = ublas_v1 - ublas_v2 / alpha;
956 vcl_v1 = vcl_v1 - vcl_v2 / gpu_alpha;
958 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
961 std::cout <<
"Testing division-subtract on vector with GPU scalar (left)..." << std::endl;
962 ublas_v2 = 3 * ublas_v1;
966 ublas_v1 = ublas_v1 - ublas_v2 / alpha;
967 vcl_v1 = vcl_v1 - vcl_v2 / gpu_alpha;
969 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
972 std::cout <<
"Testing division-subtract on vector with GPU scalar (both)..." << 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 inplace division-subtract on vector with GPU scalar (both, adding)..." << 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 inplace division-subtract on vector with GPU scalar (both, subtracting)..." << 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 multiply-division-subtract on vector with GPU scalar..." << 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 division-multiply-subtract on vector with GPU scalar..." << 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 (adding)..." << 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 (adding)..." << 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;
1049 std::cout <<
"Testing inplace multiply-division-subtract on vector with GPU scalar (subtracting)..." << std::endl;
1050 ublas_v2 = 3 * ublas_v1;
1051 viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
1052 viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
1054 ublas_v1 -= ublas_v1 * alpha - ublas_v2 / beta;
1055 vcl_v1 -= vcl_v1 * gpu_alpha - vcl_v2 / gpu_beta;
1057 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1058 return EXIT_FAILURE;
1060 std::cout <<
"Testing inplace division-multiply-subtract on vector with GPU scalar (subtracting)..." << std::endl;
1061 ublas_v2 = 3 * ublas_v1;
1062 viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
1063 viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
1065 ublas_v1 -= ublas_v1 / alpha - ublas_v2 * beta;
1066 vcl_v1 -= vcl_v1 / gpu_alpha - vcl_v2 * gpu_beta;
1068 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1069 return EXIT_FAILURE;
1072 std::cout <<
"Testing inplace division-subtract on vector with GPU scalar..." << std::endl;
1073 ublas_v2 = 3 * ublas_v1;
1074 viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
1075 viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
1077 ublas_v1 -= alpha * ublas_v2;
1078 vcl_v1 -= gpu_alpha * vcl_v2;
1080 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1081 return EXIT_FAILURE;
1088 for (
size_t i=0; i < ublas_v1.size(); ++i)
1090 ublas_v2 = 3 * ublas_v1;
1091 viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
1092 viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
1094 std::cout <<
"Testing three vector additions..." << std::endl;
1095 ublas_v1 = ublas_v2 + ublas_v1 + ublas_v2;
1096 vcl_v1 = vcl_v2 + vcl_v1 + vcl_v2;
1098 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1099 return EXIT_FAILURE;
1102 ublas_v2 = 3 * ublas_v1;
1103 viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
1104 viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
1106 std::cout <<
"Testing complicated vector expression with CPU scalar..." << std::endl;
1107 ublas_v1 = beta * (ublas_v1 - alpha * ublas_v2);
1108 vcl_v1 = beta * (vcl_v1 - alpha * vcl_v2);
1110 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1111 return EXIT_FAILURE;
1113 std::cout <<
"Testing complicated vector expression with GPU scalar..." << std::endl;
1114 ublas_v1 = beta * (ublas_v1 - alpha * ublas_v2);
1115 vcl_v1 = gpu_beta * (vcl_v1 - gpu_alpha * vcl_v2);
1117 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1118 return EXIT_FAILURE;
1121 ublas_v2 = 3 * ublas_v1;
1122 viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
1123 viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
1125 std::cout <<
"Testing swap..." << std::endl;
1126 swap(ublas_v1, ublas_v2);
1127 swap(vcl_v1, vcl_v2);
1129 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1130 return EXIT_FAILURE;
1133 for (std::size_t i=0; i<ublas_v1.size(); ++i)
1139 viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
1140 viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
1142 std::cout <<
"Testing unary operator-..." << std::endl;
1143 ublas_v1 = - ublas_v2;
1146 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1147 return EXIT_FAILURE;
1150 std::cout <<
"Testing elementwise multiplication..." << std::endl;
1151 std::cout <<
" v1 = element_prod(v1, v2);" << std::endl;
1155 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1156 return EXIT_FAILURE;
1158 std::cout <<
" v1 += element_prod(v1, v2);" << std::endl;
1162 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1163 return EXIT_FAILURE;
1165 std::cout <<
" v1 -= element_prod(v1, v2);" << std::endl;
1169 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1170 return EXIT_FAILURE;
1173 std::cout <<
" v1 = element_prod(v1 + v2, v2);" << std::endl;
1177 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1178 return EXIT_FAILURE;
1180 std::cout <<
" v1 += element_prod(v1 + v2, v2);" << std::endl;
1184 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1185 return EXIT_FAILURE;
1187 std::cout <<
" v1 -= element_prod(v1 + v2, v2);" << std::endl;
1191 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1192 return EXIT_FAILURE;
1195 std::cout <<
" v1 = element_prod(v1, 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 + v1);" << std::endl;
1206 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1207 return EXIT_FAILURE;
1209 std::cout <<
" v1 -= element_prod(v1, v2 + v1);" << std::endl;
1213 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1214 return EXIT_FAILURE;
1217 std::cout <<
" v1 = element_prod(v1 + v2, v2 + v1);" << std::endl;
1221 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1222 return EXIT_FAILURE;
1224 std::cout <<
" v1 += element_prod(v1 + v2, v2 + v1);" << std::endl;
1228 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1229 return EXIT_FAILURE;
1231 std::cout <<
" v1 -= element_prod(v1 + v2, v2 + v1);" << std::endl;
1235 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1236 return EXIT_FAILURE;
1239 std::cout <<
"Testing elementwise division..." << std::endl;
1240 for (std::size_t i=0; i<ublas_v1.size(); ++i)
1246 viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
1247 viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
1252 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1253 return EXIT_FAILURE;
1258 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1259 return EXIT_FAILURE;
1264 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1265 return EXIT_FAILURE;
1271 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1272 return EXIT_FAILURE;
1277 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1278 return EXIT_FAILURE;
1283 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1284 return EXIT_FAILURE;
1290 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1291 return EXIT_FAILURE;
1296 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1297 return EXIT_FAILURE;
1302 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1303 return EXIT_FAILURE;
1309 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1310 return EXIT_FAILURE;
1315 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1316 return EXIT_FAILURE;
1321 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1322 return EXIT_FAILURE;
1324 std::cout <<
"Testing unary elementwise operations..." << std::endl;
1326 #define GENERATE_UNARY_OP_TEST(FUNCNAME) \
1327 ublas_v2 = 3 * ublas_v1; \
1328 viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin()); \
1329 viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin()); \
1331 for (std::size_t i=0; i<ublas_v1.size(); ++i) \
1332 ublas_v1[i] = std::FUNCNAME(ublas_v2[i]); \
1333 vcl_v1 = viennacl::linalg::element_##FUNCNAME(vcl_v2); \
1335 if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS) \
1337 std::cout << "Failure at v1 = " << #FUNCNAME << "(v2)" << std::endl; \
1338 return EXIT_FAILURE; \
1341 for (std::size_t i=0; i<ublas_v1.size(); ++i) \
1342 ublas_v1[i] = std::FUNCNAME(ublas_v1[i] + ublas_v2[i]); \
1343 vcl_v1 = viennacl::linalg::element_##FUNCNAME(vcl_v1 + vcl_v2); \
1345 if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS) \
1347 std::cout << "Failure at v1 = " << #FUNCNAME << "(v1 + v2)" << std::endl; \
1348 return EXIT_FAILURE; \
1351 for (std::size_t i=0; i<ublas_v1.size(); ++i) \
1352 ublas_v1[i] += std::FUNCNAME(ublas_v1[i]); \
1353 vcl_v1 += viennacl::linalg::element_##FUNCNAME(vcl_v1); \
1355 if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS) \
1357 std::cout << "Failure at v1 += " << #FUNCNAME << "(v2)" << std::endl; \
1358 return EXIT_FAILURE; \
1361 for (std::size_t i=0; i<ublas_v1.size(); ++i) \
1362 ublas_v1[i] += std::FUNCNAME(ublas_v1[i] + ublas_v2[i]); \
1363 vcl_v1 += viennacl::linalg::element_##FUNCNAME(vcl_v1 + vcl_v2); \
1365 if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS) \
1367 std::cout << "Failure at v1 += " << #FUNCNAME << "(v1 + v2)" << std::endl; \
1368 return EXIT_FAILURE; \
1371 for (std::size_t i=0; i<ublas_v1.size(); ++i) \
1372 ublas_v1[i] -= std::FUNCNAME(ublas_v2[i]); \
1373 vcl_v1 -= viennacl::linalg::element_##FUNCNAME(vcl_v2); \
1375 if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS) \
1377 std::cout << "Failure at v1 -= " << #FUNCNAME << "(v2)" << std::endl; \
1378 return EXIT_FAILURE; \
1381 for (std::size_t i=0; i<ublas_v1.size(); ++i) \
1382 ublas_v1[i] -= std::FUNCNAME(ublas_v1[i] + ublas_v2[i]); \
1383 vcl_v1 -= viennacl::linalg::element_##FUNCNAME(vcl_v1 + vcl_v2); \
1385 if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS) \
1387 std::cout << "Failure at v1 -= " << #FUNCNAME << "(v1 + v2)" << std::endl; \
1388 return EXIT_FAILURE; \
1406 std::cout <<
"Testing lenghty sum of scaled vectors..." << std::endl;
1407 ublas_v2 = 3 * ublas_v1;
1408 viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
1409 viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
1411 ublas_v1 = ublas_v2 / alpha + beta * ublas_v1 - alpha * ublas_v2 + beta * ublas_v1 - alpha * ublas_v1;
1412 vcl_v1 = vcl_v2 / gpu_alpha + gpu_beta * vcl_v1 - alpha * vcl_v2 + beta * vcl_v1 - alpha * vcl_v1;
1414 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1415 return EXIT_FAILURE;
1422 template<
typename NumericT >
1425 int retval = EXIT_SUCCESS;
1426 std::size_t
size = 12345;
1428 std::cout <<
"Running tests for vector of size " << size << std::endl;
1433 ublas::vector<NumericT> ublas_full_vec(size);
1434 ublas::vector<NumericT> ublas_full_vec2(ublas_full_vec.size());
1436 for (std::size_t i=0; i<ublas_full_vec.size(); ++i)
1442 ublas::range r1( ublas_full_vec.size() / 4, 2 * ublas_full_vec.size() / 4);
1443 ublas::range r2(2 * ublas_full_vec2.size() / 4, 3 * ublas_full_vec2.size() / 4);
1444 ublas::vector_range< ublas::vector<NumericT> > ublas_range_vec(ublas_full_vec, r1);
1445 ublas::vector_range< ublas::vector<NumericT> > ublas_range_vec2(ublas_full_vec2, r2);
1447 ublas::slice s1( ublas_full_vec.size() / 4, 3, ublas_full_vec.size() / 4);
1448 ublas::slice s2(2 * ublas_full_vec2.size() / 4, 2, ublas_full_vec2.size() / 4);
1449 ublas::vector_slice< ublas::vector<NumericT> > ublas_slice_vec(ublas_full_vec,
s1);
1450 ublas::vector_slice< ublas::vector<NumericT> > ublas_slice_vec2(ublas_full_vec2,
s2);
1459 viennacl::copy(ublas_full_vec2.begin(), ublas_full_vec2.end(), vcl_full_vec2.begin());
1461 viennacl::range vcl_r1( vcl_full_vec.size() / 4, 2 * vcl_full_vec.size() / 4);
1462 viennacl::range vcl_r2(2 * vcl_full_vec2.size() / 4, 3 * vcl_full_vec2.size() / 4);
1470 ublas::vector<NumericT> ublas_short_vec(ublas_range_vec);
1471 ublas::vector<NumericT> ublas_short_vec2(ublas_range_vec2);
1473 std::cout <<
"Testing creation of vectors from range..." << std::endl;
1474 if (
check(ublas_short_vec, vcl_short_vec) != EXIT_SUCCESS)
1475 return EXIT_FAILURE;
1476 if (
check(ublas_short_vec2, vcl_short_vec2) != EXIT_SUCCESS)
1477 return EXIT_FAILURE;
1480 viennacl::slice vcl_s1( vcl_full_vec.size() / 4, 3, vcl_full_vec.size() / 4);
1481 viennacl::slice vcl_s2(2 * vcl_full_vec2.size() / 4, 2, vcl_full_vec2.size() / 4);
1488 ublas::vector<NumericT> ublas_short_vec(ublas_slice_vec);
1489 ublas::vector<NumericT> ublas_short_vec2(ublas_slice_vec2);
1491 std::cout <<
"Testing creation of vectors from slice..." << std::endl;
1492 if (
check(ublas_short_vec, vcl_short_vec) != EXIT_SUCCESS)
1493 return EXIT_FAILURE;
1494 if (
check(ublas_short_vec2, vcl_short_vec2) != EXIT_SUCCESS)
1495 return EXIT_FAILURE;
1502 std::cout <<
" ** vcl_v1 = vector, vcl_v2 = vector **" << std::endl;
1503 retval = test<NumericT>(ublas_short_vec, ublas_short_vec2,
1504 vcl_short_vec, vcl_short_vec2);
1505 if (retval != EXIT_SUCCESS)
1506 return EXIT_FAILURE;
1508 std::cout <<
" ** vcl_v1 = vector, vcl_v2 = range **" << std::endl;
1509 retval = test<NumericT>(ublas_short_vec, ublas_short_vec2,
1510 vcl_short_vec, vcl_range_vec2);
1511 if (retval != EXIT_SUCCESS)
1512 return EXIT_FAILURE;
1514 std::cout <<
" ** vcl_v1 = vector, vcl_v2 = slice **" << std::endl;
1515 retval = test<NumericT>(ublas_short_vec, ublas_short_vec2,
1516 vcl_short_vec, vcl_slice_vec2);
1517 if (retval != EXIT_SUCCESS)
1518 return EXIT_FAILURE;
1522 std::cout <<
" ** vcl_v1 = range, vcl_v2 = vector **" << std::endl;
1523 retval = test<NumericT>(ublas_short_vec, ublas_short_vec2,
1524 vcl_range_vec, vcl_short_vec2);
1525 if (retval != EXIT_SUCCESS)
1526 return EXIT_FAILURE;
1528 std::cout <<
" ** vcl_v1 = range, vcl_v2 = range **" << std::endl;
1529 retval = test<NumericT>(ublas_short_vec, ublas_short_vec2,
1530 vcl_range_vec, vcl_range_vec2);
1531 if (retval != EXIT_SUCCESS)
1532 return EXIT_FAILURE;
1534 std::cout <<
" ** vcl_v1 = range, vcl_v2 = slice **" << std::endl;
1535 retval = test<NumericT>(ublas_short_vec, ublas_short_vec2,
1536 vcl_range_vec, vcl_slice_vec2);
1537 if (retval != EXIT_SUCCESS)
1538 return EXIT_FAILURE;
1542 std::cout <<
" ** vcl_v1 = slice, vcl_v2 = vector **" << std::endl;
1543 retval = test<NumericT>(ublas_short_vec, ublas_short_vec2,
1544 vcl_slice_vec, vcl_short_vec2);
1545 if (retval != EXIT_SUCCESS)
1546 return EXIT_FAILURE;
1548 std::cout <<
" ** vcl_v1 = slice, vcl_v2 = range **" << std::endl;
1549 retval = test<NumericT>(ublas_short_vec, ublas_short_vec2,
1550 vcl_slice_vec, vcl_range_vec2);
1551 if (retval != EXIT_SUCCESS)
1552 return EXIT_FAILURE;
1554 std::cout <<
" ** vcl_v1 = slice, vcl_v2 = slice **" << std::endl;
1555 retval = test<NumericT>(ublas_short_vec, ublas_short_vec2,
1556 vcl_slice_vec, vcl_slice_vec2);
1557 if (retval != EXIT_SUCCESS)
1558 return EXIT_FAILURE;
1560 return EXIT_SUCCESS;
1570 std::cout << std::endl;
1571 std::cout <<
"----------------------------------------------" << std::endl;
1572 std::cout <<
"----------------------------------------------" << std::endl;
1573 std::cout <<
"## Test :: Vector with Integer types" << std::endl;
1574 std::cout <<
"----------------------------------------------" << std::endl;
1575 std::cout <<
"----------------------------------------------" << std::endl;
1576 std::cout << std::endl;
1578 int retval = EXIT_SUCCESS;
1580 std::cout << std::endl;
1581 std::cout <<
"----------------------------------------------" << std::endl;
1582 std::cout << std::endl;
1584 std::cout <<
"# Testing setup:" << std::endl;
1585 std::cout <<
" numeric: int" << std::endl;
1586 retval = test<int>();
1587 if ( retval == EXIT_SUCCESS )
1588 std::cout <<
"# Test passed" << std::endl;
1592 std::cout << std::endl;
1593 std::cout <<
"----------------------------------------------" << std::endl;
1594 std::cout << std::endl;
1596 std::cout <<
"# Testing setup:" << std::endl;
1597 std::cout <<
" numeric: long" << std::endl;
1598 retval = test<long>();
1599 if ( retval == EXIT_SUCCESS )
1600 std::cout <<
"# Test passed" << std::endl;
1604 std::cout << std::endl;
1605 std::cout <<
"----------------------------------------------" << std::endl;
1606 std::cout << std::endl;
1608 std::cout << std::endl;
1609 std::cout <<
"------- Test completed --------" << std::endl;
1610 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...
viennacl::scalar_expression< const viennacl::vector_base< NumericT >, const viennacl::vector_base< NumericT >, viennacl::op_sum > sum(viennacl::vector_base< NumericT > const &x)
User interface function for computing the sum of all elements of a vector.
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.
Stub routines for the summation of elements in a vector, or all elements in either a row or column of...
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)