// 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.

package testlapack

import (
	"math/rand/v2"
	"testing"

	"gonum.org/v1/gonum/blas/blas64"
	"gonum.org/v1/gonum/lapack"
)

func DgeevBenchmark(b *testing.B, impl Dgeever) {
	var resultGeneral blas64.General
	rnd := rand.New(rand.NewPCG(1, 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.LeftEVCompute, lapack.RightEVCompute, n, a.Data, a.Stride, wr, wi, vl.Data, vl.Stride, vr.Data, vr.Stride, 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.LeftEVCompute, lapack.RightEVCompute, n, a.Data, a.Stride, wr, wi,
					vl.Data, vl.Stride, vr.Data, vr.Stride, work, len(work))
			}
			resultGeneral = a
		})
	}
	if resultGeneral.Data == nil {
		b.Error("unexpected nil data")
	}
}
