LAPACK  3.10.1
LAPACK: Linear Algebra PACKage
cqrt12.f
Go to the documentation of this file.
1 *> \brief \b CQRT12
2 *
3 * =========== DOCUMENTATION ===========
4 *
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
7 *
8 * Definition:
9 * ===========
10 *
11 * REAL FUNCTION CQRT12( M, N, A, LDA, S, WORK, LWORK,
12 * RWORK )
13 *
14 * .. Scalar Arguments ..
15 * INTEGER LDA, LWORK, M, N
16 * ..
17 * .. Array Arguments ..
18 * REAL RWORK( * ), S( * )
19 * COMPLEX A( LDA, * ), WORK( LWORK )
20 * ..
21 *
22 *
23 *> \par Purpose:
24 * =============
25 *>
26 *> \verbatim
27 *>
28 *> CQRT12 computes the singular values `svlues' of the upper trapezoid
29 *> of A(1:M,1:N) and returns the ratio
30 *>
31 *> || s - svlues||/(||svlues||*eps*max(M,N))
32 *> \endverbatim
33 *
34 * Arguments:
35 * ==========
36 *
37 *> \param[in] M
38 *> \verbatim
39 *> M is INTEGER
40 *> The number of rows of the matrix A.
41 *> \endverbatim
42 *>
43 *> \param[in] N
44 *> \verbatim
45 *> N is INTEGER
46 *> The number of columns of the matrix A.
47 *> \endverbatim
48 *>
49 *> \param[in] A
50 *> \verbatim
51 *> A is COMPLEX array, dimension (LDA,N)
52 *> The M-by-N matrix A. Only the upper trapezoid is referenced.
53 *> \endverbatim
54 *>
55 *> \param[in] LDA
56 *> \verbatim
57 *> LDA is INTEGER
58 *> The leading dimension of the array A.
59 *> \endverbatim
60 *>
61 *> \param[in] S
62 *> \verbatim
63 *> S is REAL array, dimension (min(M,N))
64 *> The singular values of the matrix A.
65 *> \endverbatim
66 *>
67 *> \param[out] WORK
68 *> \verbatim
69 *> WORK is COMPLEX array, dimension (LWORK)
70 *> \endverbatim
71 *>
72 *> \param[in] LWORK
73 *> \verbatim
74 *> LWORK is INTEGER
75 *> The length of the array WORK. LWORK >= M*N + 2*min(M,N) +
76 *> max(M,N).
77 *> \endverbatim
78 *>
79 *> \param[out] RWORK
80 *> \verbatim
81 *> RWORK is REAL array, dimension (4*min(M,N))
82 *> \endverbatim
83 *
84 * Authors:
85 * ========
86 *
87 *> \author Univ. of Tennessee
88 *> \author Univ. of California Berkeley
89 *> \author Univ. of Colorado Denver
90 *> \author NAG Ltd.
91 *
92 *> \ingroup complex_lin
93 *
94 * =====================================================================
95  REAL function cqrt12( m, n, a, lda, s, work, lwork,
96  $ rwork )
97 *
98 * -- LAPACK test routine --
99 * -- LAPACK is a software package provided by Univ. of Tennessee, --
100 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
101 *
102 * .. Scalar Arguments ..
103  INTEGER lda, lwork, m, n
104 * ..
105 * .. Array Arguments ..
106  REAL rwork( * ), s( * )
107  COMPLEX a( lda, * ), work( lwork )
108 * ..
109 *
110 * =====================================================================
111 *
112 * .. Parameters ..
113  REAL zero, one
114  parameter( zero = 0.0e0, one = 1.0e0 )
115 * ..
116 * .. Local Scalars ..
117  INTEGER i, info, iscl, j, mn
118  REAL anrm, bignum, nrmsvl, smlnum
119 * ..
120 * .. Local Arrays ..
121  REAL dummy( 1 )
122 * ..
123 * .. External Functions ..
124  REAL clange, sasum, slamch, snrm2
125  EXTERNAL clange, sasum, slamch, snrm2
126 * ..
127 * .. External Subroutines ..
128  EXTERNAL cgebd2, clascl, claset, saxpy, sbdsqr, slabad,
129  $ slascl, xerbla
130 * ..
131 * .. Intrinsic Functions ..
132  INTRINSIC cmplx, max, min, real
133 * ..
134 * .. Executable Statements ..
135 *
136  cqrt12 = zero
137 *
138 * Test that enough workspace is supplied
139 *
140  IF( lwork.LT.m*n+2*min( m, n )+max( m, n ) ) THEN
141  CALL xerbla( 'CQRT12', 7 )
142  RETURN
143  END IF
144 *
145 * Quick return if possible
146 *
147  mn = min( m, n )
148  IF( mn.LE.zero )
149  $ RETURN
150 *
151  nrmsvl = snrm2( mn, s, 1 )
152 *
153 * Copy upper triangle of A into work
154 *
155  CALL claset( 'Full', m, n, cmplx( zero ), cmplx( zero ), work, m )
156  DO 20 j = 1, n
157  DO 10 i = 1, min( j, m )
158  work( ( j-1 )*m+i ) = a( i, j )
159  10 CONTINUE
160  20 CONTINUE
161 *
162 * Get machine parameters
163 *
164  smlnum = slamch( 'S' ) / slamch( 'P' )
165  bignum = one / smlnum
166  CALL slabad( smlnum, bignum )
167 *
168 * Scale work if max entry outside range [SMLNUM,BIGNUM]
169 *
170  anrm = clange( 'M', m, n, work, m, dummy )
171  iscl = 0
172  IF( anrm.GT.zero .AND. anrm.LT.smlnum ) THEN
173 *
174 * Scale matrix norm up to SMLNUM
175 *
176  CALL clascl( 'G', 0, 0, anrm, smlnum, m, n, work, m, info )
177  iscl = 1
178  ELSE IF( anrm.GT.bignum ) THEN
179 *
180 * Scale matrix norm down to BIGNUM
181 *
182  CALL clascl( 'G', 0, 0, anrm, bignum, m, n, work, m, info )
183  iscl = 1
184  END IF
185 *
186  IF( anrm.NE.zero ) THEN
187 *
188 * Compute SVD of work
189 *
190  CALL cgebd2( m, n, work, m, rwork( 1 ), rwork( mn+1 ),
191  $ work( m*n+1 ), work( m*n+mn+1 ),
192  $ work( m*n+2*mn+1 ), info )
193  CALL sbdsqr( 'Upper', mn, 0, 0, 0, rwork( 1 ), rwork( mn+1 ),
194  $ dummy, mn, dummy, 1, dummy, mn, rwork( 2*mn+1 ),
195  $ info )
196 *
197  IF( iscl.EQ.1 ) THEN
198  IF( anrm.GT.bignum ) THEN
199  CALL slascl( 'G', 0, 0, bignum, anrm, mn, 1, rwork( 1 ),
200  $ mn, info )
201  END IF
202  IF( anrm.LT.smlnum ) THEN
203  CALL slascl( 'G', 0, 0, smlnum, anrm, mn, 1, rwork( 1 ),
204  $ mn, info )
205  END IF
206  END IF
207 *
208  ELSE
209 *
210  DO 30 i = 1, mn
211  rwork( i ) = zero
212  30 CONTINUE
213  END IF
214 *
215 * Compare s and singular values of work
216 *
217  CALL saxpy( mn, -one, s, 1, rwork( 1 ), 1 )
218  cqrt12 = sasum( mn, rwork( 1 ), 1 ) /
219  $ ( slamch( 'Epsilon' )*real( max( m, n ) ) )
220  IF( nrmsvl.NE.zero )
221  $ cqrt12 = cqrt12 / nrmsvl
222 *
223  RETURN
224 *
225 * End of CQRT12
226 *
227  END
subroutine slabad(SMALL, LARGE)
SLABAD
Definition: slabad.f:74
subroutine slascl(TYPE, KL, KU, CFROM, CTO, M, N, A, LDA, INFO)
SLASCL multiplies a general rectangular matrix by a real scalar defined as cto/cfrom.
Definition: slascl.f:143
subroutine xerbla(SRNAME, INFO)
XERBLA
Definition: xerbla.f:60
subroutine sbdsqr(UPLO, N, NCVT, NRU, NCC, D, E, VT, LDVT, U, LDU, C, LDC, WORK, INFO)
SBDSQR
Definition: sbdsqr.f:240
real function cqrt12(M, N, A, LDA, S, WORK, LWORK, RWORK)
CQRT12
Definition: cqrt12.f:97
real function clange(NORM, M, N, A, LDA, WORK)
CLANGE returns the value of the 1-norm, Frobenius norm, infinity-norm, or the largest absolute value ...
Definition: clange.f:115
subroutine cgebd2(M, N, A, LDA, D, E, TAUQ, TAUP, WORK, INFO)
CGEBD2 reduces a general matrix to bidiagonal form using an unblocked algorithm.
Definition: cgebd2.f:190
subroutine claset(UPLO, M, N, ALPHA, BETA, A, LDA)
CLASET initializes the off-diagonal elements and the diagonal elements of a matrix to given values.
Definition: claset.f:106
subroutine clascl(TYPE, KL, KU, CFROM, CTO, M, N, A, LDA, INFO)
CLASCL multiplies a general rectangular matrix by a real scalar defined as cto/cfrom.
Definition: clascl.f:143
real(wp) function snrm2(n, x, incx)
SNRM2
Definition: snrm2.f90:89
subroutine saxpy(N, SA, SX, INCX, SY, INCY)
SAXPY
Definition: saxpy.f:89
real function sasum(N, SX, INCX)
SASUM
Definition: sasum.f:72
real function slamch(CMACH)
SLAMCH
Definition: slamch.f:68