1 // Copyright ©2016 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.
11 "golang.org/x/exp/rand"
13 "gonum.org/v1/gonum/blas"
14 "gonum.org/v1/gonum/blas/blas64"
17 type Dlacn2er interface {
18 Dlacn2(n int, v, x []float64, isgn []int, est float64, kase int, isave *[3]int) (float64, int)
21 func Dlacn2Test(t *testing.T, impl Dlacn2er) {
22 rnd := rand.New(rand.NewSource(1))
23 for _, n := range []int{1, 2, 3, 4, 5, 7, 10, 15, 20, 100} {
24 for cas := 0; cas < 10; cas++ {
25 a := randomGeneral(n, n, n, rnd)
27 // Compute the 1-norm of A explicitly.
29 for j := 0; j < n; j++ {
31 for i := 0; i < n; i++ {
32 sum += math.Abs(a.Data[i*a.Stride+j])
39 // Compute the estimate of 1-norm using Dlanc2.
40 x := make([]float64, n)
41 work := make([]float64, n)
42 v := make([]float64, n)
43 isgn := make([]int, n)
51 got, kase = impl.Dlacn2(n, v, x, isgn, got, kase, &isave)
54 panic("Dlacn2 returned invalid value of kase")
58 blas64.Gemv(blas.NoTrans, 1, a, blas64.Vector{1, x}, 0, blas64.Vector{1, work})
61 blas64.Gemv(blas.Trans, 1, a, blas64.Vector{1, x}, 0, blas64.Vector{1, work})
66 // Check that got is either accurate enough or a
67 // lower estimate of the 1-norm of A.
68 if math.Abs(got-norm1) > 1e-8 && got > norm1 {
69 t.Errorf("Case n=%v: not lower estimate. 1-norm %v, estimate %v", n, norm1, got)