33 #include <boost/numeric/ublas/io.hpp>
34 #include <boost/numeric/ublas/vector.hpp>
35 #include <boost/numeric/ublas/vector_proxy.hpp>
41 #define VIENNACL_WITH_UBLAS 1
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])
101 template<
typename T1,
typename T2>
102 int check(T1
const & t1, T2
const & t2)
104 int retval = EXIT_SUCCESS;
106 if (
diff(t1, t2) != 0)
108 std::cout <<
"# Error! Difference: " <<
diff(t1, t2) << std::endl;
109 retval = EXIT_FAILURE;
118 template<
typename NumericT,
typename UblasVectorType,
typename ViennaCLVectorType1,
typename ViennaCLVectorType2 >
119 int test(UblasVectorType & ublas_v1, UblasVectorType & ublas_v2,
120 ViennaCLVectorType1 & vcl_v1, ViennaCLVectorType2 & vcl_v2)
122 int retval = EXIT_SUCCESS;
130 std::cout <<
"Checking for zero_vector initializer..." << std::endl;
132 for (std::size_t i=0; i<ublas_v1.size(); ++i)
135 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
138 std::cout <<
"Checking for scalar_vector initializer..." << std::endl;
140 for (std::size_t i=0; i<ublas_v1.size(); ++i)
141 ublas_v1[i] = cpu_result;
143 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
147 for (std::size_t i=0; i<ublas_v1.size(); ++i)
148 ublas_v1[i] = cpu_result + 1;
150 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
153 std::cout <<
"Checking for unit_vector initializer..." << std::endl;
155 for (std::size_t i=0; i<ublas_v1.size(); ++i)
156 ublas_v1[i] = (i == 5) ? 1 : 0;
158 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
161 for (std::size_t i=0; i<ublas_v1.size(); ++i)
170 std::cout <<
"Checking for successful copy..." << std::endl;
171 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
173 if (
check(ublas_v2, vcl_v2) != EXIT_SUCCESS)
181 std::cout <<
"Testing inner_prod..." << std::endl;
186 if (
check(cpu_result, cpu_result2) != EXIT_SUCCESS)
188 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
191 cpu_result =
inner_prod(ublas_v1 + ublas_v2, 2*ublas_v2);
195 if (
check(cpu_result, cpu_result3) != EXIT_SUCCESS)
197 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
201 std::cout <<
"Testing norm_1..." << std::endl;
203 for (std::size_t i=0; i<ublas_v1.size(); ++i)
204 cpu_result += ublas_v1[i];
207 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
211 for (std::size_t i=0; i<ublas_v1.size(); ++i)
212 cpu_result2 += ublas_v1[i];
215 if (
check(cpu_result, cpu_result2) != EXIT_SUCCESS)
219 for (std::size_t i=0; i<ublas_v1.size(); ++i)
220 cpu_result2 += ublas_v1[i] + ublas_v2[i];
223 if (
check(cpu_result, cpu_result2) != EXIT_SUCCESS)
227 std::cout <<
"Testing norm_inf..." << std::endl;
229 for (std::size_t i=0; i<ublas_v1.size(); ++i)
230 if (ublas_v1[i] > cpu_result)
231 cpu_result = ublas_v1[i];
234 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
238 for (std::size_t i=0; i<ublas_v1.size(); ++i)
239 if (ublas_v1[i] > cpu_result2)
240 cpu_result2 = ublas_v1[i];
243 if (
check(cpu_result, cpu_result2) != EXIT_SUCCESS)
247 for (std::size_t i=0; i<ublas_v1.size(); ++i)
248 if (ublas_v1[i] + ublas_v2[i] > cpu_result2)
249 cpu_result2 = ublas_v1[i] + ublas_v2[i];
252 if (
check(cpu_result, cpu_result2) != EXIT_SUCCESS)
256 std::cout <<
"Testing index_norm_inf..." << std::endl;
258 std::size_t cpu_index = 0;
260 for (std::size_t i=0; i<ublas_v1.size(); ++i)
261 if (ublas_v1[i] > cpu_result)
263 cpu_result = ublas_v1[i];
268 if (
check(static_cast<NumericT>(cpu_index), static_cast<NumericT>(gpu_index)) != EXIT_SUCCESS)
273 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
278 for (std::size_t i=0; i<ublas_v1.size(); ++i)
279 if (ublas_v1[i] + ublas_v2[i] > cpu_result)
281 cpu_result = ublas_v1[i];
286 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
290 std::cout <<
"Testing max..." << std::endl;
291 cpu_result = ublas_v1[0];
292 for (std::size_t i=0; i<ublas_v1.size(); ++i)
293 cpu_result = std::max<NumericT>(cpu_result, ublas_v1[i]);
296 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
299 cpu_result = ublas_v1[0];
300 for (std::size_t i=0; i<ublas_v1.size(); ++i)
301 cpu_result = std::max<NumericT>(cpu_result, ublas_v1[i]);
302 gpu_result = cpu_result;
306 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
309 cpu_result = ublas_v1[0] + ublas_v2[0];
310 for (std::size_t i=0; i<ublas_v1.size(); ++i)
311 cpu_result = std::max<NumericT>(cpu_result, ublas_v1[i] + ublas_v2[i]);
312 gpu_result = cpu_result;
316 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
321 std::cout <<
"Testing min..." << std::endl;
322 cpu_result = ublas_v1[0];
323 for (std::size_t i=0; i<ublas_v1.size(); ++i)
324 cpu_result = std::min<NumericT>(cpu_result, ublas_v1[i]);
327 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
330 cpu_result = ublas_v1[0];
331 for (std::size_t i=0; i<ublas_v1.size(); ++i)
332 cpu_result = std::min<NumericT>(cpu_result, ublas_v1[i]);
333 gpu_result = cpu_result;
337 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
340 cpu_result = ublas_v1[0] + ublas_v2[0];
341 for (std::size_t i=0; i<ublas_v1.size(); ++i)
342 cpu_result = std::min<NumericT>(cpu_result, ublas_v1[i] + ublas_v2[i]);
343 gpu_result = cpu_result;
347 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
351 std::cout <<
"Testing sum..." << std::endl;
353 for (std::size_t i=0; i<ublas_v1.size(); ++i)
354 cpu_result += ublas_v1[i];
358 if (
check(cpu_result, cpu_result2) != EXIT_SUCCESS)
360 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
364 for (std::size_t i=0; i<ublas_v1.size(); ++i)
365 cpu_result += ublas_v1[i] + ublas_v2[i];
369 if (
check(cpu_result, cpu_result3) != EXIT_SUCCESS)
371 if (
check(cpu_result, gpu_result) != EXIT_SUCCESS)
377 std::cout <<
"Testing assignments..." << std::endl;
379 for (
size_t i=0; i < ublas_v1.size(); ++i)
382 for (
size_t i=0; i < vcl_v1.size(); ++i)
385 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
392 std::cout <<
"Testing scaling with CPU scalar..." << std::endl;
399 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
402 std::cout <<
"Testing scaling with GPU scalar..." << std::endl;
406 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
412 std::cout <<
"Testing shrinking with CPU scalar..." << std::endl;
416 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
419 std::cout <<
"Testing shrinking with GPU scalar..." << std::endl;
423 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
430 for (
size_t i=0; i < ublas_v1.size(); ++i)
432 ublas_v2 = 3 * ublas_v1;
436 std::cout <<
"Testing add on vector..." << std::endl;
438 std::cout <<
"Checking for successful copy..." << std::endl;
439 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
441 if (
check(ublas_v2, vcl_v2) != EXIT_SUCCESS)
444 ublas_v1 = ublas_v1 + ublas_v2;
445 vcl_v1 = vcl_v1 + vcl_v2;
447 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
450 std::cout <<
"Testing inplace-add on vector..." << std::endl;
451 ublas_v1 += ublas_v2;
454 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
461 std::cout <<
"Testing multiply-add on vector with CPU scalar (right)..." << std::endl;
462 for (
size_t i=0; i < ublas_v1.size(); ++i)
464 ublas_v2 = 3 * ublas_v1;
468 ublas_v1 = ublas_v1 + alpha * ublas_v2;
469 vcl_v1 = vcl_v1 + alpha * vcl_v2;
471 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
474 std::cout <<
"Testing multiply-add on vector with CPU scalar (left)..." << std::endl;
475 ublas_v2 = 3 * ublas_v1;
479 ublas_v1 = alpha * ublas_v1 + ublas_v2;
480 vcl_v1 = alpha * vcl_v1 + vcl_v2;
482 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
485 std::cout <<
"Testing multiply-add on vector with CPU scalar (both)..." << std::endl;
486 ublas_v2 = 3 * ublas_v1;
490 ublas_v1 = alpha * ublas_v1 + beta * ublas_v2;
491 vcl_v1 = alpha * vcl_v1 + beta * vcl_v2;
493 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
497 std::cout <<
"Testing inplace multiply-add on vector with CPU scalar..." << std::endl;
498 ublas_v2 = 3 * ublas_v1;
502 ublas_v1 += alpha * ublas_v2;
503 vcl_v1 += alpha * vcl_v2;
505 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
509 std::cout <<
"Testing multiply-add on vector with GPU scalar (right)..." << std::endl;
510 ublas_v2 = 3 * ublas_v1;
514 ublas_v1 = ublas_v1 + alpha * ublas_v2;
515 vcl_v1 = vcl_v1 + gpu_alpha * vcl_v2;
517 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
520 std::cout <<
"Testing multiply-add on vector with GPU scalar (left)..." << std::endl;
521 ublas_v2 = 3 * ublas_v1;
525 ublas_v1 = ublas_v1 + alpha * ublas_v2;
526 vcl_v1 = vcl_v1 + gpu_alpha * vcl_v2;
528 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
531 std::cout <<
"Testing multiply-add on vector with GPU scalar (both)..." << std::endl;
532 ublas_v2 = 3 * ublas_v1;
536 ublas_v1 = alpha * ublas_v1 + beta * ublas_v2;
537 vcl_v1 = gpu_alpha * vcl_v1 + gpu_beta * vcl_v2;
539 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
543 std::cout <<
"Testing inplace multiply-add on vector with GPU scalar (both, adding)..." << std::endl;
544 ublas_v2 = 3 * ublas_v1;
548 ublas_v1 += alpha * ublas_v1 + beta * ublas_v2;
549 vcl_v1 += gpu_alpha * vcl_v1 + gpu_beta * vcl_v2;
551 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
555 std::cout <<
"Testing inplace multiply-add on vector with GPU scalar..." << std::endl;
556 ublas_v2 = 3 * ublas_v1;
560 ublas_v1 += alpha * ublas_v2;
561 vcl_v1 += gpu_alpha * vcl_v2;
563 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
570 std::cout <<
"Testing division-add on vector with CPU scalar (right)..." << std::endl;
571 for (
size_t i=0; i < ublas_v1.size(); ++i)
573 ublas_v2 = 3 * ublas_v1;
577 ublas_v1 = ublas_v1 + ublas_v2 / alpha;
578 vcl_v1 = vcl_v1 + vcl_v2 / alpha;
580 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
584 std::cout <<
"Testing division-add on vector with CPU scalar (left)..." << std::endl;
585 ublas_v2 = 3 * ublas_v1;
589 ublas_v1 = ublas_v1 / alpha + ublas_v2;
590 vcl_v1 = vcl_v1 / alpha + vcl_v2;
592 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
595 std::cout <<
"Testing division-add on vector with CPU scalar (both)..." << std::endl;
596 ublas_v2 = 3 * ublas_v1;
600 ublas_v1 = ublas_v1 / alpha + ublas_v2 / beta;
601 vcl_v1 = vcl_v1 / alpha + vcl_v2 / beta;
603 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
606 std::cout <<
"Testing division-multiply-add on vector with CPU scalar..." << std::endl;
607 ublas_v2 = 3 * ublas_v1;
611 ublas_v1 = ublas_v1 / alpha + ublas_v2 * beta;
612 vcl_v1 = vcl_v1 / alpha + vcl_v2 * beta;
614 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
618 std::cout <<
"Testing multiply-division-add on vector with CPU scalar..." << std::endl;
619 ublas_v2 = 3 * ublas_v1;
623 ublas_v1 = ublas_v1 * alpha + ublas_v2 / beta;
624 vcl_v1 = vcl_v1 * alpha + vcl_v2 / beta;
626 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
631 std::cout <<
"Testing inplace division-add on vector with CPU scalar..." << std::endl;
632 ublas_v2 = 3 * ublas_v1;
636 ublas_v1 += ublas_v2 / alpha;
637 vcl_v1 += vcl_v2 / alpha;
639 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
643 std::cout <<
"Testing division-add on vector with GPU scalar (right)..." << std::endl;
644 ublas_v2 = 3 * ublas_v1;
648 ublas_v1 = ublas_v1 + ublas_v2 / alpha;
649 vcl_v1 = vcl_v1 + vcl_v2 / gpu_alpha;
651 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
654 std::cout <<
"Testing division-add on vector with GPU scalar (left)..." << std::endl;
655 ublas_v2 = 3 * ublas_v1;
659 ublas_v1 = ublas_v1 + ublas_v2 / alpha;
660 vcl_v1 = vcl_v1 + vcl_v2 / gpu_alpha;
662 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
665 std::cout <<
"Testing division-add on vector with GPU scalar (both)..." << std::endl;
666 ublas_v2 = 3 * ublas_v1;
670 ublas_v1 = ublas_v1 / alpha + ublas_v2 / beta;
671 vcl_v1 = vcl_v1 / gpu_alpha + vcl_v2 / gpu_beta;
673 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
677 std::cout <<
"Testing inplace division-add on vector with GPU scalar (both, adding)..." << std::endl;
678 ublas_v2 = 3 * ublas_v1;
682 ublas_v1 += ublas_v1 / alpha + ublas_v2 / beta;
683 vcl_v1 += vcl_v1 / gpu_alpha + vcl_v2 / gpu_beta;
685 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
688 std::cout <<
"Testing inplace division-multiply-add on vector with GPU scalar (adding)..." << std::endl;
689 ublas_v2 = 3 * ublas_v1;
693 ublas_v1 += ublas_v1 / alpha + ublas_v2 * beta;
694 vcl_v1 += vcl_v1 / gpu_alpha + vcl_v2 * gpu_beta;
696 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
700 std::cout <<
"Testing inplace division-add on vector with GPU scalar..." << std::endl;
701 ublas_v2 = 3 * ublas_v1;
705 ublas_v1 += ublas_v2 * alpha;
706 vcl_v1 += vcl_v2 * gpu_alpha;
708 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
714 for (
size_t i=0; i < ublas_v1.size(); ++i)
716 ublas_v2 = 3 * ublas_v1;
720 std::cout <<
"Testing three vector additions..." << std::endl;
721 ublas_v1 = ublas_v2 + ublas_v1 + ublas_v2;
722 vcl_v1 = vcl_v2 + vcl_v1 + vcl_v2;
724 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
728 ublas_v2 = 3 * ublas_v1;
732 std::cout <<
"Testing swap..." << std::endl;
733 swap(ublas_v1, ublas_v2);
734 swap(vcl_v1, vcl_v2);
736 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
739 std::cout <<
"Testing elementwise multiplication..." << std::endl;
740 std::cout <<
" v1 = element_prod(v1, v2);" << std::endl;
744 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
747 std::cout <<
" v1 += element_prod(v1, v2);" << std::endl;
751 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
755 std::cout <<
" v1 = element_prod(v1 + v2, v2);" << std::endl;
759 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
762 std::cout <<
" v1 += element_prod(v1 + v2, v2);" << std::endl;
766 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
770 std::cout <<
" v1 = element_prod(v1, v2 + v1);" << std::endl;
774 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
777 std::cout <<
" v1 += element_prod(v1, v2 + v1);" << std::endl;
781 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
785 std::cout <<
" v1 = element_prod(v1 + v2, v2 + v1);" << std::endl;
789 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
792 std::cout <<
" v1 += element_prod(v1 + v2, v2 + v1);" << std::endl;
796 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
800 std::cout <<
"Testing elementwise division..." << std::endl;
801 for (std::size_t i=0; i<ublas_v1.size(); ++i)
813 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
819 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
826 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
832 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
839 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
845 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
852 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
858 if (
check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
866 template<
typename NumericT >
869 int retval = EXIT_SUCCESS;
870 std::size_t
size = 12345;
872 std::cout <<
"Running tests for vector of size " << size << std::endl;
877 ublas::vector<NumericT> ublas_full_vec(size);
878 ublas::vector<NumericT> ublas_full_vec2(ublas_full_vec.size());
880 for (std::size_t i=0; i<ublas_full_vec.size(); ++i)
886 ublas::range r1( ublas_full_vec.size() / 4, 2 * ublas_full_vec.size() / 4);
887 ublas::range r2(2 * ublas_full_vec2.size() / 4, 3 * ublas_full_vec2.size() / 4);
888 ublas::vector_range< ublas::vector<NumericT> > ublas_range_vec(ublas_full_vec, r1);
889 ublas::vector_range< ublas::vector<NumericT> > ublas_range_vec2(ublas_full_vec2, r2);
891 ublas::slice s1( ublas_full_vec.size() / 4, 3, ublas_full_vec.size() / 4);
892 ublas::slice s2(2 * ublas_full_vec2.size() / 4, 2, ublas_full_vec2.size() / 4);
893 ublas::vector_slice< ublas::vector<NumericT> > ublas_slice_vec(ublas_full_vec,
s1);
894 ublas::vector_slice< ublas::vector<NumericT> > ublas_slice_vec2(ublas_full_vec2,
s2);
903 viennacl::copy(ublas_full_vec2.begin(), ublas_full_vec2.end(), vcl_full_vec2.begin());
905 viennacl::range vcl_r1( vcl_full_vec.size() / 4, 2 * vcl_full_vec.size() / 4);
906 viennacl::range vcl_r2(2 * vcl_full_vec2.size() / 4, 3 * vcl_full_vec2.size() / 4);
914 ublas::vector<NumericT> ublas_short_vec(ublas_range_vec);
915 ublas::vector<NumericT> ublas_short_vec2(ublas_range_vec2);
917 std::cout <<
"Testing creation of vectors from range..." << std::endl;
918 if (
check(ublas_short_vec, vcl_short_vec) != EXIT_SUCCESS)
920 if (
check(ublas_short_vec2, vcl_short_vec2) != EXIT_SUCCESS)
924 viennacl::slice vcl_s1( vcl_full_vec.size() / 4, 3, vcl_full_vec.size() / 4);
925 viennacl::slice vcl_s2(2 * vcl_full_vec2.size() / 4, 2, vcl_full_vec2.size() / 4);
932 ublas::vector<NumericT> ublas_short_vec(ublas_slice_vec);
933 ublas::vector<NumericT> ublas_short_vec2(ublas_slice_vec2);
935 std::cout <<
"Testing creation of vectors from slice..." << std::endl;
936 if (
check(ublas_short_vec, vcl_short_vec) != EXIT_SUCCESS)
938 if (
check(ublas_short_vec2, vcl_short_vec2) != EXIT_SUCCESS)
946 std::cout <<
" ** vcl_v1 = vector, vcl_v2 = vector **" << std::endl;
947 retval = test<NumericT>(ublas_short_vec, ublas_short_vec2,
948 vcl_short_vec, vcl_short_vec2);
949 if (retval != EXIT_SUCCESS)
952 std::cout <<
" ** vcl_v1 = vector, vcl_v2 = range **" << std::endl;
953 retval = test<NumericT>(ublas_short_vec, ublas_short_vec2,
954 vcl_short_vec, vcl_range_vec2);
955 if (retval != EXIT_SUCCESS)
958 std::cout <<
" ** vcl_v1 = vector, vcl_v2 = slice **" << std::endl;
959 retval = test<NumericT>(ublas_short_vec, ublas_short_vec2,
960 vcl_short_vec, vcl_slice_vec2);
961 if (retval != EXIT_SUCCESS)
966 std::cout <<
" ** vcl_v1 = range, vcl_v2 = vector **" << std::endl;
967 retval = test<NumericT>(ublas_short_vec, ublas_short_vec2,
968 vcl_range_vec, vcl_short_vec2);
969 if (retval != EXIT_SUCCESS)
972 std::cout <<
" ** vcl_v1 = range, vcl_v2 = range **" << std::endl;
973 retval = test<NumericT>(ublas_short_vec, ublas_short_vec2,
974 vcl_range_vec, vcl_range_vec2);
975 if (retval != EXIT_SUCCESS)
978 std::cout <<
" ** vcl_v1 = range, vcl_v2 = slice **" << std::endl;
979 retval = test<NumericT>(ublas_short_vec, ublas_short_vec2,
980 vcl_range_vec, vcl_slice_vec2);
981 if (retval != EXIT_SUCCESS)
986 std::cout <<
" ** vcl_v1 = slice, vcl_v2 = vector **" << std::endl;
987 retval = test<NumericT>(ublas_short_vec, ublas_short_vec2,
988 vcl_slice_vec, vcl_short_vec2);
989 if (retval != EXIT_SUCCESS)
992 std::cout <<
" ** vcl_v1 = slice, vcl_v2 = range **" << std::endl;
993 retval = test<NumericT>(ublas_short_vec, ublas_short_vec2,
994 vcl_slice_vec, vcl_range_vec2);
995 if (retval != EXIT_SUCCESS)
998 std::cout <<
" ** vcl_v1 = slice, vcl_v2 = slice **" << std::endl;
999 retval = test<NumericT>(ublas_short_vec, ublas_short_vec2,
1000 vcl_slice_vec, vcl_slice_vec2);
1001 if (retval != EXIT_SUCCESS)
1002 return EXIT_FAILURE;
1004 return EXIT_SUCCESS;
1014 std::cout << std::endl;
1015 std::cout <<
"----------------------------------------------" << std::endl;
1016 std::cout <<
"----------------------------------------------" << std::endl;
1017 std::cout <<
"## Test :: Vector with Integer types" << std::endl;
1018 std::cout <<
"----------------------------------------------" << std::endl;
1019 std::cout <<
"----------------------------------------------" << std::endl;
1020 std::cout << std::endl;
1022 int retval = EXIT_SUCCESS;
1024 std::cout << std::endl;
1025 std::cout <<
"----------------------------------------------" << std::endl;
1026 std::cout << std::endl;
1028 std::cout <<
"# Testing setup:" << std::endl;
1029 std::cout <<
" numeric: unsigned int" << std::endl;
1030 retval = test<unsigned int>();
1031 if ( retval == EXIT_SUCCESS )
1032 std::cout <<
"# Test passed" << std::endl;
1036 std::cout << std::endl;
1037 std::cout <<
"----------------------------------------------" << std::endl;
1038 std::cout << std::endl;
1040 std::cout <<
"# Testing setup:" << std::endl;
1041 std::cout <<
" numeric: long" << std::endl;
1042 retval = test<unsigned long>();
1043 if ( retval == EXIT_SUCCESS )
1044 std::cout <<
"# Test passed" << std::endl;
1048 std::cout << std::endl;
1049 std::cout <<
"----------------------------------------------" << std::endl;
1050 std::cout << std::endl;
1052 std::cout << std::endl;
1053 std::cout <<
"------- Test completed --------" << std::endl;
1054 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.
int check(T1 const &t1, T2 const &t2)
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...
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.
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.
ScalarType diff(ScalarType const &s1, ScalarType const &s2)
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)