diff --git a/cgo/lapack_test.go b/cgo/lapack_test.go index f946daa4..5456a4ce 100644 --- a/cgo/lapack_test.go +++ b/cgo/lapack_test.go @@ -5,7 +5,6 @@ package cgo import ( - "math/rand" "testing" "github.com/gonum/blas" @@ -219,60 +218,6 @@ func TestDtrtri(t *testing.T) { testlapack.DtrtriTest(t, impl) } -func BenchmarkDgeevAntisymRandomN3(b *testing.B) { - rnd := rand.New(rand.NewSource(1)) - testlapack.DgeevBenchmark(b, impl, testlapack.NewAntisymRandom(3, rnd).Matrix()) -} -func BenchmarkDgeevAntisymRandomN4(b *testing.B) { - rnd := rand.New(rand.NewSource(1)) - testlapack.DgeevBenchmark(b, impl, testlapack.NewAntisymRandom(4, rnd).Matrix()) -} -func BenchmarkDgeevAntisymRandomN5(b *testing.B) { - rnd := rand.New(rand.NewSource(1)) - testlapack.DgeevBenchmark(b, impl, testlapack.NewAntisymRandom(5, rnd).Matrix()) -} -func BenchmarkDgeevAntisymRandomN10(b *testing.B) { - rnd := rand.New(rand.NewSource(1)) - testlapack.DgeevBenchmark(b, impl, testlapack.NewAntisymRandom(10, rnd).Matrix()) -} -func BenchmarkDgeevAntisymRandomN50(b *testing.B) { - rnd := rand.New(rand.NewSource(1)) - testlapack.DgeevBenchmark(b, impl, testlapack.NewAntisymRandom(50, rnd).Matrix()) -} -func BenchmarkDgeevAntisymRandomN100(b *testing.B) { - rnd := rand.New(rand.NewSource(1)) - testlapack.DgeevBenchmark(b, impl, testlapack.NewAntisymRandom(100, rnd).Matrix()) -} -func BenchmarkDgeevAntisymRandomN200(b *testing.B) { - rnd := rand.New(rand.NewSource(1)) - testlapack.DgeevBenchmark(b, impl, testlapack.NewAntisymRandom(200, rnd).Matrix()) -} -func BenchmarkDgeevAntisymRandomN500(b *testing.B) { - rnd := rand.New(rand.NewSource(1)) - testlapack.DgeevBenchmark(b, impl, testlapack.NewAntisymRandom(500, rnd).Matrix()) -} - -func BenchmarkDgeevCirculantN3(b *testing.B) { - testlapack.DgeevBenchmark(b, impl, testlapack.Circulant(3).Matrix()) -} -func BenchmarkDgeevCirculantN4(b *testing.B) { - testlapack.DgeevBenchmark(b, impl, testlapack.Circulant(4).Matrix()) -} -func BenchmarkDgeevCirculantN5(b *testing.B) { - testlapack.DgeevBenchmark(b, impl, testlapack.Circulant(5).Matrix()) -} -func BenchmarkDgeevCirculantN10(b *testing.B) { - testlapack.DgeevBenchmark(b, impl, testlapack.Circulant(10).Matrix()) -} -func BenchmarkDgeevCirculantN50(b *testing.B) { - testlapack.DgeevBenchmark(b, impl, testlapack.Circulant(50).Matrix()) -} -func BenchmarkDgeevCirculantN100(b *testing.B) { - testlapack.DgeevBenchmark(b, impl, testlapack.Circulant(100).Matrix()) -} -func BenchmarkDgeevCirculantN200(b *testing.B) { - testlapack.DgeevBenchmark(b, impl, testlapack.Circulant(200).Matrix()) -} -func BenchmarkDgeevCirculantN500(b *testing.B) { - testlapack.DgeevBenchmark(b, impl, testlapack.Circulant(500).Matrix()) +func BenchmarkDgeev(b *testing.B) { + testlapack.DgeevBenchmark(b, impl) } diff --git a/native/lapack_test.go b/native/lapack_test.go index b80b9ef5..4c9d61e7 100644 --- a/native/lapack_test.go +++ b/native/lapack_test.go @@ -5,7 +5,6 @@ package native import ( - "math/rand" "testing" "github.com/gonum/lapack/testlapack" @@ -353,60 +352,6 @@ func TestIladlr(t *testing.T) { testlapack.IladlrTest(t, impl) } -func BenchmarkDgeevAntisymRandomN3(b *testing.B) { - rnd := rand.New(rand.NewSource(1)) - testlapack.DgeevBenchmark(b, impl, testlapack.NewAntisymRandom(3, rnd).Matrix()) -} -func BenchmarkDgeevAntisymRandomN4(b *testing.B) { - rnd := rand.New(rand.NewSource(1)) - testlapack.DgeevBenchmark(b, impl, testlapack.NewAntisymRandom(4, rnd).Matrix()) -} -func BenchmarkDgeevAntisymRandomN5(b *testing.B) { - rnd := rand.New(rand.NewSource(1)) - testlapack.DgeevBenchmark(b, impl, testlapack.NewAntisymRandom(5, rnd).Matrix()) -} -func BenchmarkDgeevAntisymRandomN10(b *testing.B) { - rnd := rand.New(rand.NewSource(1)) - testlapack.DgeevBenchmark(b, impl, testlapack.NewAntisymRandom(10, rnd).Matrix()) -} -func BenchmarkDgeevAntisymRandomN50(b *testing.B) { - rnd := rand.New(rand.NewSource(1)) - testlapack.DgeevBenchmark(b, impl, testlapack.NewAntisymRandom(50, rnd).Matrix()) -} -func BenchmarkDgeevAntisymRandomN100(b *testing.B) { - rnd := rand.New(rand.NewSource(1)) - testlapack.DgeevBenchmark(b, impl, testlapack.NewAntisymRandom(100, rnd).Matrix()) -} -func BenchmarkDgeevAntisymRandomN200(b *testing.B) { - rnd := rand.New(rand.NewSource(1)) - testlapack.DgeevBenchmark(b, impl, testlapack.NewAntisymRandom(200, rnd).Matrix()) -} -func BenchmarkDgeevAntisymRandomN500(b *testing.B) { - rnd := rand.New(rand.NewSource(1)) - testlapack.DgeevBenchmark(b, impl, testlapack.NewAntisymRandom(500, rnd).Matrix()) -} - -func BenchmarkDgeevCirculantN3(b *testing.B) { - testlapack.DgeevBenchmark(b, impl, testlapack.Circulant(3).Matrix()) -} -func BenchmarkDgeevCirculantN4(b *testing.B) { - testlapack.DgeevBenchmark(b, impl, testlapack.Circulant(4).Matrix()) -} -func BenchmarkDgeevCirculantN5(b *testing.B) { - testlapack.DgeevBenchmark(b, impl, testlapack.Circulant(5).Matrix()) -} -func BenchmarkDgeevCirculantN10(b *testing.B) { - testlapack.DgeevBenchmark(b, impl, testlapack.Circulant(10).Matrix()) -} -func BenchmarkDgeevCirculantN50(b *testing.B) { - testlapack.DgeevBenchmark(b, impl, testlapack.Circulant(50).Matrix()) -} -func BenchmarkDgeevCirculantN100(b *testing.B) { - testlapack.DgeevBenchmark(b, impl, testlapack.Circulant(100).Matrix()) -} -func BenchmarkDgeevCirculantN200(b *testing.B) { - testlapack.DgeevBenchmark(b, impl, testlapack.Circulant(200).Matrix()) -} -func BenchmarkDgeevCirculantN500(b *testing.B) { - testlapack.DgeevBenchmark(b, impl, testlapack.Circulant(500).Matrix()) +func BenchmarkDgeev(b *testing.B) { + testlapack.DgeevBenchmark(b, impl) } diff --git a/testlapack/dgeev.go b/testlapack/dgeev.go index 68ffc2bd..f54aa8c3 100644 --- a/testlapack/dgeev.go +++ b/testlapack/dgeev.go @@ -736,26 +736,48 @@ func dgeevTestForAntisymRandom(n int, rnd *rand.Rand) dgeevTest { var resultGeneral blas64.General -func DgeevBenchmark(b *testing.B, impl Dgeever, a blas64.General) { - n := a.Rows - if n != a.Cols { - panic("testlapack: matrix not square") +func DgeevBenchmark(b *testing.B, impl Dgeever) { + rnd := rand.New(rand.NewSource(1)) + benchmarks := []struct { + name string + a blas64.General + }{ + {"AntisymRandom3", NewAntisymRandom(3, rnd).Matrix()}, + {"AntisymRandom4", NewAntisymRandom(4, rnd).Matrix()}, + {"AntisymRandom5", NewAntisymRandom(5, rnd).Matrix()}, + {"AntisymRandom10", NewAntisymRandom(10, rnd).Matrix()}, + {"AntisymRandom50", NewAntisymRandom(50, rnd).Matrix()}, + {"AntisymRandom100", NewAntisymRandom(100, rnd).Matrix()}, + {"AntisymRandom200", NewAntisymRandom(200, rnd).Matrix()}, + {"AntisymRandom500", NewAntisymRandom(500, rnd).Matrix()}, + {"Circulant3", Circulant(3).Matrix()}, + {"Circulant4", Circulant(4).Matrix()}, + {"Circulant5", Circulant(5).Matrix()}, + {"Circulant10", Circulant(10).Matrix()}, + {"Circulant50", Circulant(50).Matrix()}, + {"Circulant100", Circulant(100).Matrix()}, + {"Circulant200", Circulant(200).Matrix()}, + {"Circulant500", Circulant(500).Matrix()}, } - aComp := zeros(n, n, n) - vl := zeros(n, n, n) - vr := zeros(n, n, n) - work := make([]float64, 1) - impl.Dgeev(lapack.ComputeLeftEV, lapack.ComputeRightEV, n, nil, n, nil, nil, nil, n, nil, n, work, -1) - work = make([]float64, int(work[0])) - wr := make([]float64, n) - wi := make([]float64, n) - b.ResetTimer() - for i := 0; i < b.N; i++ { - copyGeneral(aComp, a) - b.StartTimer() - impl.Dgeev(lapack.ComputeLeftEV, lapack.ComputeRightEV, n, aComp.Data, aComp.Stride, wr, wi, - vl.Data, vl.Stride, vr.Data, vr.Stride, work, len(work)) - b.StopTimer() + for _, bm := range benchmarks { + n := bm.a.Rows + a := zeros(n, n, n) + vl := zeros(n, n, n) + vr := zeros(n, n, n) + wr := make([]float64, n) + wi := make([]float64, n) + work := make([]float64, 1) + impl.Dgeev(lapack.ComputeLeftEV, lapack.ComputeRightEV, n, nil, n, nil, nil, nil, n, nil, n, work, -1) + work = make([]float64, int(work[0])) + b.Run(bm.name, func(b *testing.B) { + for i := 0; i < b.N; i++ { + b.StopTimer() + copyGeneral(a, bm.a) + b.StartTimer() + impl.Dgeev(lapack.ComputeLeftEV, lapack.ComputeRightEV, n, a.Data, a.Stride, wr, wi, + vl.Data, vl.Stride, vr.Data, vr.Stride, work, len(work)) + } + resultGeneral = a + }) } - resultGeneral = aComp }