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/floats"
16 type Dlaqr1er interface {
17 Dlaqr1(n int, h []float64, ldh int, sr1, si1, sr2, si2 float64, v []float64)
20 func Dlaqr1Test(t *testing.T, impl Dlaqr1er) {
21 rnd := rand.New(rand.NewSource(1))
23 for _, n := range []int{2, 3} {
24 for _, ldh := range []int{n, n + 1, n + 10} {
25 for _, cas := range []int{1, 2} {
26 for k := 0; k < 100; k++ {
27 v := make([]float64, n)
31 h := make([]float64, n*(n-1)*ldh)
35 for i := 0; i < n; i++ {
36 for j := 0; j < n; j++ {
37 h[i*ldh+j] = rnd.NormFloat64()
40 var sr1, sr2, si1, si2 float64
42 sr1 = rnd.NormFloat64()
44 si1 = rnd.NormFloat64()
47 sr1 = rnd.NormFloat64()
48 sr2 = rnd.NormFloat64()
52 impl.Dlaqr1(n, h, ldh, sr1, si1, sr2, si2, v)
55 h1 := make([]complex128, n*n)
56 for i := 0; i < n; i++ {
57 for j := 0; j < n; j++ {
58 h1[i*n+j] = complex(h[i*ldh+j], 0)
60 h1[i*n+j] -= complex(sr1, si1)
64 // First column of H - s2*I.
65 h2 := make([]complex128, n)
66 for i := 0; i < n; i++ {
67 h2[i] = complex(h[i*ldh], 0)
69 h2[0] -= complex(sr2, si2)
71 wantv := make([]float64, n)
72 // Multiply (H-s1*I)*(H-s2*I) to get a tentative
74 for i := 0; i < n; i++ {
75 for j := 0; j < n; j++ {
76 wantv[i] += real(h1[i*n+j] * h2[j])
79 // Get the unknown scale.
80 scale := v[0] / wantv[0]
81 // Compute the actual wantv.
82 floats.Scale(scale, wantv)
84 // The scale must be the same for all elements.
85 if floats.Distance(wantv, v, math.Inf(1)) > 1e-13 {
86 t.Errorf("n = %v, ldh = %v, case = %v: Unexpected value of v: got %v, want %v", n, ldh, cas, v, wantv)