LAPACK  3.10.1 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.

scale and sumsq must be supplied in SCALE and SUMSQ and
scl and smsq are overwritten on SCALE and SUMSQ respectively.

If scale * sqrt( sumsq ) > tbig then
we require:   scale >= sqrt( TINY*EPS ) / sbig   on entry,
and if 0 < scale * sqrt( sumsq ) < tsml then
we require:   scale <= sqrt( HUGE ) / ssml       on entry,
where
tbig -- upper threshold for values whose square is representable;
sbig -- scaling constant for big numbers; \see la_constants.f90
tsml -- lower threshold for values whose square is representable;
ssml -- scaling constant for small numbers; \see la_constants.f90
and
TINY*EPS -- tiniest representable number;
HUGE     -- biggest representable number.```
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 136 of file zlassq.f90.

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