LAPACK  3.10.0 LAPACK: Linear Algebra PACKage

## ◆ zlassq()

 subroutine zlassq ( integer n, complex(wp), dimension(*) x, integer incx, real(wp) scl, real(wp) sumsq )

ZLASSQ updates a sum of squares represented in scaled form.

Purpose:
``` ZLASSQ  returns the values  scl  and  smsq  such that

( scl**2 )*smsq = 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 and  scl  returns the value

scl = max( scale, abs( x( i ) ) ).

scale and sumsq must be supplied in SCALE and SUMSQ and
scl and smsq 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 DOUBLE 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 DOUBLE PRECISION On entry, the value scale in the equation above. On exit, SCALE is overwritten with scl , the scaling factor for the sum of squares.``` [in,out] SUMSQ ``` SUMSQ is DOUBLE PRECISION On entry, the value sumsq in the equation above. On exit, SUMSQ is overwritten with smsq , the basic sum of squares from which scl has been factored out.```
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 125 of file zlassq.f90.

126  use la_constants, &
127  only: wp=>dp, zero=>dzero, one=>done, &
128  sbig=>dsbig, ssml=>dssml, tbig=>dtbig, tsml=>dtsml
129  use la_xisnan
130 !
131 ! -- LAPACK auxiliary routine --
132 ! -- LAPACK is a software package provided by Univ. of Tennessee, --
133 ! -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
134 !
135 ! .. Scalar Arguments ..
136  integer :: incx, n
137  real(wp) :: scl, sumsq
138 ! ..
139 ! .. Array Arguments ..
140  complex(wp) :: x(*)
141 ! ..
142 ! .. Local Scalars ..
143  integer :: i, ix
144  logical :: notbig
145  real(wp) :: abig, amed, asml, ax, ymax, ymin
146 ! ..
147 !
148 ! Quick return if possible
149 !
150  if( la_isnan(scl) .or. la_isnan(sumsq) ) return
151  if( sumsq == zero ) scl = one
152  if( scl == zero ) then
153  scl = one
154  sumsq = zero
155  end if
156  if (n <= 0) then
157  return
158  end if
159 !
160 ! Compute the sum of squares in 3 accumulators:
161 ! abig -- sums of squares scaled down to avoid overflow
162 ! asml -- sums of squares scaled up to avoid underflow
163 ! amed -- sums of squares that do not require scaling
164 ! The thresholds and multipliers are
165 ! tbig -- values bigger than this are scaled down by sbig
166 ! tsml -- values smaller than this are scaled up by ssml
167 !
168  notbig = .true.
169  asml = zero
170  amed = zero
171  abig = zero
172  ix = 1
173  if( incx < 0 ) ix = 1 - (n-1)*incx
174  do i = 1, n
175  ax = abs(real(x(ix)))
176  if (ax > tbig) then
177  abig = abig + (ax*sbig)**2
178  notbig = .false.
179  else if (ax < tsml) then
180  if (notbig) asml = asml + (ax*ssml)**2
181  else
182  amed = amed + ax**2
183  end if
184  ax = abs(aimag(x(ix)))
185  if (ax > tbig) then
186  abig = abig + (ax*sbig)**2
187  notbig = .false.
188  else if (ax < tsml) then
189  if (notbig) asml = asml + (ax*ssml)**2
190  else
191  amed = amed + ax**2
192  end if
193  ix = ix + incx
194  end do
195 !
196 ! Put the existing sum of squares into one of the accumulators
197 !
198  if( sumsq > zero ) then
199  ax = scl*sqrt( sumsq )
200  if (ax > tbig) then
201  abig = abig + (ax*sbig)**2
202  notbig = .false.
203  else if (ax < tsml) then
204  if (notbig) asml = asml + (ax*ssml)**2
205  else
206  amed = amed + ax**2
207  end if
208  end if
209 !
210 ! Combine abig and amed or amed and asml if more than one
211 ! accumulator was used.
212 !
213  if (abig > zero) then
214 !
215 ! Combine abig and amed if abig > 0.
216 !
217  if (amed > zero .or. la_isnan(amed)) then
218  abig = abig + (amed*sbig)*sbig
219  end if
220  scl = one / sbig
221  sumsq = abig
222  else if (asml > zero) then
223 !
224 ! Combine amed and asml if asml > 0.
225 !
226  if (amed > zero .or. la_isnan(amed)) then
227  amed = sqrt(amed)
228  asml = sqrt(asml) / ssml
229  if (asml > amed) then
230  ymin = amed
231  ymax = asml
232  else
233  ymin = asml
234  ymax = amed
235  end if
236  scl = one
237  sumsq = ymax**2*( one + (ymin/ymax)**2 )
238  else
239  scl = one / ssml
240  sumsq = asml
241  end if
242  else
243 !
244 ! Otherwise all values are mid-range or zero
245 !
246  scl = one
247  sumsq = amed
248  end if
249  return
real(dp), parameter dtsml
real(dp), parameter dzero
real(dp), parameter dsbig
integer, parameter dp
real(dp), parameter done
real(dp), parameter dtbig
real(dp), parameter dssml
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: