1 /*****************************************************************************
2 Copyright (c) 2011-2016, The OpenBLAS Project
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
9 1. Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in
14 the documentation and/or other materials provided with the
16 3. Neither the name of the OpenBLAS project nor the names of
17 its contributors may be used to endorse or promote products
18 derived from this software without specific prior written
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
30 USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 **********************************************************************************/
38 #define CTEST_SEGFAULT
39 #define CTEST_ADD_TESTS_MANUALLY
41 #include "openblas_utest.h"
45 float te_max=0.0, tr_max=0.0;
46 float x[]={-1.1, 2.2, -3.3};
47 te_max=BLASFUNC(samax)(&N, x, &inc);
50 ASSERT_DBL_NEAR_TOL((double)(tr_max), (double)(te_max), SINGLE_EPS);
55 double te_max=0.0, tr_max=0.0;
56 double x[]={-1.1, 2.2, -3.3};
58 te_max=BLASFUNC(damax)(&N, x, &inc);
61 ASSERT_DBL_NEAR_TOL((double)(tr_max), (double)(te_max), DOUBLE_EPS);
73 // original test case for libGoto bug fixed by feb2014 rewrite
74 te_d1= 0.21149573940783739;
75 te_d2= 0.046892057172954082;
76 te_x1= -0.42272687517106533;
77 te_y1= 0.42211309121921659;
81 te_param[i]=tr_param[i]=0.0;
84 //reference values as calculated by netlib blas
90 tr_d1= 0.17320483687975;
91 tr_d2= 0.03840233915037;
92 tr_x1= -0.51618034832329;
93 tr_y1= 0.42211309121922;
97 tr_param[2]= 0.99854803659786;
98 tr_param[3]= -0.22139439665872;
101 BLASFUNC(drotmg)(&te_d1, &te_d2, &te_x1, &te_y1, te_param);
102 ASSERT_DBL_NEAR_TOL(tr_d1, te_d1, DOUBLE_EPS);
103 ASSERT_DBL_NEAR_TOL(tr_d2, te_d2, DOUBLE_EPS);
104 ASSERT_DBL_NEAR_TOL(tr_x1, te_x1, DOUBLE_EPS);
105 ASSERT_DBL_NEAR_TOL(tr_y1, te_y1, DOUBLE_EPS);
108 ASSERT_DBL_NEAR_TOL(tr_param[i], te_param[i], DOUBLE_EPS);
112 CTEST (drotmg,rotmg_issue1452)
129 te_param[i]=tr_param[i]=0.0;
131 te_param[3]=1./4096.;
132 //reference values as calculated by gonum blas with rotmg rewritten to Hopkins' algorithm
133 tr_d1= 0.99995592822897;
134 tr_d2= 0.98981219860583;
135 tr_x1= 0.03662270484346;
136 tr_y1= 150.000000000000;
139 tr_param[1]= 0.00000161109346;
140 tr_param[2]= -0.00024414062500;
141 tr_param[3]= 0.00024414062500;
142 tr_param[4]= 0.00000162760417;
145 BLASFUNC(drotmg)(&te_d1, &te_d2, &te_x1, &te_y1, te_param);
147 ASSERT_DBL_NEAR_TOL(tr_d1, te_d1, DOUBLE_EPS);
148 ASSERT_DBL_NEAR_TOL(tr_d2, te_d2, DOUBLE_EPS);
149 ASSERT_DBL_NEAR_TOL(tr_x1, te_x1, DOUBLE_EPS);
150 ASSERT_DBL_NEAR_TOL(tr_y1, te_y1, DOUBLE_EPS);
153 ASSERT_DBL_NEAR_TOL(tr_param[i], te_param[i], DOUBLE_EPS);
158 CTEST(drotmg, rotmg_D1eqD2_X1eqX2)
173 te_param[i]=tr_param[i]=0.0;
176 //reference values as calculated by netlib blas
189 BLASFUNC(drotmg)(&te_d1, &te_d2, &te_x1, &te_y1, te_param);
191 ASSERT_DBL_NEAR_TOL(tr_d1, te_d1, DOUBLE_EPS);
192 ASSERT_DBL_NEAR_TOL(tr_d2, te_d2, DOUBLE_EPS);
193 ASSERT_DBL_NEAR_TOL(tr_x1, te_x1, DOUBLE_EPS);
194 ASSERT_DBL_NEAR_TOL(tr_y1, te_y1, DOUBLE_EPS);
197 ASSERT_DBL_NEAR_TOL(tr_param[i], te_param[i], DOUBLE_EPS);
201 CTEST(drotmg, drotmg_D1_big_D2_big_flag_zero)
207 double te_param[5]={1.,4096.,-4096.,1.,4096.};
208 double tr_param[5]={-1.,4096.,-3584.,1792.,4096.};
210 te_d1= tr_d1=1600000000.;
211 te_d2= tr_d2=800000000.;
216 //reference values as calculated by gonum
217 tr_d1= 68.96627824858757;
218 tr_d2= 34.483139124293785;
224 BLASFUNC(drotmg)(&te_d1, &te_d2, &te_x1, &te_y1, te_param);
226 ASSERT_DBL_NEAR_TOL(tr_d1, te_d1, DOUBLE_EPS);
227 ASSERT_DBL_NEAR_TOL(tr_d2, te_d2, DOUBLE_EPS);
228 ASSERT_DBL_NEAR_TOL(tr_x1, te_x1, DOUBLE_EPS);
229 ASSERT_DBL_NEAR_TOL(tr_y1, te_y1, DOUBLE_EPS);
232 ASSERT_DBL_NEAR_TOL(tr_param[i], te_param[i], DOUBLE_EPS);
236 CTEST(axpy,daxpy_inc_0)
239 blasint N=8,incX=0,incY=0;
241 double x1[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
242 double y1[]={2.0,4.0,6.0,8.0,2.0,4.0,6.0,8.0};
244 double x2[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
245 double y2[]={4.0,4.0,6.0,8.0,2.0,4.0,6.0,8.0};
248 BLASFUNC(daxpy)(&N,&a,x1,&incX,y1,&incY);
251 ASSERT_DBL_NEAR_TOL(x2[i], x1[i], DOUBLE_EPS);
252 ASSERT_DBL_NEAR_TOL(y2[i], y1[i], DOUBLE_EPS);
256 CTEST(axpy,zaxpy_inc_0)
259 blasint N=4,incX=0,incY=0;
260 double a[2]={0.25,0.5};
261 double x1[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
262 double y1[]={2.0,4.0,6.0,8.0,2.0,4.0,6.0,8.0};
263 double x2[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
264 double y2[]={-3.0,9.0,6.0,8.0,2.0,4.0,6.0,8.0};
267 BLASFUNC(zaxpy)(&N,a,x1,&incX,y1,&incY);
269 for(i=0; i<2*N; i++){
270 ASSERT_DBL_NEAR_TOL(x2[i], x1[i], DOUBLE_EPS);
271 ASSERT_DBL_NEAR_TOL(y2[i], y1[i], DOUBLE_EPS);
275 CTEST(axpy,saxpy_inc_0)
278 blasint N=8,incX=0,incY=0;
280 float x1[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
281 float y1[]={2.0,4.0,6.0,8.0,2.0,4.0,6.0,8.0};
282 float x2[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
283 float y2[]={4.0,4.0,6.0,8.0,2.0,4.0,6.0,8.0};
286 BLASFUNC(saxpy)(&N,&a,x1,&incX,y1,&incY);
289 ASSERT_DBL_NEAR_TOL(x2[i], x1[i], DOUBLE_EPS);
290 ASSERT_DBL_NEAR_TOL(y2[i], y1[i], DOUBLE_EPS);
294 CTEST(axpy,caxpy_inc_0)
297 blasint N=4,incX=0,incY=0;
298 float a[2]={0.25,0.5};
299 float x1[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
300 float y1[]={2.0,4.0,6.0,8.0,2.0,4.0,6.0,8.0};
301 float x2[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
302 float y2[]={-3.0,9.0,6.0,8.0,2.0,4.0,6.0,8.0};
305 BLASFUNC(caxpy)(&N,a,x1,&incX,y1,&incY);
307 for(i=0; i<2*N; i++){
308 ASSERT_DBL_NEAR_TOL(x2[i], x1[i], DOUBLE_EPS);
309 ASSERT_DBL_NEAR_TOL(y2[i], y1[i], DOUBLE_EPS);
313 CTEST( zdotu,zdotu_n_1)
315 blasint N=1,incX=1,incY=1;
316 double x1[]={1.0,1.0};
317 double y1[]={1.0,2.0};
318 openblas_complex_double result1=openblas_make_complex_double(0.0,0.0);
319 openblas_complex_double result2=openblas_make_complex_double(-1.0,3.0);
320 #ifdef RETURN_BY_STACK
321 BLASFUNC(zdotu)(&result1,&N,x1,&incX,y1,&incY);
323 result1=BLASFUNC(zdotu)(&N,x1,&incX,y1,&incY);
326 #ifdef OPENBLAS_COMPLEX_STRUCT
327 ASSERT_DBL_NEAR_TOL(result2.real, result1.real, DOUBLE_EPS);
328 ASSERT_DBL_NEAR_TOL(result2.imag, result1.imag, DOUBLE_EPS);
330 ASSERT_DBL_NEAR_TOL(creal(result2), creal(result1), DOUBLE_EPS);
331 ASSERT_DBL_NEAR_TOL(cimag(result2), cimag(result1), DOUBLE_EPS);
335 CTEST(zdotu, zdotu_offset_1)
337 blasint N=1,incX=1,incY=1;
338 double x1[]={1.0,2.0,3.0,4.0};
339 double y1[]={5.0,6.0,7.0,8.0};
340 openblas_complex_double result1=openblas_make_complex_double(0.0,0.0);
341 openblas_complex_double result2=openblas_make_complex_double(-9.0,32.0);
342 #ifdef RETURN_BY_STACK
343 BLASFUNC(zdotu)(&result1,&N,x1+1,&incX,y1+1,&incY);
345 result1=BLASFUNC(zdotu)(&N,x1+1,&incX,y1+1,&incY);
348 #ifdef OPENBLAS_COMPLEX_STRUCT
349 ASSERT_DBL_NEAR_TOL(result2.real, result1.real, DOUBLE_EPS);
350 ASSERT_DBL_NEAR_TOL(result2.imag, result1.imag, DOUBLE_EPS);
352 ASSERT_DBL_NEAR_TOL(creal(result2), creal(result1), DOUBLE_EPS);
353 ASSERT_DBL_NEAR_TOL(cimag(result2), cimag(result1), DOUBLE_EPS);
357 CTEST(dsdot,dsdot_n_1)
359 float x= 0.172555164F;
360 float y= -0.0138700781F;
365 double res1=0.0f, res2=-0.00239335360107;
367 res1=BLASFUNC(dsdot)(&n, &x, &incx, &y, &incy);
368 ASSERT_DBL_NEAR_TOL(res2, res1, DOUBLE_EPS);
372 #if defined(BUILD_DOUBLE)
373 CTEST(dnrm2,dnrm2_inf)
376 #define INFINITY HUGE_VAL
382 double res1=0.0f, res2=INFINITY;
384 for (i=0;i<n;i++)x[i]=0.0f;
386 res1=BLASFUNC(dnrm2)(&n, x, &incx);
387 ASSERT_DBL_NEAR_TOL(res2, res1, DOUBLE_EPS);
390 CTEST(dnrm2,dnrm2_tiny)
396 double res1=0.0f, res2=0.0f;
398 for (i=0;i<n;i++)x[i]=7.457008414e-310;
399 res1=BLASFUNC(dnrm2)(&n, x, &incx);
400 ASSERT_DBL_NEAR_TOL(res2, res1, DOUBLE_EPS);
404 CTEST(rot,drot_inc_0)
407 blasint N=4,incX=0,incY=0;
409 double x1[]={1.0,3.0,5.0,7.0};
410 double y1[]={2.0,4.0,6.0,8.0};
411 double x2[]={-0.21484375000000,3.0,5.0,7.0};
412 double y2[]={ 0.03906250000000,4.0,6.0,8.0};
416 BLASFUNC(drot)(&N,x1,&incX,y1,&incY,&c,&s);
419 ASSERT_DBL_NEAR_TOL(x2[i], x1[i], DOUBLE_EPS);
420 ASSERT_DBL_NEAR_TOL(y2[i], y1[i], DOUBLE_EPS);
424 CTEST(rot,zdrot_inc_0)
427 blasint N=4,incX=0,incY=0;
429 double x1[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
430 double y1[]={2.0,4.0,6.0,8.0,2.0,4.0,6.0,8.0};
431 double x2[]={-0.21484375000000,-0.45703125000000 ,5.0,7.0,1.0,3.0,5.0,7.0};
432 double y2[]={ 0.03906250000000, 0.17187500000000 ,6.0,8.0,2.0,4.0,6.0,8.0};
436 BLASFUNC(zdrot)(&N,x1,&incX,y1,&incY,&c,&s);
438 for(i=0; i<2*N; i++){
439 ASSERT_DBL_NEAR_TOL(x2[i], x1[i], DOUBLE_EPS);
440 ASSERT_DBL_NEAR_TOL(y2[i], y1[i], DOUBLE_EPS);
444 CTEST(rot,srot_inc_0)
447 blasint N=4,incX=0,incY=0;
449 float x1[]={1.0,3.0,5.0,7.0};
450 float y1[]={2.0,4.0,6.0,8.0};
451 float x2[]={-0.21484375000000,3.0,5.0,7.0};
452 float y2[]={ 0.03906250000000,4.0,6.0,8.0};
455 BLASFUNC(srot)(&N,x1,&incX,y1,&incY,&c,&s);
458 ASSERT_DBL_NEAR_TOL(x2[i], x1[i], SINGLE_EPS);
459 ASSERT_DBL_NEAR_TOL(y2[i], y1[i], SINGLE_EPS);
463 CTEST(rot, csrot_inc_0)
466 blasint N=4,incX=0,incY=0;
468 float x1[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
469 float y1[]={2.0,4.0,6.0,8.0,2.0,4.0,6.0,8.0};
470 float x2[]={-0.21484375000000,-0.45703125000000 ,5.0,7.0,1.0,3.0,5.0,7.0};
471 float y2[]={ 0.03906250000000, 0.17187500000000 ,6.0,8.0,2.0,4.0,6.0,8.0};
474 BLASFUNC(csrot)(&N,x1,&incX,y1,&incY,&c,&s);
476 for(i=0; i<2*N; i++){
477 ASSERT_DBL_NEAR_TOL(x2[i], x1[i], SINGLE_EPS);
478 ASSERT_DBL_NEAR_TOL(y2[i], y1[i], SINGLE_EPS);
482 CTEST(swap,dswap_inc_0)
485 blasint N=4,incX=0,incY=0;
486 double x1[]={1.0,3.0,5.0,7.0};
487 double y1[]={2.0,4.0,6.0,8.0};
488 double x2[]={1.0,3.0,5.0,7.0};
489 double y2[]={2.0,4.0,6.0,8.0};
492 BLASFUNC(dswap)(&N,x1,&incX,y1,&incY);
495 ASSERT_DBL_NEAR_TOL(x2[i], x1[i], DOUBLE_EPS);
496 ASSERT_DBL_NEAR_TOL(y2[i], y1[i], DOUBLE_EPS);
500 CTEST(swap,zswap_inc_0)
503 blasint N=4,incX=0,incY=0;
504 double x1[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
505 double y1[]={2.0,4.0,6.0,8.0,2.0,4.0,6.0,8.0};
506 double x2[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
507 double y2[]={2.0,4.0,6.0,8.0,2.0,4.0,6.0,8.0};
510 BLASFUNC(zswap)(&N,x1,&incX,y1,&incY);
512 for(i=0; i<2*N; i++){
513 ASSERT_DBL_NEAR_TOL(x2[i], x1[i], DOUBLE_EPS);
514 ASSERT_DBL_NEAR_TOL(y2[i], y1[i], DOUBLE_EPS);
518 CTEST(swap,sswap_inc_0)
521 blasint N=4,incX=0,incY=0;
522 float x1[]={1.0,3.0,5.0,7.0};
523 float y1[]={2.0,4.0,6.0,8.0};
524 float x2[]={1.0,3.0,5.0,7.0};
525 float y2[]={2.0,4.0,6.0,8.0};
528 BLASFUNC(sswap)(&N,x1,&incX,y1,&incY);
531 ASSERT_DBL_NEAR_TOL(x2[i], x1[i], SINGLE_EPS);
532 ASSERT_DBL_NEAR_TOL(y2[i], y1[i], SINGLE_EPS);
536 CTEST(swap,cswap_inc_0)
539 blasint N=4,incX=0,incY=0;
540 float x1[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
541 float y1[]={2.0,4.0,6.0,8.0,2.0,4.0,6.0,8.0};
542 float x2[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
543 float y2[]={2.0,4.0,6.0,8.0,2.0,4.0,6.0,8.0};
546 BLASFUNC(cswap)(&N,x1,&incX,y1,&incY);
548 for(i=0; i<2*N; i++){
549 ASSERT_DBL_NEAR_TOL(x2[i], x1[i], SINGLE_EPS);
550 ASSERT_DBL_NEAR_TOL(y2[i], y1[i], SINGLE_EPS);
554 CTEST(min, smin_negative){
556 float te_min=0.0, tr_min=0.0;
557 float x[]={-1.1, -2.2, -3.3};
559 te_min=BLASFUNC(smin)(&N, x, &inc);
562 ASSERT_DBL_NEAR_TOL((double)(tr_min), (double)(te_min), SINGLE_EPS);
565 CTEST(min, dmin_positive){
567 double te_min=0.0, tr_min=0.0;
568 double x[]={1.1, 0.0, 3.3};
570 te_min=BLASFUNC(dmin)(&N, x, &inc);
573 ASSERT_DBL_NEAR_TOL((double)(tr_min), (double)(te_min), DOUBLE_EPS);
576 CTEST(min, smin_zero){
578 float te_min=0.0, tr_min=0.0;
579 float x[]={1.1, 2.2, 0.0};
581 te_min=BLASFUNC(smin)(&N, x, &inc);
584 ASSERT_DBL_NEAR_TOL((double)(tr_min), (double)(te_min), SINGLE_EPS);
587 CTEST(max, smax_negative){
589 float te_max=0.0, tr_max=0.0;
590 float x[]={-1.1, -2.2, -3.3};
592 te_max=BLASFUNC(smax)(&N, x, &inc);
595 ASSERT_DBL_NEAR_TOL((double)(tr_max), (double)(te_max), SINGLE_EPS);
598 CTEST(max, dmax_positive){
600 double te_max=0.0, tr_max=0.0;
601 double x[]={1.1, 0.0, 3.3};
603 te_max=BLASFUNC(dmax)(&N, x, &inc);
606 ASSERT_DBL_NEAR_TOL((double)(tr_max), (double)(te_max), DOUBLE_EPS);
609 CTEST(max, smax_zero){
611 float te_max=0.0, tr_max=0.0;
612 float x[]={-1.1, -2.2, 0.0};
614 te_max=BLASFUNC(smax)(&N, x, &inc);
617 ASSERT_DBL_NEAR_TOL((double)(tr_max), (double)(te_max), SINGLE_EPS);
620 int main(int argc, const char ** argv){
622 CTEST_ADD (amax, samax);
623 CTEST_ADD (amax, damax);
624 CTEST_ADD (min, smin_negative);
625 CTEST_ADD (min, dmin_positive);
626 CTEST_ADD (min, smin_zero);
627 CTEST_ADD (max, smax_negative);
628 CTEST_ADD (max, dmax_positive);
629 CTEST_ADD (max, smax_zero);
630 CTEST_ADD (drotmg,rotmg);
631 CTEST_ADD (drotmg,rotmg_issue1452);
632 CTEST_ADD (drotmg,rotmg_D1eqD2_X1eqX2);
633 CTEST_ADD (drotmg,drotmg_D1_big_D2_big_flag_zero);
634 CTEST_ADD (axpy,daxpy_inc_0);
635 CTEST_ADD (axpy,zaxpy_inc_0);
636 CTEST_ADD (axpy,saxpy_inc_0);
637 CTEST_ADD (axpy,caxpy_inc_0);
638 CTEST_ADD (zdotu,zdotu_n_1);
639 CTEST_ADD (zdotu,zdotu_offset_1);
640 CTEST_ADD (dsdot,dsdot_n_1);
641 CTEST_ADD (dnrm2,dnrm2_inf);
642 CTEST_ADD (dnrm2,dnrm2_tiny);
643 CTEST_ADD (rot,drot_inc_0);
644 CTEST_ADD (rot,zdrot_inc_0);
645 CTEST_ADD (rot,srot_inc_0);
646 CTEST_ADD (rot,csrot_inc_0);
647 CTEST_ADD (swap,dswap_inc_0);
648 CTEST_ADD (swap,zswap_inc_0);
649 CTEST_ADD (swap,sswap_inc_0);
650 CTEST_ADD (swap,cswap_inc_0);
654 num_fail=ctest_main(argc, argv);