File: izamax.go

package info (click to toggle)
golang-gonum-v1-gonum 0.15.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 18,792 kB
  • sloc: asm: 6,252; fortran: 5,271; sh: 377; ruby: 211; makefile: 98
file content (47 lines) | stat: -rw-r--r-- 1,042 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright ©2017 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 testblas

import (
	"testing"

	"golang.org/x/exp/rand"
)

type Izamaxer interface {
	Izamax(n int, x []complex128, incX int) int
}

func IzamaxTest(t *testing.T, impl Izamaxer) {
	rnd := rand.New(rand.NewSource(1))
	for _, n := range []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 50, 100} {
		for _, incX := range []int{-5, 1, 2, 10} {
			aincX := abs(incX)
			var x []complex128
			if n > 0 {
				x = make([]complex128, (n-1)*aincX+1)
			}
			for i := range x {
				x[i] = znan
			}
			for i := 0; i < n; i++ {
				re := 2*rnd.Float64() - 1
				im := 2*rnd.Float64() - 1
				x[i*aincX] = complex(re, im)
			}

			want := -1
			if incX > 0 && n > 0 {
				want = rnd.Intn(n)
				x[want*incX] = 10 + 10i
			}
			got := impl.Izamax(n, x, incX)

			if got != want {
				t.Errorf("Case n=%v,incX=%v: unexpected result. want %v, got %v", n, incX, want, got)
			}
		}
	}
}