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.

zstemr.f 28 kB

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