LAPACK 3.12.0 LAPACK: Linear Algebra PACKage
Searching...
No Matches
classq.f90
Go to the documentation of this file.
1
2!
3! =========== DOCUMENTATION ===========
4!
5! Online html documentation available at
6! http://www.netlib.org/lapack/explore-html/
7!
17!
18! Definition:
19! ===========
20!
21! SUBROUTINE CLASSQ( N, X, INCX, SCALE, SUMSQ )
22!
23! .. Scalar Arguments ..
24! INTEGER INCX, N
25! REAL SCALE, SUMSQ
26! ..
27! .. Array Arguments ..
28! COMPLEX X( * )
29! ..
30!
31!
33! =============
48!
49! Arguments:
50! ==========
51!
91!
92! Authors:
93! ========
94!
96!
98! ==================
102!
104! =====================
119!
121!
122! =====================================================================
123subroutine classq( n, x, incx, scale, sumsq )
124 use la_constants, &
125 only: wp=>sp, zero=>szero, one=>sone, &
126 sbig=>ssbig, ssml=>sssml, tbig=>stbig, tsml=>stsml
127 use la_xisnan
128!
129! -- LAPACK auxiliary routine --
130! -- LAPACK is a software package provided by Univ. of Tennessee, --
131! -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
132!
133! .. Scalar Arguments ..
134 integer :: incx, n
135 real(wp) :: scale, sumsq
136! ..
137! .. Array Arguments ..
138 complex(wp) :: x(*)
139! ..
140! .. Local Scalars ..
141 integer :: i, ix
142 logical :: notbig
143 real(wp) :: abig, amed, asml, ax, ymax, ymin
144! ..
145!
146! Quick return if possible
147!
148 if( la_isnan(scale) .or. la_isnan(sumsq) ) return
149 if( sumsq == zero ) scale = one
150 if( scale == zero ) then
151 scale = one
152 sumsq = zero
153 end if
154 if (n <= 0) then
155 return
156 end if
157!
158! Compute the sum of squares in 3 accumulators:
159! abig -- sums of squares scaled down to avoid overflow
160! asml -- sums of squares scaled up to avoid underflow
161! amed -- sums of squares that do not require scaling
162! The thresholds and multipliers are
163! tbig -- values bigger than this are scaled down by sbig
164! tsml -- values smaller than this are scaled up by ssml
165!
166 notbig = .true.
167 asml = zero
168 amed = zero
169 abig = zero
170 ix = 1
171 if( incx < 0 ) ix = 1 - (n-1)*incx
172 do i = 1, n
173 ax = abs(real(x(ix)))
174 if (ax > tbig) then
175 abig = abig + (ax*sbig)**2
176 notbig = .false.
177 else if (ax < tsml) then
178 if (notbig) asml = asml + (ax*ssml)**2
179 else
180 amed = amed + ax**2
181 end if
182 ax = abs(aimag(x(ix)))
183 if (ax > tbig) then
184 abig = abig + (ax*sbig)**2
185 notbig = .false.
186 else if (ax < tsml) then
187 if (notbig) asml = asml + (ax*ssml)**2
188 else
189 amed = amed + ax**2
190 end if
191 ix = ix + incx
192 end do
193!
194! Put the existing sum of squares into one of the accumulators
195!
196 if( sumsq > zero ) then
197 ax = scale*sqrt( sumsq )
198 if (ax > tbig) then
199 if (scale > one) then
200 scale = scale * sbig
201 abig = abig + scale * (scale * sumsq)
202 else
203 ! sumsq > tbig^2 => (sbig * (sbig * sumsq)) is representable
204 abig = abig + scale * (scale * (sbig * (sbig * sumsq)))
205 end if
206 else if (ax < tsml) then
207 if (notbig) then
208 if (scale < one) then
209 scale = scale * ssml
210 asml = asml + scale * (scale * sumsq)
211 else
212 ! sumsq < tsml^2 => (ssml * (ssml * sumsq)) is representable
213 asml = asml + scale * (scale * (ssml * (ssml * sumsq)))
214 end if
215 end if
216 else
217 amed = amed + scale * (scale * sumsq)
218 end if
219 end if
220!
221! Combine abig and amed or amed and asml if more than one
222! accumulator was used.
223!
224 if (abig > zero) then
225!
226! Combine abig and amed if abig > 0.
227!
228 if (amed > zero .or. la_isnan(amed)) then
229 abig = abig + (amed*sbig)*sbig
230 end if
231 scale = one / sbig
232 sumsq = abig
233 else if (asml > zero) then
234!
235! Combine amed and asml if asml > 0.
236!
237 if (amed > zero .or. la_isnan(amed)) then
238 amed = sqrt(amed)
239 asml = sqrt(asml) / ssml
240 if (asml > amed) then
241 ymin = amed
242 ymax = asml
243 else
244 ymin = asml
245 ymax = amed
246 end if
247 scale = one
248 sumsq = ymax**2*( one + (ymin/ymax)**2 )
249 else
250 scale = one / ssml
251 sumsq = asml
252 end if
253 else
254!
255! Otherwise all values are mid-range or zero
256!
257 scale = one
258 sumsq = amed
259 end if
260 return
261end subroutine
subroutine classq(n, x, incx, scale, sumsq)
CLASSQ updates a sum of squares represented in scaled form.
Definition classq.f90:124
real(sp), parameter stbig
real(sp), parameter sssml
real(sp), parameter sone
real(sp), parameter stsml
real(sp), parameter ssbig
integer, parameter sp
real(sp), parameter szero
LA_CONSTANTS is a module for the scaling constants for the compiled Fortran single and double precisi...