Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.ALGLIB/2.5.0/ALGLIB-2.5.0/hblas.cs @ 4068

Last change on this file since 4068 was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

File size: 5.1 KB
Line 
1/*************************************************************************
2Copyright (c) 1992-2007 The University of Tennessee.  All rights reserved.
3
4Contributors:
5    * Sergey Bochkanov (ALGLIB project). Translation from FORTRAN to
6      pseudocode.
7
8See subroutines comments for additional copyrights.
9
10>>> SOURCE LICENSE >>>
11This program is free software; you can redistribute it and/or modify
12it under the terms of the GNU General Public License as published by
13the Free Software Foundation (www.fsf.org); either version 2 of the
14License, or (at your option) any later version.
15
16This program is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19GNU General Public License for more details.
20
21A copy of the GNU General Public License is available at
22http://www.fsf.org/licensing/licenses
23
24>>> END OF LICENSE >>>
25*************************************************************************/
26
27
28namespace alglib {
29  public class hblas {
30    public static void hermitianmatrixvectormultiply(ref AP.Complex[,] a,
31        bool isupper,
32        int i1,
33        int i2,
34        ref AP.Complex[] x,
35        AP.Complex alpha,
36        ref AP.Complex[] y) {
37      int i = 0;
38      int ba1 = 0;
39      int ba2 = 0;
40      int by1 = 0;
41      int by2 = 0;
42      int bx1 = 0;
43      int bx2 = 0;
44      int n = 0;
45      AP.Complex v = 0;
46      int i_ = 0;
47      int i1_ = 0;
48
49      n = i2 - i1 + 1;
50      if (n <= 0) {
51        return;
52      }
53
54      //
55      // Let A = L + D + U, where
56      //  L is strictly lower triangular (main diagonal is zero)
57      //  D is diagonal
58      //  U is strictly upper triangular (main diagonal is zero)
59      //
60      // A*x = L*x + D*x + U*x
61      //
62      // Calculate D*x first
63      //
64      for (i = i1; i <= i2; i++) {
65        y[i - i1 + 1] = a[i, i] * x[i - i1 + 1];
66      }
67
68      //
69      // Add L*x + U*x
70      //
71      if (isupper) {
72        for (i = i1; i <= i2 - 1; i++) {
73
74          //
75          // Add L*x to the result
76          //
77          v = x[i - i1 + 1];
78          by1 = i - i1 + 2;
79          by2 = n;
80          ba1 = i + 1;
81          ba2 = i2;
82          i1_ = (ba1) - (by1);
83          for (i_ = by1; i_ <= by2; i_++) {
84            y[i_] = y[i_] + v * AP.Math.Conj(a[i, i_ + i1_]);
85          }
86
87          //
88          // Add U*x to the result
89          //
90          bx1 = i - i1 + 2;
91          bx2 = n;
92          ba1 = i + 1;
93          ba2 = i2;
94          i1_ = (ba1) - (bx1);
95          v = 0.0;
96          for (i_ = bx1; i_ <= bx2; i_++) {
97            v += x[i_] * a[i, i_ + i1_];
98          }
99          y[i - i1 + 1] = y[i - i1 + 1] + v;
100        }
101      } else {
102        for (i = i1 + 1; i <= i2; i++) {
103
104          //
105          // Add L*x to the result
106          //
107          bx1 = 1;
108          bx2 = i - i1;
109          ba1 = i1;
110          ba2 = i - 1;
111          i1_ = (ba1) - (bx1);
112          v = 0.0;
113          for (i_ = bx1; i_ <= bx2; i_++) {
114            v += x[i_] * a[i, i_ + i1_];
115          }
116          y[i - i1 + 1] = y[i - i1 + 1] + v;
117
118          //
119          // Add U*x to the result
120          //
121          v = x[i - i1 + 1];
122          by1 = 1;
123          by2 = i - i1;
124          ba1 = i1;
125          ba2 = i - 1;
126          i1_ = (ba1) - (by1);
127          for (i_ = by1; i_ <= by2; i_++) {
128            y[i_] = y[i_] + v * AP.Math.Conj(a[i, i_ + i1_]);
129          }
130        }
131      }
132      for (i_ = 1; i_ <= n; i_++) {
133        y[i_] = alpha * y[i_];
134      }
135    }
136
137
138    public static void hermitianrank2update(ref AP.Complex[,] a,
139        bool isupper,
140        int i1,
141        int i2,
142        ref AP.Complex[] x,
143        ref AP.Complex[] y,
144        ref AP.Complex[] t,
145        AP.Complex alpha) {
146      int i = 0;
147      int tp1 = 0;
148      int tp2 = 0;
149      AP.Complex v = 0;
150      int i_ = 0;
151      int i1_ = 0;
152
153      if (isupper) {
154        for (i = i1; i <= i2; i++) {
155          tp1 = i + 1 - i1;
156          tp2 = i2 - i1 + 1;
157          v = alpha * x[i + 1 - i1];
158          for (i_ = tp1; i_ <= tp2; i_++) {
159            t[i_] = v * AP.Math.Conj(y[i_]);
160          }
161          v = AP.Math.Conj(alpha) * y[i + 1 - i1];
162          for (i_ = tp1; i_ <= tp2; i_++) {
163            t[i_] = t[i_] + v * AP.Math.Conj(x[i_]);
164          }
165          i1_ = (tp1) - (i);
166          for (i_ = i; i_ <= i2; i_++) {
167            a[i, i_] = a[i, i_] + t[i_ + i1_];
168          }
169        }
170      } else {
171        for (i = i1; i <= i2; i++) {
172          tp1 = 1;
173          tp2 = i + 1 - i1;
174          v = alpha * x[i + 1 - i1];
175          for (i_ = tp1; i_ <= tp2; i_++) {
176            t[i_] = v * AP.Math.Conj(y[i_]);
177          }
178          v = AP.Math.Conj(alpha) * y[i + 1 - i1];
179          for (i_ = tp1; i_ <= tp2; i_++) {
180            t[i_] = t[i_] + v * AP.Math.Conj(x[i_]);
181          }
182          i1_ = (tp1) - (i1);
183          for (i_ = i1; i_ <= i; i_++) {
184            a[i, i_] = a[i, i_] + t[i_ + i1_];
185          }
186        }
187      }
188    }
189  }
190}
Note: See TracBrowser for help on using the repository browser.