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.

cstemr.f 29 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
  1. *> \brief \b CSTEMR
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download CSTEMR + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cstemr.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cstemr.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cstemr.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE CSTEMR( 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. * REAL VL, VU
  30. * ..
  31. * .. Array Arguments ..
  32. * INTEGER ISUPPZ( * ), IWORK( * )
  33. * REAL D( * ), E( * ), W( * ), WORK( * )
  34. * COMPLEX Z( LDZ, * )
  35. * ..
  36. *
  37. *
  38. *> \par Purpose:
  39. * =============
  40. *>
  41. *> \verbatim
  42. *>
  43. *> CSTEMR 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.CSTEMR 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. *> CSTEMR accepts complex workspace to facilitate interoperability
  109. *> with CUNMTR or CUPMTR.
  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 REAL 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 REAL 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 REAL
  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 REAL
  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 REAL 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 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 = .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 = .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 REAL 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 SLARRE,
  309. *> if INFO = 2X, internal error in CLARRV.
  310. *> Here, the digit X = ABS( IINFO ) < 10, where IINFO is
  311. *> the nonzero error code returned by SLARRE or
  312. *> CLARRV, 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. *> \ingroup stemr
  324. *
  325. *> \par Contributors:
  326. * ==================
  327. *>
  328. *> Beresford Parlett, University of California, Berkeley, USA \n
  329. *> Jim Demmel, University of California, Berkeley, USA \n
  330. *> Inderjit Dhillon, University of Texas, Austin, USA \n
  331. *> Osni Marques, LBNL/NERSC, USA \n
  332. *> Christof Voemel, University of California, Berkeley, USA \n
  333. *> Aravindh Krishnamoorthy, FAU, Erlangen, Germany \n
  334. *
  335. * =====================================================================
  336. SUBROUTINE CSTEMR( JOBZ, RANGE, N, D, E, VL, VU, IL, IU,
  337. $ M, W, Z, LDZ, NZC, ISUPPZ, TRYRAC, WORK, LWORK,
  338. $ IWORK, LIWORK, INFO )
  339. *
  340. * -- LAPACK computational routine --
  341. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  342. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  343. *
  344. * .. Scalar Arguments ..
  345. CHARACTER JOBZ, RANGE
  346. LOGICAL TRYRAC
  347. INTEGER IL, INFO, IU, LDZ, NZC, LIWORK, LWORK, M, N
  348. REAL VL, VU
  349. * ..
  350. * .. Array Arguments ..
  351. INTEGER ISUPPZ( * ), IWORK( * )
  352. REAL D( * ), E( * ), W( * ), WORK( * )
  353. COMPLEX Z( LDZ, * )
  354. * ..
  355. *
  356. * =====================================================================
  357. *
  358. * .. Parameters ..
  359. REAL ZERO, ONE, FOUR, MINRGP
  360. PARAMETER ( ZERO = 0.0E0, ONE = 1.0E0,
  361. $ FOUR = 4.0E0,
  362. $ MINRGP = 3.0E-3 )
  363. * ..
  364. * .. Local Scalars ..
  365. LOGICAL ALLEIG, INDEIG, LQUERY, VALEIG, WANTZ, ZQUERY,
  366. $ LAESWAP
  367. INTEGER I, IBEGIN, IEND, IFIRST, IIL, IINDBL, IINDW,
  368. $ IINDWK, IINFO, IINSPL, IIU, ILAST, IN, INDD,
  369. $ INDE2, INDERR, INDGP, INDGRS, INDWRK, ITMP,
  370. $ ITMP2, J, JBLK, JJ, LIWMIN, LWMIN, NSPLIT,
  371. $ NZCMIN, OFFSET, WBEGIN, WEND
  372. REAL BIGNUM, CS, EPS, PIVMIN, R1, R2, RMAX, RMIN,
  373. $ RTOL1, RTOL2, SAFMIN, SCALE, SMLNUM, SN,
  374. $ THRESH, TMP, TNRM, WL, WU
  375. * ..
  376. * ..
  377. * .. External Functions ..
  378. LOGICAL LSAME
  379. REAL SLAMCH, SLANST, SROUNDUP_LWORK
  380. EXTERNAL LSAME, SLAMCH, SLANST, SROUNDUP_LWORK
  381. * ..
  382. * .. External Subroutines ..
  383. EXTERNAL CLARRV, CSWAP, SCOPY, SLAE2, SLAEV2, SLARRC,
  384. $ SLARRE, SLARRJ, SLARRR, SLASRT, SSCAL, XERBLA
  385. * ..
  386. * .. Intrinsic Functions ..
  387. INTRINSIC MAX, MIN, SQRT
  388. * ..
  389. * .. Executable Statements ..
  390. *
  391. * Test the input parameters.
  392. *
  393. WANTZ = LSAME( JOBZ, 'V' )
  394. ALLEIG = LSAME( RANGE, 'A' )
  395. VALEIG = LSAME( RANGE, 'V' )
  396. INDEIG = LSAME( RANGE, 'I' )
  397. *
  398. LQUERY = ( ( LWORK.EQ.-1 ).OR.( LIWORK.EQ.-1 ) )
  399. ZQUERY = ( NZC.EQ.-1 )
  400. LAESWAP = .FALSE.
  401. * SSTEMR needs WORK of size 6*N, IWORK of size 3*N.
  402. * In addition, SLARRE needs WORK of size 6*N, IWORK of size 5*N.
  403. * Furthermore, CLARRV 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 SLARRE.
  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 = SLAMCH( 'Safe minimum' )
  453. EPS = SLAMCH( '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 ) = SROUNDUP_LWORK(LWMIN)
  461. IWORK( 1 ) = LIWMIN
  462. *
  463. IF( WANTZ .AND. ALLEIG ) THEN
  464. NZCMIN = N
  465. ELSE IF( WANTZ .AND. VALEIG ) THEN
  466. CALL SLARRC( '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( 'CSTEMR', -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 SLAE2( D(1), E(1), D(2), R1, R2 )
  516. ELSE IF( WANTZ.AND.(.NOT.ZQUERY) ) THEN
  517. CALL SLAEV2( D(1), E(1), D(2), R1, R2, CS, SN )
  518. END IF
  519. * D/S/LAE2 and D/S/LAEV2 outputs satisfy |R1| >= |R2|. However,
  520. * the following code requires R1 >= R2. Hence, we correct
  521. * the order of R1, R2, CS, SN if R1 < R2 before further processing.
  522. IF( R1.LT.R2 ) THEN
  523. E(2) = R1
  524. R1 = R2
  525. R2 = E(2)
  526. LAESWAP = .TRUE.
  527. ENDIF
  528. IF( ALLEIG.OR.
  529. $ (VALEIG.AND.(R2.GT.WL).AND.
  530. $ (R2.LE.WU)).OR.
  531. $ (INDEIG.AND.(IIL.EQ.1)) ) THEN
  532. M = M+1
  533. W( M ) = R2
  534. IF( WANTZ.AND.(.NOT.ZQUERY) ) THEN
  535. IF( LAESWAP ) THEN
  536. Z( 1, M ) = CS
  537. Z( 2, M ) = SN
  538. ELSE
  539. Z( 1, M ) = -SN
  540. Z( 2, M ) = CS
  541. ENDIF
  542. * Note: At most one of SN and CS can be zero.
  543. IF (SN.NE.ZERO) THEN
  544. IF (CS.NE.ZERO) THEN
  545. ISUPPZ(2*M-1) = 1
  546. ISUPPZ(2*M) = 2
  547. ELSE
  548. ISUPPZ(2*M-1) = 1
  549. ISUPPZ(2*M) = 1
  550. END IF
  551. ELSE
  552. ISUPPZ(2*M-1) = 2
  553. ISUPPZ(2*M) = 2
  554. END IF
  555. ENDIF
  556. ENDIF
  557. IF( ALLEIG.OR.
  558. $ (VALEIG.AND.(R1.GT.WL).AND.
  559. $ (R1.LE.WU)).OR.
  560. $ (INDEIG.AND.(IIU.EQ.2)) ) THEN
  561. M = M+1
  562. W( M ) = R1
  563. IF( WANTZ.AND.(.NOT.ZQUERY) ) THEN
  564. IF( LAESWAP ) THEN
  565. Z( 1, M ) = -SN
  566. Z( 2, M ) = CS
  567. ELSE
  568. Z( 1, M ) = CS
  569. Z( 2, M ) = SN
  570. ENDIF
  571. * Note: At most one of SN and CS can be zero.
  572. IF (SN.NE.ZERO) THEN
  573. IF (CS.NE.ZERO) THEN
  574. ISUPPZ(2*M-1) = 1
  575. ISUPPZ(2*M) = 2
  576. ELSE
  577. ISUPPZ(2*M-1) = 1
  578. ISUPPZ(2*M) = 1
  579. END IF
  580. ELSE
  581. ISUPPZ(2*M-1) = 2
  582. ISUPPZ(2*M) = 2
  583. END IF
  584. ENDIF
  585. ENDIF
  586. ELSE
  587. * Continue with general N
  588. INDGRS = 1
  589. INDERR = 2*N + 1
  590. INDGP = 3*N + 1
  591. INDD = 4*N + 1
  592. INDE2 = 5*N + 1
  593. INDWRK = 6*N + 1
  594. *
  595. IINSPL = 1
  596. IINDBL = N + 1
  597. IINDW = 2*N + 1
  598. IINDWK = 3*N + 1
  599. *
  600. * Scale matrix to allowable range, if necessary.
  601. * The allowable range is related to the PIVMIN parameter; see the
  602. * comments in SLARRD. The preference for scaling small values
  603. * up is heuristic; we expect users' matrices not to be close to the
  604. * RMAX threshold.
  605. *
  606. SCALE = ONE
  607. TNRM = SLANST( 'M', N, D, E )
  608. IF( TNRM.GT.ZERO .AND. TNRM.LT.RMIN ) THEN
  609. SCALE = RMIN / TNRM
  610. ELSE IF( TNRM.GT.RMAX ) THEN
  611. SCALE = RMAX / TNRM
  612. END IF
  613. IF( SCALE.NE.ONE ) THEN
  614. CALL SSCAL( N, SCALE, D, 1 )
  615. CALL SSCAL( N-1, SCALE, E, 1 )
  616. TNRM = TNRM*SCALE
  617. IF( VALEIG ) THEN
  618. * If eigenvalues in interval have to be found,
  619. * scale (WL, WU] accordingly
  620. WL = WL*SCALE
  621. WU = WU*SCALE
  622. ENDIF
  623. END IF
  624. *
  625. * Compute the desired eigenvalues of the tridiagonal after splitting
  626. * into smaller subblocks if the corresponding off-diagonal elements
  627. * are small
  628. * THRESH is the splitting parameter for SLARRE
  629. * A negative THRESH forces the old splitting criterion based on the
  630. * size of the off-diagonal. A positive THRESH switches to splitting
  631. * which preserves relative accuracy.
  632. *
  633. IF( TRYRAC ) THEN
  634. * Test whether the matrix warrants the more expensive relative approach.
  635. CALL SLARRR( N, D, E, IINFO )
  636. ELSE
  637. * The user does not care about relative accurately eigenvalues
  638. IINFO = -1
  639. ENDIF
  640. * Set the splitting criterion
  641. IF (IINFO.EQ.0) THEN
  642. THRESH = EPS
  643. ELSE
  644. THRESH = -EPS
  645. * relative accuracy is desired but T does not guarantee it
  646. TRYRAC = .FALSE.
  647. ENDIF
  648. *
  649. IF( TRYRAC ) THEN
  650. * Copy original diagonal, needed to guarantee relative accuracy
  651. CALL SCOPY(N,D,1,WORK(INDD),1)
  652. ENDIF
  653. * Store the squares of the offdiagonal values of T
  654. DO 5 J = 1, N-1
  655. WORK( INDE2+J-1 ) = E(J)**2
  656. 5 CONTINUE
  657. * Set the tolerance parameters for bisection
  658. IF( .NOT.WANTZ ) THEN
  659. * SLARRE computes the eigenvalues to full precision.
  660. RTOL1 = FOUR * EPS
  661. RTOL2 = FOUR * EPS
  662. ELSE
  663. * SLARRE computes the eigenvalues to less than full precision.
  664. * CLARRV will refine the eigenvalue approximations, and we only
  665. * need less accurate initial bisection in SLARRE.
  666. * Note: these settings do only affect the subset case and SLARRE
  667. RTOL1 = MAX( SQRT(EPS)*5.0E-2, FOUR * EPS )
  668. RTOL2 = MAX( SQRT(EPS)*5.0E-3, FOUR * EPS )
  669. ENDIF
  670. CALL SLARRE( RANGE, N, WL, WU, IIL, IIU, D, E,
  671. $ WORK(INDE2), RTOL1, RTOL2, THRESH, NSPLIT,
  672. $ IWORK( IINSPL ), M, W, WORK( INDERR ),
  673. $ WORK( INDGP ), IWORK( IINDBL ),
  674. $ IWORK( IINDW ), WORK( INDGRS ), PIVMIN,
  675. $ WORK( INDWRK ), IWORK( IINDWK ), IINFO )
  676. IF( IINFO.NE.0 ) THEN
  677. INFO = 10 + ABS( IINFO )
  678. RETURN
  679. END IF
  680. * Note that if RANGE .NE. 'V', SLARRE computes bounds on the desired
  681. * part of the spectrum. All desired eigenvalues are contained in
  682. * (WL,WU]
  683. IF( WANTZ ) THEN
  684. *
  685. * Compute the desired eigenvectors corresponding to the computed
  686. * eigenvalues
  687. *
  688. CALL CLARRV( N, WL, WU, D, E,
  689. $ PIVMIN, IWORK( IINSPL ), M,
  690. $ 1, M, MINRGP, RTOL1, RTOL2,
  691. $ W, WORK( INDERR ), WORK( INDGP ), IWORK( IINDBL ),
  692. $ IWORK( IINDW ), WORK( INDGRS ), Z, LDZ,
  693. $ ISUPPZ, WORK( INDWRK ), IWORK( IINDWK ), IINFO )
  694. IF( IINFO.NE.0 ) THEN
  695. INFO = 20 + ABS( IINFO )
  696. RETURN
  697. END IF
  698. ELSE
  699. * SLARRE computes eigenvalues of the (shifted) root representation
  700. * CLARRV returns the eigenvalues of the unshifted matrix.
  701. * However, if the eigenvectors are not desired by the user, we need
  702. * to apply the corresponding shifts from SLARRE to obtain the
  703. * eigenvalues of the original matrix.
  704. DO 20 J = 1, M
  705. ITMP = IWORK( IINDBL+J-1 )
  706. W( J ) = W( J ) + E( IWORK( IINSPL+ITMP-1 ) )
  707. 20 CONTINUE
  708. END IF
  709. *
  710. IF ( TRYRAC ) THEN
  711. * Refine computed eigenvalues so that they are relatively accurate
  712. * with respect to the original matrix T.
  713. IBEGIN = 1
  714. WBEGIN = 1
  715. DO 39 JBLK = 1, IWORK( IINDBL+M-1 )
  716. IEND = IWORK( IINSPL+JBLK-1 )
  717. IN = IEND - IBEGIN + 1
  718. WEND = WBEGIN - 1
  719. * check if any eigenvalues have to be refined in this block
  720. 36 CONTINUE
  721. IF( WEND.LT.M ) THEN
  722. IF( IWORK( IINDBL+WEND ).EQ.JBLK ) THEN
  723. WEND = WEND + 1
  724. GO TO 36
  725. END IF
  726. END IF
  727. IF( WEND.LT.WBEGIN ) THEN
  728. IBEGIN = IEND + 1
  729. GO TO 39
  730. END IF
  731. OFFSET = IWORK(IINDW+WBEGIN-1)-1
  732. IFIRST = IWORK(IINDW+WBEGIN-1)
  733. ILAST = IWORK(IINDW+WEND-1)
  734. RTOL2 = FOUR * EPS
  735. CALL SLARRJ( IN,
  736. $ WORK(INDD+IBEGIN-1), WORK(INDE2+IBEGIN-1),
  737. $ IFIRST, ILAST, RTOL2, OFFSET, W(WBEGIN),
  738. $ WORK( INDERR+WBEGIN-1 ),
  739. $ WORK( INDWRK ), IWORK( IINDWK ), PIVMIN,
  740. $ TNRM, IINFO )
  741. IBEGIN = IEND + 1
  742. WBEGIN = WEND + 1
  743. 39 CONTINUE
  744. ENDIF
  745. *
  746. * If matrix was scaled, then rescale eigenvalues appropriately.
  747. *
  748. IF( SCALE.NE.ONE ) THEN
  749. CALL SSCAL( M, ONE / SCALE, W, 1 )
  750. END IF
  751. END IF
  752. *
  753. * If eigenvalues are not in increasing order, then sort them,
  754. * possibly along with eigenvectors.
  755. *
  756. IF( NSPLIT.GT.1 .OR. N.EQ.2 ) THEN
  757. IF( .NOT. WANTZ ) THEN
  758. CALL SLASRT( 'I', M, W, IINFO )
  759. IF( IINFO.NE.0 ) THEN
  760. INFO = 3
  761. RETURN
  762. END IF
  763. ELSE
  764. DO 60 J = 1, M - 1
  765. I = 0
  766. TMP = W( J )
  767. DO 50 JJ = J + 1, M
  768. IF( W( JJ ).LT.TMP ) THEN
  769. I = JJ
  770. TMP = W( JJ )
  771. END IF
  772. 50 CONTINUE
  773. IF( I.NE.0 ) THEN
  774. W( I ) = W( J )
  775. W( J ) = TMP
  776. IF( WANTZ ) THEN
  777. CALL CSWAP( N, Z( 1, I ), 1, Z( 1, J ), 1 )
  778. ITMP = ISUPPZ( 2*I-1 )
  779. ISUPPZ( 2*I-1 ) = ISUPPZ( 2*J-1 )
  780. ISUPPZ( 2*J-1 ) = ITMP
  781. ITMP = ISUPPZ( 2*I )
  782. ISUPPZ( 2*I ) = ISUPPZ( 2*J )
  783. ISUPPZ( 2*J ) = ITMP
  784. END IF
  785. END IF
  786. 60 CONTINUE
  787. END IF
  788. ENDIF
  789. *
  790. *
  791. WORK( 1 ) = SROUNDUP_LWORK(LWMIN)
  792. IWORK( 1 ) = LIWMIN
  793. RETURN
  794. *
  795. * End of CSTEMR
  796. *
  797. END