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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  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 November 2013
  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.5.0) --
  333. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  334. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  335. * November 2013
  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. NSPLIT = 0
  408. IF( VALEIG ) THEN
  409. * We do not reference VL, VU in the cases RANGE = 'I','A'
  410. * The interval (WL, WU] contains all the wanted eigenvalues.
  411. * It is either given by the user or computed in SLARRE.
  412. WL = VL
  413. WU = VU
  414. ELSEIF( INDEIG ) THEN
  415. * We do not reference IL, IU in the cases RANGE = 'V','A'
  416. IIL = IL
  417. IIU = IU
  418. ENDIF
  419. *
  420. INFO = 0
  421. IF( .NOT.( WANTZ .OR. LSAME( JOBZ, 'N' ) ) ) THEN
  422. INFO = -1
  423. ELSE IF( .NOT.( ALLEIG .OR. VALEIG .OR. INDEIG ) ) THEN
  424. INFO = -2
  425. ELSE IF( N.LT.0 ) THEN
  426. INFO = -3
  427. ELSE IF( VALEIG .AND. N.GT.0 .AND. WU.LE.WL ) THEN
  428. INFO = -7
  429. ELSE IF( INDEIG .AND. ( IIL.LT.1 .OR. IIL.GT.N ) ) THEN
  430. INFO = -8
  431. ELSE IF( INDEIG .AND. ( IIU.LT.IIL .OR. IIU.GT.N ) ) THEN
  432. INFO = -9
  433. ELSE IF( LDZ.LT.1 .OR. ( WANTZ .AND. LDZ.LT.N ) ) THEN
  434. INFO = -13
  435. ELSE IF( LWORK.LT.LWMIN .AND. .NOT.LQUERY ) THEN
  436. INFO = -17
  437. ELSE IF( LIWORK.LT.LIWMIN .AND. .NOT.LQUERY ) THEN
  438. INFO = -19
  439. END IF
  440. *
  441. * Get machine constants.
  442. *
  443. SAFMIN = SLAMCH( 'Safe minimum' )
  444. EPS = SLAMCH( 'Precision' )
  445. SMLNUM = SAFMIN / EPS
  446. BIGNUM = ONE / SMLNUM
  447. RMIN = SQRT( SMLNUM )
  448. RMAX = MIN( SQRT( BIGNUM ), ONE / SQRT( SQRT( SAFMIN ) ) )
  449. *
  450. IF( INFO.EQ.0 ) THEN
  451. WORK( 1 ) = LWMIN
  452. IWORK( 1 ) = LIWMIN
  453. *
  454. IF( WANTZ .AND. ALLEIG ) THEN
  455. NZCMIN = N
  456. ELSE IF( WANTZ .AND. VALEIG ) THEN
  457. CALL SLARRC( 'T', N, VL, VU, D, E, SAFMIN,
  458. $ NZCMIN, ITMP, ITMP2, INFO )
  459. ELSE IF( WANTZ .AND. INDEIG ) THEN
  460. NZCMIN = IIU-IIL+1
  461. ELSE
  462. * WANTZ .EQ. FALSE.
  463. NZCMIN = 0
  464. ENDIF
  465. IF( ZQUERY .AND. INFO.EQ.0 ) THEN
  466. Z( 1,1 ) = NZCMIN
  467. ELSE IF( NZC.LT.NZCMIN .AND. .NOT.ZQUERY ) THEN
  468. INFO = -14
  469. END IF
  470. END IF
  471. IF( INFO.NE.0 ) THEN
  472. *
  473. CALL XERBLA( 'CSTEMR', -INFO )
  474. *
  475. RETURN
  476. ELSE IF( LQUERY .OR. ZQUERY ) THEN
  477. RETURN
  478. END IF
  479. *
  480. * Handle N = 0, 1, and 2 cases immediately
  481. *
  482. M = 0
  483. IF( N.EQ.0 )
  484. $ RETURN
  485. *
  486. IF( N.EQ.1 ) THEN
  487. IF( ALLEIG .OR. INDEIG ) THEN
  488. M = 1
  489. W( 1 ) = D( 1 )
  490. ELSE
  491. IF( WL.LT.D( 1 ) .AND. WU.GE.D( 1 ) ) THEN
  492. M = 1
  493. W( 1 ) = D( 1 )
  494. END IF
  495. END IF
  496. IF( WANTZ.AND.(.NOT.ZQUERY) ) THEN
  497. Z( 1, 1 ) = ONE
  498. ISUPPZ(1) = 1
  499. ISUPPZ(2) = 1
  500. END IF
  501. RETURN
  502. END IF
  503. *
  504. IF( N.EQ.2 ) THEN
  505. IF( .NOT.WANTZ ) THEN
  506. CALL SLAE2( D(1), E(1), D(2), R1, R2 )
  507. ELSE IF( WANTZ.AND.(.NOT.ZQUERY) ) THEN
  508. CALL SLAEV2( D(1), E(1), D(2), R1, R2, CS, SN )
  509. END IF
  510. IF( ALLEIG.OR.
  511. $ (VALEIG.AND.(R2.GT.WL).AND.
  512. $ (R2.LE.WU)).OR.
  513. $ (INDEIG.AND.(IIL.EQ.1)) ) THEN
  514. M = M+1
  515. W( M ) = R2
  516. IF( WANTZ.AND.(.NOT.ZQUERY) ) THEN
  517. Z( 1, M ) = -SN
  518. Z( 2, M ) = CS
  519. * Note: At most one of SN and CS can be zero.
  520. IF (SN.NE.ZERO) THEN
  521. IF (CS.NE.ZERO) THEN
  522. ISUPPZ(2*M-1) = 1
  523. ISUPPZ(2*M-1) = 2
  524. ELSE
  525. ISUPPZ(2*M-1) = 1
  526. ISUPPZ(2*M-1) = 1
  527. END IF
  528. ELSE
  529. ISUPPZ(2*M-1) = 2
  530. ISUPPZ(2*M) = 2
  531. END IF
  532. ENDIF
  533. ENDIF
  534. IF( ALLEIG.OR.
  535. $ (VALEIG.AND.(R1.GT.WL).AND.
  536. $ (R1.LE.WU)).OR.
  537. $ (INDEIG.AND.(IIU.EQ.2)) ) THEN
  538. M = M+1
  539. W( M ) = R1
  540. IF( WANTZ.AND.(.NOT.ZQUERY) ) THEN
  541. Z( 1, M ) = CS
  542. Z( 2, M ) = SN
  543. * Note: At most one of SN and CS can be zero.
  544. IF (SN.NE.ZERO) THEN
  545. IF (CS.NE.ZERO) THEN
  546. ISUPPZ(2*M-1) = 1
  547. ISUPPZ(2*M-1) = 2
  548. ELSE
  549. ISUPPZ(2*M-1) = 1
  550. ISUPPZ(2*M-1) = 1
  551. END IF
  552. ELSE
  553. ISUPPZ(2*M-1) = 2
  554. ISUPPZ(2*M) = 2
  555. END IF
  556. ENDIF
  557. ENDIF
  558. ELSE
  559. * Continue with general N
  560. INDGRS = 1
  561. INDERR = 2*N + 1
  562. INDGP = 3*N + 1
  563. INDD = 4*N + 1
  564. INDE2 = 5*N + 1
  565. INDWRK = 6*N + 1
  566. *
  567. IINSPL = 1
  568. IINDBL = N + 1
  569. IINDW = 2*N + 1
  570. IINDWK = 3*N + 1
  571. *
  572. * Scale matrix to allowable range, if necessary.
  573. * The allowable range is related to the PIVMIN parameter; see the
  574. * comments in SLARRD. The preference for scaling small values
  575. * up is heuristic; we expect users' matrices not to be close to the
  576. * RMAX threshold.
  577. *
  578. SCALE = ONE
  579. TNRM = SLANST( 'M', N, D, E )
  580. IF( TNRM.GT.ZERO .AND. TNRM.LT.RMIN ) THEN
  581. SCALE = RMIN / TNRM
  582. ELSE IF( TNRM.GT.RMAX ) THEN
  583. SCALE = RMAX / TNRM
  584. END IF
  585. IF( SCALE.NE.ONE ) THEN
  586. CALL SSCAL( N, SCALE, D, 1 )
  587. CALL SSCAL( N-1, SCALE, E, 1 )
  588. TNRM = TNRM*SCALE
  589. IF( VALEIG ) THEN
  590. * If eigenvalues in interval have to be found,
  591. * scale (WL, WU] accordingly
  592. WL = WL*SCALE
  593. WU = WU*SCALE
  594. ENDIF
  595. END IF
  596. *
  597. * Compute the desired eigenvalues of the tridiagonal after splitting
  598. * into smaller subblocks if the corresponding off-diagonal elements
  599. * are small
  600. * THRESH is the splitting parameter for SLARRE
  601. * A negative THRESH forces the old splitting criterion based on the
  602. * size of the off-diagonal. A positive THRESH switches to splitting
  603. * which preserves relative accuracy.
  604. *
  605. IF( TRYRAC ) THEN
  606. * Test whether the matrix warrants the more expensive relative approach.
  607. CALL SLARRR( N, D, E, IINFO )
  608. ELSE
  609. * The user does not care about relative accurately eigenvalues
  610. IINFO = -1
  611. ENDIF
  612. * Set the splitting criterion
  613. IF (IINFO.EQ.0) THEN
  614. THRESH = EPS
  615. ELSE
  616. THRESH = -EPS
  617. * relative accuracy is desired but T does not guarantee it
  618. TRYRAC = .FALSE.
  619. ENDIF
  620. *
  621. IF( TRYRAC ) THEN
  622. * Copy original diagonal, needed to guarantee relative accuracy
  623. CALL SCOPY(N,D,1,WORK(INDD),1)
  624. ENDIF
  625. * Store the squares of the offdiagonal values of T
  626. DO 5 J = 1, N-1
  627. WORK( INDE2+J-1 ) = E(J)**2
  628. 5 CONTINUE
  629. * Set the tolerance parameters for bisection
  630. IF( .NOT.WANTZ ) THEN
  631. * SLARRE computes the eigenvalues to full precision.
  632. RTOL1 = FOUR * EPS
  633. RTOL2 = FOUR * EPS
  634. ELSE
  635. * SLARRE computes the eigenvalues to less than full precision.
  636. * CLARRV will refine the eigenvalue approximations, and we only
  637. * need less accurate initial bisection in SLARRE.
  638. * Note: these settings do only affect the subset case and SLARRE
  639. RTOL1 = MAX( SQRT(EPS)*5.0E-2, FOUR * EPS )
  640. RTOL2 = MAX( SQRT(EPS)*5.0E-3, FOUR * EPS )
  641. ENDIF
  642. CALL SLARRE( RANGE, N, WL, WU, IIL, IIU, D, E,
  643. $ WORK(INDE2), RTOL1, RTOL2, THRESH, NSPLIT,
  644. $ IWORK( IINSPL ), M, W, WORK( INDERR ),
  645. $ WORK( INDGP ), IWORK( IINDBL ),
  646. $ IWORK( IINDW ), WORK( INDGRS ), PIVMIN,
  647. $ WORK( INDWRK ), IWORK( IINDWK ), IINFO )
  648. IF( IINFO.NE.0 ) THEN
  649. INFO = 10 + ABS( IINFO )
  650. RETURN
  651. END IF
  652. * Note that if RANGE .NE. 'V', SLARRE computes bounds on the desired
  653. * part of the spectrum. All desired eigenvalues are contained in
  654. * (WL,WU]
  655. IF( WANTZ ) THEN
  656. *
  657. * Compute the desired eigenvectors corresponding to the computed
  658. * eigenvalues
  659. *
  660. CALL CLARRV( N, WL, WU, D, E,
  661. $ PIVMIN, IWORK( IINSPL ), M,
  662. $ 1, M, MINRGP, RTOL1, RTOL2,
  663. $ W, WORK( INDERR ), WORK( INDGP ), IWORK( IINDBL ),
  664. $ IWORK( IINDW ), WORK( INDGRS ), Z, LDZ,
  665. $ ISUPPZ, WORK( INDWRK ), IWORK( IINDWK ), IINFO )
  666. IF( IINFO.NE.0 ) THEN
  667. INFO = 20 + ABS( IINFO )
  668. RETURN
  669. END IF
  670. ELSE
  671. * SLARRE computes eigenvalues of the (shifted) root representation
  672. * CLARRV returns the eigenvalues of the unshifted matrix.
  673. * However, if the eigenvectors are not desired by the user, we need
  674. * to apply the corresponding shifts from SLARRE to obtain the
  675. * eigenvalues of the original matrix.
  676. DO 20 J = 1, M
  677. ITMP = IWORK( IINDBL+J-1 )
  678. W( J ) = W( J ) + E( IWORK( IINSPL+ITMP-1 ) )
  679. 20 CONTINUE
  680. END IF
  681. *
  682. IF ( TRYRAC ) THEN
  683. * Refine computed eigenvalues so that they are relatively accurate
  684. * with respect to the original matrix T.
  685. IBEGIN = 1
  686. WBEGIN = 1
  687. DO 39 JBLK = 1, IWORK( IINDBL+M-1 )
  688. IEND = IWORK( IINSPL+JBLK-1 )
  689. IN = IEND - IBEGIN + 1
  690. WEND = WBEGIN - 1
  691. * check if any eigenvalues have to be refined in this block
  692. 36 CONTINUE
  693. IF( WEND.LT.M ) THEN
  694. IF( IWORK( IINDBL+WEND ).EQ.JBLK ) THEN
  695. WEND = WEND + 1
  696. GO TO 36
  697. END IF
  698. END IF
  699. IF( WEND.LT.WBEGIN ) THEN
  700. IBEGIN = IEND + 1
  701. GO TO 39
  702. END IF
  703. OFFSET = IWORK(IINDW+WBEGIN-1)-1
  704. IFIRST = IWORK(IINDW+WBEGIN-1)
  705. ILAST = IWORK(IINDW+WEND-1)
  706. RTOL2 = FOUR * EPS
  707. CALL SLARRJ( IN,
  708. $ WORK(INDD+IBEGIN-1), WORK(INDE2+IBEGIN-1),
  709. $ IFIRST, ILAST, RTOL2, OFFSET, W(WBEGIN),
  710. $ WORK( INDERR+WBEGIN-1 ),
  711. $ WORK( INDWRK ), IWORK( IINDWK ), PIVMIN,
  712. $ TNRM, IINFO )
  713. IBEGIN = IEND + 1
  714. WBEGIN = WEND + 1
  715. 39 CONTINUE
  716. ENDIF
  717. *
  718. * If matrix was scaled, then rescale eigenvalues appropriately.
  719. *
  720. IF( SCALE.NE.ONE ) THEN
  721. CALL SSCAL( M, ONE / SCALE, W, 1 )
  722. END IF
  723. END IF
  724. *
  725. * If eigenvalues are not in increasing order, then sort them,
  726. * possibly along with eigenvectors.
  727. *
  728. IF( NSPLIT.GT.1 .OR. N.EQ.2 ) THEN
  729. IF( .NOT. WANTZ ) THEN
  730. CALL SLASRT( 'I', M, W, IINFO )
  731. IF( IINFO.NE.0 ) THEN
  732. INFO = 3
  733. RETURN
  734. END IF
  735. ELSE
  736. DO 60 J = 1, M - 1
  737. I = 0
  738. TMP = W( J )
  739. DO 50 JJ = J + 1, M
  740. IF( W( JJ ).LT.TMP ) THEN
  741. I = JJ
  742. TMP = W( JJ )
  743. END IF
  744. 50 CONTINUE
  745. IF( I.NE.0 ) THEN
  746. W( I ) = W( J )
  747. W( J ) = TMP
  748. IF( WANTZ ) THEN
  749. CALL CSWAP( N, Z( 1, I ), 1, Z( 1, J ), 1 )
  750. ITMP = ISUPPZ( 2*I-1 )
  751. ISUPPZ( 2*I-1 ) = ISUPPZ( 2*J-1 )
  752. ISUPPZ( 2*J-1 ) = ITMP
  753. ITMP = ISUPPZ( 2*I )
  754. ISUPPZ( 2*I ) = ISUPPZ( 2*J )
  755. ISUPPZ( 2*J ) = ITMP
  756. END IF
  757. END IF
  758. 60 CONTINUE
  759. END IF
  760. ENDIF
  761. *
  762. *
  763. WORK( 1 ) = LWMIN
  764. IWORK( 1 ) = LIWMIN
  765. RETURN
  766. *
  767. * End of CSTEMR
  768. *
  769. END