From 50b349daceea6cf53debf75513892d30a058290f Mon Sep 17 00:00:00 2001 From: Vladimir Chalupecky Date: Tue, 25 Oct 2016 22:52:56 +0200 Subject: [PATCH] testlapack,native,cgo: build Dgeev benchmark conditioned on go1.7 tag --- cgo/bench_test.go | 15 ++++++++++ cgo/lapack_test.go | 4 --- native/bench_test.go | 15 ++++++++++ native/lapack_test.go | 4 --- testlapack/dgeev.go | 48 ----------------------------- testlapack/dgeev_bench.go | 63 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 93 insertions(+), 56 deletions(-) create mode 100644 cgo/bench_test.go create mode 100644 native/bench_test.go create mode 100644 testlapack/dgeev_bench.go diff --git a/cgo/bench_test.go b/cgo/bench_test.go new file mode 100644 index 00000000..5deae590 --- /dev/null +++ b/cgo/bench_test.go @@ -0,0 +1,15 @@ +// Copyright ©2016 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build go1.7 + +package cgo + +import ( + "testing" + + "github.com/gonum/lapack/testlapack" +) + +func BenchmarkDgeev(b *testing.B) { testlapack.DgeevBenchmark(b, impl) } diff --git a/cgo/lapack_test.go b/cgo/lapack_test.go index 5456a4ce..fc7fffdf 100644 --- a/cgo/lapack_test.go +++ b/cgo/lapack_test.go @@ -217,7 +217,3 @@ func TestDtrcon(t *testing.T) { func TestDtrtri(t *testing.T) { testlapack.DtrtriTest(t, impl) } - -func BenchmarkDgeev(b *testing.B) { - testlapack.DgeevBenchmark(b, impl) -} diff --git a/native/bench_test.go b/native/bench_test.go new file mode 100644 index 00000000..b253cd6f --- /dev/null +++ b/native/bench_test.go @@ -0,0 +1,15 @@ +// Copyright ©2016 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build go1.7 + +package native + +import ( + "testing" + + "github.com/gonum/lapack/testlapack" +) + +func BenchmarkDgeev(b *testing.B) { testlapack.DgeevBenchmark(b, impl) } diff --git a/native/lapack_test.go b/native/lapack_test.go index 4c9d61e7..e2bb0dff 100644 --- a/native/lapack_test.go +++ b/native/lapack_test.go @@ -351,7 +351,3 @@ func TestIladlc(t *testing.T) { func TestIladlr(t *testing.T) { testlapack.IladlrTest(t, impl) } - -func BenchmarkDgeev(b *testing.B) { - testlapack.DgeevBenchmark(b, impl) -} diff --git a/testlapack/dgeev.go b/testlapack/dgeev.go index f54aa8c3..05763821 100644 --- a/testlapack/dgeev.go +++ b/testlapack/dgeev.go @@ -733,51 +733,3 @@ func dgeevTestForAntisymRandom(n int, rnd *rand.Rand) dgeevTest { evWant: a.Eigenvalues(), } } - -var resultGeneral blas64.General - -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()}, - } - 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 - }) - } -} diff --git a/testlapack/dgeev_bench.go b/testlapack/dgeev_bench.go new file mode 100644 index 00000000..c7ebaf98 --- /dev/null +++ b/testlapack/dgeev_bench.go @@ -0,0 +1,63 @@ +// Copyright ©2016 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build go1.7 + +package testlapack + +import ( + "math/rand" + "testing" + + "github.com/gonum/blas/blas64" + "github.com/gonum/lapack" +) + +var resultGeneral blas64.General + +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()}, + } + 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 + }) + } +}