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.

chpt21.f 14 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. *> \brief \b CHPT21
  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 CHPT21( ITYPE, UPLO, N, KBAND, AP, D, E, U, LDU, VP,
  12. * TAU, WORK, RWORK, RESULT )
  13. *
  14. * .. Scalar Arguments ..
  15. * CHARACTER UPLO
  16. * INTEGER ITYPE, KBAND, LDU, N
  17. * ..
  18. * .. Array Arguments ..
  19. * REAL D( * ), E( * ), RESULT( 2 ), RWORK( * )
  20. * COMPLEX AP( * ), TAU( * ), U( LDU, * ), VP( * ),
  21. * $ WORK( * )
  22. * ..
  23. *
  24. *
  25. *> \par Purpose:
  26. * =============
  27. *>
  28. *> \verbatim
  29. *>
  30. *> CHPT21 generally checks a decomposition of the form
  31. *>
  32. *> A = U S U**H
  33. *>
  34. *> where **H means conjugate transpose, A is hermitian, U is
  35. *> unitary, and S is diagonal (if KBAND=0) or (real) symmetric
  36. *> tridiagonal (if KBAND=1). If ITYPE=1, then U is represented as
  37. *> a dense matrix, otherwise the U is expressed as a product of
  38. *> Householder transformations, whose vectors are stored in the
  39. *> array "V" and whose scaling constants are in "TAU"; we shall
  40. *> use the letter "V" to refer to the product of Householder
  41. *> transformations (which should be equal to U).
  42. *>
  43. *> Specifically, if ITYPE=1, then:
  44. *>
  45. *> RESULT(1) = | A - U S U**H | / ( |A| n ulp ) and
  46. *> RESULT(2) = | I - U U**H | / ( n ulp )
  47. *>
  48. *> If ITYPE=2, then:
  49. *>
  50. *> RESULT(1) = | A - V S V**H | / ( |A| n ulp )
  51. *>
  52. *> If ITYPE=3, then:
  53. *>
  54. *> RESULT(1) = | I - U V**H | / ( n ulp )
  55. *>
  56. *> Packed storage means that, for example, if UPLO='U', then the columns
  57. *> of the upper triangle of A are stored one after another, so that
  58. *> A(1,j+1) immediately follows A(j,j) in the array AP. Similarly, if
  59. *> UPLO='L', then the columns of the lower triangle of A are stored one
  60. *> after another in AP, so that A(j+1,j+1) immediately follows A(n,j)
  61. *> in the array AP. This means that A(i,j) is stored in:
  62. *>
  63. *> AP( i + j*(j-1)/2 ) if UPLO='U'
  64. *>
  65. *> AP( i + (2*n-j)*(j-1)/2 ) if UPLO='L'
  66. *>
  67. *> The array VP bears the same relation to the matrix V that A does to
  68. *> AP.
  69. *>
  70. *> For ITYPE > 1, the transformation U is expressed as a product
  71. *> of Householder transformations:
  72. *>
  73. *> If UPLO='U', then V = H(n-1)...H(1), where
  74. *>
  75. *> H(j) = I - tau(j) v(j) v(j)**H
  76. *>
  77. *> and the first j-1 elements of v(j) are stored in V(1:j-1,j+1),
  78. *> (i.e., VP( j*(j+1)/2 + 1 : j*(j+1)/2 + j-1 ) ),
  79. *> the j-th element is 1, and the last n-j elements are 0.
  80. *>
  81. *> If UPLO='L', then V = H(1)...H(n-1), where
  82. *>
  83. *> H(j) = I - tau(j) v(j) v(j)**H
  84. *>
  85. *> and the first j elements of v(j) are 0, the (j+1)-st is 1, and the
  86. *> (j+2)-nd through n-th elements are stored in V(j+2:n,j) (i.e.,
  87. *> in VP( (2*n-j)*(j-1)/2 + j+2 : (2*n-j)*(j-1)/2 + n ) .)
  88. *> \endverbatim
  89. *
  90. * Arguments:
  91. * ==========
  92. *
  93. *> \param[in] ITYPE
  94. *> \verbatim
  95. *> ITYPE is INTEGER
  96. *> Specifies the type of tests to be performed.
  97. *> 1: U expressed as a dense unitary matrix:
  98. *> RESULT(1) = | A - U S U**H | / ( |A| n ulp ) and
  99. *> RESULT(2) = | I - U U**H | / ( n ulp )
  100. *>
  101. *> 2: U expressed as a product V of Housholder transformations:
  102. *> RESULT(1) = | A - V S V**H | / ( |A| n ulp )
  103. *>
  104. *> 3: U expressed both as a dense unitary matrix and
  105. *> as a product of Housholder transformations:
  106. *> RESULT(1) = | I - U V**H | / ( n ulp )
  107. *> \endverbatim
  108. *>
  109. *> \param[in] UPLO
  110. *> \verbatim
  111. *> UPLO is CHARACTER
  112. *> If UPLO='U', the upper triangle of A and V will be used and
  113. *> the (strictly) lower triangle will not be referenced.
  114. *> If UPLO='L', the lower triangle of A and V will be used and
  115. *> the (strictly) upper triangle will not be referenced.
  116. *> \endverbatim
  117. *>
  118. *> \param[in] N
  119. *> \verbatim
  120. *> N is INTEGER
  121. *> The size of the matrix. If it is zero, CHPT21 does nothing.
  122. *> It must be at least zero.
  123. *> \endverbatim
  124. *>
  125. *> \param[in] KBAND
  126. *> \verbatim
  127. *> KBAND is INTEGER
  128. *> The bandwidth of the matrix. It may only be zero or one.
  129. *> If zero, then S is diagonal, and E is not referenced. If
  130. *> one, then S is symmetric tri-diagonal.
  131. *> \endverbatim
  132. *>
  133. *> \param[in] AP
  134. *> \verbatim
  135. *> AP is COMPLEX array, dimension (N*(N+1)/2)
  136. *> The original (unfactored) matrix. It is assumed to be
  137. *> hermitian, and contains the columns of just the upper
  138. *> triangle (UPLO='U') or only the lower triangle (UPLO='L'),
  139. *> packed one after another.
  140. *> \endverbatim
  141. *>
  142. *> \param[in] D
  143. *> \verbatim
  144. *> D is REAL array, dimension (N)
  145. *> The diagonal of the (symmetric tri-) diagonal matrix.
  146. *> \endverbatim
  147. *>
  148. *> \param[in] E
  149. *> \verbatim
  150. *> E is REAL array, dimension (N)
  151. *> The off-diagonal of the (symmetric tri-) diagonal matrix.
  152. *> E(1) is the (1,2) and (2,1) element, E(2) is the (2,3) and
  153. *> (3,2) element, etc.
  154. *> Not referenced if KBAND=0.
  155. *> \endverbatim
  156. *>
  157. *> \param[in] U
  158. *> \verbatim
  159. *> U is COMPLEX array, dimension (LDU, N)
  160. *> If ITYPE=1 or 3, this contains the unitary matrix in
  161. *> the decomposition, expressed as a dense matrix. If ITYPE=2,
  162. *> then it is not referenced.
  163. *> \endverbatim
  164. *>
  165. *> \param[in] LDU
  166. *> \verbatim
  167. *> LDU is INTEGER
  168. *> The leading dimension of U. LDU must be at least N and
  169. *> at least 1.
  170. *> \endverbatim
  171. *>
  172. *> \param[in] VP
  173. *> \verbatim
  174. *> VP is REAL array, dimension (N*(N+1)/2)
  175. *> If ITYPE=2 or 3, the columns of this array contain the
  176. *> Householder vectors used to describe the unitary matrix
  177. *> in the decomposition, as described in purpose.
  178. *> *NOTE* If ITYPE=2 or 3, V is modified and restored. The
  179. *> subdiagonal (if UPLO='L') or the superdiagonal (if UPLO='U')
  180. *> is set to one, and later reset to its original value, during
  181. *> the course of the calculation.
  182. *> If ITYPE=1, then it is neither referenced nor modified.
  183. *> \endverbatim
  184. *>
  185. *> \param[in] TAU
  186. *> \verbatim
  187. *> TAU is COMPLEX array, dimension (N)
  188. *> If ITYPE >= 2, then TAU(j) is the scalar factor of
  189. *> v(j) v(j)**H in the Householder transformation H(j) of
  190. *> the product U = H(1)...H(n-2)
  191. *> If ITYPE < 2, then TAU is not referenced.
  192. *> \endverbatim
  193. *>
  194. *> \param[out] WORK
  195. *> \verbatim
  196. *> WORK is COMPLEX array, dimension (N**2)
  197. *> Workspace.
  198. *> \endverbatim
  199. *>
  200. *> \param[out] RWORK
  201. *> \verbatim
  202. *> RWORK is REAL array, dimension (N)
  203. *> Workspace.
  204. *> \endverbatim
  205. *>
  206. *> \param[out] RESULT
  207. *> \verbatim
  208. *> RESULT is REAL array, dimension (2)
  209. *> The values computed by the two tests described above. The
  210. *> values are currently limited to 1/ulp, to avoid overflow.
  211. *> RESULT(1) is always modified. RESULT(2) is modified only
  212. *> if ITYPE=1.
  213. *> \endverbatim
  214. *
  215. * Authors:
  216. * ========
  217. *
  218. *> \author Univ. of Tennessee
  219. *> \author Univ. of California Berkeley
  220. *> \author Univ. of Colorado Denver
  221. *> \author NAG Ltd.
  222. *
  223. *> \date December 2016
  224. *
  225. *> \ingroup complex_eig
  226. *
  227. * =====================================================================
  228. SUBROUTINE CHPT21( ITYPE, UPLO, N, KBAND, AP, D, E, U, LDU, VP,
  229. $ TAU, WORK, RWORK, RESULT )
  230. *
  231. * -- LAPACK test routine (version 3.7.0) --
  232. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  233. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  234. * December 2016
  235. *
  236. * .. Scalar Arguments ..
  237. CHARACTER UPLO
  238. INTEGER ITYPE, KBAND, LDU, N
  239. * ..
  240. * .. Array Arguments ..
  241. REAL D( * ), E( * ), RESULT( 2 ), RWORK( * )
  242. COMPLEX AP( * ), TAU( * ), U( LDU, * ), VP( * ),
  243. $ WORK( * )
  244. * ..
  245. *
  246. * =====================================================================
  247. *
  248. * .. Parameters ..
  249. REAL ZERO, ONE, TEN
  250. PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0, TEN = 10.0E+0 )
  251. REAL HALF
  252. PARAMETER ( HALF = 1.0E+0 / 2.0E+0 )
  253. COMPLEX CZERO, CONE
  254. PARAMETER ( CZERO = ( 0.0E+0, 0.0E+0 ),
  255. $ CONE = ( 1.0E+0, 0.0E+0 ) )
  256. * ..
  257. * .. Local Scalars ..
  258. LOGICAL LOWER
  259. CHARACTER CUPLO
  260. INTEGER IINFO, J, JP, JP1, JR, LAP
  261. REAL ANORM, ULP, UNFL, WNORM
  262. COMPLEX TEMP, VSAVE
  263. * ..
  264. * .. External Functions ..
  265. LOGICAL LSAME
  266. REAL CLANGE, CLANHP, SLAMCH
  267. COMPLEX CDOTC
  268. EXTERNAL LSAME, CLANGE, CLANHP, SLAMCH, CDOTC
  269. * ..
  270. * .. External Subroutines ..
  271. EXTERNAL CAXPY, CCOPY, CGEMM, CHPMV, CHPR, CHPR2,
  272. $ CLACPY, CLASET, CUPMTR
  273. * ..
  274. * .. Intrinsic Functions ..
  275. INTRINSIC CMPLX, MAX, MIN, REAL
  276. * ..
  277. * .. Executable Statements ..
  278. *
  279. * Constants
  280. *
  281. RESULT( 1 ) = ZERO
  282. IF( ITYPE.EQ.1 )
  283. $ RESULT( 2 ) = ZERO
  284. IF( N.LE.0 )
  285. $ RETURN
  286. *
  287. LAP = ( N*( N+1 ) ) / 2
  288. *
  289. IF( LSAME( UPLO, 'U' ) ) THEN
  290. LOWER = .FALSE.
  291. CUPLO = 'U'
  292. ELSE
  293. LOWER = .TRUE.
  294. CUPLO = 'L'
  295. END IF
  296. *
  297. UNFL = SLAMCH( 'Safe minimum' )
  298. ULP = SLAMCH( 'Epsilon' )*SLAMCH( 'Base' )
  299. *
  300. * Some Error Checks
  301. *
  302. IF( ITYPE.LT.1 .OR. ITYPE.GT.3 ) THEN
  303. RESULT( 1 ) = TEN / ULP
  304. RETURN
  305. END IF
  306. *
  307. * Do Test 1
  308. *
  309. * Norm of A:
  310. *
  311. IF( ITYPE.EQ.3 ) THEN
  312. ANORM = ONE
  313. ELSE
  314. ANORM = MAX( CLANHP( '1', CUPLO, N, AP, RWORK ), UNFL )
  315. END IF
  316. *
  317. * Compute error matrix:
  318. *
  319. IF( ITYPE.EQ.1 ) THEN
  320. *
  321. * ITYPE=1: error = A - U S U**H
  322. *
  323. CALL CLASET( 'Full', N, N, CZERO, CZERO, WORK, N )
  324. CALL CCOPY( LAP, AP, 1, WORK, 1 )
  325. *
  326. DO 10 J = 1, N
  327. CALL CHPR( CUPLO, N, -D( J ), U( 1, J ), 1, WORK )
  328. 10 CONTINUE
  329. *
  330. IF( N.GT.1 .AND. KBAND.EQ.1 ) THEN
  331. DO 20 J = 2, N - 1
  332. CALL CHPR2( CUPLO, N, -CMPLX( E( J ) ), U( 1, J ), 1,
  333. $ U( 1, J-1 ), 1, WORK )
  334. 20 CONTINUE
  335. END IF
  336. WNORM = CLANHP( '1', CUPLO, N, WORK, RWORK )
  337. *
  338. ELSE IF( ITYPE.EQ.2 ) THEN
  339. *
  340. * ITYPE=2: error = V S V**H - A
  341. *
  342. CALL CLASET( 'Full', N, N, CZERO, CZERO, WORK, N )
  343. *
  344. IF( LOWER ) THEN
  345. WORK( LAP ) = D( N )
  346. DO 40 J = N - 1, 1, -1
  347. JP = ( ( 2*N-J )*( J-1 ) ) / 2
  348. JP1 = JP + N - J
  349. IF( KBAND.EQ.1 ) THEN
  350. WORK( JP+J+1 ) = ( CONE-TAU( J ) )*E( J )
  351. DO 30 JR = J + 2, N
  352. WORK( JP+JR ) = -TAU( J )*E( J )*VP( JP+JR )
  353. 30 CONTINUE
  354. END IF
  355. *
  356. IF( TAU( J ).NE.CZERO ) THEN
  357. VSAVE = VP( JP+J+1 )
  358. VP( JP+J+1 ) = CONE
  359. CALL CHPMV( 'L', N-J, CONE, WORK( JP1+J+1 ),
  360. $ VP( JP+J+1 ), 1, CZERO, WORK( LAP+1 ), 1 )
  361. TEMP = -HALF*TAU( J )*CDOTC( N-J, WORK( LAP+1 ), 1,
  362. $ VP( JP+J+1 ), 1 )
  363. CALL CAXPY( N-J, TEMP, VP( JP+J+1 ), 1, WORK( LAP+1 ),
  364. $ 1 )
  365. CALL CHPR2( 'L', N-J, -TAU( J ), VP( JP+J+1 ), 1,
  366. $ WORK( LAP+1 ), 1, WORK( JP1+J+1 ) )
  367. *
  368. VP( JP+J+1 ) = VSAVE
  369. END IF
  370. WORK( JP+J ) = D( J )
  371. 40 CONTINUE
  372. ELSE
  373. WORK( 1 ) = D( 1 )
  374. DO 60 J = 1, N - 1
  375. JP = ( J*( J-1 ) ) / 2
  376. JP1 = JP + J
  377. IF( KBAND.EQ.1 ) THEN
  378. WORK( JP1+J ) = ( CONE-TAU( J ) )*E( J )
  379. DO 50 JR = 1, J - 1
  380. WORK( JP1+JR ) = -TAU( J )*E( J )*VP( JP1+JR )
  381. 50 CONTINUE
  382. END IF
  383. *
  384. IF( TAU( J ).NE.CZERO ) THEN
  385. VSAVE = VP( JP1+J )
  386. VP( JP1+J ) = CONE
  387. CALL CHPMV( 'U', J, CONE, WORK, VP( JP1+1 ), 1, CZERO,
  388. $ WORK( LAP+1 ), 1 )
  389. TEMP = -HALF*TAU( J )*CDOTC( J, WORK( LAP+1 ), 1,
  390. $ VP( JP1+1 ), 1 )
  391. CALL CAXPY( J, TEMP, VP( JP1+1 ), 1, WORK( LAP+1 ),
  392. $ 1 )
  393. CALL CHPR2( 'U', J, -TAU( J ), VP( JP1+1 ), 1,
  394. $ WORK( LAP+1 ), 1, WORK )
  395. VP( JP1+J ) = VSAVE
  396. END IF
  397. WORK( JP1+J+1 ) = D( J+1 )
  398. 60 CONTINUE
  399. END IF
  400. *
  401. DO 70 J = 1, LAP
  402. WORK( J ) = WORK( J ) - AP( J )
  403. 70 CONTINUE
  404. WNORM = CLANHP( '1', CUPLO, N, WORK, RWORK )
  405. *
  406. ELSE IF( ITYPE.EQ.3 ) THEN
  407. *
  408. * ITYPE=3: error = U V**H - I
  409. *
  410. IF( N.LT.2 )
  411. $ RETURN
  412. CALL CLACPY( ' ', N, N, U, LDU, WORK, N )
  413. CALL CUPMTR( 'R', CUPLO, 'C', N, N, VP, TAU, WORK, N,
  414. $ WORK( N**2+1 ), IINFO )
  415. IF( IINFO.NE.0 ) THEN
  416. RESULT( 1 ) = TEN / ULP
  417. RETURN
  418. END IF
  419. *
  420. DO 80 J = 1, N
  421. WORK( ( N+1 )*( J-1 )+1 ) = WORK( ( N+1 )*( J-1 )+1 ) - CONE
  422. 80 CONTINUE
  423. *
  424. WNORM = CLANGE( '1', N, N, WORK, N, RWORK )
  425. END IF
  426. *
  427. IF( ANORM.GT.WNORM ) THEN
  428. RESULT( 1 ) = ( WNORM / ANORM ) / ( N*ULP )
  429. ELSE
  430. IF( ANORM.LT.ONE ) THEN
  431. RESULT( 1 ) = ( MIN( WNORM, N*ANORM ) / ANORM ) / ( N*ULP )
  432. ELSE
  433. RESULT( 1 ) = MIN( WNORM / ANORM, REAL( N ) ) / ( N*ULP )
  434. END IF
  435. END IF
  436. *
  437. * Do Test 2
  438. *
  439. * Compute U U**H - I
  440. *
  441. IF( ITYPE.EQ.1 ) THEN
  442. CALL CGEMM( 'N', 'C', N, N, N, CONE, U, LDU, U, LDU, CZERO,
  443. $ WORK, N )
  444. *
  445. DO 90 J = 1, N
  446. WORK( ( N+1 )*( J-1 )+1 ) = WORK( ( N+1 )*( J-1 )+1 ) - CONE
  447. 90 CONTINUE
  448. *
  449. RESULT( 2 ) = MIN( CLANGE( '1', N, N, WORK, N, RWORK ),
  450. $ REAL( N ) ) / ( N*ULP )
  451. END IF
  452. *
  453. RETURN
  454. *
  455. * End of CHPT21
  456. *
  457. END