Fixing copyright issues and code contributors
[alexxy/gromacs.git] / src / gmxlib / gmx_blas / dsyr2.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 <ctype.h>
36 #include <math.h>
37
38 #include <types/simple.h>
39
40 #include "gmx_blas.h"
41
42 void
43 F77_FUNC(dsyr2,DSYR2)(const char *    uplo,
44                       int *     n__,
45                       double *  alpha__,
46                       double *  x,
47                       int *     incx__,
48                       double *  y,
49                       int *     incy__,
50                       double *  a,
51                       int *     lda__)
52 {
53     int kx,ky,ix,iy,jx,jy,j,i;
54     double temp1,temp2;
55     const char ch=toupper(*uplo);
56     
57     int n = *n__;
58     int lda = *lda__;
59     int incx = *incx__;
60     int incy = *incy__;
61     float alpha = *alpha__;
62     
63     
64     if(n<=0 || fabs(alpha)<GMX_DOUBLE_MIN || incx==0 || incy==0 ||
65        (ch != 'U' && ch != 'L'))
66         return;
67     
68     jx = jy = kx = ky = 0;
69     
70     /* init start points for non-unit increments */
71     if(incx!=1 || incy!=1) {
72         if(incx>0)
73             kx = 1;
74         else
75             kx = 1 - (n - 1)*(incx);
76         if(incy>0)
77             ky = 1;
78         else
79             ky = 1 - (n - 1)*(incy);
80         
81         jx = kx;
82         jy = ky;
83     }
84     
85     if(ch == 'U') {
86         /* Data in upper part of A */
87         if(incx==1 && incy==1) {
88             /* Unit increments for both x and y */
89             for(j=1;j<=n;j++) {
90                 if( fabs(x[j-1])>GMX_DOUBLE_MIN  || fabs(y[j-1])>GMX_DOUBLE_MIN ) {
91                     temp1 = alpha * y[j-1];
92                     temp2 = alpha * x[j-1];
93                     for(i=1;i<=j;i++)
94                         a[(j-1)*(lda)+(i-1)] += x[i-1]*temp1 + y[i-1]*temp2;
95                 }
96             }
97         } else {
98             
99             /* non-unit increments */
100             for(j=1;j<=n;j++) {
101                 
102                 if( fabs(x[jx-1])>GMX_DOUBLE_MIN || fabs(y[jy-1])>GMX_DOUBLE_MIN ) {
103                     temp1 = alpha * y[jy-1];
104                     temp2 = alpha * x[jx-1];
105                     ix = kx;
106                     iy = ky;
107                     for(i=1;i<=j;i++) {
108                         a[(j-1)*(lda)+(i-1)] += x[ix-1]*temp1 + y[iy-1]*temp2;
109                         ix += incx;
110                         iy += incy;
111                     }
112                 }
113                 jx += incx;
114                 jy += incy;
115             }
116         }
117     } else {
118         /* Data in lower part of A */
119         if(incx==1 && incy==1) {
120             /* Unit increments for both x and y */
121             for(j=1;j<=n;j++) {
122                 if( fabs(x[j-1])>GMX_DOUBLE_MIN  || fabs(y[j-1])>GMX_DOUBLE_MIN ) {
123                     temp1 = alpha * y[j-1];
124                     temp2 = alpha * x[j-1];
125                     for(i=j;i<=n;i++)
126                         a[(j-1)*(lda)+(i-1)] += x[i-1]*temp1 + y[i-1]*temp2;
127                 }
128             }
129         } else {
130             
131             /* non-unit increments */
132             for(j=1;j<=n;j++) {
133                 
134                 if( fabs(x[jx-1])>GMX_DOUBLE_MIN || fabs(y[jy-1])>GMX_DOUBLE_MIN ) {
135                     temp1 = alpha * y[jy-1];
136                     temp2 = alpha * x[jx-1];
137                     ix = jx;
138                     iy = jy;
139                     for(i=j;i<=n;i++) {
140                         a[(j-1)*(lda)+(i-1)] += x[ix-1]*temp1 + y[iy-1]*temp2;
141                         ix += incx;
142                         iy += incy;
143                     }
144                 }
145                 jx += incx;
146                 jy += incy;
147             }
148         }
149     }
150     
151     return;
152 }