Upgrade to version 0.3.21
[platform/upstream/openblas.git] / utest / test_axpy.c
1 /*****************************************************************************
2 Copyright (c) 2011-2014, The OpenBLAS Project
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8
9    1. Redistributions of source code must retain the above copyright
10       notice, this list of conditions and the following disclaimer.
11
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
15       distribution.
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 
19       permission.
20
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.
31
32 **********************************************************************************/
33
34 #include "openblas_utest.h"
35
36 #ifdef BUILD_DOUBLE
37 CTEST(axpy,daxpy_inc_0)
38 {
39         blasint i;
40         blasint N=8,incX=0,incY=0;
41         double a=0.25;
42         double x1[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
43         double y1[]={2.0,4.0,6.0,8.0,2.0,4.0,6.0,8.0};
44
45         double x2[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
46         double y2[]={4.0,4.0,6.0,8.0,2.0,4.0,6.0,8.0};
47
48         //OpenBLAS
49         BLASFUNC(daxpy)(&N,&a,x1,&incX,y1,&incY);
50
51         for(i=0; i<N; i++){
52                 ASSERT_DBL_NEAR_TOL(x2[i], x1[i], DOUBLE_EPS);
53                 ASSERT_DBL_NEAR_TOL(y2[i], y1[i], DOUBLE_EPS);
54         }
55 }
56 #endif
57
58 #ifdef BUILD_COMPLEX16
59 CTEST(axpy,zaxpy_inc_0)
60 {
61         blasint i;
62         blasint N=4,incX=0,incY=0;
63         double a[2]={0.25,0.5};
64         double x1[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
65         double y1[]={2.0,4.0,6.0,8.0,2.0,4.0,6.0,8.0};
66         double x2[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
67         double y2[]={-3.0,9.0,6.0,8.0,2.0,4.0,6.0,8.0};
68
69         //OpenBLAS
70         BLASFUNC(zaxpy)(&N,a,x1,&incX,y1,&incY);
71
72         for(i=0; i<2*N; i++){
73                 ASSERT_DBL_NEAR_TOL(x2[i], x1[i], DOUBLE_EPS);
74                 ASSERT_DBL_NEAR_TOL(y2[i], y1[i], DOUBLE_EPS);
75         }
76 }
77 #endif
78
79 #ifdef BUILD_SINGLE
80 CTEST(axpy,saxpy_inc_0)
81 {
82         blasint i;
83         blasint N=8,incX=0,incY=0;
84         float a=0.25;
85         float x1[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
86         float y1[]={2.0,4.0,6.0,8.0,2.0,4.0,6.0,8.0};
87         float x2[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
88         float y2[]={4.0,4.0,6.0,8.0,2.0,4.0,6.0,8.0};
89
90         //OpenBLAS
91         BLASFUNC(saxpy)(&N,&a,x1,&incX,y1,&incY);
92
93         for(i=0; i<N; i++){
94                 ASSERT_DBL_NEAR_TOL(x2[i], x1[i], DOUBLE_EPS);
95                 ASSERT_DBL_NEAR_TOL(y2[i], y1[i], DOUBLE_EPS);
96         }
97 }
98 #endif
99
100 #ifdef BUILD_COMPLEX
101 CTEST(axpy,caxpy_inc_0)
102 {
103         blasint i;
104         blasint N=4,incX=0,incY=0;
105         float a[2]={0.25,0.5};
106         float x1[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
107         float y1[]={2.0,4.0,6.0,8.0,2.0,4.0,6.0,8.0};
108         float x2[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
109         float y2[]={-3.0,9.0,6.0,8.0,2.0,4.0,6.0,8.0};
110
111         //OpenBLAS
112         BLASFUNC(caxpy)(&N,a,x1,&incX,y1,&incY);
113
114         for(i=0; i<2*N; i++){
115                 ASSERT_DBL_NEAR_TOL(x2[i], x1[i], DOUBLE_EPS);
116                 ASSERT_DBL_NEAR_TOL(y2[i], y1[i], DOUBLE_EPS);
117         }
118 }
119 #endif
120