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.

zlaror.f 11 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. *> \brief \b ZLAROR
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. * Definition:
  9. * ===========
  10. *
  11. * SUBROUTINE ZLAROR( SIDE, INIT, M, N, A, LDA, ISEED, X, INFO )
  12. *
  13. * .. Scalar Arguments ..
  14. * CHARACTER INIT, SIDE
  15. * INTEGER INFO, LDA, M, N
  16. * ..
  17. * .. Array Arguments ..
  18. * INTEGER ISEED( 4 )
  19. * COMPLEX*16 A( LDA, * ), X( * )
  20. * ..
  21. *
  22. *
  23. *> \par Purpose:
  24. * =============
  25. *>
  26. *> \verbatim
  27. *>
  28. *> ZLAROR pre- or post-multiplies an M by N matrix A by a random
  29. *> unitary matrix U, overwriting A. A may optionally be
  30. *> initialized to the identity matrix before multiplying by U.
  31. *> U is generated using the method of G.W. Stewart
  32. *> ( SIAM J. Numer. Anal. 17, 1980, pp. 403-409 ).
  33. *> (BLAS-2 version)
  34. *> \endverbatim
  35. *
  36. * Arguments:
  37. * ==========
  38. *
  39. *> \param[in] SIDE
  40. *> \verbatim
  41. *> SIDE is CHARACTER*1
  42. *> SIDE specifies whether A is multiplied on the left or right
  43. *> by U.
  44. *> SIDE = 'L' Multiply A on the left (premultiply) by U
  45. *> SIDE = 'R' Multiply A on the right (postmultiply) by UC> SIDE = 'C' Multiply A on the left by U and the right by UC> SIDE = 'T' Multiply A on the left by U and the right by U'
  46. *> Not modified.
  47. *> \endverbatim
  48. *>
  49. *> \param[in] INIT
  50. *> \verbatim
  51. *> INIT is CHARACTER*1
  52. *> INIT specifies whether or not A should be initialized to
  53. *> the identity matrix.
  54. *> INIT = 'I' Initialize A to (a section of) the
  55. *> identity matrix before applying U.
  56. *> INIT = 'N' No initialization. Apply U to the
  57. *> input matrix A.
  58. *>
  59. *> INIT = 'I' may be used to generate square (i.e., unitary)
  60. *> or rectangular orthogonal matrices (orthogonality being
  61. *> in the sense of ZDOTC):
  62. *>
  63. *> For square matrices, M=N, and SIDE many be either 'L' or
  64. *> 'R'; the rows will be orthogonal to each other, as will the
  65. *> columns.
  66. *> For rectangular matrices where M < N, SIDE = 'R' will
  67. *> produce a dense matrix whose rows will be orthogonal and
  68. *> whose columns will not, while SIDE = 'L' will produce a
  69. *> matrix whose rows will be orthogonal, and whose first M
  70. *> columns will be orthogonal, the remaining columns being
  71. *> zero.
  72. *> For matrices where M > N, just use the previous
  73. *> explanation, interchanging 'L' and 'R' and "rows" and
  74. *> "columns".
  75. *>
  76. *> Not modified.
  77. *> \endverbatim
  78. *>
  79. *> \param[in] M
  80. *> \verbatim
  81. *> M is INTEGER
  82. *> Number of rows of A. Not modified.
  83. *> \endverbatim
  84. *>
  85. *> \param[in] N
  86. *> \verbatim
  87. *> N is INTEGER
  88. *> Number of columns of A. Not modified.
  89. *> \endverbatim
  90. *>
  91. *> \param[in,out] A
  92. *> \verbatim
  93. *> A is COMPLEX*16 array, dimension ( LDA, N )
  94. *> Input and output array. Overwritten by U A ( if SIDE = 'L' )
  95. *> or by A U ( if SIDE = 'R' )
  96. *> or by U A U* ( if SIDE = 'C')
  97. *> or by U A U' ( if SIDE = 'T') on exit.
  98. *> \endverbatim
  99. *>
  100. *> \param[in] LDA
  101. *> \verbatim
  102. *> LDA is INTEGER
  103. *> Leading dimension of A. Must be at least MAX ( 1, M ).
  104. *> Not modified.
  105. *> \endverbatim
  106. *>
  107. *> \param[in,out] ISEED
  108. *> \verbatim
  109. *> ISEED is INTEGER array, dimension ( 4 )
  110. *> On entry ISEED specifies the seed of the random number
  111. *> generator. The array elements should be between 0 and 4095;
  112. *> if not they will be reduced mod 4096. Also, ISEED(4) must
  113. *> be odd. The random number generator uses a linear
  114. *> congruential sequence limited to small integers, and so
  115. *> should produce machine independent random numbers. The
  116. *> values of ISEED are changed on exit, and can be used in the
  117. *> next call to ZLAROR to continue the same random number
  118. *> sequence.
  119. *> Modified.
  120. *> \endverbatim
  121. *>
  122. *> \param[out] X
  123. *> \verbatim
  124. *> X is COMPLEX*16 array, dimension ( 3*MAX( M, N ) )
  125. *> Workspace. Of length:
  126. *> 2*M + N if SIDE = 'L',
  127. *> 2*N + M if SIDE = 'R',
  128. *> 3*N if SIDE = 'C' or 'T'.
  129. *> Modified.
  130. *> \endverbatim
  131. *>
  132. *> \param[out] INFO
  133. *> \verbatim
  134. *> INFO is INTEGER
  135. *> An error flag. It is set to:
  136. *> 0 if no error.
  137. *> 1 if ZLARND returned a bad random number (installation
  138. *> problem)
  139. *> -1 if SIDE is not L, R, C, or T.
  140. *> -3 if M is negative.
  141. *> -4 if N is negative or if SIDE is C or T and N is not equal
  142. *> to M.
  143. *> -6 if LDA is less than M.
  144. *> \endverbatim
  145. *
  146. * Authors:
  147. * ========
  148. *
  149. *> \author Univ. of Tennessee
  150. *> \author Univ. of California Berkeley
  151. *> \author Univ. of Colorado Denver
  152. *> \author NAG Ltd.
  153. *
  154. *> \ingroup complex16_matgen
  155. *
  156. * =====================================================================
  157. SUBROUTINE ZLAROR( SIDE, INIT, M, N, A, LDA, ISEED, X, INFO )
  158. *
  159. * -- LAPACK auxiliary routine --
  160. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  161. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  162. *
  163. * .. Scalar Arguments ..
  164. CHARACTER INIT, SIDE
  165. INTEGER INFO, LDA, M, N
  166. * ..
  167. * .. Array Arguments ..
  168. INTEGER ISEED( 4 )
  169. COMPLEX*16 A( LDA, * ), X( * )
  170. * ..
  171. *
  172. * =====================================================================
  173. *
  174. * .. Parameters ..
  175. DOUBLE PRECISION ZERO, ONE, TOOSML
  176. PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0,
  177. $ TOOSML = 1.0D-20 )
  178. COMPLEX*16 CZERO, CONE
  179. PARAMETER ( CZERO = ( 0.0D+0, 0.0D+0 ),
  180. $ CONE = ( 1.0D+0, 0.0D+0 ) )
  181. * ..
  182. * .. Local Scalars ..
  183. INTEGER IROW, ITYPE, IXFRM, J, JCOL, KBEG, NXFRM
  184. DOUBLE PRECISION FACTOR, XABS, XNORM
  185. COMPLEX*16 CSIGN, XNORMS
  186. * ..
  187. * .. External Functions ..
  188. LOGICAL LSAME
  189. DOUBLE PRECISION DZNRM2
  190. COMPLEX*16 ZLARND
  191. EXTERNAL LSAME, DZNRM2, ZLARND
  192. * ..
  193. * .. External Subroutines ..
  194. EXTERNAL XERBLA, ZGEMV, ZGERC, ZLACGV, ZLASET, ZSCAL
  195. * ..
  196. * .. Intrinsic Functions ..
  197. INTRINSIC ABS, DCMPLX, DCONJG
  198. * ..
  199. * .. Executable Statements ..
  200. *
  201. INFO = 0
  202. IF( N.EQ.0 .OR. M.EQ.0 )
  203. $ RETURN
  204. *
  205. ITYPE = 0
  206. IF( LSAME( SIDE, 'L' ) ) THEN
  207. ITYPE = 1
  208. ELSE IF( LSAME( SIDE, 'R' ) ) THEN
  209. ITYPE = 2
  210. ELSE IF( LSAME( SIDE, 'C' ) ) THEN
  211. ITYPE = 3
  212. ELSE IF( LSAME( SIDE, 'T' ) ) THEN
  213. ITYPE = 4
  214. END IF
  215. *
  216. * Check for argument errors.
  217. *
  218. IF( ITYPE.EQ.0 ) THEN
  219. INFO = -1
  220. ELSE IF( M.LT.0 ) THEN
  221. INFO = -3
  222. ELSE IF( N.LT.0 .OR. ( ITYPE.EQ.3 .AND. N.NE.M ) ) THEN
  223. INFO = -4
  224. ELSE IF( LDA.LT.M ) THEN
  225. INFO = -6
  226. END IF
  227. IF( INFO.NE.0 ) THEN
  228. CALL XERBLA( 'ZLAROR', -INFO )
  229. RETURN
  230. END IF
  231. *
  232. IF( ITYPE.EQ.1 ) THEN
  233. NXFRM = M
  234. ELSE
  235. NXFRM = N
  236. END IF
  237. *
  238. * Initialize A to the identity matrix if desired
  239. *
  240. IF( LSAME( INIT, 'I' ) )
  241. $ CALL ZLASET( 'Full', M, N, CZERO, CONE, A, LDA )
  242. *
  243. * If no rotation possible, still multiply by
  244. * a random complex number from the circle |x| = 1
  245. *
  246. * 2) Compute Rotation by computing Householder
  247. * Transformations H(2), H(3), ..., H(n). Note that the
  248. * order in which they are computed is irrelevant.
  249. *
  250. DO 10 J = 1, NXFRM
  251. X( J ) = CZERO
  252. 10 CONTINUE
  253. *
  254. DO 30 IXFRM = 2, NXFRM
  255. KBEG = NXFRM - IXFRM + 1
  256. *
  257. * Generate independent normal( 0, 1 ) random numbers
  258. *
  259. DO 20 J = KBEG, NXFRM
  260. X( J ) = ZLARND( 3, ISEED )
  261. 20 CONTINUE
  262. *
  263. * Generate a Householder transformation from the random vector X
  264. *
  265. XNORM = DZNRM2( IXFRM, X( KBEG ), 1 )
  266. XABS = ABS( X( KBEG ) )
  267. IF( XABS.NE.CZERO ) THEN
  268. CSIGN = X( KBEG ) / XABS
  269. ELSE
  270. CSIGN = CONE
  271. END IF
  272. XNORMS = CSIGN*XNORM
  273. X( NXFRM+KBEG ) = -CSIGN
  274. FACTOR = XNORM*( XNORM+XABS )
  275. IF( ABS( FACTOR ).LT.TOOSML ) THEN
  276. INFO = 1
  277. CALL XERBLA( 'ZLAROR', -INFO )
  278. RETURN
  279. ELSE
  280. FACTOR = ONE / FACTOR
  281. END IF
  282. X( KBEG ) = X( KBEG ) + XNORMS
  283. *
  284. * Apply Householder transformation to A
  285. *
  286. IF( ITYPE.EQ.1 .OR. ITYPE.EQ.3 .OR. ITYPE.EQ.4 ) THEN
  287. *
  288. * Apply H(k) on the left of A
  289. *
  290. CALL ZGEMV( 'C', IXFRM, N, CONE, A( KBEG, 1 ), LDA,
  291. $ X( KBEG ), 1, CZERO, X( 2*NXFRM+1 ), 1 )
  292. CALL ZGERC( IXFRM, N, -DCMPLX( FACTOR ), X( KBEG ), 1,
  293. $ X( 2*NXFRM+1 ), 1, A( KBEG, 1 ), LDA )
  294. *
  295. END IF
  296. *
  297. IF( ITYPE.GE.2 .AND. ITYPE.LE.4 ) THEN
  298. *
  299. * Apply H(k)* (or H(k)') on the right of A
  300. *
  301. IF( ITYPE.EQ.4 ) THEN
  302. CALL ZLACGV( IXFRM, X( KBEG ), 1 )
  303. END IF
  304. *
  305. CALL ZGEMV( 'N', M, IXFRM, CONE, A( 1, KBEG ), LDA,
  306. $ X( KBEG ), 1, CZERO, X( 2*NXFRM+1 ), 1 )
  307. CALL ZGERC( M, IXFRM, -DCMPLX( FACTOR ), X( 2*NXFRM+1 ), 1,
  308. $ X( KBEG ), 1, A( 1, KBEG ), LDA )
  309. *
  310. END IF
  311. 30 CONTINUE
  312. *
  313. X( 1 ) = ZLARND( 3, ISEED )
  314. XABS = ABS( X( 1 ) )
  315. IF( XABS.NE.ZERO ) THEN
  316. CSIGN = X( 1 ) / XABS
  317. ELSE
  318. CSIGN = CONE
  319. END IF
  320. X( 2*NXFRM ) = CSIGN
  321. *
  322. * Scale the matrix A by D.
  323. *
  324. IF( ITYPE.EQ.1 .OR. ITYPE.EQ.3 .OR. ITYPE.EQ.4 ) THEN
  325. DO 40 IROW = 1, M
  326. CALL ZSCAL( N, DCONJG( X( NXFRM+IROW ) ), A( IROW, 1 ),
  327. $ LDA )
  328. 40 CONTINUE
  329. END IF
  330. *
  331. IF( ITYPE.EQ.2 .OR. ITYPE.EQ.3 ) THEN
  332. DO 50 JCOL = 1, N
  333. CALL ZSCAL( M, X( NXFRM+JCOL ), A( 1, JCOL ), 1 )
  334. 50 CONTINUE
  335. END IF
  336. *
  337. IF( ITYPE.EQ.4 ) THEN
  338. DO 60 JCOL = 1, N
  339. CALL ZSCAL( M, DCONJG( X( NXFRM+JCOL ) ), A( 1, JCOL ), 1 )
  340. 60 CONTINUE
  341. END IF
  342. RETURN
  343. *
  344. * End of ZLAROR
  345. *
  346. END