github.com/gonum/lapack@v0.0.0-20181123203213-e4cdc5a0bff9/native/dlassq.go (about) 1 // Copyright ©2015 The gonum Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package native 6 7 import "math" 8 9 // Dlassq updates a sum of squares in scaled form. The input parameters scale and 10 // sumsq represent the current scale and total sum of squares. These values are 11 // updated with the information in the first n elements of the vector specified 12 // by x and incX. 13 // 14 // Dlassq is an internal routine. It is exported for testing purposes. 15 func (impl Implementation) Dlassq(n int, x []float64, incx int, scale float64, sumsq float64) (scl, smsq float64) { 16 if n <= 0 { 17 return scale, sumsq 18 } 19 for ix := 0; ix <= (n-1)*incx; ix += incx { 20 absxi := math.Abs(x[ix]) 21 if absxi > 0 || math.IsNaN(absxi) { 22 if scale < absxi { 23 sumsq = 1 + sumsq*(scale/absxi)*(scale/absxi) 24 scale = absxi 25 } else { 26 sumsq += (absxi / scale) * (absxi / scale) 27 } 28 } 29 } 30 return scale, sumsq 31 }