LAPACK  3.8.0
LAPACK: Linear Algebra PACKage
sqrt04.f
Go to the documentation of this file.
1 *> \brief \b SQRT04
2 *
3 * =========== DOCUMENTATION ===========
4 *
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
7 *
8 * Definition:
9 * ===========
10 *
11 * SUBROUTINE SQRT04(M,N,NB,RESULT)
12 *
13 * .. Scalar Arguments ..
14 * INTEGER M, N, NB, LDT
15 * .. Return values ..
16 * REAL RESULT(6)
17 *
18 *
19 *> \par Purpose:
20 * =============
21 *>
22 *> \verbatim
23 *>
24 *> SQRT04 tests SGEQRT and SGEMQRT.
25 *> \endverbatim
26 *
27 * Arguments:
28 * ==========
29 *
30 *> \param[in] M
31 *> \verbatim
32 *> M is INTEGER
33 *> Number of rows in test matrix.
34 *> \endverbatim
35 *>
36 *> \param[in] N
37 *> \verbatim
38 *> N is INTEGER
39 *> Number of columns in test matrix.
40 *> \endverbatim
41 *>
42 *> \param[in] NB
43 *> \verbatim
44 *> NB is INTEGER
45 *> Block size of test matrix. NB <= Min(M,N).
46 *> \endverbatim
47 *>
48 *> \param[out] RESULT
49 *> \verbatim
50 *> RESULT is REAL array, dimension (6)
51 *> Results of each of the six tests below.
52 *>
53 *> RESULT(1) = | A - Q R |
54 *> RESULT(2) = | I - Q^H Q |
55 *> RESULT(3) = | Q C - Q C |
56 *> RESULT(4) = | Q^H C - Q^H C |
57 *> RESULT(5) = | C Q - C Q |
58 *> RESULT(6) = | C Q^H - C Q^H |
59 *> \endverbatim
60 *
61 * Authors:
62 * ========
63 *
64 *> \author Univ. of Tennessee
65 *> \author Univ. of California Berkeley
66 *> \author Univ. of Colorado Denver
67 *> \author NAG Ltd.
68 *
69 *> \date April 2012
70 *
71 *> \ingroup single_lin
72 *
73 * =====================================================================
74  SUBROUTINE sqrt04(M,N,NB,RESULT)
75  IMPLICIT NONE
76 *
77 * -- LAPACK test routine (version 3.8.0) --
78 * -- LAPACK is a software package provided by Univ. of Tennessee, --
79 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
80 * April 2012
81 *
82 * .. Scalar Arguments ..
83  INTEGER M, N, NB, LDT
84 * .. Return values ..
85  REAL RESULT(6)
86 *
87 * =====================================================================
88 *
89 * ..
90 * .. Local allocatable arrays
91  REAL, ALLOCATABLE :: AF(:,:), Q(:,:),
92  $ r(:,:), rwork(:), work( : ), t(:,:),
93  $ cf(:,:), df(:,:), a(:,:), c(:,:), d(:,:)
94 *
95 * .. Parameters ..
96  REAL ONE, ZERO
97  parameter( zero = 0.0, one = 1.0 )
98 * ..
99 * .. Local Scalars ..
100  INTEGER INFO, J, K, L, LWORK
101  REAL ANORM, EPS, RESID, CNORM, DNORM
102 * ..
103 * .. Local Arrays ..
104  INTEGER ISEED( 4 )
105 * ..
106 * .. External Subroutine ..
107  EXTERNAL sgemm, slacpy, slarnv, sgemqrt, slaset, sgeqrt, ssyrk
108 * ..
109 * .. External Functions ..
110  REAL SLAMCH
111  REAL SLANGE, SLANSY
112  LOGICAL LSAME
113  EXTERNAL slamch, slange, slansy, lsame
114 * ..
115 * .. Intrinsic Functions ..
116  INTRINSIC max, min
117 * ..
118 * .. Data statements ..
119  DATA iseed / 1988, 1989, 1990, 1991 /
120 *
121  eps = slamch( 'Epsilon' )
122  k = min(m,n)
123  l = max(m,n)
124  lwork = max(2,l)*max(2,l)*nb
125 *
126 * Dynamically allocate local arrays
127 *
128  ALLOCATE ( a(m,n), af(m,n), q(m,m), r(m,l), rwork(l),
129  $ work(lwork), t(nb,n), c(m,n), cf(m,n),
130  $ d(n,m), df(n,m) )
131 *
132 * Put random numbers into A and copy to AF
133 *
134  ldt=nb
135  DO j=1,n
136  CALL slarnv( 2, iseed, m, a( 1, j ) )
137  END DO
138  CALL slacpy( 'Full', m, n, a, m, af, m )
139 *
140 * Factor the matrix A in the array AF.
141 *
142  CALL sgeqrt( m, n, nb, af, m, t, ldt, work, info )
143 *
144 * Generate the m-by-m matrix Q
145 *
146  CALL slaset( 'Full', m, m, zero, one, q, m )
147  CALL sgemqrt( 'R', 'N', m, m, k, nb, af, m, t, ldt, q, m,
148  $ work, info )
149 *
150 * Copy R
151 *
152  CALL slaset( 'Full', m, n, zero, zero, r, m )
153  CALL slacpy( 'Upper', m, n, af, m, r, m )
154 *
155 * Compute |R - Q'*A| / |A| and store in RESULT(1)
156 *
157  CALL sgemm( 'T', 'N', m, n, m, -one, q, m, a, m, one, r, m )
158  anorm = slange( '1', m, n, a, m, rwork )
159  resid = slange( '1', m, n, r, m, rwork )
160  IF( anorm.GT.zero ) THEN
161  result( 1 ) = resid / (eps*max(1,m)*anorm)
162  ELSE
163  result( 1 ) = zero
164  END IF
165 *
166 * Compute |I - Q'*Q| and store in RESULT(2)
167 *
168  CALL slaset( 'Full', m, m, zero, one, r, m )
169  CALL ssyrk( 'U', 'C', m, m, -one, q, m, one, r, m )
170  resid = slansy( '1', 'Upper', m, r, m, rwork )
171  result( 2 ) = resid / (eps*max(1,m))
172 *
173 * Generate random m-by-n matrix C and a copy CF
174 *
175  DO j=1,n
176  CALL slarnv( 2, iseed, m, c( 1, j ) )
177  END DO
178  cnorm = slange( '1', m, n, c, m, rwork)
179  CALL slacpy( 'Full', m, n, c, m, cf, m )
180 *
181 * Apply Q to C as Q*C
182 *
183  CALL sgemqrt( 'L', 'N', m, n, k, nb, af, m, t, nb, cf, m,
184  $ work, info)
185 *
186 * Compute |Q*C - Q*C| / |C|
187 *
188  CALL sgemm( 'N', 'N', m, n, m, -one, q, m, c, m, one, cf, m )
189  resid = slange( '1', m, n, cf, m, rwork )
190  IF( cnorm.GT.zero ) THEN
191  result( 3 ) = resid / (eps*max(1,m)*cnorm)
192  ELSE
193  result( 3 ) = zero
194  END IF
195 *
196 * Copy C into CF again
197 *
198  CALL slacpy( 'Full', m, n, c, m, cf, m )
199 *
200 * Apply Q to C as QT*C
201 *
202  CALL sgemqrt( 'L', 'T', m, n, k, nb, af, m, t, nb, cf, m,
203  $ work, info)
204 *
205 * Compute |QT*C - QT*C| / |C|
206 *
207  CALL sgemm( 'T', 'N', m, n, m, -one, q, m, c, m, one, cf, m )
208  resid = slange( '1', m, n, cf, m, rwork )
209  IF( cnorm.GT.zero ) THEN
210  result( 4 ) = resid / (eps*max(1,m)*cnorm)
211  ELSE
212  result( 4 ) = zero
213  END IF
214 *
215 * Generate random n-by-m matrix D and a copy DF
216 *
217  DO j=1,m
218  CALL slarnv( 2, iseed, n, d( 1, j ) )
219  END DO
220  dnorm = slange( '1', n, m, d, n, rwork)
221  CALL slacpy( 'Full', n, m, d, n, df, n )
222 *
223 * Apply Q to D as D*Q
224 *
225  CALL sgemqrt( 'R', 'N', n, m, k, nb, af, m, t, nb, df, n,
226  $ work, info)
227 *
228 * Compute |D*Q - D*Q| / |D|
229 *
230  CALL sgemm( 'N', 'N', n, m, m, -one, d, n, q, m, one, df, n )
231  resid = slange( '1', n, m, df, n, rwork )
232  IF( cnorm.GT.zero ) THEN
233  result( 5 ) = resid / (eps*max(1,m)*dnorm)
234  ELSE
235  result( 5 ) = zero
236  END IF
237 *
238 * Copy D into DF again
239 *
240  CALL slacpy( 'Full', n, m, d, n, df, n )
241 *
242 * Apply Q to D as D*QT
243 *
244  CALL sgemqrt( 'R', 'T', n, m, k, nb, af, m, t, nb, df, n,
245  $ work, info)
246 *
247 * Compute |D*QT - D*QT| / |D|
248 *
249  CALL sgemm( 'N', 'T', n, m, m, -one, d, n, q, m, one, df, n )
250  resid = slange( '1', n, m, df, n, rwork )
251  IF( cnorm.GT.zero ) THEN
252  result( 6 ) = resid / (eps*max(1,m)*dnorm)
253  ELSE
254  result( 6 ) = zero
255  END IF
256 *
257 * Deallocate all arrays
258 *
259  DEALLOCATE ( a, af, q, r, rwork, work, t, c, d, cf, df)
260 *
261  RETURN
262  END
263 
subroutine sqrt04(M, N, NB, RESULT)
SQRT04
Definition: sqrt04.f:75
subroutine sgeqrt(M, N, NB, A, LDA, T, LDT, WORK, INFO)
SGEQRT
Definition: sgeqrt.f:143
subroutine ssyrk(UPLO, TRANS, N, K, ALPHA, A, LDA, BETA, C, LDC)
SSYRK
Definition: ssyrk.f:171
subroutine sgemm(TRANSA, TRANSB, M, N, K, ALPHA, A, LDA, B, LDB, BETA, C, LDC)
SGEMM
Definition: sgemm.f:189
subroutine slaset(UPLO, M, N, ALPHA, BETA, A, LDA)
SLASET initializes the off-diagonal elements and the diagonal elements of a matrix to given values...
Definition: slaset.f:112
subroutine slarnv(IDIST, ISEED, N, X)
SLARNV returns a vector of random numbers from a uniform or normal distribution.
Definition: slarnv.f:99
subroutine slacpy(UPLO, M, N, A, LDA, B, LDB)
SLACPY copies all or part of one two-dimensional array to another.
Definition: slacpy.f:105
subroutine sgemqrt(SIDE, TRANS, M, N, K, NB, V, LDV, T, LDT, C, LDC, WORK, INFO)
SGEMQRT
Definition: sgemqrt.f:170