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.

cgeqp3rk.f 39 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093
  1. *> \brief \b CGEQP3RK computes a truncated Householder QR factorization with column pivoting of a complex m-by-n matrix A by using Level 3 BLAS and overwrites m-by-nrhs matrix B with Q**H * B.
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download CGEQP3RK + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cgeqp3rk.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cgeqp3rk.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cgeqp3rk.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE CGEQP3RK( M, N, NRHS, KMAX, ABSTOL, RELTOL, A, LDA,
  22. * $ K, MAXC2NRMK, RELMAXC2NRMK, JPIV, TAU,
  23. * $ WORK, LWORK, RWORK, IWORK, INFO )
  24. * IMPLICIT NONE
  25. *
  26. * .. Scalar Arguments ..
  27. * INTEGER INFO, K, KMAX, LDA, LWORK, M, N, NRHS
  28. * REAL ABSTOL, MAXC2NRMK, RELMAXC2NRMK, RELTOL
  29. * ..
  30. * .. Array Arguments ..
  31. * INTEGER IWORK( * ), JPIV( * )
  32. * REAL RWORK( * )
  33. * COMPLEX A( LDA, * ), TAU( * ), WORK( * )
  34. * ..
  35. *
  36. *
  37. *> \par Purpose:
  38. * =============
  39. *>
  40. *> \verbatim
  41. *>
  42. *> CGEQP3RK performs two tasks simultaneously:
  43. *>
  44. *> Task 1: The routine computes a truncated (rank K) or full rank
  45. *> Householder QR factorization with column pivoting of a complex
  46. *> M-by-N matrix A using Level 3 BLAS. K is the number of columns
  47. *> that were factorized, i.e. factorization rank of the
  48. *> factor R, K <= min(M,N).
  49. *>
  50. *> A * P(K) = Q(K) * R(K) =
  51. *>
  52. *> = Q(K) * ( R11(K) R12(K) ) = Q(K) * ( R(K)_approx )
  53. *> ( 0 R22(K) ) ( 0 R(K)_residual ),
  54. *>
  55. *> where:
  56. *>
  57. *> P(K) is an N-by-N permutation matrix;
  58. *> Q(K) is an M-by-M unitary matrix;
  59. *> R(K)_approx = ( R11(K), R12(K) ) is a rank K approximation of the
  60. *> full rank factor R with K-by-K upper-triangular
  61. *> R11(K) and K-by-N rectangular R12(K). The diagonal
  62. *> entries of R11(K) appear in non-increasing order
  63. *> of absolute value, and absolute values of all of
  64. *> them exceed the maximum column 2-norm of R22(K)
  65. *> up to roundoff error.
  66. *> R(K)_residual = R22(K) is the residual of a rank K approximation
  67. *> of the full rank factor R. It is a
  68. *> an (M-K)-by-(N-K) rectangular matrix;
  69. *> 0 is a an (M-K)-by-K zero matrix.
  70. *>
  71. *> Task 2: At the same time, the routine overwrites a complex M-by-NRHS
  72. *> matrix B with Q(K)**H * B using Level 3 BLAS.
  73. *>
  74. *> =====================================================================
  75. *>
  76. *> The matrices A and B are stored on input in the array A as
  77. *> the left and right blocks A(1:M,1:N) and A(1:M, N+1:N+NRHS)
  78. *> respectively.
  79. *>
  80. *> N NRHS
  81. *> array_A = M [ mat_A, mat_B ]
  82. *>
  83. *> The truncation criteria (i.e. when to stop the factorization)
  84. *> can be any of the following:
  85. *>
  86. *> 1) The input parameter KMAX, the maximum number of columns
  87. *> KMAX to factorize, i.e. the factorization rank is limited
  88. *> to KMAX. If KMAX >= min(M,N), the criterion is not used.
  89. *>
  90. *> 2) The input parameter ABSTOL, the absolute tolerance for
  91. *> the maximum column 2-norm of the residual matrix R22(K). This
  92. *> means that the factorization stops if this norm is less or
  93. *> equal to ABSTOL. If ABSTOL < 0.0, the criterion is not used.
  94. *>
  95. *> 3) The input parameter RELTOL, the tolerance for the maximum
  96. *> column 2-norm matrix of the residual matrix R22(K) divided
  97. *> by the maximum column 2-norm of the original matrix A, which
  98. *> is equal to abs(R(1,1)). This means that the factorization stops
  99. *> when the ratio of the maximum column 2-norm of R22(K) to
  100. *> the maximum column 2-norm of A is less than or equal to RELTOL.
  101. *> If RELTOL < 0.0, the criterion is not used.
  102. *>
  103. *> 4) In case both stopping criteria ABSTOL or RELTOL are not used,
  104. *> and when the residual matrix R22(K) is a zero matrix in some
  105. *> factorization step K. ( This stopping criterion is implicit. )
  106. *>
  107. *> The algorithm stops when any of these conditions is first
  108. *> satisfied, otherwise the whole matrix A is factorized.
  109. *>
  110. *> To factorize the whole matrix A, use the values
  111. *> KMAX >= min(M,N), ABSTOL < 0.0 and RELTOL < 0.0.
  112. *>
  113. *> The routine returns:
  114. *> a) Q(K), R(K)_approx = ( R11(K), R12(K) ),
  115. *> R(K)_residual = R22(K), P(K), i.e. the resulting matrices
  116. *> of the factorization; P(K) is represented by JPIV,
  117. *> ( if K = min(M,N), R(K)_approx is the full factor R,
  118. *> and there is no residual matrix R(K)_residual);
  119. *> b) K, the number of columns that were factorized,
  120. *> i.e. factorization rank;
  121. *> c) MAXC2NRMK, the maximum column 2-norm of the residual
  122. *> matrix R(K)_residual = R22(K),
  123. *> ( if K = min(M,N), MAXC2NRMK = 0.0 );
  124. *> d) RELMAXC2NRMK equals MAXC2NRMK divided by MAXC2NRM, the maximum
  125. *> column 2-norm of the original matrix A, which is equal
  126. *> to abs(R(1,1)), ( if K = min(M,N), RELMAXC2NRMK = 0.0 );
  127. *> e) Q(K)**H * B, the matrix B with the unitary
  128. *> transformation Q(K)**H applied on the left.
  129. *>
  130. *> The N-by-N permutation matrix P(K) is stored in a compact form in
  131. *> the integer array JPIV. For 1 <= j <= N, column j
  132. *> of the matrix A was interchanged with column JPIV(j).
  133. *>
  134. *> The M-by-M unitary matrix Q is represented as a product
  135. *> of elementary Householder reflectors
  136. *>
  137. *> Q(K) = H(1) * H(2) * . . . * H(K),
  138. *>
  139. *> where K is the number of columns that were factorized.
  140. *>
  141. *> Each H(j) has the form
  142. *>
  143. *> H(j) = I - tau * v * v**H,
  144. *>
  145. *> where 1 <= j <= K and
  146. *> I is an M-by-M identity matrix,
  147. *> tau is a complex scalar,
  148. *> v is a complex vector with v(1:j-1) = 0 and v(j) = 1.
  149. *>
  150. *> v(j+1:M) is stored on exit in A(j+1:M,j) and tau in TAU(j).
  151. *>
  152. *> See the Further Details section for more information.
  153. *> \endverbatim
  154. *
  155. * Arguments:
  156. * ==========
  157. *
  158. *> \param[in] M
  159. *> \verbatim
  160. *> M is INTEGER
  161. *> The number of rows of the matrix A. M >= 0.
  162. *> \endverbatim
  163. *>
  164. *> \param[in] N
  165. *> \verbatim
  166. *> N is INTEGER
  167. *> The number of columns of the matrix A. N >= 0.
  168. *> \endverbatim
  169. *>
  170. *> \param[in] NRHS
  171. *> \verbatim
  172. *> NRHS is INTEGER
  173. *> The number of right hand sides, i.e. the number of
  174. *> columns of the matrix B. NRHS >= 0.
  175. *> \endverbatim
  176. *>
  177. *> \param[in] KMAX
  178. *> \verbatim
  179. *> KMAX is INTEGER
  180. *>
  181. *> The first factorization stopping criterion. KMAX >= 0.
  182. *>
  183. *> The maximum number of columns of the matrix A to factorize,
  184. *> i.e. the maximum factorization rank.
  185. *>
  186. *> a) If KMAX >= min(M,N), then this stopping criterion
  187. *> is not used, the routine factorizes columns
  188. *> depending on ABSTOL and RELTOL.
  189. *>
  190. *> b) If KMAX = 0, then this stopping criterion is
  191. *> satisfied on input and the routine exits immediately.
  192. *> This means that the factorization is not performed,
  193. *> the matrices A and B are not modified, and
  194. *> the matrix A is itself the residual.
  195. *> \endverbatim
  196. *>
  197. *> \param[in] ABSTOL
  198. *> \verbatim
  199. *> ABSTOL is REAL
  200. *>
  201. *> The second factorization stopping criterion, cannot be NaN.
  202. *>
  203. *> The absolute tolerance (stopping threshold) for
  204. *> maximum column 2-norm of the residual matrix R22(K).
  205. *> The algorithm converges (stops the factorization) when
  206. *> the maximum column 2-norm of the residual matrix R22(K)
  207. *> is less than or equal to ABSTOL. Let SAFMIN = DLAMCH('S').
  208. *>
  209. *> a) If ABSTOL is NaN, then no computation is performed
  210. *> and an error message ( INFO = -5 ) is issued
  211. *> by XERBLA.
  212. *>
  213. *> b) If ABSTOL < 0.0, then this stopping criterion is not
  214. *> used, the routine factorizes columns depending
  215. *> on KMAX and RELTOL.
  216. *> This includes the case ABSTOL = -Inf.
  217. *>
  218. *> c) If 0.0 <= ABSTOL < 2*SAFMIN, then ABSTOL = 2*SAFMIN
  219. *> is used. This includes the case ABSTOL = -0.0.
  220. *>
  221. *> d) If 2*SAFMIN <= ABSTOL then the input value
  222. *> of ABSTOL is used.
  223. *>
  224. *> Let MAXC2NRM be the maximum column 2-norm of the
  225. *> whole original matrix A.
  226. *> If ABSTOL chosen above is >= MAXC2NRM, then this
  227. *> stopping criterion is satisfied on input and routine exits
  228. *> immediately after MAXC2NRM is computed. The routine
  229. *> returns MAXC2NRM in MAXC2NORMK,
  230. *> and 1.0 in RELMAXC2NORMK.
  231. *> This includes the case ABSTOL = +Inf. This means that the
  232. *> factorization is not performed, the matrices A and B are not
  233. *> modified, and the matrix A is itself the residual.
  234. *> \endverbatim
  235. *>
  236. *> \param[in] RELTOL
  237. *> \verbatim
  238. *> RELTOL is REAL
  239. *>
  240. *> The third factorization stopping criterion, cannot be NaN.
  241. *>
  242. *> The tolerance (stopping threshold) for the ratio
  243. *> abs(R(K+1,K+1))/abs(R(1,1)) of the maximum column 2-norm of
  244. *> the residual matrix R22(K) to the maximum column 2-norm of
  245. *> the original matrix A. The algorithm converges (stops the
  246. *> factorization), when abs(R(K+1,K+1))/abs(R(1,1)) A is less
  247. *> than or equal to RELTOL. Let EPS = DLAMCH('E').
  248. *>
  249. *> a) If RELTOL is NaN, then no computation is performed
  250. *> and an error message ( INFO = -6 ) is issued
  251. *> by XERBLA.
  252. *>
  253. *> b) If RELTOL < 0.0, then this stopping criterion is not
  254. *> used, the routine factorizes columns depending
  255. *> on KMAX and ABSTOL.
  256. *> This includes the case RELTOL = -Inf.
  257. *>
  258. *> c) If 0.0 <= RELTOL < EPS, then RELTOL = EPS is used.
  259. *> This includes the case RELTOL = -0.0.
  260. *>
  261. *> d) If EPS <= RELTOL then the input value of RELTOL
  262. *> is used.
  263. *>
  264. *> Let MAXC2NRM be the maximum column 2-norm of the
  265. *> whole original matrix A.
  266. *> If RELTOL chosen above is >= 1.0, then this stopping
  267. *> criterion is satisfied on input and routine exits
  268. *> immediately after MAXC2NRM is computed.
  269. *> The routine returns MAXC2NRM in MAXC2NORMK,
  270. *> and 1.0 in RELMAXC2NORMK.
  271. *> This includes the case RELTOL = +Inf. This means that the
  272. *> factorization is not performed, the matrices A and B are not
  273. *> modified, and the matrix A is itself the residual.
  274. *>
  275. *> NOTE: We recommend that RELTOL satisfy
  276. *> min( 10*max(M,N)*EPS, sqrt(EPS) ) <= RELTOL
  277. *> \endverbatim
  278. *>
  279. *> \param[in,out] A
  280. *> \verbatim
  281. *> A is COMPLEX array, dimension (LDA,N+NRHS)
  282. *>
  283. *> On entry:
  284. *>
  285. *> a) The subarray A(1:M,1:N) contains the M-by-N matrix A.
  286. *> b) The subarray A(1:M,N+1:N+NRHS) contains the M-by-NRHS
  287. *> matrix B.
  288. *>
  289. *> N NRHS
  290. *> array_A = M [ mat_A, mat_B ]
  291. *>
  292. *> On exit:
  293. *>
  294. *> a) The subarray A(1:M,1:N) contains parts of the factors
  295. *> of the matrix A:
  296. *>
  297. *> 1) If K = 0, A(1:M,1:N) contains the original matrix A.
  298. *> 2) If K > 0, A(1:M,1:N) contains parts of the
  299. *> factors:
  300. *>
  301. *> 1. The elements below the diagonal of the subarray
  302. *> A(1:M,1:K) together with TAU(1:K) represent the
  303. *> unitary matrix Q(K) as a product of K Householder
  304. *> elementary reflectors.
  305. *>
  306. *> 2. The elements on and above the diagonal of
  307. *> the subarray A(1:K,1:N) contain K-by-N
  308. *> upper-trapezoidal matrix
  309. *> R(K)_approx = ( R11(K), R12(K) ).
  310. *> NOTE: If K=min(M,N), i.e. full rank factorization,
  311. *> then R_approx(K) is the full factor R which
  312. *> is upper-trapezoidal. If, in addition, M>=N,
  313. *> then R is upper-triangular.
  314. *>
  315. *> 3. The subarray A(K+1:M,K+1:N) contains (M-K)-by-(N-K)
  316. *> rectangular matrix R(K)_residual = R22(K).
  317. *>
  318. *> b) If NRHS > 0, the subarray A(1:M,N+1:N+NRHS) contains
  319. *> the M-by-NRHS product Q(K)**H * B.
  320. *> \endverbatim
  321. *>
  322. *> \param[in] LDA
  323. *> \verbatim
  324. *> LDA is INTEGER
  325. *> The leading dimension of the array A. LDA >= max(1,M).
  326. *> This is the leading dimension for both matrices, A and B.
  327. *> \endverbatim
  328. *>
  329. *> \param[out] K
  330. *> \verbatim
  331. *> K is INTEGER
  332. *> Factorization rank of the matrix A, i.e. the rank of
  333. *> the factor R, which is the same as the number of non-zero
  334. *> rows of the factor R. 0 <= K <= min(M,KMAX,N).
  335. *>
  336. *> K also represents the number of non-zero Householder
  337. *> vectors.
  338. *>
  339. *> NOTE: If K = 0, a) the arrays A and B are not modified;
  340. *> b) the array TAU(1:min(M,N)) is set to ZERO,
  341. *> if the matrix A does not contain NaN,
  342. *> otherwise the elements TAU(1:min(M,N))
  343. *> are undefined;
  344. *> c) the elements of the array JPIV are set
  345. *> as follows: for j = 1:N, JPIV(j) = j.
  346. *> \endverbatim
  347. *>
  348. *> \param[out] MAXC2NRMK
  349. *> \verbatim
  350. *> MAXC2NRMK is REAL
  351. *> The maximum column 2-norm of the residual matrix R22(K),
  352. *> when the factorization stopped at rank K. MAXC2NRMK >= 0.
  353. *>
  354. *> a) If K = 0, i.e. the factorization was not performed,
  355. *> the matrix A was not modified and is itself a residual
  356. *> matrix, then MAXC2NRMK equals the maximum column 2-norm
  357. *> of the original matrix A.
  358. *>
  359. *> b) If 0 < K < min(M,N), then MAXC2NRMK is returned.
  360. *>
  361. *> c) If K = min(M,N), i.e. the whole matrix A was
  362. *> factorized and there is no residual matrix,
  363. *> then MAXC2NRMK = 0.0.
  364. *>
  365. *> NOTE: MAXC2NRMK in the factorization step K would equal
  366. *> R(K+1,K+1) in the next factorization step K+1.
  367. *> \endverbatim
  368. *>
  369. *> \param[out] RELMAXC2NRMK
  370. *> \verbatim
  371. *> RELMAXC2NRMK is REAL
  372. *> The ratio MAXC2NRMK / MAXC2NRM of the maximum column
  373. *> 2-norm of the residual matrix R22(K) (when the factorization
  374. *> stopped at rank K) to the maximum column 2-norm of the
  375. *> whole original matrix A. RELMAXC2NRMK >= 0.
  376. *>
  377. *> a) If K = 0, i.e. the factorization was not performed,
  378. *> the matrix A was not modified and is itself a residual
  379. *> matrix, then RELMAXC2NRMK = 1.0.
  380. *>
  381. *> b) If 0 < K < min(M,N), then
  382. *> RELMAXC2NRMK = MAXC2NRMK / MAXC2NRM is returned.
  383. *>
  384. *> c) If K = min(M,N), i.e. the whole matrix A was
  385. *> factorized and there is no residual matrix,
  386. *> then RELMAXC2NRMK = 0.0.
  387. *>
  388. *> NOTE: RELMAXC2NRMK in the factorization step K would equal
  389. *> abs(R(K+1,K+1))/abs(R(1,1)) in the next factorization
  390. *> step K+1.
  391. *> \endverbatim
  392. *>
  393. *> \param[out] JPIV
  394. *> \verbatim
  395. *> JPIV is INTEGER array, dimension (N)
  396. *> Column pivot indices. For 1 <= j <= N, column j
  397. *> of the matrix A was interchanged with column JPIV(j).
  398. *>
  399. *> The elements of the array JPIV(1:N) are always set
  400. *> by the routine, for example, even when no columns
  401. *> were factorized, i.e. when K = 0, the elements are
  402. *> set as JPIV(j) = j for j = 1:N.
  403. *> \endverbatim
  404. *>
  405. *> \param[out] TAU
  406. *> \verbatim
  407. *> TAU is COMPLEX array, dimension (min(M,N))
  408. *> The scalar factors of the elementary reflectors.
  409. *>
  410. *> If 0 < K <= min(M,N), only the elements TAU(1:K) of
  411. *> the array TAU are modified by the factorization.
  412. *> After the factorization computed, if no NaN was found
  413. *> during the factorization, the remaining elements
  414. *> TAU(K+1:min(M,N)) are set to zero, otherwise the
  415. *> elements TAU(K+1:min(M,N)) are not set and therefore
  416. *> undefined.
  417. *> ( If K = 0, all elements of TAU are set to zero, if
  418. *> the matrix A does not contain NaN. )
  419. *> \endverbatim
  420. *>
  421. *> \param[out] WORK
  422. *> \verbatim
  423. *> WORK is COMPLEX array, dimension (MAX(1,LWORK))
  424. *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
  425. *> \endverbatim
  426. *>
  427. *> \param[in] LWORK
  428. *> \verbatim
  429. *> LWORK is INTEGER
  430. *> The dimension of the array WORK.
  431. *> LWORK >= 1, if MIN(M,N) = 0, and
  432. *> LWORK >= N+NRHS-1, otherwise.
  433. *> For optimal performance LWORK >= NB*( N+NRHS+1 ),
  434. *> where NB is the optimal block size for CGEQP3RK returned
  435. *> by ILAENV. Minimal block size MINNB=2.
  436. *>
  437. *> NOTE: The decision, whether to use unblocked BLAS 2
  438. *> or blocked BLAS 3 code is based not only on the dimension
  439. *> LWORK of the availbale workspace WORK, but also also on the
  440. *> matrix A dimension N via crossover point NX returned
  441. *> by ILAENV. (For N less than NX, unblocked code should be
  442. *> used.)
  443. *>
  444. *> If LWORK = -1, then a workspace query is assumed;
  445. *> the routine only calculates the optimal size of the WORK
  446. *> array, returns this value as the first entry of the WORK
  447. *> array, and no error message related to LWORK is issued
  448. *> by XERBLA.
  449. *> \endverbatim
  450. *>
  451. *> \param[out] RWORK
  452. *> \verbatim
  453. *> RWORK is REAL array, dimension (2*N)
  454. *> \endverbatim
  455. *>
  456. *> \param[out] IWORK
  457. *> \verbatim
  458. *> IWORK is INTEGER array, dimension (N-1).
  459. *> Is a work array. ( IWORK is used to store indices
  460. *> of "bad" columns for norm downdating in the residual
  461. *> matrix in the blocked step auxiliary subroutine CLAQP3RK ).
  462. *> \endverbatim
  463. *>
  464. *> \param[out] INFO
  465. *> \verbatim
  466. *> INFO is INTEGER
  467. *> 1) INFO = 0: successful exit.
  468. *> 2) INFO < 0: if INFO = -i, the i-th argument had an
  469. *> illegal value.
  470. *> 3) If INFO = j_1, where 1 <= j_1 <= N, then NaN was
  471. *> detected and the routine stops the computation.
  472. *> The j_1-th column of the matrix A or the j_1-th
  473. *> element of array TAU contains the first occurrence
  474. *> of NaN in the factorization step K+1 ( when K columns
  475. *> have been factorized ).
  476. *>
  477. *> On exit:
  478. *> K is set to the number of
  479. *> factorized columns without
  480. *> exception.
  481. *> MAXC2NRMK is set to NaN.
  482. *> RELMAXC2NRMK is set to NaN.
  483. *> TAU(K+1:min(M,N)) is not set and contains undefined
  484. *> elements. If j_1=K+1, TAU(K+1)
  485. *> may contain NaN.
  486. *> 4) If INFO = j_2, where N+1 <= j_2 <= 2*N, then no NaN
  487. *> was detected, but +Inf (or -Inf) was detected and
  488. *> the routine continues the computation until completion.
  489. *> The (j_2-N)-th column of the matrix A contains the first
  490. *> occurrence of +Inf (or -Inf) in the factorization
  491. *> step K+1 ( when K columns have been factorized ).
  492. *> \endverbatim
  493. *
  494. * Authors:
  495. * ========
  496. *
  497. *> \author Univ. of Tennessee
  498. *> \author Univ. of California Berkeley
  499. *> \author Univ. of Colorado Denver
  500. *> \author NAG Ltd.
  501. *
  502. *> \ingroup geqp3rk
  503. *
  504. *> \par Further Details:
  505. * =====================
  506. *
  507. *> \verbatim
  508. *> CGEQP3RK is based on the same BLAS3 Householder QR factorization
  509. *> algorithm with column pivoting as in CGEQP3 routine which uses
  510. *> CLARFG routine to generate Householder reflectors
  511. *> for QR factorization.
  512. *>
  513. *> We can also write:
  514. *>
  515. *> A = A_approx(K) + A_residual(K)
  516. *>
  517. *> The low rank approximation matrix A(K)_approx from
  518. *> the truncated QR factorization of rank K of the matrix A is:
  519. *>
  520. *> A(K)_approx = Q(K) * ( R(K)_approx ) * P(K)**T
  521. *> ( 0 0 )
  522. *>
  523. *> = Q(K) * ( R11(K) R12(K) ) * P(K)**T
  524. *> ( 0 0 )
  525. *>
  526. *> The residual A_residual(K) of the matrix A is:
  527. *>
  528. *> A_residual(K) = Q(K) * ( 0 0 ) * P(K)**T =
  529. *> ( 0 R(K)_residual )
  530. *>
  531. *> = Q(K) * ( 0 0 ) * P(K)**T
  532. *> ( 0 R22(K) )
  533. *>
  534. *> The truncated (rank K) factorization guarantees that
  535. *> the maximum column 2-norm of A_residual(K) is less than
  536. *> or equal to MAXC2NRMK up to roundoff error.
  537. *>
  538. *> NOTE: An approximation of the null vectors
  539. *> of A can be easily computed from R11(K)
  540. *> and R12(K):
  541. *>
  542. *> Null( A(K) )_approx = P * ( inv(R11(K)) * R12(K) )
  543. *> ( -I )
  544. *>
  545. *> \endverbatim
  546. *
  547. *> \par References:
  548. * ================
  549. *> [1] A Level 3 BLAS QR factorization algorithm with column pivoting developed in 1996.
  550. *> G. Quintana-Orti, Depto. de Informatica, Universidad Jaime I, Spain.
  551. *> X. Sun, Computer Science Dept., Duke University, USA.
  552. *> C. H. Bischof, Math. and Comp. Sci. Div., Argonne National Lab, USA.
  553. *> A BLAS-3 version of the QR factorization with column pivoting.
  554. *> LAPACK Working Note 114
  555. *> \htmlonly
  556. *> <a href="https://www.netlib.org/lapack/lawnspdf/lawn114.pdf">https://www.netlib.org/lapack/lawnspdf/lawn114.pdf</a>
  557. *> \endhtmlonly
  558. *> and in
  559. *> SIAM J. Sci. Comput., 19(5):1486-1494, Sept. 1998.
  560. *> \htmlonly
  561. *> <a href="https://doi.org/10.1137/S1064827595296732">https://doi.org/10.1137/S1064827595296732</a>
  562. *> \endhtmlonly
  563. *>
  564. *> [2] A partial column norm updating strategy developed in 2006.
  565. *> Z. Drmac and Z. Bujanovic, Dept. of Math., University of Zagreb, Croatia.
  566. *> On the failure of rank revealing QR factorization software – a case study.
  567. *> LAPACK Working Note 176.
  568. *> \htmlonly
  569. *> <a href="http://www.netlib.org/lapack/lawnspdf/lawn176.pdf">http://www.netlib.org/lapack/lawnspdf/lawn176.pdf</a>
  570. *> \endhtmlonly
  571. *> and in
  572. *> ACM Trans. Math. Softw. 35, 2, Article 12 (July 2008), 28 pages.
  573. *> \htmlonly
  574. *> <a href="https://doi.org/10.1145/1377612.1377616">https://doi.org/10.1145/1377612.1377616</a>
  575. *> \endhtmlonly
  576. *
  577. *> \par Contributors:
  578. * ==================
  579. *>
  580. *> \verbatim
  581. *>
  582. *> November 2023, Igor Kozachenko, James Demmel,
  583. *> EECS Department,
  584. *> University of California, Berkeley, USA.
  585. *>
  586. *> \endverbatim
  587. *
  588. * =====================================================================
  589. SUBROUTINE CGEQP3RK( M, N, NRHS, KMAX, ABSTOL, RELTOL, A, LDA,
  590. $ K, MAXC2NRMK, RELMAXC2NRMK, JPIV, TAU,
  591. $ WORK, LWORK, RWORK, IWORK, INFO )
  592. IMPLICIT NONE
  593. *
  594. * -- LAPACK computational routine --
  595. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  596. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  597. *
  598. * .. Scalar Arguments ..
  599. INTEGER INFO, K, KF, KMAX, LDA, LWORK, M, N, NRHS
  600. REAL ABSTOL, MAXC2NRMK, RELMAXC2NRMK, RELTOL
  601. * ..
  602. * .. Array Arguments ..
  603. INTEGER IWORK( * ), JPIV( * )
  604. REAL RWORK( * )
  605. COMPLEX A( LDA, * ), TAU( * ), WORK( * )
  606. * ..
  607. *
  608. * =====================================================================
  609. *
  610. * .. Parameters ..
  611. INTEGER INB, INBMIN, IXOVER
  612. PARAMETER ( INB = 1, INBMIN = 2, IXOVER = 3 )
  613. REAL ZERO, ONE, TWO
  614. PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0, TWO = 2.0E+0 )
  615. COMPLEX CZERO
  616. PARAMETER ( CZERO = ( 0.0E+0, 0.0E+0 ) )
  617. * ..
  618. * .. Local Scalars ..
  619. LOGICAL LQUERY, DONE
  620. INTEGER IINFO, IOFFSET, IWS, J, JB, JBF, JMAXB, JMAX,
  621. $ JMAXC2NRM, KP1, LWKOPT, MINMN, N_SUB, NB,
  622. $ NBMIN, NX
  623. REAL EPS, HUGEVAL, MAXC2NRM, SAFMIN
  624. * ..
  625. * .. External Subroutines ..
  626. EXTERNAL CLAQP2RK, CLAQP3RK, XERBLA
  627. * ..
  628. * .. External Functions ..
  629. LOGICAL SISNAN
  630. INTEGER ISAMAX, ILAENV
  631. REAL SLAMCH, SCNRM2, SROUNDUP_LWORK
  632. EXTERNAL SISNAN, SLAMCH, SCNRM2, ISAMAX, ILAENV,
  633. $ SROUNDUP_LWORK
  634. * ..
  635. * .. Intrinsic Functions ..
  636. INTRINSIC CMPLX, MAX, MIN
  637. * ..
  638. * .. Executable Statements ..
  639. *
  640. * Test input arguments
  641. * ====================
  642. *
  643. INFO = 0
  644. LQUERY = ( LWORK.EQ.-1 )
  645. IF( M.LT.0 ) THEN
  646. INFO = -1
  647. ELSE IF( N.LT.0 ) THEN
  648. INFO = -2
  649. ELSE IF( NRHS.LT.0 ) THEN
  650. INFO = -3
  651. ELSE IF( KMAX.LT.0 ) THEN
  652. INFO = -4
  653. ELSE IF( SISNAN( ABSTOL ) ) THEN
  654. INFO = -5
  655. ELSE IF( SISNAN( RELTOL ) ) THEN
  656. INFO = -6
  657. ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
  658. INFO = -8
  659. END IF
  660. *
  661. * If the input parameters M, N, NRHS, KMAX, LDA are valid:
  662. * a) Test the input workspace size LWORK for the minimum
  663. * size requirement IWS.
  664. * b) Determine the optimal block size NB and optimal
  665. * workspace size LWKOPT to be returned in WORK(1)
  666. * in case of (1) LWORK < IWS, (2) LQUERY = .TRUE.,
  667. * (3) when routine exits.
  668. * Here, IWS is the miminum workspace required for unblocked
  669. * code.
  670. *
  671. IF( INFO.EQ.0 ) THEN
  672. MINMN = MIN( M, N )
  673. IF( MINMN.EQ.0 ) THEN
  674. IWS = 1
  675. LWKOPT = 1
  676. ELSE
  677. *
  678. * Minimal workspace size in case of using only unblocked
  679. * BLAS 2 code in CLAQP2RK.
  680. * 1) CLAQP2RK: N+NRHS-1 to use in WORK array that is used
  681. * in CLARF subroutine inside CLAQP2RK to apply an
  682. * elementary reflector from the left.
  683. * TOTAL_WORK_SIZE = 3*N + NRHS - 1
  684. *
  685. IWS = N + NRHS - 1
  686. *
  687. * Assign to NB optimal block size.
  688. *
  689. NB = ILAENV( INB, 'CGEQP3RK', ' ', M, N, -1, -1 )
  690. *
  691. * A formula for the optimal workspace size in case of using
  692. * both unblocked BLAS 2 in CLAQP2RK and blocked BLAS 3 code
  693. * in CLAQP3RK.
  694. * 1) CGEQP3RK, CLAQP2RK, CLAQP3RK: 2*N to store full and
  695. * partial column 2-norms.
  696. * 2) CLAQP2RK: N+NRHS-1 to use in WORK array that is used
  697. * in CLARF subroutine to apply an elementary reflector
  698. * from the left.
  699. * 3) CLAQP3RK: NB*(N+NRHS) to use in the work array F that
  700. * is used to apply a block reflector from
  701. * the left.
  702. * 4) CLAQP3RK: NB to use in the auxilixary array AUX.
  703. * Sizes (2) and ((3) + (4)) should intersect, therefore
  704. * TOTAL_WORK_SIZE = 2*N + NB*( N+NRHS+1 ), given NBMIN=2.
  705. *
  706. LWKOPT = 2*N + NB*( N+NRHS+1 )
  707. END IF
  708. WORK( 1 ) = SROUNDUP_LWORK( LWKOPT )
  709. *
  710. IF( ( LWORK.LT.IWS ) .AND. .NOT.LQUERY ) THEN
  711. INFO = -15
  712. END IF
  713. END IF
  714. *
  715. * NOTE: The optimal workspace size is returned in WORK(1), if
  716. * the input parameters M, N, NRHS, KMAX, LDA are valid.
  717. *
  718. IF( INFO.NE.0 ) THEN
  719. CALL XERBLA( 'CGEQP3RK', -INFO )
  720. RETURN
  721. ELSE IF( LQUERY ) THEN
  722. RETURN
  723. END IF
  724. *
  725. * Quick return if possible for M=0 or N=0.
  726. *
  727. IF( MINMN.EQ.0 ) THEN
  728. K = 0
  729. MAXC2NRMK = ZERO
  730. RELMAXC2NRMK = ZERO
  731. WORK( 1 ) = SROUNDUP_LWORK( LWKOPT )
  732. RETURN
  733. END IF
  734. *
  735. * ==================================================================
  736. *
  737. * Initialize column pivot array JPIV.
  738. *
  739. DO J = 1, N
  740. JPIV( J ) = J
  741. END DO
  742. *
  743. * ==================================================================
  744. *
  745. * Initialize storage for partial and exact column 2-norms.
  746. * a) The elements WORK(1:N) are used to store partial column
  747. * 2-norms of the matrix A, and may decrease in each computation
  748. * step; initialize to the values of complete columns 2-norms.
  749. * b) The elements WORK(N+1:2*N) are used to store complete column
  750. * 2-norms of the matrix A, they are not changed during the
  751. * computation; initialize the values of complete columns 2-norms.
  752. *
  753. DO J = 1, N
  754. RWORK( J ) = SCNRM2( M, A( 1, J ), 1 )
  755. RWORK( N+J ) = RWORK( J )
  756. END DO
  757. *
  758. * ==================================================================
  759. *
  760. * Compute the pivot column index and the maximum column 2-norm
  761. * for the whole original matrix stored in A(1:M,1:N).
  762. *
  763. KP1 = ISAMAX( N, RWORK( 1 ), 1 )
  764. *
  765. * ==================================================================.
  766. *
  767. IF( SISNAN( MAXC2NRM ) ) THEN
  768. *
  769. * Check if the matrix A contains NaN, set INFO parameter
  770. * to the column number where the first NaN is found and return
  771. * from the routine.
  772. *
  773. K = 0
  774. INFO = KP1
  775. *
  776. * Set MAXC2NRMK and RELMAXC2NRMK to NaN.
  777. *
  778. MAXC2NRMK = MAXC2NRM
  779. RELMAXC2NRMK = MAXC2NRM
  780. *
  781. * Array TAU is not set and contains undefined elements.
  782. *
  783. WORK( 1 ) = SROUNDUP_LWORK( LWKOPT )
  784. RETURN
  785. END IF
  786. *
  787. * ===================================================================
  788. *
  789. IF( MAXC2NRM.EQ.ZERO ) THEN
  790. *
  791. * Check is the matrix A is a zero matrix, set array TAU and
  792. * return from the routine.
  793. *
  794. K = 0
  795. MAXC2NRMK = ZERO
  796. RELMAXC2NRMK = ZERO
  797. *
  798. DO J = 1, MINMN
  799. TAU( J ) = CZERO
  800. END DO
  801. *
  802. WORK( 1 ) = SROUNDUP_LWORK( LWKOPT )
  803. RETURN
  804. *
  805. END IF
  806. *
  807. * ===================================================================
  808. *
  809. HUGEVAL = SLAMCH( 'Overflow' )
  810. *
  811. IF( MAXC2NRM.GT.HUGEVAL ) THEN
  812. *
  813. * Check if the matrix A contains +Inf or -Inf, set INFO parameter
  814. * to the column number, where the first +/-Inf is found plus N,
  815. * and continue the computation.
  816. *
  817. INFO = N + KP1
  818. *
  819. END IF
  820. *
  821. * ==================================================================
  822. *
  823. * Quick return if possible for the case when the first
  824. * stopping criterion is satisfied, i.e. KMAX = 0.
  825. *
  826. IF( KMAX.EQ.0 ) THEN
  827. K = 0
  828. MAXC2NRMK = MAXC2NRM
  829. RELMAXC2NRMK = ONE
  830. DO J = 1, MINMN
  831. TAU( J ) = CZERO
  832. END DO
  833. WORK( 1 ) = SROUNDUP_LWORK( LWKOPT )
  834. RETURN
  835. END IF
  836. *
  837. * ==================================================================
  838. *
  839. EPS = SLAMCH('Epsilon')
  840. *
  841. * Adjust ABSTOL
  842. *
  843. IF( ABSTOL.GE.ZERO ) THEN
  844. SAFMIN = SLAMCH('Safe minimum')
  845. ABSTOL = MAX( ABSTOL, TWO*SAFMIN )
  846. END IF
  847. *
  848. * Adjust RELTOL
  849. *
  850. IF( RELTOL.GE.ZERO ) THEN
  851. RELTOL = MAX( RELTOL, EPS )
  852. END IF
  853. *
  854. * ===================================================================
  855. *
  856. * JMAX is the maximum index of the column to be factorized,
  857. * which is also limited by the first stopping criterion KMAX.
  858. *
  859. JMAX = MIN( KMAX, MINMN )
  860. *
  861. * ===================================================================
  862. *
  863. * Quick return if possible for the case when the second or third
  864. * stopping criterion for the whole original matrix is satified,
  865. * i.e. MAXC2NRM <= ABSTOL or RELMAXC2NRM <= RELTOL
  866. * (which is ONE <= RELTOL).
  867. *
  868. IF( MAXC2NRM.LE.ABSTOL .OR. ONE.LE.RELTOL ) THEN
  869. *
  870. K = 0
  871. MAXC2NRMK = MAXC2NRM
  872. RELMAXC2NRMK = ONE
  873. *
  874. DO J = 1, MINMN
  875. TAU( J ) = CZERO
  876. END DO
  877. *
  878. WORK( 1 ) = SROUNDUP_LWORK( LWKOPT )
  879. RETURN
  880. END IF
  881. *
  882. * ==================================================================
  883. * Factorize columns
  884. * ==================================================================
  885. *
  886. * Determine the block size.
  887. *
  888. NBMIN = 2
  889. NX = 0
  890. *
  891. IF( ( NB.GT.1 ) .AND. ( NB.LT.MINMN ) ) THEN
  892. *
  893. * Determine when to cross over from blocked to unblocked code.
  894. * (for N less than NX, unblocked code should be used).
  895. *
  896. NX = MAX( 0, ILAENV( IXOVER, 'CGEQP3RK', ' ', M, N, -1, -1 ) )
  897. *
  898. IF( NX.LT.MINMN ) THEN
  899. *
  900. * Determine if workspace is large enough for blocked code.
  901. *
  902. IF( LWORK.LT.LWKOPT ) THEN
  903. *
  904. * Not enough workspace to use optimal block size that
  905. * is currently stored in NB.
  906. * Reduce NB and determine the minimum value of NB.
  907. *
  908. NB = ( LWORK-2*N ) / ( N+1 )
  909. NBMIN = MAX( 2, ILAENV( INBMIN, 'CGEQP3RK', ' ', M, N,
  910. $ -1, -1 ) )
  911. *
  912. END IF
  913. END IF
  914. END IF
  915. *
  916. * ==================================================================
  917. *
  918. * DONE is the boolean flag to rerpresent the case when the
  919. * factorization completed in the block factorization routine,
  920. * before the end of the block.
  921. *
  922. DONE = .FALSE.
  923. *
  924. * J is the column index.
  925. *
  926. J = 1
  927. *
  928. * (1) Use blocked code initially.
  929. *
  930. * JMAXB is the maximum column index of the block, when the
  931. * blocked code is used, is also limited by the first stopping
  932. * criterion KMAX.
  933. *
  934. JMAXB = MIN( KMAX, MINMN - NX )
  935. *
  936. IF( NB.GE.NBMIN .AND. NB.LT.JMAX .AND. JMAXB.GT.0 ) THEN
  937. *
  938. * Loop over the column blocks of the matrix A(1:M,1:JMAXB). Here:
  939. * J is the column index of a column block;
  940. * JB is the column block size to pass to block factorization
  941. * routine in a loop step;
  942. * JBF is the number of columns that were actually factorized
  943. * that was returned by the block factorization routine
  944. * in a loop step, JBF <= JB;
  945. * N_SUB is the number of columns in the submatrix;
  946. * IOFFSET is the number of rows that should not be factorized.
  947. *
  948. DO WHILE( J.LE.JMAXB )
  949. *
  950. JB = MIN( NB, JMAXB-J+1 )
  951. N_SUB = N-J+1
  952. IOFFSET = J-1
  953. *
  954. * Factorize JB columns among the columns A(J:N).
  955. *
  956. CALL CLAQP3RK( M, N_SUB, NRHS, IOFFSET, JB, ABSTOL,
  957. $ RELTOL, KP1, MAXC2NRM, A( 1, J ), LDA,
  958. $ DONE, JBF, MAXC2NRMK, RELMAXC2NRMK,
  959. $ JPIV( J ), TAU( J ),
  960. $ RWORK( J ), RWORK( N+J ),
  961. $ WORK( 1 ), WORK( JB+1 ),
  962. $ N+NRHS-J+1, IWORK, IINFO )
  963. *
  964. * Set INFO on the first occurence of Inf.
  965. *
  966. IF( IINFO.GT.N_SUB .AND. INFO.EQ.0 ) THEN
  967. INFO = 2*IOFFSET + IINFO
  968. END IF
  969. *
  970. IF( DONE ) THEN
  971. *
  972. * Either the submatrix is zero before the end of the
  973. * column block, or ABSTOL or RELTOL criterion is
  974. * satisfied before the end of the column block, we can
  975. * return from the routine. Perform the following before
  976. * returning:
  977. * a) Set the number of factorized columns K,
  978. * K = IOFFSET + JBF from the last call of blocked
  979. * routine.
  980. * NOTE: 1) MAXC2NRMK and RELMAXC2NRMK are returned
  981. * by the block factorization routine;
  982. * 2) The remaining TAUs are set to ZERO by the
  983. * block factorization routine.
  984. *
  985. K = IOFFSET + JBF
  986. *
  987. * Set INFO on the first occurrence of NaN, NaN takes
  988. * prcedence over Inf.
  989. *
  990. IF( IINFO.LE.N_SUB .AND. IINFO.GT.0 ) THEN
  991. INFO = IOFFSET + IINFO
  992. END IF
  993. *
  994. * Return from the routine.
  995. *
  996. WORK( 1 ) = SROUNDUP_LWORK( LWKOPT )
  997. *
  998. RETURN
  999. *
  1000. END IF
  1001. *
  1002. J = J + JBF
  1003. *
  1004. END DO
  1005. *
  1006. END IF
  1007. *
  1008. * Use unblocked code to factor the last or only block.
  1009. * J = JMAX+1 means we factorized the maximum possible number of
  1010. * columns, that is in ELSE clause we need to compute
  1011. * the MAXC2NORM and RELMAXC2NORM to return after we processed
  1012. * the blocks.
  1013. *
  1014. IF( J.LE.JMAX ) THEN
  1015. *
  1016. * N_SUB is the number of columns in the submatrix;
  1017. * IOFFSET is the number of rows that should not be factorized.
  1018. *
  1019. N_SUB = N-J+1
  1020. IOFFSET = J-1
  1021. *
  1022. CALL CLAQP2RK( M, N_SUB, NRHS, IOFFSET, JMAX-J+1,
  1023. $ ABSTOL, RELTOL, KP1, MAXC2NRM, A( 1, J ), LDA,
  1024. $ KF, MAXC2NRMK, RELMAXC2NRMK, JPIV( J ),
  1025. $ TAU( J ), RWORK( J ), RWORK( N+J ),
  1026. $ WORK( 1 ), IINFO )
  1027. *
  1028. * ABSTOL or RELTOL criterion is satisfied when the number of
  1029. * the factorized columns KF is smaller then the number
  1030. * of columns JMAX-J+1 supplied to be factorized by the
  1031. * unblocked routine, we can return from
  1032. * the routine. Perform the following before returning:
  1033. * a) Set the number of factorized columns K,
  1034. * b) MAXC2NRMK and RELMAXC2NRMK are returned by the
  1035. * unblocked factorization routine above.
  1036. *
  1037. K = J - 1 + KF
  1038. *
  1039. * Set INFO on the first exception occurence.
  1040. *
  1041. * Set INFO on the first exception occurence of Inf or NaN,
  1042. * (NaN takes precedence over Inf).
  1043. *
  1044. IF( IINFO.GT.N_SUB .AND. INFO.EQ.0 ) THEN
  1045. INFO = 2*IOFFSET + IINFO
  1046. ELSE IF( IINFO.LE.N_SUB .AND. IINFO.GT.0 ) THEN
  1047. INFO = IOFFSET + IINFO
  1048. END IF
  1049. *
  1050. ELSE
  1051. *
  1052. * Compute the return values for blocked code.
  1053. *
  1054. * Set the number of factorized columns if the unblocked routine
  1055. * was not called.
  1056. *
  1057. K = JMAX
  1058. *
  1059. * If there exits a residual matrix after the blocked code:
  1060. * 1) compute the values of MAXC2NRMK, RELMAXC2NRMK of the
  1061. * residual matrix, otherwise set them to ZERO;
  1062. * 2) Set TAU(K+1:MINMN) to ZERO.
  1063. *
  1064. IF( K.LT.MINMN ) THEN
  1065. JMAXC2NRM = K + ISAMAX( N-K, RWORK( K+1 ), 1 )
  1066. MAXC2NRMK = RWORK( JMAXC2NRM )
  1067. IF( K.EQ.0 ) THEN
  1068. RELMAXC2NRMK = ONE
  1069. ELSE
  1070. RELMAXC2NRMK = MAXC2NRMK / MAXC2NRM
  1071. END IF
  1072. *
  1073. DO J = K + 1, MINMN
  1074. TAU( J ) = CZERO
  1075. END DO
  1076. *
  1077. ELSE
  1078. MAXC2NRMK = ZERO
  1079. RELMAXC2NRMK = ZERO
  1080. *
  1081. END IF
  1082. *
  1083. * END IF( J.LE.JMAX ) THEN
  1084. *
  1085. END IF
  1086. *
  1087. WORK( 1 ) = SROUNDUP_LWORK( LWKOPT )
  1088. *
  1089. RETURN
  1090. *
  1091. * End of CGEQP3RK
  1092. *
  1093. END