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 routine (version 3.1) --
21: /// Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
22: /// November 2006
23: /// Purpose
24: /// =======
25: ///
26: /// DGELQ2 computes an LQ factorization of a real m by n matrix A:
27: /// A = L * Q.
28: ///
29: ///</summary>
30: public class DGELQ2
31: {
32:
33:
34: #region Dependencies
35:
36: DLARF _dlarf; DLARFG _dlarfg; XERBLA _xerbla;
37:
38: #endregion
39:
40:
41: #region Fields
42:
43: const double ONE = 1.0E+0; int I = 0; int K = 0; double AII = 0;
44:
45: #endregion
46:
47: public DGELQ2(DLARF dlarf, DLARFG dlarfg, XERBLA xerbla)
48: {
49:
50:
51: #region Set Dependencies
52:
53: this._dlarf = dlarf; this._dlarfg = dlarfg; this._xerbla = xerbla;
54:
55: #endregion
56:
57: }
58:
59: public DGELQ2()
60: {
61:
62:
63: #region Dependencies (Initialization)
64:
65: LSAME lsame = new LSAME();
66: XERBLA xerbla = new XERBLA();
67: DLAMC3 dlamc3 = new DLAMC3();
68: DLAPY2 dlapy2 = new DLAPY2();
69: DNRM2 dnrm2 = new DNRM2();
70: DSCAL dscal = new DSCAL();
71: DGEMV dgemv = new DGEMV(lsame, xerbla);
72: DGER dger = new DGER(xerbla);
73: DLARF dlarf = new DLARF(dgemv, dger, lsame);
74: DLAMC1 dlamc1 = new DLAMC1(dlamc3);
75: DLAMC4 dlamc4 = new DLAMC4(dlamc3);
76: DLAMC5 dlamc5 = new DLAMC5(dlamc3);
77: DLAMC2 dlamc2 = new DLAMC2(dlamc3, dlamc1, dlamc4, dlamc5);
78: DLAMCH dlamch = new DLAMCH(lsame, dlamc2);
79: DLARFG dlarfg = new DLARFG(dlamch, dlapy2, dnrm2, dscal);
80:
81: #endregion
82:
83:
84: #region Set Dependencies
85:
86: this._dlarf = dlarf; this._dlarfg = dlarfg; this._xerbla = xerbla;
87:
88: #endregion
89:
90: }
91: /// <summary>
92: /// Purpose
93: /// =======
94: ///
95: /// DGELQ2 computes an LQ factorization of a real m by n matrix A:
96: /// A = L * Q.
97: ///
98: ///</summary>
99: /// <param name="M">
100: /// (input) INTEGER
101: /// The number of rows of the matrix A. M .GE. 0.
102: ///</param>
103: /// <param name="N">
104: /// (input) INTEGER
105: /// The number of columns of the matrix A. N .GE. 0.
106: ///</param>
107: /// <param name="A">
108: /// (input/output) DOUBLE PRECISION array, dimension (LDA,N)
109: /// On entry, the m by n matrix A.
110: /// On exit, the elements on and below the diagonal of the array
111: /// contain the m by min(m,n) lower trapezoidal matrix L (L is
112: /// lower triangular if m .LE. n); the elements above the diagonal,
113: /// with the array TAU, represent the orthogonal matrix Q as a
114: /// product of elementary reflectors (see Further Details).
115: ///</param>
116: /// <param name="LDA">
117: /// (input) INTEGER
118: /// The leading dimension of the array A. LDA .GE. max(1,M).
119: ///</param>
120: /// <param name="TAU">
121: /// (output) DOUBLE PRECISION array, dimension (min(M,N))
122: /// The scalar factors of the elementary reflectors (see Further
123: /// Details).
124: ///</param>
125: /// <param name="WORK">
126: /// (workspace) DOUBLE PRECISION array, dimension (M)
127: ///</param>
128: /// <param name="INFO">
129: /// (output) INTEGER
130: /// = 0: successful exit
131: /// .LT. 0: if INFO = -i, the i-th argument had an illegal value
132: ///</param>
133: public void Run(int M, int N, ref double[] A, int offset_a, int LDA, ref double[] TAU, int offset_tau, ref double[] WORK, int offset_work
134: , ref int INFO)
135: {
136:
137: #region Array Index Correction
138:
139: int o_a = -1 - LDA + offset_a; int o_tau = -1 + offset_tau; int o_work = -1 + offset_work;
140:
141: #endregion
142:
143:
144: #region Prolog
145:
146: // *
147: // * -- LAPACK routine (version 3.1) --
148: // * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
149: // * November 2006
150: // *
151: // * .. Scalar Arguments ..
152: // * ..
153: // * .. Array Arguments ..
154: // * ..
155: // *
156: // * Purpose
157: // * =======
158: // *
159: // * DGELQ2 computes an LQ factorization of a real m by n matrix A:
160: // * A = L * Q.
161: // *
162: // * Arguments
163: // * =========
164: // *
165: // * M (input) INTEGER
166: // * The number of rows of the matrix A. M >= 0.
167: // *
168: // * N (input) INTEGER
169: // * The number of columns of the matrix A. N >= 0.
170: // *
171: // * A (input/output) DOUBLE PRECISION array, dimension (LDA,N)
172: // * On entry, the m by n matrix A.
173: // * On exit, the elements on and below the diagonal of the array
174: // * contain the m by min(m,n) lower trapezoidal matrix L (L is
175: // * lower triangular if m <= n); the elements above the diagonal,
176: // * with the array TAU, represent the orthogonal matrix Q as a
177: // * product of elementary reflectors (see Further Details).
178: // *
179: // * LDA (input) INTEGER
180: // * The leading dimension of the array A. LDA >= max(1,M).
181: // *
182: // * TAU (output) DOUBLE PRECISION array, dimension (min(M,N))
183: // * The scalar factors of the elementary reflectors (see Further
184: // * Details).
185: // *
186: // * WORK (workspace) DOUBLE PRECISION array, dimension (M)
187: // *
188: // * INFO (output) INTEGER
189: // * = 0: successful exit
190: // * < 0: if INFO = -i, the i-th argument had an illegal value
191: // *
192: // * Further Details
193: // * ===============
194: // *
195: // * The matrix Q is represented as a product of elementary reflectors
196: // *
197: // * Q = H(k) . . . H(2) H(1), where k = min(m,n).
198: // *
199: // * Each H(i) has the form
200: // *
201: // * H(i) = I - tau * v * v'
202: // *
203: // * where tau is a real scalar, and v is a real vector with
204: // * v(1:i-1) = 0 and v(i) = 1; v(i+1:n) is stored on exit in A(i,i+1:n),
205: // * and tau in TAU(i).
206: // *
207: // * =====================================================================
208: // *
209: // * .. Parameters ..
210: // * ..
211: // * .. Local Scalars ..
212: // * ..
213: // * .. External Subroutines ..
214: // * ..
215: // * .. Intrinsic Functions ..
216: // INTRINSIC MAX, MIN;
217: // * ..
218: // * .. Executable Statements ..
219: // *
220: // * Test the input arguments
221: // *
222:
223: #endregion
224:
225:
226: #region Body
227:
228: INFO = 0;
229: if (M < 0)
230: {
231: INFO = - 1;
232: }
233: else
234: {
235: if (N < 0)
236: {
237: INFO = - 2;
238: }
239: else
240: {
241: if (LDA < Math.Max(1, M))
242: {
243: INFO = - 4;
244: }
245: }
246: }
247: if (INFO != 0)
248: {
249: this._xerbla.Run("DGELQ2", - INFO);
250: return;
251: }
252: // *
253: K = Math.Min(M, N);
254: // *
255: for (I = 1; I <= K; I++)
256: {
257: // *
258: // * Generate elementary reflector H(i) to annihilate A(i,i+1:n)
259: // *
260: this._dlarfg.Run(N - I + 1, ref A[I+I * LDA + o_a], ref A, I+Math.Min(I + 1, N) * LDA + o_a, LDA, ref TAU[I + o_tau]);
261: if (I < M)
262: {
263: // *
264: // * Apply H(i) to A(i+1:m,i:n) from the right
265: // *
266: AII = A[I+I * LDA + o_a];
267: A[I+I * LDA + o_a] = ONE;
268: this._dlarf.Run("Right", M - I, N - I + 1, A, I+I * LDA + o_a, LDA, TAU[I + o_tau]
269: , ref A, I + 1+I * LDA + o_a, LDA, ref WORK, offset_work);
270: A[I+I * LDA + o_a] = AII;
271: }
272: }
273: return;
274: // *
275: // * End of DGELQ2
276: // *
277:
278: #endregion
279:
280: }
281: }
282: }