Fixing copyright issues and code contributors
[alexxy/gromacs.git] / src / gmxlib / gmx_blas / ssymv.c
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2012,2013, by the GROMACS development team, led by
5  * David van der Spoel, Berk Hess, Erik Lindahl, and including many
6  * others, as listed in the AUTHORS file in the top-level source
7  * directory and at http://www.gromacs.org.
8  *
9  * GROMACS is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * GROMACS is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with GROMACS; if not, see
21  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23  *
24  * If you want to redistribute modifications to GROMACS, please
25  * consider that scientific software is very special. Version
26  * control is crucial - bugs must be traceable. We will be happy to
27  * consider code for inclusion in the official distribution, but
28  * derived work must not be called official GROMACS. Details are found
29  * in the README & COPYING files - if they are missing, get the
30  * official version at http://www.gromacs.org.
31  *
32  * To help us fund GROMACS development, we humbly ask that you cite
33  * the research papers on the package. Check out http://www.gromacs.org.
34  */
35 #include <math.h>
36 #include <ctype.h>
37
38 #include <types/simple.h>
39 #include "gmx_blas.h"
40
41 void
42 F77_FUNC(ssymv,SSYMV)(const char *uplo,
43                       int *n__,
44                       float *alpha__,
45                       float *a,
46                       int *lda__,
47                       float *x,
48                       int *incx__,
49                       float *beta__,
50                       float *y,
51                       int *incy__)
52 {
53     const char ch=toupper(*uplo);
54     int kx,ky,i,j,ix,iy,jx,jy;
55     float temp1,temp2;
56     
57     int n = *n__;
58     int lda = *lda__;
59     int incx = *incx__;
60     int incy = *incy__;
61     float alpha = *alpha__;
62     float beta  = *beta__;
63     
64     if(n<=0 || incx==0 || incy==0)
65         return;
66     
67     if(incx>0)
68         kx = 1;
69     else
70         kx = 1 - (n -1)*(incx);
71     
72     if(incy>0)
73         ky = 1;
74     else
75         ky = 1 - (n -1)*(incy);
76     
77     if(fabs(beta-1.0)>GMX_FLOAT_EPS) {
78         if(incy==1) {
79             if(fabs(beta)<GMX_FLOAT_MIN) 
80                 for(i=1;i<=n;i++)
81                     y[i-1] = 0.0;
82             else
83                 for(i=1;i<=n;i++)
84                     y[i-1] *= beta;
85         } else {
86             /* non-unit incr. */
87             iy = ky;
88             if(fabs(beta)<GMX_FLOAT_MIN) 
89                 for(i=1;i<=n;i++) {
90                     y[iy-1] = 0.0;
91                     iy += incy;
92                 }
93                     else
94                         for(i=1;i<=n;i++) {
95                             y[iy-1] *= beta;
96                             iy += incy;
97                         }
98         }
99     }
100         
101         if(fabs(alpha)<GMX_FLOAT_MIN) 
102             return;
103         
104         if(ch=='U') {
105             if(incx==1 && incy==1) {
106                 for(j=1;j<=n;j++) {
107                     temp1 = alpha * x[j-1];
108                     temp2 = 0.0;
109                     for(i=1;i<j;i++) {
110                         y[i-1] += temp1*a[(j-1)*(lda)+(i-1)];
111                         temp2 += a[(j-1)*(lda)+(i-1)] * x[i-1];
112                     }
113                     y[j-1] += temp1*a[(j-1)*(lda)+(j-1)] + alpha *temp2;
114                 }
115             } else {
116                 /* non-unit incr. */
117                 jx = kx;
118                 jy = ky;
119                 for(j=1;j<=n;j++) {
120                     temp1 = alpha * x[jx-1];
121                     temp2 = 0.0;
122                     ix = kx;
123                     iy = ky;
124                     for(i=1;i<j;i++) {
125                         y[iy-1] += temp1 * a[(j-1)*(lda)+(i-1)];
126                         temp2 += a[(j-1)*(lda)+(i-1)] * x[ix-1];
127                         ix += incx;
128                         iy += incy;
129                     }
130                     y[jy-1] += temp1*a[(j-1)*(lda)+(j-1)] + alpha*temp2;
131                     jx += incx;
132                     jy += incy;
133                 }
134             }
135         } else {
136             /* lower */
137             if(incx==1 && incy==1) {
138                 for(j=1;j<=n;j++) {
139                     temp1 = alpha * x[j-1];
140                     temp2 = 0.0;
141                     y[j-1] += temp1 * a[(j-1)*(lda)+(j-1)];
142                     for(i=j+1;i<=n;i++) {
143                         y[i-1] += temp1*a[(j-1)*(lda)+(i-1)];
144                         temp2 += a[(j-1)*(lda)+(i-1)] * x[i-1];
145                     }
146                     y[j-1] += alpha *temp2;
147                 }
148             } else {
149                 /* non-unit incr. */
150                 jx = kx;
151                 jy = ky;
152                 for(j=1;j<=n;j++) {
153                     temp1 = alpha * x[jx-1];
154                     temp2 = 0.0;
155                     y[jy-1] += temp1 * a[(j-1)*(lda)+(j-1)];
156                     ix = jx;
157                     iy = jy;
158                     for(i=j+1;i<=n;i++) {
159                         ix += incx;
160                         iy += incy;
161                         y[iy-1] += temp1 * a[(j-1)*(lda)+(i-1)];
162                         temp2 += a[(j-1)*(lda)+(i-1)] * x[ix-1];
163                     }
164                     y[jy-1] += alpha*temp2;
165                     jx += incx;
166                     jy += incy;
167                 }
168             }
169         }
170         return;
171 }