1:  #region Translated by Jose Antonio De Santiago-Castillo.
2:
3:  //Translated by Jose Antonio De Santiago-Castillo.
4:  //E-mail:JAntonioDeSantiago@gmail.com
5:  //Web: www.DotNumerics.com
6:  //
7:  //Fortran to C# Translation.
8:  //Translated by:
9:  //F2CSharp Version 0.71 (November 10, 2009)
10:  //Code Optimizations: None
11:  //
12:  #endregion
13:
14:  using System;
15:  using DotNumerics.FortranLibrary;
16:
17:  namespace DotNumerics.CSLapack
18:  {
19:      /// <summary>
20:      /// -- LAPACK auxiliary routine (version 3.1) --
21:      /// Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
22:      /// November 2006
23:      /// Purpose
24:      /// =======
25:      ///
26:      /// Given two column vectors X and Y, let
27:      ///
28:      /// A = ( X Y ).
29:      ///
30:      /// The subroutine first computes the QR factorization of A = Q*R,
31:      /// and then computes the SVD of the 2-by-2 upper triangular matrix R.
32:      /// The smaller singular value of R is returned in SSMIN, which is used
33:      /// as the measurement of the linear dependency of the vectors X and Y.
34:      ///
35:      ///</summary>
36:      public class DLAPLL
37:      {
38:
39:
40:          #region Dependencies
41:
42:          DDOT _ddot; DAXPY _daxpy; DLARFG _dlarfg; DLAS2 _dlas2;
43:
44:          #endregion
45:
46:
47:          #region Fields
48:
49:          const double ZERO = 0.0E+0; const double ONE = 1.0E+0; double A11 = 0; double A12 = 0; double A22 = 0; double C = 0;
50:          double SSMAX = 0;double TAU = 0;
51:
52:          #endregion
53:
54:          public DLAPLL(DDOT ddot, DAXPY daxpy, DLARFG dlarfg, DLAS2 dlas2)
55:          {
56:
57:
58:              #region Set Dependencies
59:
60:              this._ddot = ddot; this._daxpy = daxpy; this._dlarfg = dlarfg; this._dlas2 = dlas2;
61:
62:              #endregion
63:
64:          }
65:
66:          public DLAPLL()
67:          {
68:
69:
70:              #region Dependencies (Initialization)
71:
72:              DDOT ddot = new DDOT();
73:              DAXPY daxpy = new DAXPY();
74:              LSAME lsame = new LSAME();
75:              DLAMC3 dlamc3 = new DLAMC3();
76:              DLAPY2 dlapy2 = new DLAPY2();
77:              DNRM2 dnrm2 = new DNRM2();
78:              DSCAL dscal = new DSCAL();
79:              DLAS2 dlas2 = new DLAS2();
80:              DLAMC1 dlamc1 = new DLAMC1(dlamc3);
81:              DLAMC4 dlamc4 = new DLAMC4(dlamc3);
82:              DLAMC5 dlamc5 = new DLAMC5(dlamc3);
83:              DLAMC2 dlamc2 = new DLAMC2(dlamc3, dlamc1, dlamc4, dlamc5);
84:              DLAMCH dlamch = new DLAMCH(lsame, dlamc2);
85:              DLARFG dlarfg = new DLARFG(dlamch, dlapy2, dnrm2, dscal);
86:
87:              #endregion
88:
89:
90:              #region Set Dependencies
91:
92:              this._ddot = ddot; this._daxpy = daxpy; this._dlarfg = dlarfg; this._dlas2 = dlas2;
93:
94:              #endregion
95:
96:          }
97:          /// <summary>
98:          /// Purpose
99:          /// =======
100:          ///
101:          /// Given two column vectors X and Y, let
102:          ///
103:          /// A = ( X Y ).
104:          ///
105:          /// The subroutine first computes the QR factorization of A = Q*R,
106:          /// and then computes the SVD of the 2-by-2 upper triangular matrix R.
107:          /// The smaller singular value of R is returned in SSMIN, which is used
108:          /// as the measurement of the linear dependency of the vectors X and Y.
109:          ///
110:          ///</summary>
111:          /// <param name="N">
112:          /// (input) INTEGER
113:          /// The length of the vectors X and Y.
114:          ///</param>
115:          /// <param name="X">
116:          /// (input/output) DOUBLE PRECISION array,
117:          /// dimension (1+(N-1)*INCX)
118:          /// On entry, X contains the N-vector X.
119:          /// On exit, X is overwritten.
120:          ///</param>
121:          /// <param name="INCX">
122:          /// (input) INTEGER
123:          /// The increment between successive elements of X. INCX .GT. 0.
124:          ///</param>
125:          /// <param name="Y">
126:          /// (input/output) DOUBLE PRECISION array,
127:          /// dimension (1+(N-1)*INCY)
128:          /// On entry, Y contains the N-vector Y.
129:          /// On exit, Y is overwritten.
130:          ///</param>
131:          /// <param name="INCY">
132:          /// (input) INTEGER
133:          /// The increment between successive elements of Y. INCY .GT. 0.
134:          ///</param>
135:          /// <param name="SSMIN">
136:          /// (output) DOUBLE PRECISION
137:          /// The smallest singular value of the N-by-2 matrix A = ( X Y ).
138:          ///</param>
139:          public void Run(int N, ref double[] X, int offset_x, int INCX, ref double[] Y, int offset_y, int INCY, ref double SSMIN)
140:          {
141:
142:              #region Array Index Correction
143:
144:               int o_x = -1 + offset_x;  int o_y = -1 + offset_y;
145:
146:              #endregion
147:
148:
149:              #region Prolog
150:
151:              // *
152:              // *  -- LAPACK auxiliary routine (version 3.1) --
153:              // *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
154:              // *     November 2006
155:              // *
156:              // *     .. Scalar Arguments ..
157:              // *     ..
158:              // *     .. Array Arguments ..
159:              // *     ..
160:              // *
161:              // *  Purpose
162:              // *  =======
163:              // *
164:              // *  Given two column vectors X and Y, let
165:              // *
166:              // *                       A = ( X Y ).
167:              // *
168:              // *  The subroutine first computes the QR factorization of A = Q*R,
169:              // *  and then computes the SVD of the 2-by-2 upper triangular matrix R.
170:              // *  The smaller singular value of R is returned in SSMIN, which is used
171:              // *  as the measurement of the linear dependency of the vectors X and Y.
172:              // *
173:              // *  Arguments
174:              // *  =========
175:              // *
176:              // *  N       (input) INTEGER
177:              // *          The length of the vectors X and Y.
178:              // *
179:              // *  X       (input/output) DOUBLE PRECISION array,
180:              // *                         dimension (1+(N-1)*INCX)
181:              // *          On entry, X contains the N-vector X.
182:              // *          On exit, X is overwritten.
183:              // *
184:              // *  INCX    (input) INTEGER
185:              // *          The increment between successive elements of X. INCX > 0.
186:              // *
187:              // *  Y       (input/output) DOUBLE PRECISION array,
188:              // *                         dimension (1+(N-1)*INCY)
189:              // *          On entry, Y contains the N-vector Y.
190:              // *          On exit, Y is overwritten.
191:              // *
192:              // *  INCY    (input) INTEGER
193:              // *          The increment between successive elements of Y. INCY > 0.
194:              // *
195:              // *  SSMIN   (output) DOUBLE PRECISION
196:              // *          The smallest singular value of the N-by-2 matrix A = ( X Y ).
197:              // *
198:              // *  =====================================================================
199:              // *
200:              // *     .. Parameters ..
201:              // *     ..
202:              // *     .. Local Scalars ..
203:              // *     ..
204:              // *     .. External Functions ..
205:              // *     ..
206:              // *     .. External Subroutines ..
207:              // *     ..
208:              // *     .. Executable Statements ..
209:              // *
210:              // *     Quick return if possible
211:              // *
212:
213:              #endregion
214:
215:
216:              #region Body
217:
218:              if (N <= 1)
219:              {
220:                  SSMIN = ZERO;
221:                  return;
222:              }
223:              // *
224:              // *     Compute the QR factorization of the N-by-2 matrix ( X Y )
225:              // *
226:              this._dlarfg.Run(N, ref X[1 + o_x], ref X, 1 + INCX + o_x, INCX, ref TAU);
227:              A11 = X[1 + o_x];
228:              X[1 + o_x] = ONE;
229:              // *
230:              C =  - TAU * this._ddot.Run(N, X, offset_x, INCX, Y, offset_y, INCY);
231:              this._daxpy.Run(N, C, X, offset_x, INCX, ref Y, offset_y, INCY);
232:              // *
233:              this._dlarfg.Run(N - 1, ref Y[1 + INCY + o_y], ref Y, 1 + 2 * INCY + o_y, INCY, ref TAU);
234:              // *
235:              A12 = Y[1 + o_y];
236:              A22 = Y[1 + INCY + o_y];
237:              // *
238:              // *     Compute the SVD of 2-by-2 Upper triangular matrix.
239:              // *
240:              this._dlas2.Run(A11, A12, A22, ref SSMIN, ref SSMAX);
241:              // *
242:              return;
243:              // *
244:              // *     End of DLAPLL
245:              // *
246:
247:              #endregion
248:
249:          }
250:      }
251:  }