You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

slabrd.f 14 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. *> \brief \b SLABRD reduces the first nb rows and columns of a general matrix to a bidiagonal form.
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download SLABRD + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/slabrd.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/slabrd.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/slabrd.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE SLABRD( M, N, NB, A, LDA, D, E, TAUQ, TAUP, X, LDX, Y,
  22. * LDY )
  23. *
  24. * .. Scalar Arguments ..
  25. * INTEGER LDA, LDX, LDY, M, N, NB
  26. * ..
  27. * .. Array Arguments ..
  28. * REAL A( LDA, * ), D( * ), E( * ), TAUP( * ),
  29. * $ TAUQ( * ), X( LDX, * ), Y( LDY, * )
  30. * ..
  31. *
  32. *
  33. *> \par Purpose:
  34. * =============
  35. *>
  36. *> \verbatim
  37. *>
  38. *> SLABRD reduces the first NB rows and columns of a real general
  39. *> m by n matrix A to upper or lower bidiagonal form by an orthogonal
  40. *> transformation Q**T * A * P, and returns the matrices X and Y which
  41. *> are needed to apply the transformation to the unreduced part of A.
  42. *>
  43. *> If m >= n, A is reduced to upper bidiagonal form; if m < n, to lower
  44. *> bidiagonal form.
  45. *>
  46. *> This is an auxiliary routine called by SGEBRD
  47. *> \endverbatim
  48. *
  49. * Arguments:
  50. * ==========
  51. *
  52. *> \param[in] M
  53. *> \verbatim
  54. *> M is INTEGER
  55. *> The number of rows in the matrix A.
  56. *> \endverbatim
  57. *>
  58. *> \param[in] N
  59. *> \verbatim
  60. *> N is INTEGER
  61. *> The number of columns in the matrix A.
  62. *> \endverbatim
  63. *>
  64. *> \param[in] NB
  65. *> \verbatim
  66. *> NB is INTEGER
  67. *> The number of leading rows and columns of A to be reduced.
  68. *> \endverbatim
  69. *>
  70. *> \param[in,out] A
  71. *> \verbatim
  72. *> A is REAL array, dimension (LDA,N)
  73. *> On entry, the m by n general matrix to be reduced.
  74. *> On exit, the first NB rows and columns of the matrix are
  75. *> overwritten; the rest of the array is unchanged.
  76. *> If m >= n, elements on and below the diagonal in the first NB
  77. *> columns, with the array TAUQ, represent the orthogonal
  78. *> matrix Q as a product of elementary reflectors; and
  79. *> elements above the diagonal in the first NB rows, with the
  80. *> array TAUP, represent the orthogonal matrix P as a product
  81. *> of elementary reflectors.
  82. *> If m < n, elements below the diagonal in the first NB
  83. *> columns, with the array TAUQ, represent the orthogonal
  84. *> matrix Q as a product of elementary reflectors, and
  85. *> elements on and above the diagonal in the first NB rows,
  86. *> with the array TAUP, represent the orthogonal matrix P as
  87. *> a product of elementary reflectors.
  88. *> See Further Details.
  89. *> \endverbatim
  90. *>
  91. *> \param[in] LDA
  92. *> \verbatim
  93. *> LDA is INTEGER
  94. *> The leading dimension of the array A. LDA >= max(1,M).
  95. *> \endverbatim
  96. *>
  97. *> \param[out] D
  98. *> \verbatim
  99. *> D is REAL array, dimension (NB)
  100. *> The diagonal elements of the first NB rows and columns of
  101. *> the reduced matrix. D(i) = A(i,i).
  102. *> \endverbatim
  103. *>
  104. *> \param[out] E
  105. *> \verbatim
  106. *> E is REAL array, dimension (NB)
  107. *> The off-diagonal elements of the first NB rows and columns of
  108. *> the reduced matrix.
  109. *> \endverbatim
  110. *>
  111. *> \param[out] TAUQ
  112. *> \verbatim
  113. *> TAUQ is REAL array, dimension (NB)
  114. *> The scalar factors of the elementary reflectors which
  115. *> represent the orthogonal matrix Q. See Further Details.
  116. *> \endverbatim
  117. *>
  118. *> \param[out] TAUP
  119. *> \verbatim
  120. *> TAUP is REAL array, dimension (NB)
  121. *> The scalar factors of the elementary reflectors which
  122. *> represent the orthogonal matrix P. See Further Details.
  123. *> \endverbatim
  124. *>
  125. *> \param[out] X
  126. *> \verbatim
  127. *> X is REAL array, dimension (LDX,NB)
  128. *> The m-by-nb matrix X required to update the unreduced part
  129. *> of A.
  130. *> \endverbatim
  131. *>
  132. *> \param[in] LDX
  133. *> \verbatim
  134. *> LDX is INTEGER
  135. *> The leading dimension of the array X. LDX >= max(1,M).
  136. *> \endverbatim
  137. *>
  138. *> \param[out] Y
  139. *> \verbatim
  140. *> Y is REAL array, dimension (LDY,NB)
  141. *> The n-by-nb matrix Y required to update the unreduced part
  142. *> of A.
  143. *> \endverbatim
  144. *>
  145. *> \param[in] LDY
  146. *> \verbatim
  147. *> LDY is INTEGER
  148. *> The leading dimension of the array Y. LDY >= max(1,N).
  149. *> \endverbatim
  150. *
  151. * Authors:
  152. * ========
  153. *
  154. *> \author Univ. of Tennessee
  155. *> \author Univ. of California Berkeley
  156. *> \author Univ. of Colorado Denver
  157. *> \author NAG Ltd.
  158. *
  159. *> \ingroup realOTHERauxiliary
  160. *
  161. *> \par Further Details:
  162. * =====================
  163. *>
  164. *> \verbatim
  165. *>
  166. *> The matrices Q and P are represented as products of elementary
  167. *> reflectors:
  168. *>
  169. *> Q = H(1) H(2) . . . H(nb) and P = G(1) G(2) . . . G(nb)
  170. *>
  171. *> Each H(i) and G(i) has the form:
  172. *>
  173. *> H(i) = I - tauq * v * v**T and G(i) = I - taup * u * u**T
  174. *>
  175. *> where tauq and taup are real scalars, and v and u are real vectors.
  176. *>
  177. *> If m >= n, v(1:i-1) = 0, v(i) = 1, and v(i:m) is stored on exit in
  178. *> A(i:m,i); u(1:i) = 0, u(i+1) = 1, and u(i+1:n) is stored on exit in
  179. *> A(i,i+1:n); tauq is stored in TAUQ(i) and taup in TAUP(i).
  180. *>
  181. *> If m < n, v(1:i) = 0, v(i+1) = 1, and v(i+1:m) is stored on exit in
  182. *> A(i+2:m,i); u(1:i-1) = 0, u(i) = 1, and u(i:n) is stored on exit in
  183. *> A(i,i+1:n); tauq is stored in TAUQ(i) and taup in TAUP(i).
  184. *>
  185. *> The elements of the vectors v and u together form the m-by-nb matrix
  186. *> V and the nb-by-n matrix U**T which are needed, with X and Y, to apply
  187. *> the transformation to the unreduced part of the matrix, using a block
  188. *> update of the form: A := A - V*Y**T - X*U**T.
  189. *>
  190. *> The contents of A on exit are illustrated by the following examples
  191. *> with nb = 2:
  192. *>
  193. *> m = 6 and n = 5 (m > n): m = 5 and n = 6 (m < n):
  194. *>
  195. *> ( 1 1 u1 u1 u1 ) ( 1 u1 u1 u1 u1 u1 )
  196. *> ( v1 1 1 u2 u2 ) ( 1 1 u2 u2 u2 u2 )
  197. *> ( v1 v2 a a a ) ( v1 1 a a a a )
  198. *> ( v1 v2 a a a ) ( v1 v2 a a a a )
  199. *> ( v1 v2 a a a ) ( v1 v2 a a a a )
  200. *> ( v1 v2 a a a )
  201. *>
  202. *> where a denotes an element of the original matrix which is unchanged,
  203. *> vi denotes an element of the vector defining H(i), and ui an element
  204. *> of the vector defining G(i).
  205. *> \endverbatim
  206. *>
  207. * =====================================================================
  208. SUBROUTINE SLABRD( M, N, NB, A, LDA, D, E, TAUQ, TAUP, X, LDX, Y,
  209. $ LDY )
  210. *
  211. * -- LAPACK auxiliary routine --
  212. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  213. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  214. *
  215. * .. Scalar Arguments ..
  216. INTEGER LDA, LDX, LDY, M, N, NB
  217. * ..
  218. * .. Array Arguments ..
  219. REAL A( LDA, * ), D( * ), E( * ), TAUP( * ),
  220. $ TAUQ( * ), X( LDX, * ), Y( LDY, * )
  221. * ..
  222. *
  223. * =====================================================================
  224. *
  225. * .. Parameters ..
  226. REAL ZERO, ONE
  227. PARAMETER ( ZERO = 0.0E0, ONE = 1.0E0 )
  228. * ..
  229. * .. Local Scalars ..
  230. INTEGER I
  231. * ..
  232. * .. External Subroutines ..
  233. EXTERNAL SGEMV, SLARFG, SSCAL
  234. * ..
  235. * .. Intrinsic Functions ..
  236. INTRINSIC MIN
  237. * ..
  238. * .. Executable Statements ..
  239. *
  240. * Quick return if possible
  241. *
  242. IF( M.LE.0 .OR. N.LE.0 )
  243. $ RETURN
  244. *
  245. IF( M.GE.N ) THEN
  246. *
  247. * Reduce to upper bidiagonal form
  248. *
  249. DO 10 I = 1, NB
  250. *
  251. * Update A(i:m,i)
  252. *
  253. CALL SGEMV( 'No transpose', M-I+1, I-1, -ONE, A( I, 1 ),
  254. $ LDA, Y( I, 1 ), LDY, ONE, A( I, I ), 1 )
  255. CALL SGEMV( 'No transpose', M-I+1, I-1, -ONE, X( I, 1 ),
  256. $ LDX, A( 1, I ), 1, ONE, A( I, I ), 1 )
  257. *
  258. * Generate reflection Q(i) to annihilate A(i+1:m,i)
  259. *
  260. CALL SLARFG( M-I+1, A( I, I ), A( MIN( I+1, M ), I ), 1,
  261. $ TAUQ( I ) )
  262. D( I ) = A( I, I )
  263. IF( I.LT.N ) THEN
  264. A( I, I ) = ONE
  265. *
  266. * Compute Y(i+1:n,i)
  267. *
  268. CALL SGEMV( 'Transpose', M-I+1, N-I, ONE, A( I, I+1 ),
  269. $ LDA, A( I, I ), 1, ZERO, Y( I+1, I ), 1 )
  270. CALL SGEMV( 'Transpose', M-I+1, I-1, ONE, A( I, 1 ), LDA,
  271. $ A( I, I ), 1, ZERO, Y( 1, I ), 1 )
  272. CALL SGEMV( 'No transpose', N-I, I-1, -ONE, Y( I+1, 1 ),
  273. $ LDY, Y( 1, I ), 1, ONE, Y( I+1, I ), 1 )
  274. CALL SGEMV( 'Transpose', M-I+1, I-1, ONE, X( I, 1 ), LDX,
  275. $ A( I, I ), 1, ZERO, Y( 1, I ), 1 )
  276. CALL SGEMV( 'Transpose', I-1, N-I, -ONE, A( 1, I+1 ),
  277. $ LDA, Y( 1, I ), 1, ONE, Y( I+1, I ), 1 )
  278. CALL SSCAL( N-I, TAUQ( I ), Y( I+1, I ), 1 )
  279. *
  280. * Update A(i,i+1:n)
  281. *
  282. CALL SGEMV( 'No transpose', N-I, I, -ONE, Y( I+1, 1 ),
  283. $ LDY, A( I, 1 ), LDA, ONE, A( I, I+1 ), LDA )
  284. CALL SGEMV( 'Transpose', I-1, N-I, -ONE, A( 1, I+1 ),
  285. $ LDA, X( I, 1 ), LDX, ONE, A( I, I+1 ), LDA )
  286. *
  287. * Generate reflection P(i) to annihilate A(i,i+2:n)
  288. *
  289. CALL SLARFG( N-I, A( I, I+1 ), A( I, MIN( I+2, N ) ),
  290. $ LDA, TAUP( I ) )
  291. E( I ) = A( I, I+1 )
  292. A( I, I+1 ) = ONE
  293. *
  294. * Compute X(i+1:m,i)
  295. *
  296. CALL SGEMV( 'No transpose', M-I, N-I, ONE, A( I+1, I+1 ),
  297. $ LDA, A( I, I+1 ), LDA, ZERO, X( I+1, I ), 1 )
  298. CALL SGEMV( 'Transpose', N-I, I, ONE, Y( I+1, 1 ), LDY,
  299. $ A( I, I+1 ), LDA, ZERO, X( 1, I ), 1 )
  300. CALL SGEMV( 'No transpose', M-I, I, -ONE, A( I+1, 1 ),
  301. $ LDA, X( 1, I ), 1, ONE, X( I+1, I ), 1 )
  302. CALL SGEMV( 'No transpose', I-1, N-I, ONE, A( 1, I+1 ),
  303. $ LDA, A( I, I+1 ), LDA, ZERO, X( 1, I ), 1 )
  304. CALL SGEMV( 'No transpose', M-I, I-1, -ONE, X( I+1, 1 ),
  305. $ LDX, X( 1, I ), 1, ONE, X( I+1, I ), 1 )
  306. CALL SSCAL( M-I, TAUP( I ), X( I+1, I ), 1 )
  307. END IF
  308. 10 CONTINUE
  309. ELSE
  310. *
  311. * Reduce to lower bidiagonal form
  312. *
  313. DO 20 I = 1, NB
  314. *
  315. * Update A(i,i:n)
  316. *
  317. CALL SGEMV( 'No transpose', N-I+1, I-1, -ONE, Y( I, 1 ),
  318. $ LDY, A( I, 1 ), LDA, ONE, A( I, I ), LDA )
  319. CALL SGEMV( 'Transpose', I-1, N-I+1, -ONE, A( 1, I ), LDA,
  320. $ X( I, 1 ), LDX, ONE, A( I, I ), LDA )
  321. *
  322. * Generate reflection P(i) to annihilate A(i,i+1:n)
  323. *
  324. CALL SLARFG( N-I+1, A( I, I ), A( I, MIN( I+1, N ) ), LDA,
  325. $ TAUP( I ) )
  326. D( I ) = A( I, I )
  327. IF( I.LT.M ) THEN
  328. A( I, I ) = ONE
  329. *
  330. * Compute X(i+1:m,i)
  331. *
  332. CALL SGEMV( 'No transpose', M-I, N-I+1, ONE, A( I+1, I ),
  333. $ LDA, A( I, I ), LDA, ZERO, X( I+1, I ), 1 )
  334. CALL SGEMV( 'Transpose', N-I+1, I-1, ONE, Y( I, 1 ), LDY,
  335. $ A( I, I ), LDA, ZERO, X( 1, I ), 1 )
  336. CALL SGEMV( 'No transpose', M-I, I-1, -ONE, A( I+1, 1 ),
  337. $ LDA, X( 1, I ), 1, ONE, X( I+1, I ), 1 )
  338. CALL SGEMV( 'No transpose', I-1, N-I+1, ONE, A( 1, I ),
  339. $ LDA, A( I, I ), LDA, ZERO, X( 1, I ), 1 )
  340. CALL SGEMV( 'No transpose', M-I, I-1, -ONE, X( I+1, 1 ),
  341. $ LDX, X( 1, I ), 1, ONE, X( I+1, I ), 1 )
  342. CALL SSCAL( M-I, TAUP( I ), X( I+1, I ), 1 )
  343. *
  344. * Update A(i+1:m,i)
  345. *
  346. CALL SGEMV( 'No transpose', M-I, I-1, -ONE, A( I+1, 1 ),
  347. $ LDA, Y( I, 1 ), LDY, ONE, A( I+1, I ), 1 )
  348. CALL SGEMV( 'No transpose', M-I, I, -ONE, X( I+1, 1 ),
  349. $ LDX, A( 1, I ), 1, ONE, A( I+1, I ), 1 )
  350. *
  351. * Generate reflection Q(i) to annihilate A(i+2:m,i)
  352. *
  353. CALL SLARFG( M-I, A( I+1, I ), A( MIN( I+2, M ), I ), 1,
  354. $ TAUQ( I ) )
  355. E( I ) = A( I+1, I )
  356. A( I+1, I ) = ONE
  357. *
  358. * Compute Y(i+1:n,i)
  359. *
  360. CALL SGEMV( 'Transpose', M-I, N-I, ONE, A( I+1, I+1 ),
  361. $ LDA, A( I+1, I ), 1, ZERO, Y( I+1, I ), 1 )
  362. CALL SGEMV( 'Transpose', M-I, I-1, ONE, A( I+1, 1 ), LDA,
  363. $ A( I+1, I ), 1, ZERO, Y( 1, I ), 1 )
  364. CALL SGEMV( 'No transpose', N-I, I-1, -ONE, Y( I+1, 1 ),
  365. $ LDY, Y( 1, I ), 1, ONE, Y( I+1, I ), 1 )
  366. CALL SGEMV( 'Transpose', M-I, I, ONE, X( I+1, 1 ), LDX,
  367. $ A( I+1, I ), 1, ZERO, Y( 1, I ), 1 )
  368. CALL SGEMV( 'Transpose', I, N-I, -ONE, A( 1, I+1 ), LDA,
  369. $ Y( 1, I ), 1, ONE, Y( I+1, I ), 1 )
  370. CALL SSCAL( N-I, TAUQ( I ), Y( I+1, I ), 1 )
  371. END IF
  372. 20 CONTINUE
  373. END IF
  374. RETURN
  375. *
  376. * End of SLABRD
  377. *
  378. END