LAPACK  3.10.0
LAPACK: Linear Algebra PACKage

◆ dlassq()

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

DLASSQ updates a sum of squares represented in scaled form.

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

Purpose:
 DLASSQ  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 PRECISION 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.
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 125 of file dlassq.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  real(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(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  ix = ix + incx
185  end do
186 !
187 ! Put the existing sum of squares into one of the accumulators
188 !
189  if( sumsq > zero ) then
190  ax = scl*sqrt( sumsq )
191  if (ax > tbig) then
192  abig = abig + (ax*sbig)**2
193  notbig = .false.
194  else if (ax < tsml) then
195  if (notbig) asml = asml + (ax*ssml)**2
196  else
197  amed = amed + ax**2
198  end if
199  end if
200 !
201 ! Combine abig and amed or amed and asml if more than one
202 ! accumulator was used.
203 !
204  if (abig > zero) then
205 !
206 ! Combine abig and amed if abig > 0.
207 !
208  if (amed > zero .or. la_isnan(amed)) then
209  abig = abig + (amed*sbig)*sbig
210  end if
211  scl = one / sbig
212  sumsq = abig
213  else if (asml > zero) then
214 !
215 ! Combine amed and asml if asml > 0.
216 !
217  if (amed > zero .or. la_isnan(amed)) then
218  amed = sqrt(amed)
219  asml = sqrt(asml) / ssml
220  if (asml > amed) then
221  ymin = amed
222  ymax = asml
223  else
224  ymin = asml
225  ymax = amed
226  end if
227  scl = one
228  sumsq = ymax**2*( one + (ymin/ymax)**2 )
229  else
230  scl = one / ssml
231  sumsq = asml
232  end if
233  else
234 !
235 ! Otherwise all values are mid-range or zero
236 !
237  scl = one
238  sumsq = amed
239  end if
240  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: