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.
5 // dlahr2test generates test data for Dlahr2. Test cases are stored in
6 // gzip-compressed JSON file testlapack/testdata/dlahr2data.json.gz which is
7 // read during testing by testlapack/dlahr2.go.
9 // This program uses cgo to call Fortran version of DLAHR2. Therefore, matrices
10 // passed to the Fortran routine are in column-major format but are written into
11 // the output file in row-major format.
21 "golang.org/x/exp/rand"
23 "gonum.org/v1/gonum/lapack/internal/testdata/netlib"
26 type Dlahr2Test struct {
37 file, err := os.Create(filepath.FromSlash("../../../testlapack/testdata/dlahr2data.json.gz"))
42 w := gzip.NewWriter(file)
44 rnd := rand.New(rand.NewSource(1))
46 var tests []Dlahr2Test
47 for _, n := range []int{4, 5, 6, 7, 11} {
48 for k := 0; k <= n/2; k++ {
49 for nb := 1; nb <= k; nb++ {
50 ain := genrand(n, n-k+1, rnd)
51 a := make([]float64, len(ain))
54 t := genrand(nb, nb, rnd)
55 y := genrand(n, nb, rnd)
56 tau := genrand(nb, 1, rnd)
58 netlib.Dlahr2(n, k, nb, a, n, tau, t, nb, y, n)
60 tests = append(tests, Dlahr2Test{
64 A: rowMajor(n, n-k+1, ain),
65 AWant: rowMajor(n, n-k+1, a),
66 TWant: rowMajor(nb, nb, t),
67 YWant: rowMajor(n, nb, y),
73 json.NewEncoder(w).Encode(tests)
81 // genrand returns a general r×c matrix with random entries.
82 func genrand(r, c int, rnd *rand.Rand) []float64 {
83 m := make([]float64, r*c)
85 m[i] = rnd.NormFloat64()
90 // rowMajor returns the given r×c column-major matrix a in row-major format.
91 func rowMajor(r, c int, a []float64) []float64 {
93 panic("testdata: slice length mismatch")
95 m := make([]float64, len(a))
96 for i := 0; i < r; i++ {
97 for j := 0; j < c; j++ {