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

◆ slassq()

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

SLASSQ updates a sum of squares represented in scaled form.

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