OSDN Git Service

new repo
[bytom/vapor.git] / vendor / gonum.org / v1 / gonum / lapack / testlapack / dlapll.go
1 // Copyright ©2017 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         "testing"
9
10         "golang.org/x/exp/rand"
11
12         "gonum.org/v1/gonum/floats"
13         "gonum.org/v1/gonum/lapack"
14 )
15
16 type Dlapller interface {
17         Dgesvder
18         Dlapll(n int, x []float64, incX int, y []float64, incY int) float64
19 }
20
21 func DlapllTest(t *testing.T, impl Dlapller) {
22         rnd := rand.New(rand.NewSource(1))
23         for i, m := range []int{5, 6, 9, 300, 400, 600} {
24                 n := 2
25                 lda := n
26                 a := make([]float64, m*lda)
27                 for i := range a {
28                         a[i] = rnd.NormFloat64()
29                 }
30
31                 aCopy := make([]float64, len(a))
32                 copy(aCopy, a)
33
34                 got := impl.Dlapll(m, a[0:], 2, a[1:], 2)
35
36                 s := make([]float64, min(m, n))
37                 work := make([]float64, 1)
38                 impl.Dgesvd(lapack.SVDNone, lapack.SVDNone, m, n, aCopy, lda, s, nil, 0, nil, 0, work, -1)
39                 work = make([]float64, int(work[0]))
40                 impl.Dgesvd(lapack.SVDNone, lapack.SVDNone, m, n, aCopy, lda, s, nil, 0, nil, 0, work, len(work))
41                 want := s[len(s)-1]
42
43                 if !floats.EqualWithinAbsOrRel(got, want, 1e-14, 1e-14) {
44                         t.Errorf("unexpected ssmin for test %d: got:%f want:%f", i, got, want)
45                 }
46         }
47 }