LAPACK 3.12.0
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches

◆ classq()

subroutine classq ( integer  n,
complex(wp), dimension(*)  x,
integer  incx,
real(wp)  scale,
real(wp)  sumsq 
)

CLASSQ updates a sum of squares represented in scaled form.

Download CLASSQ + dependencies [TGZ] [ZIP] [TXT]

Purpose:
 CLASSQ returns the values scale_out and sumsq_out such that

    (scale_out**2)*sumsq_out = x( 1 )**2 +...+ x( n )**2 + (scale**2)*sumsq,

 where x( i ) = X( 1 + ( i - 1 )*INCX ). The value of sumsq is
 assumed to be non-negative.

 scale and sumsq must be supplied in SCALE and SUMSQ and
 scale_out and sumsq_out are overwritten on SCALE and SUMSQ respectively.
Parameters
[in]N
          N is INTEGER
          The number of elements to be used from the vector x.
[in]X
          X is COMPLEX array, dimension (1+(N-1)*abs(INCX))
          The vector for which a scaled sum of squares is computed.
             x( i ) = X( 1 + ( i - 1 )*INCX ), 1 <= i <= n.
[in]INCX
          INCX is INTEGER
          The increment between successive values of the vector x.
          If INCX > 0, X(1+(i-1)*INCX) = x(i) for 1 <= i <= n
          If INCX < 0, X(1-(n-i)*INCX) = x(i) for 1 <= i <= n
          If INCX = 0, x isn't a vector so there is no need to call
          this subroutine. If you call it anyway, it will count x(1)
          in the vector norm N times.
[in,out]SCALE
          SCALE is REAL
          On entry, the value scale in the equation above.
          On exit, SCALE is overwritten by scale_out, the scaling factor
          for the sum of squares.
[in,out]SUMSQ
          SUMSQ is REAL
          On entry, the value sumsq in the equation above.
          On exit, SUMSQ is overwritten by sumsq_out, the basic sum of
          squares from which scale_out has been factored out.
Author
Edward Anderson, Lockheed Martin
Contributors:
Weslley Pereira, University of Colorado Denver, USA Nick Papior, Technical University of Denmark, DK
Further Details:
  Anderson E. (2017)
  Algorithm 978: Safe Scaling in the Level 1 BLAS
  ACM Trans Math Softw 44:1--28
  https://doi.org/10.1145/3061665

  Blue, James L. (1978)
  A Portable Fortran Program to Find the Euclidean Norm of a Vector
  ACM Trans Math Softw 4:15--23
  https://doi.org/10.1145/355769.355771

Definition at line 123 of file classq.f90.

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
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...
Here is the caller graph for this function: