github.com/gonum/lapack@v0.0.0-20181123203213-e4cdc5a0bff9/testlapack/dlapll.go (about)

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