gonum.org/v1/gonum@v0.14.0/lapack/testlapack/dlaqr5_bench.go (about) 1 // Copyright ©2023 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 "fmt" 9 "testing" 10 11 "golang.org/x/exp/rand" 12 ) 13 14 func Dlaqr5Benchmark(b *testing.B, impl Dlaqr5er) { 15 const ( 16 random = iota 17 iplusj 18 laplacian 19 ) 20 rnd := rand.New(rand.NewSource(1)) 21 for _, typ := range []int{random, iplusj, laplacian} { 22 for _, n := range []int{100, 200, 500, 1000} { 23 h := zeros(n, n, n) 24 var name string 25 switch typ { 26 case random: 27 name = fmt.Sprintf("HessenbergRandom%d", n) 28 h = randomHessenberg(n, n, rnd) 29 case iplusj: 30 name = fmt.Sprintf("HessenbergIPlusJ%d", n) 31 for i := 0; i < n; i++ { 32 for j := max(0, i-1); j < n; j++ { 33 h.Data[i*h.Stride+j] = float64(i + j + 2) 34 } 35 } 36 case laplacian: 37 name = fmt.Sprintf("Laplacian%d", n) 38 for i := 0; i < n; i++ { 39 if i > 0 { 40 h.Data[i*h.Stride+i-1] = -1 41 } 42 h.Data[i*h.Stride+i] = 2 43 if i < n-1 { 44 h.Data[i*h.Stride+i+1] = -1 45 } 46 } 47 } 48 hCopy := cloneGeneral(h) 49 nshifts := 2 * n 50 sr := make([]float64, nshifts) 51 si := make([]float64, nshifts) 52 for i := 0; i < nshifts; { 53 if i == nshifts-1 || rnd.Float64() < 0.5 { 54 re := rnd.NormFloat64() 55 sr[i], si[i] = re, 0 56 i++ 57 continue 58 } 59 re := rnd.NormFloat64() 60 im := rnd.NormFloat64() 61 sr[i], sr[i+1] = re, re 62 si[i], si[i+1] = im, -im 63 i += 2 64 } 65 v := zeros(nshifts/2, 3, 3) 66 u := zeros(2*nshifts, 2*nshifts, 2*nshifts) 67 nh := n 68 wh := zeros(2*nshifts, n, n) 69 nv := n 70 wv := zeros(n, 2*nshifts, 2*nshifts) 71 z := eye(n, n) 72 b.Run(name, func(b *testing.B) { 73 for i := 0; i < b.N; i++ { 74 copyGeneral(h, hCopy) 75 impl.Dlaqr5(true, true, 1, n, 0, n-1, nshifts, sr, si, h.Data, h.Stride, 0, n-1, z.Data, z.Stride, 76 v.Data, v.Stride, u.Data, u.Stride, nh, wv.Data, wv.Stride, nv, wh.Data, wh.Stride) 77 } 78 }) 79 } 80 } 81 }