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.

dstemr.f 27 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  1. *> \brief \b DSTEMR
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download DSTEMR + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dstemr.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dstemr.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dstemr.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE DSTEMR( JOBZ, RANGE, N, D, E, VL, VU, IL, IU,
  22. * M, W, Z, LDZ, NZC, ISUPPZ, TRYRAC, WORK, LWORK,
  23. * IWORK, LIWORK, INFO )
  24. *
  25. * .. Scalar Arguments ..
  26. * CHARACTER JOBZ, RANGE
  27. * LOGICAL TRYRAC
  28. * INTEGER IL, INFO, IU, LDZ, NZC, LIWORK, LWORK, M, N
  29. * DOUBLE PRECISION VL, VU
  30. * ..
  31. * .. Array Arguments ..
  32. * INTEGER ISUPPZ( * ), IWORK( * )
  33. * DOUBLE PRECISION D( * ), E( * ), W( * ), WORK( * )
  34. * DOUBLE PRECISION Z( LDZ, * )
  35. * ..
  36. *
  37. *
  38. *> \par Purpose:
  39. * =============
  40. *>
  41. *> \verbatim
  42. *>
  43. *> DSTEMR computes selected eigenvalues and, optionally, eigenvectors
  44. *> of a real symmetric tridiagonal matrix T. Any such unreduced matrix has
  45. *> a well defined set of pairwise different real eigenvalues, the corresponding
  46. *> real eigenvectors are pairwise orthogonal.
  47. *>
  48. *> The spectrum may be computed either completely or partially by specifying
  49. *> either an interval (VL,VU] or a range of indices IL:IU for the desired
  50. *> eigenvalues.
  51. *>
  52. *> Depending on the number of desired eigenvalues, these are computed either
  53. *> by bisection or the dqds algorithm. Numerically orthogonal eigenvectors are
  54. *> computed by the use of various suitable L D L^T factorizations near clusters
  55. *> of close eigenvalues (referred to as RRRs, Relatively Robust
  56. *> Representations). An informal sketch of the algorithm follows.
  57. *>
  58. *> For each unreduced block (submatrix) of T,
  59. *> (a) Compute T - sigma I = L D L^T, so that L and D
  60. *> define all the wanted eigenvalues to high relative accuracy.
  61. *> This means that small relative changes in the entries of D and L
  62. *> cause only small relative changes in the eigenvalues and
  63. *> eigenvectors. The standard (unfactored) representation of the
  64. *> tridiagonal matrix T does not have this property in general.
  65. *> (b) Compute the eigenvalues to suitable accuracy.
  66. *> If the eigenvectors are desired, the algorithm attains full
  67. *> accuracy of the computed eigenvalues only right before
  68. *> the corresponding vectors have to be computed, see steps c) and d).
  69. *> (c) For each cluster of close eigenvalues, select a new
  70. *> shift close to the cluster, find a new factorization, and refine
  71. *> the shifted eigenvalues to suitable accuracy.
  72. *> (d) For each eigenvalue with a large enough relative separation compute
  73. *> the corresponding eigenvector by forming a rank revealing twisted
  74. *> factorization. Go back to (c) for any clusters that remain.
  75. *>
  76. *> For more details, see:
  77. *> - Inderjit S. Dhillon and Beresford N. Parlett: "Multiple representations
  78. *> to compute orthogonal eigenvectors of symmetric tridiagonal matrices,"
  79. *> Linear Algebra and its Applications, 387(1), pp. 1-28, August 2004.
  80. *> - Inderjit Dhillon and Beresford Parlett: "Orthogonal Eigenvectors and
  81. *> Relative Gaps," SIAM Journal on Matrix Analysis and Applications, Vol. 25,
  82. *> 2004. Also LAPACK Working Note 154.
  83. *> - Inderjit Dhillon: "A new O(n^2) algorithm for the symmetric
  84. *> tridiagonal eigenvalue/eigenvector problem",
  85. *> Computer Science Division Technical Report No. UCB/CSD-97-971,
  86. *> UC Berkeley, May 1997.
  87. *>
  88. *> Further Details
  89. *> 1.DSTEMR works only on machines which follow IEEE-754
  90. *> floating-point standard in their handling of infinities and NaNs.
  91. *> This permits the use of efficient inner loops avoiding a check for
  92. *> zero divisors.
  93. *> \endverbatim
  94. *
  95. * Arguments:
  96. * ==========
  97. *
  98. *> \param[in] JOBZ
  99. *> \verbatim
  100. *> JOBZ is CHARACTER*1
  101. *> = 'N': Compute eigenvalues only;
  102. *> = 'V': Compute eigenvalues and eigenvectors.
  103. *> \endverbatim
  104. *>
  105. *> \param[in] RANGE
  106. *> \verbatim
  107. *> RANGE is CHARACTER*1
  108. *> = 'A': all eigenvalues will be found.
  109. *> = 'V': all eigenvalues in the half-open interval (VL,VU]
  110. *> will be found.
  111. *> = 'I': the IL-th through IU-th eigenvalues will be found.
  112. *> \endverbatim
  113. *>
  114. *> \param[in] N
  115. *> \verbatim
  116. *> N is INTEGER
  117. *> The order of the matrix. N >= 0.
  118. *> \endverbatim
  119. *>
  120. *> \param[in,out] D
  121. *> \verbatim
  122. *> D is DOUBLE PRECISION array, dimension (N)
  123. *> On entry, the N diagonal elements of the tridiagonal matrix
  124. *> T. On exit, D is overwritten.
  125. *> \endverbatim
  126. *>
  127. *> \param[in,out] E
  128. *> \verbatim
  129. *> E is DOUBLE PRECISION array, dimension (N)
  130. *> On entry, the (N-1) subdiagonal elements of the tridiagonal
  131. *> matrix T in elements 1 to N-1 of E. E(N) need not be set on
  132. *> input, but is used internally as workspace.
  133. *> On exit, E is overwritten.
  134. *> \endverbatim
  135. *>
  136. *> \param[in] VL
  137. *> \verbatim
  138. *> VL is DOUBLE PRECISION
  139. *>
  140. *> If RANGE='V', the lower bound of the interval to
  141. *> be searched for eigenvalues. VL < VU.
  142. *> Not referenced if RANGE = 'A' or 'I'.
  143. *> \endverbatim
  144. *>
  145. *> \param[in] VU
  146. *> \verbatim
  147. *> VU is DOUBLE PRECISION
  148. *>
  149. *> If RANGE='V', the upper bound of the interval to
  150. *> be searched for eigenvalues. VL < VU.
  151. *> Not referenced if RANGE = 'A' or 'I'.
  152. *> \endverbatim
  153. *>
  154. *> \param[in] IL
  155. *> \verbatim
  156. *> IL is INTEGER
  157. *>
  158. *> If RANGE='I', the index of the
  159. *> smallest eigenvalue to be returned.
  160. *> 1 <= IL <= IU <= N, if N > 0.
  161. *> Not referenced if RANGE = 'A' or 'V'.
  162. *> \endverbatim
  163. *>
  164. *> \param[in] IU
  165. *> \verbatim
  166. *> IU is INTEGER
  167. *>
  168. *> If RANGE='I', the index of the
  169. *> largest eigenvalue to be returned.
  170. *> 1 <= IL <= IU <= N, if N > 0.
  171. *> Not referenced if RANGE = 'A' or 'V'.
  172. *> \endverbatim
  173. *>
  174. *> \param[out] M
  175. *> \verbatim
  176. *> M is INTEGER
  177. *> The total number of eigenvalues found. 0 <= M <= N.
  178. *> If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1.
  179. *> \endverbatim
  180. *>
  181. *> \param[out] W
  182. *> \verbatim
  183. *> W is DOUBLE PRECISION array, dimension (N)
  184. *> The first M elements contain the selected eigenvalues in
  185. *> ascending order.
  186. *> \endverbatim
  187. *>
  188. *> \param[out] Z
  189. *> \verbatim
  190. *> Z is DOUBLE PRECISION array, dimension (LDZ, max(1,M) )
  191. *> If JOBZ = 'V', and if INFO = 0, then the first M columns of Z
  192. *> contain the orthonormal eigenvectors of the matrix T
  193. *> corresponding to the selected eigenvalues, with the i-th
  194. *> column of Z holding the eigenvector associated with W(i).
  195. *> If JOBZ = 'N', then Z is not referenced.
  196. *> Note: the user must ensure that at least max(1,M) columns are
  197. *> supplied in the array Z; if RANGE = 'V', the exact value of M
  198. *> is not known in advance and can be computed with a workspace
  199. *> query by setting NZC = -1, see below.
  200. *> \endverbatim
  201. *>
  202. *> \param[in] LDZ
  203. *> \verbatim
  204. *> LDZ is INTEGER
  205. *> The leading dimension of the array Z. LDZ >= 1, and if
  206. *> JOBZ = 'V', then LDZ >= max(1,N).
  207. *> \endverbatim
  208. *>
  209. *> \param[in] NZC
  210. *> \verbatim
  211. *> NZC is INTEGER
  212. *> The number of eigenvectors to be held in the array Z.
  213. *> If RANGE = 'A', then NZC >= max(1,N).
  214. *> If RANGE = 'V', then NZC >= the number of eigenvalues in (VL,VU].
  215. *> If RANGE = 'I', then NZC >= IU-IL+1.
  216. *> If NZC = -1, then a workspace query is assumed; the
  217. *> routine calculates the number of columns of the array Z that
  218. *> are needed to hold the eigenvectors.
  219. *> This value is returned as the first entry of the Z array, and
  220. *> no error message related to NZC is issued by XERBLA.
  221. *> \endverbatim
  222. *>
  223. *> \param[out] ISUPPZ
  224. *> \verbatim
  225. *> ISUPPZ is INTEGER array, dimension ( 2*max(1,M) )
  226. *> The support of the eigenvectors in Z, i.e., the indices
  227. *> indicating the nonzero elements in Z. The i-th computed eigenvector
  228. *> is nonzero only in elements ISUPPZ( 2*i-1 ) through
  229. *> ISUPPZ( 2*i ). This is relevant in the case when the matrix
  230. *> is split. ISUPPZ is only accessed when JOBZ is 'V' and N > 0.
  231. *> \endverbatim
  232. *>
  233. *> \param[in,out] TRYRAC
  234. *> \verbatim
  235. *> TRYRAC is LOGICAL
  236. *> If TRYRAC.EQ..TRUE., indicates that the code should check whether
  237. *> the tridiagonal matrix defines its eigenvalues to high relative
  238. *> accuracy. If so, the code uses relative-accuracy preserving
  239. *> algorithms that might be (a bit) slower depending on the matrix.
  240. *> If the matrix does not define its eigenvalues to high relative
  241. *> accuracy, the code can uses possibly faster algorithms.
  242. *> If TRYRAC.EQ..FALSE., the code is not required to guarantee
  243. *> relatively accurate eigenvalues and can use the fastest possible
  244. *> techniques.
  245. *> On exit, a .TRUE. TRYRAC will be set to .FALSE. if the matrix
  246. *> does not define its eigenvalues to high relative accuracy.
  247. *> \endverbatim
  248. *>
  249. *> \param[out] WORK
  250. *> \verbatim
  251. *> WORK is DOUBLE PRECISION array, dimension (LWORK)
  252. *> On exit, if INFO = 0, WORK(1) returns the optimal
  253. *> (and minimal) LWORK.
  254. *> \endverbatim
  255. *>
  256. *> \param[in] LWORK
  257. *> \verbatim
  258. *> LWORK is INTEGER
  259. *> The dimension of the array WORK. LWORK >= max(1,18*N)
  260. *> if JOBZ = 'V', and LWORK >= max(1,12*N) if JOBZ = 'N'.
  261. *> If LWORK = -1, then a workspace query is assumed; the routine
  262. *> only calculates the optimal size of the WORK array, returns
  263. *> this value as the first entry of the WORK array, and no error
  264. *> message related to LWORK is issued by XERBLA.
  265. *> \endverbatim
  266. *>
  267. *> \param[out] IWORK
  268. *> \verbatim
  269. *> IWORK is INTEGER array, dimension (LIWORK)
  270. *> On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK.
  271. *> \endverbatim
  272. *>
  273. *> \param[in] LIWORK
  274. *> \verbatim
  275. *> LIWORK is INTEGER
  276. *> The dimension of the array IWORK. LIWORK >= max(1,10*N)
  277. *> if the eigenvectors are desired, and LIWORK >= max(1,8*N)
  278. *> if only the eigenvalues are to be computed.
  279. *> If LIWORK = -1, then a workspace query is assumed; the
  280. *> routine only calculates the optimal size of the IWORK array,
  281. *> returns this value as the first entry of the IWORK array, and
  282. *> no error message related to LIWORK is issued by XERBLA.
  283. *> \endverbatim
  284. *>
  285. *> \param[out] INFO
  286. *> \verbatim
  287. *> INFO is INTEGER
  288. *> On exit, INFO
  289. *> = 0: successful exit
  290. *> < 0: if INFO = -i, the i-th argument had an illegal value
  291. *> > 0: if INFO = 1X, internal error in DLARRE,
  292. *> if INFO = 2X, internal error in DLARRV.
  293. *> Here, the digit X = ABS( IINFO ) < 10, where IINFO is
  294. *> the nonzero error code returned by DLARRE or
  295. *> DLARRV, respectively.
  296. *> \endverbatim
  297. *
  298. * Authors:
  299. * ========
  300. *
  301. *> \author Univ. of Tennessee
  302. *> \author Univ. of California Berkeley
  303. *> \author Univ. of Colorado Denver
  304. *> \author NAG Ltd.
  305. *
  306. *> \date June 2016
  307. *
  308. *> \ingroup doubleOTHERcomputational
  309. *
  310. *> \par Contributors:
  311. * ==================
  312. *>
  313. *> Beresford Parlett, University of California, Berkeley, USA \n
  314. *> Jim Demmel, University of California, Berkeley, USA \n
  315. *> Inderjit Dhillon, University of Texas, Austin, USA \n
  316. *> Osni Marques, LBNL/NERSC, USA \n
  317. *> Christof Voemel, University of California, Berkeley, USA
  318. *
  319. * =====================================================================
  320. SUBROUTINE DSTEMR( JOBZ, RANGE, N, D, E, VL, VU, IL, IU,
  321. $ M, W, Z, LDZ, NZC, ISUPPZ, TRYRAC, WORK, LWORK,
  322. $ IWORK, LIWORK, INFO )
  323. *
  324. * -- LAPACK computational routine (version 3.7.1) --
  325. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  326. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  327. * June 2016
  328. *
  329. * .. Scalar Arguments ..
  330. CHARACTER JOBZ, RANGE
  331. LOGICAL TRYRAC
  332. INTEGER IL, INFO, IU, LDZ, NZC, LIWORK, LWORK, M, N
  333. DOUBLE PRECISION VL, VU
  334. * ..
  335. * .. Array Arguments ..
  336. INTEGER ISUPPZ( * ), IWORK( * )
  337. DOUBLE PRECISION D( * ), E( * ), W( * ), WORK( * )
  338. DOUBLE PRECISION Z( LDZ, * )
  339. * ..
  340. *
  341. * =====================================================================
  342. *
  343. * .. Parameters ..
  344. DOUBLE PRECISION ZERO, ONE, FOUR, MINRGP
  345. PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0,
  346. $ FOUR = 4.0D0,
  347. $ MINRGP = 1.0D-3 )
  348. * ..
  349. * .. Local Scalars ..
  350. LOGICAL ALLEIG, INDEIG, LQUERY, VALEIG, WANTZ, ZQUERY
  351. INTEGER I, IBEGIN, IEND, IFIRST, IIL, IINDBL, IINDW,
  352. $ IINDWK, IINFO, IINSPL, IIU, ILAST, IN, INDD,
  353. $ INDE2, INDERR, INDGP, INDGRS, INDWRK, ITMP,
  354. $ ITMP2, J, JBLK, JJ, LIWMIN, LWMIN, NSPLIT,
  355. $ NZCMIN, OFFSET, WBEGIN, WEND
  356. DOUBLE PRECISION BIGNUM, CS, EPS, PIVMIN, R1, R2, RMAX, RMIN,
  357. $ RTOL1, RTOL2, SAFMIN, SCALE, SMLNUM, SN,
  358. $ THRESH, TMP, TNRM, WL, WU
  359. * ..
  360. * ..
  361. * .. External Functions ..
  362. LOGICAL LSAME
  363. DOUBLE PRECISION DLAMCH, DLANST
  364. EXTERNAL LSAME, DLAMCH, DLANST
  365. * ..
  366. * .. External Subroutines ..
  367. EXTERNAL DCOPY, DLAE2, DLAEV2, DLARRC, DLARRE, DLARRJ,
  368. $ DLARRR, DLARRV, DLASRT, DSCAL, DSWAP, XERBLA
  369. * ..
  370. * .. Intrinsic Functions ..
  371. INTRINSIC MAX, MIN, SQRT
  372. * ..
  373. * .. Executable Statements ..
  374. *
  375. * Test the input parameters.
  376. *
  377. WANTZ = LSAME( JOBZ, 'V' )
  378. ALLEIG = LSAME( RANGE, 'A' )
  379. VALEIG = LSAME( RANGE, 'V' )
  380. INDEIG = LSAME( RANGE, 'I' )
  381. *
  382. LQUERY = ( ( LWORK.EQ.-1 ).OR.( LIWORK.EQ.-1 ) )
  383. ZQUERY = ( NZC.EQ.-1 )
  384. * DSTEMR needs WORK of size 6*N, IWORK of size 3*N.
  385. * In addition, DLARRE needs WORK of size 6*N, IWORK of size 5*N.
  386. * Furthermore, DLARRV needs WORK of size 12*N, IWORK of size 7*N.
  387. IF( WANTZ ) THEN
  388. LWMIN = 18*N
  389. LIWMIN = 10*N
  390. ELSE
  391. * need less workspace if only the eigenvalues are wanted
  392. LWMIN = 12*N
  393. LIWMIN = 8*N
  394. ENDIF
  395. WL = ZERO
  396. WU = ZERO
  397. IIL = 0
  398. IIU = 0
  399. NSPLIT = 0
  400. IF( VALEIG ) THEN
  401. * We do not reference VL, VU in the cases RANGE = 'I','A'
  402. * The interval (WL, WU] contains all the wanted eigenvalues.
  403. * It is either given by the user or computed in DLARRE.
  404. WL = VL
  405. WU = VU
  406. ELSEIF( INDEIG ) THEN
  407. * We do not reference IL, IU in the cases RANGE = 'V','A'
  408. IIL = IL
  409. IIU = IU
  410. ENDIF
  411. *
  412. INFO = 0
  413. IF( .NOT.( WANTZ .OR. LSAME( JOBZ, 'N' ) ) ) THEN
  414. INFO = -1
  415. ELSE IF( .NOT.( ALLEIG .OR. VALEIG .OR. INDEIG ) ) THEN
  416. INFO = -2
  417. ELSE IF( N.LT.0 ) THEN
  418. INFO = -3
  419. ELSE IF( VALEIG .AND. N.GT.0 .AND. WU.LE.WL ) THEN
  420. INFO = -7
  421. ELSE IF( INDEIG .AND. ( IIL.LT.1 .OR. IIL.GT.N ) ) THEN
  422. INFO = -8
  423. ELSE IF( INDEIG .AND. ( IIU.LT.IIL .OR. IIU.GT.N ) ) THEN
  424. INFO = -9
  425. ELSE IF( LDZ.LT.1 .OR. ( WANTZ .AND. LDZ.LT.N ) ) THEN
  426. INFO = -13
  427. ELSE IF( LWORK.LT.LWMIN .AND. .NOT.LQUERY ) THEN
  428. INFO = -17
  429. ELSE IF( LIWORK.LT.LIWMIN .AND. .NOT.LQUERY ) THEN
  430. INFO = -19
  431. END IF
  432. *
  433. * Get machine constants.
  434. *
  435. SAFMIN = DLAMCH( 'Safe minimum' )
  436. EPS = DLAMCH( 'Precision' )
  437. SMLNUM = SAFMIN / EPS
  438. BIGNUM = ONE / SMLNUM
  439. RMIN = SQRT( SMLNUM )
  440. RMAX = MIN( SQRT( BIGNUM ), ONE / SQRT( SQRT( SAFMIN ) ) )
  441. *
  442. IF( INFO.EQ.0 ) THEN
  443. WORK( 1 ) = LWMIN
  444. IWORK( 1 ) = LIWMIN
  445. *
  446. IF( WANTZ .AND. ALLEIG ) THEN
  447. NZCMIN = N
  448. ELSE IF( WANTZ .AND. VALEIG ) THEN
  449. CALL DLARRC( 'T', N, VL, VU, D, E, SAFMIN,
  450. $ NZCMIN, ITMP, ITMP2, INFO )
  451. ELSE IF( WANTZ .AND. INDEIG ) THEN
  452. NZCMIN = IIU-IIL+1
  453. ELSE
  454. * WANTZ .EQ. FALSE.
  455. NZCMIN = 0
  456. ENDIF
  457. IF( ZQUERY .AND. INFO.EQ.0 ) THEN
  458. Z( 1,1 ) = NZCMIN
  459. ELSE IF( NZC.LT.NZCMIN .AND. .NOT.ZQUERY ) THEN
  460. INFO = -14
  461. END IF
  462. END IF
  463. IF( INFO.NE.0 ) THEN
  464. *
  465. CALL XERBLA( 'DSTEMR', -INFO )
  466. *
  467. RETURN
  468. ELSE IF( LQUERY .OR. ZQUERY ) THEN
  469. RETURN
  470. END IF
  471. *
  472. * Handle N = 0, 1, and 2 cases immediately
  473. *
  474. M = 0
  475. IF( N.EQ.0 )
  476. $ RETURN
  477. *
  478. IF( N.EQ.1 ) THEN
  479. IF( ALLEIG .OR. INDEIG ) THEN
  480. M = 1
  481. W( 1 ) = D( 1 )
  482. ELSE
  483. IF( WL.LT.D( 1 ) .AND. WU.GE.D( 1 ) ) THEN
  484. M = 1
  485. W( 1 ) = D( 1 )
  486. END IF
  487. END IF
  488. IF( WANTZ.AND.(.NOT.ZQUERY) ) THEN
  489. Z( 1, 1 ) = ONE
  490. ISUPPZ(1) = 1
  491. ISUPPZ(2) = 1
  492. END IF
  493. RETURN
  494. END IF
  495. *
  496. IF( N.EQ.2 ) THEN
  497. IF( .NOT.WANTZ ) THEN
  498. CALL DLAE2( D(1), E(1), D(2), R1, R2 )
  499. ELSE IF( WANTZ.AND.(.NOT.ZQUERY) ) THEN
  500. CALL DLAEV2( D(1), E(1), D(2), R1, R2, CS, SN )
  501. END IF
  502. IF( ALLEIG.OR.
  503. $ (VALEIG.AND.(R2.GT.WL).AND.
  504. $ (R2.LE.WU)).OR.
  505. $ (INDEIG.AND.(IIL.EQ.1)) ) THEN
  506. M = M+1
  507. W( M ) = R2
  508. IF( WANTZ.AND.(.NOT.ZQUERY) ) THEN
  509. Z( 1, M ) = -SN
  510. Z( 2, M ) = CS
  511. * Note: At most one of SN and CS can be zero.
  512. IF (SN.NE.ZERO) THEN
  513. IF (CS.NE.ZERO) THEN
  514. ISUPPZ(2*M-1) = 1
  515. ISUPPZ(2*M) = 2
  516. ELSE
  517. ISUPPZ(2*M-1) = 1
  518. ISUPPZ(2*M) = 1
  519. END IF
  520. ELSE
  521. ISUPPZ(2*M-1) = 2
  522. ISUPPZ(2*M) = 2
  523. END IF
  524. ENDIF
  525. ENDIF
  526. IF( ALLEIG.OR.
  527. $ (VALEIG.AND.(R1.GT.WL).AND.
  528. $ (R1.LE.WU)).OR.
  529. $ (INDEIG.AND.(IIU.EQ.2)) ) THEN
  530. M = M+1
  531. W( M ) = R1
  532. IF( WANTZ.AND.(.NOT.ZQUERY) ) THEN
  533. Z( 1, M ) = CS
  534. Z( 2, M ) = SN
  535. * Note: At most one of SN and CS can be zero.
  536. IF (SN.NE.ZERO) THEN
  537. IF (CS.NE.ZERO) THEN
  538. ISUPPZ(2*M-1) = 1
  539. ISUPPZ(2*M) = 2
  540. ELSE
  541. ISUPPZ(2*M-1) = 1
  542. ISUPPZ(2*M) = 1
  543. END IF
  544. ELSE
  545. ISUPPZ(2*M-1) = 2
  546. ISUPPZ(2*M) = 2
  547. END IF
  548. ENDIF
  549. ENDIF
  550. ELSE
  551. * Continue with general N
  552. INDGRS = 1
  553. INDERR = 2*N + 1
  554. INDGP = 3*N + 1
  555. INDD = 4*N + 1
  556. INDE2 = 5*N + 1
  557. INDWRK = 6*N + 1
  558. *
  559. IINSPL = 1
  560. IINDBL = N + 1
  561. IINDW = 2*N + 1
  562. IINDWK = 3*N + 1
  563. *
  564. * Scale matrix to allowable range, if necessary.
  565. * The allowable range is related to the PIVMIN parameter; see the
  566. * comments in DLARRD. The preference for scaling small values
  567. * up is heuristic; we expect users' matrices not to be close to the
  568. * RMAX threshold.
  569. *
  570. SCALE = ONE
  571. TNRM = DLANST( 'M', N, D, E )
  572. IF( TNRM.GT.ZERO .AND. TNRM.LT.RMIN ) THEN
  573. SCALE = RMIN / TNRM
  574. ELSE IF( TNRM.GT.RMAX ) THEN
  575. SCALE = RMAX / TNRM
  576. END IF
  577. IF( SCALE.NE.ONE ) THEN
  578. CALL DSCAL( N, SCALE, D, 1 )
  579. CALL DSCAL( N-1, SCALE, E, 1 )
  580. TNRM = TNRM*SCALE
  581. IF( VALEIG ) THEN
  582. * If eigenvalues in interval have to be found,
  583. * scale (WL, WU] accordingly
  584. WL = WL*SCALE
  585. WU = WU*SCALE
  586. ENDIF
  587. END IF
  588. *
  589. * Compute the desired eigenvalues of the tridiagonal after splitting
  590. * into smaller subblocks if the corresponding off-diagonal elements
  591. * are small
  592. * THRESH is the splitting parameter for DLARRE
  593. * A negative THRESH forces the old splitting criterion based on the
  594. * size of the off-diagonal. A positive THRESH switches to splitting
  595. * which preserves relative accuracy.
  596. *
  597. IF( TRYRAC ) THEN
  598. * Test whether the matrix warrants the more expensive relative approach.
  599. CALL DLARRR( N, D, E, IINFO )
  600. ELSE
  601. * The user does not care about relative accurately eigenvalues
  602. IINFO = -1
  603. ENDIF
  604. * Set the splitting criterion
  605. IF (IINFO.EQ.0) THEN
  606. THRESH = EPS
  607. ELSE
  608. THRESH = -EPS
  609. * relative accuracy is desired but T does not guarantee it
  610. TRYRAC = .FALSE.
  611. ENDIF
  612. *
  613. IF( TRYRAC ) THEN
  614. * Copy original diagonal, needed to guarantee relative accuracy
  615. CALL DCOPY(N,D,1,WORK(INDD),1)
  616. ENDIF
  617. * Store the squares of the offdiagonal values of T
  618. DO 5 J = 1, N-1
  619. WORK( INDE2+J-1 ) = E(J)**2
  620. 5 CONTINUE
  621. * Set the tolerance parameters for bisection
  622. IF( .NOT.WANTZ ) THEN
  623. * DLARRE computes the eigenvalues to full precision.
  624. RTOL1 = FOUR * EPS
  625. RTOL2 = FOUR * EPS
  626. ELSE
  627. * DLARRE computes the eigenvalues to less than full precision.
  628. * DLARRV will refine the eigenvalue approximations, and we can
  629. * need less accurate initial bisection in DLARRE.
  630. * Note: these settings do only affect the subset case and DLARRE
  631. RTOL1 = SQRT(EPS)
  632. RTOL2 = MAX( SQRT(EPS)*5.0D-3, FOUR * EPS )
  633. ENDIF
  634. CALL DLARRE( RANGE, N, WL, WU, IIL, IIU, D, E,
  635. $ WORK(INDE2), RTOL1, RTOL2, THRESH, NSPLIT,
  636. $ IWORK( IINSPL ), M, W, WORK( INDERR ),
  637. $ WORK( INDGP ), IWORK( IINDBL ),
  638. $ IWORK( IINDW ), WORK( INDGRS ), PIVMIN,
  639. $ WORK( INDWRK ), IWORK( IINDWK ), IINFO )
  640. IF( IINFO.NE.0 ) THEN
  641. INFO = 10 + ABS( IINFO )
  642. RETURN
  643. END IF
  644. * Note that if RANGE .NE. 'V', DLARRE computes bounds on the desired
  645. * part of the spectrum. All desired eigenvalues are contained in
  646. * (WL,WU]
  647. IF( WANTZ ) THEN
  648. *
  649. * Compute the desired eigenvectors corresponding to the computed
  650. * eigenvalues
  651. *
  652. CALL DLARRV( N, WL, WU, D, E,
  653. $ PIVMIN, IWORK( IINSPL ), M,
  654. $ 1, M, MINRGP, RTOL1, RTOL2,
  655. $ W, WORK( INDERR ), WORK( INDGP ), IWORK( IINDBL ),
  656. $ IWORK( IINDW ), WORK( INDGRS ), Z, LDZ,
  657. $ ISUPPZ, WORK( INDWRK ), IWORK( IINDWK ), IINFO )
  658. IF( IINFO.NE.0 ) THEN
  659. INFO = 20 + ABS( IINFO )
  660. RETURN
  661. END IF
  662. ELSE
  663. * DLARRE computes eigenvalues of the (shifted) root representation
  664. * DLARRV returns the eigenvalues of the unshifted matrix.
  665. * However, if the eigenvectors are not desired by the user, we need
  666. * to apply the corresponding shifts from DLARRE to obtain the
  667. * eigenvalues of the original matrix.
  668. DO 20 J = 1, M
  669. ITMP = IWORK( IINDBL+J-1 )
  670. W( J ) = W( J ) + E( IWORK( IINSPL+ITMP-1 ) )
  671. 20 CONTINUE
  672. END IF
  673. *
  674. IF ( TRYRAC ) THEN
  675. * Refine computed eigenvalues so that they are relatively accurate
  676. * with respect to the original matrix T.
  677. IBEGIN = 1
  678. WBEGIN = 1
  679. DO 39 JBLK = 1, IWORK( IINDBL+M-1 )
  680. IEND = IWORK( IINSPL+JBLK-1 )
  681. IN = IEND - IBEGIN + 1
  682. WEND = WBEGIN - 1
  683. * check if any eigenvalues have to be refined in this block
  684. 36 CONTINUE
  685. IF( WEND.LT.M ) THEN
  686. IF( IWORK( IINDBL+WEND ).EQ.JBLK ) THEN
  687. WEND = WEND + 1
  688. GO TO 36
  689. END IF
  690. END IF
  691. IF( WEND.LT.WBEGIN ) THEN
  692. IBEGIN = IEND + 1
  693. GO TO 39
  694. END IF
  695. OFFSET = IWORK(IINDW+WBEGIN-1)-1
  696. IFIRST = IWORK(IINDW+WBEGIN-1)
  697. ILAST = IWORK(IINDW+WEND-1)
  698. RTOL2 = FOUR * EPS
  699. CALL DLARRJ( IN,
  700. $ WORK(INDD+IBEGIN-1), WORK(INDE2+IBEGIN-1),
  701. $ IFIRST, ILAST, RTOL2, OFFSET, W(WBEGIN),
  702. $ WORK( INDERR+WBEGIN-1 ),
  703. $ WORK( INDWRK ), IWORK( IINDWK ), PIVMIN,
  704. $ TNRM, IINFO )
  705. IBEGIN = IEND + 1
  706. WBEGIN = WEND + 1
  707. 39 CONTINUE
  708. ENDIF
  709. *
  710. * If matrix was scaled, then rescale eigenvalues appropriately.
  711. *
  712. IF( SCALE.NE.ONE ) THEN
  713. CALL DSCAL( M, ONE / SCALE, W, 1 )
  714. END IF
  715. END IF
  716. *
  717. * If eigenvalues are not in increasing order, then sort them,
  718. * possibly along with eigenvectors.
  719. *
  720. IF( NSPLIT.GT.1 .OR. N.EQ.2 ) THEN
  721. IF( .NOT. WANTZ ) THEN
  722. CALL DLASRT( 'I', M, W, IINFO )
  723. IF( IINFO.NE.0 ) THEN
  724. INFO = 3
  725. RETURN
  726. END IF
  727. ELSE
  728. DO 60 J = 1, M - 1
  729. I = 0
  730. TMP = W( J )
  731. DO 50 JJ = J + 1, M
  732. IF( W( JJ ).LT.TMP ) THEN
  733. I = JJ
  734. TMP = W( JJ )
  735. END IF
  736. 50 CONTINUE
  737. IF( I.NE.0 ) THEN
  738. W( I ) = W( J )
  739. W( J ) = TMP
  740. IF( WANTZ ) THEN
  741. CALL DSWAP( N, Z( 1, I ), 1, Z( 1, J ), 1 )
  742. ITMP = ISUPPZ( 2*I-1 )
  743. ISUPPZ( 2*I-1 ) = ISUPPZ( 2*J-1 )
  744. ISUPPZ( 2*J-1 ) = ITMP
  745. ITMP = ISUPPZ( 2*I )
  746. ISUPPZ( 2*I ) = ISUPPZ( 2*J )
  747. ISUPPZ( 2*J ) = ITMP
  748. END IF
  749. END IF
  750. 60 CONTINUE
  751. END IF
  752. ENDIF
  753. *
  754. *
  755. WORK( 1 ) = LWMIN
  756. IWORK( 1 ) = LIWMIN
  757. RETURN
  758. *
  759. * End of DSTEMR
  760. *
  761. END