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 28 kB

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