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.
9 // Dlasv2 computes the singular value decomposition of a 2×2 matrix.
10 // [ csl snl] [f g] [csr -snr] = [ssmax 0]
11 // [-snl csl] [0 h] [snr csr] = [ 0 ssmin]
12 // ssmax is the larger absolute singular value, and ssmin is the smaller absolute
13 // singular value. [cls, snl] and [csr, snr] are the left and right singular vectors.
15 // Dlasv2 is an internal routine. It is exported for testing purposes.
16 func (impl Implementation) Dlasv2(f, g, h float64) (ssmin, ssmax, snr, csr, snl, csl float64) {
21 // pmax points to the largest element of the matrix in terms of absolute value.
22 // 1 if F, 2 if G, 3 if H.
32 var clt, crt, slt, srt float64
44 if (fa / ga) < dlamchE {
48 ssmin = fa / (ga / ha)
50 ssmin = (fa / ga) * ha
61 if d == fa { // deal with inf
78 t = math.Copysign(2, ft) * math.Copysign(1, gt)
80 t = gt/math.Copysign(d, ft) + m/t
83 t = (m/(s+t) + m/(r+l)) * (1 + a)
88 clt = (crt + srt*m) / a
89 slt = (ht / ft) * srt / a
106 tsign = math.Copysign(1, csr) * math.Copysign(1, csl) * math.Copysign(1, f)
108 tsign = math.Copysign(1, snr) * math.Copysign(1, csl) * math.Copysign(1, g)
110 tsign = math.Copysign(1, snr) * math.Copysign(1, snl) * math.Copysign(1, h)
112 ssmax = math.Copysign(ssmax, tsign)
113 ssmin = math.Copysign(ssmin, tsign*math.Copysign(1, f)*math.Copysign(1, h))
114 return ssmin, ssmax, snr, csr, snl, csl