File: dlapmt.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 (113 lines) | stat: -rw-r--r-- 2,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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// 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 testlapack

import (
	"fmt"
	"testing"

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

type Dlapmter interface {
	Dlapmt(forward bool, m, n int, x []float64, ldx int, k []int)
}

func DlapmtTest(t *testing.T, impl Dlapmter) {
	for ti, test := range []struct {
		forward bool
		k       []int

		want blas64.General
	}{
		{
			forward: true, k: []int{0, 1, 2},
			want: blas64.General{
				Rows:   4,
				Cols:   3,
				Stride: 3,
				Data: []float64{
					1, 2, 3,
					4, 5, 6,
					7, 8, 9,
					10, 11, 12,
				},
			},
		},
		{
			forward: false, k: []int{0, 1, 2},
			want: blas64.General{
				Rows:   4,
				Cols:   3,
				Stride: 3,
				Data: []float64{
					1, 2, 3,
					4, 5, 6,
					7, 8, 9,
					10, 11, 12,
				},
			},
		},
		{
			forward: true, k: []int{1, 2, 0},
			want: blas64.General{
				Rows:   4,
				Cols:   3,
				Stride: 3,
				Data: []float64{
					2, 3, 1,
					5, 6, 4,
					8, 9, 7,
					11, 12, 10,
				},
			},
		},
		{
			forward: false, k: []int{1, 2, 0},
			want: blas64.General{
				Rows:   4,
				Cols:   3,
				Stride: 3,
				Data: []float64{
					3, 1, 2,
					6, 4, 5,
					9, 7, 8,
					12, 10, 11,
				},
			},
		},
	} {
		m := test.want.Rows
		n := test.want.Cols
		if len(test.k) != n {
			panic("bad length of k")
		}

		for _, extra := range []int{0, 11} {
			x := zeros(m, n, n+extra)
			c := 1
			for i := 0; i < m; i++ {
				for j := 0; j < n; j++ {
					x.Data[i*x.Stride+j] = float64(c)
					c++
				}
			}

			k := make([]int, len(test.k))
			copy(k, test.k)

			impl.Dlapmt(test.forward, m, n, x.Data, x.Stride, k)

			prefix := fmt.Sprintf("Case %v (forward=%t,m=%v,n=%v,extra=%v)", ti, test.forward, m, n, extra)
			if !generalOutsideAllNaN(x) {
				t.Errorf("%v: out-of-range write to X", prefix)
			}

			if !equalApproxGeneral(x, test.want, 0) {
				t.Errorf("%v: unexpected X\n%v\n%v", prefix, x, test.want)
			}
		}
	}
}