LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
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.

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

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.
!> 
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 121 of file slassq.f90.

122 use la_constants, &
123 only: wp=>sp, zero=>szero, one=>sone, &
124 sbig=>ssbig, ssml=>sssml, tbig=>stbig, tsml=>stsml
125 use la_xisnan
126!
127! -- LAPACK auxiliary routine --
128! -- LAPACK is a software package provided by Univ. of Tennessee, --
129! -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
130!
131! .. Scalar Arguments ..
132 integer :: incx, n
133 real(wp) :: scale, sumsq
134! ..
135! .. Array Arguments ..
136 real(wp) :: x(*)
137! ..
138! .. Local Scalars ..
139 integer :: i, ix
140 logical :: notbig
141 real(wp) :: abig, amed, asml, ax, ymax, ymin
142! ..
143!
144! Quick return if possible
145!
146 if( la_isnan(scale) .or. la_isnan(sumsq) ) return
147 if( sumsq == zero ) scale = one
148 if( scale == zero ) then
149 scale = one
150 sumsq = zero
151 end if
152 if (n <= 0) then
153 return
154 end if
155!
156! Compute the sum of squares in 3 accumulators:
157! abig -- sums of squares scaled down to avoid overflow
158! asml -- sums of squares scaled up to avoid underflow
159! amed -- sums of squares that do not require scaling
160! The thresholds and multipliers are
161! tbig -- values bigger than this are scaled down by sbig
162! tsml -- values smaller than this are scaled up by ssml
163!
164 notbig = .true.
165 asml = zero
166 amed = zero
167 abig = zero
168 ix = 1
169 if( incx < 0 ) ix = 1 - (n-1)*incx
170 do i = 1, n
171 ax = abs(x(ix))
172 if (ax > tbig) then
173 abig = abig + (ax*sbig)**2
174 notbig = .false.
175 else if (ax < tsml) then
176 if (notbig) asml = asml + (ax*ssml)**2
177 else
178 amed = amed + ax**2
179 end if
180 ix = ix + incx
181 end do
182!
183! Put the existing sum of squares into one of the accumulators
184!
185 if( sumsq > zero ) then
186 ax = scale*sqrt( sumsq )
187 if (ax > tbig) then
188 if (scale > one) then
189 scale = scale * sbig
190 abig = abig + scale * (scale * sumsq)
191 else
192 ! sumsq > tbig^2 => (sbig * (sbig * sumsq)) is representable
193 abig = abig + scale * (scale * (sbig * (sbig * sumsq)))
194 end if
195 else if (ax < tsml) then
196 if (notbig) then
197 if (scale < one) then
198 scale = scale * ssml
199 asml = asml + scale * (scale * sumsq)
200 else
201 ! sumsq < tsml^2 => (ssml * (ssml * sumsq)) is representable
202 asml = asml + scale * (scale * (ssml * (ssml * sumsq)))
203 end if
204 end if
205 else
206 amed = amed + scale * (scale * sumsq)
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 scale = 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 scale = one
237 sumsq = ymax**2*( one + (ymin/ymax)**2 )
238 else
239 scale = one / ssml
240 sumsq = asml
241 end if
242 else
243!
244! Otherwise all values are mid-range or zero
245!
246 scale = one
247 sumsq = amed
248 end if
249 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: