github.com/gonum/lapack@v0.0.0-20181123203213-e4cdc5a0bff9/testlapack/dlasv2.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 testlapack 6 7 import ( 8 "math/rand" 9 "testing" 10 11 "github.com/gonum/floats" 12 ) 13 14 type Dlasv2er interface { 15 Dlasv2(f, g, h float64) (ssmin, ssmax, snr, csr, snl, csl float64) 16 } 17 18 func Dlasv2Test(t *testing.T, impl Dlasv2er) { 19 rnd := rand.New(rand.NewSource(1)) 20 for i := 0; i < 100; i++ { 21 f := rnd.NormFloat64() 22 g := rnd.NormFloat64() 23 h := rnd.NormFloat64() 24 25 ssmin, ssmax, snr, csr, snl, csl := impl.Dlasv2(f, g, h) 26 27 // tmp = 28 // [ csl snl] [f g] 29 // [-snl csl] [0 h] 30 tmp11 := csl * f 31 tmp12 := csl*g + snl*h 32 tmp21 := -snl * f 33 tmp22 := -snl*g + csl*h 34 // lhs = 35 // [tmp11 tmp12] [csr -snr] 36 // [tmp21 tmp22] [snr csr] 37 ans11 := tmp11*csr + tmp12*snr 38 ans12 := tmp11*-snr + tmp12*csr 39 ans21 := tmp21*csr + tmp22*snr 40 ans22 := tmp21*-snr + tmp22*csr 41 42 lhs := []float64{ans11, ans12, ans21, ans22} 43 rhs := []float64{ssmax, 0, 0, ssmin} 44 if !floats.EqualApprox(rhs, lhs, 1e-12) { 45 t.Errorf("SVD mismatch. f = %v, g = %v, h = %v.\nLHS: %v\nRHS: %v", f, g, h, lhs, rhs) 46 } 47 } 48 }