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.

sspt21.f 14 kB

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