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.

dspt21.f 14 kB

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