File: dtrsv.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 (148 lines) | stat: -rw-r--r-- 2,760 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// Copyright ©2014 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"

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

type Dtrsver interface {
	Dtrsv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, a []float64, lda int, x []float64, incX int)
}

func DtrsvTest(t *testing.T, blasser Dtrsver) {
	for i, test := range []struct {
		n   int
		a   [][]float64
		ul  blas.Uplo
		tA  blas.Transpose
		d   blas.Diag
		x   []float64
		ans []float64
	}{
		{
			n: 3,
			a: [][]float64{
				{1, 2, 3},
				{0, 8, 15},
				{0, 0, 8},
			},
			ul:  blas.Upper,
			tA:  blas.NoTrans,
			d:   blas.NonUnit,
			x:   []float64{5, 6, 7},
			ans: []float64{4.15625, -0.890625, 0.875},
		},
		{
			n: 3,
			a: [][]float64{
				{1, 2, 3},
				{0, 1, 15},
				{0, 0, 1},
			},
			ul:  blas.Upper,
			tA:  blas.NoTrans,
			d:   blas.Unit,
			x:   []float64{5, 6, 7},
			ans: []float64{182, -99, 7},
		},
		{
			n: 3,
			a: [][]float64{
				{1, 0, 0},
				{2, 8, 0},
				{3, 15, 8},
			},
			ul:  blas.Lower,
			tA:  blas.NoTrans,
			d:   blas.NonUnit,
			x:   []float64{5, 6, 7},
			ans: []float64{5, -0.5, -0.0625},
		},
		{
			n: 3,
			a: [][]float64{
				{1, 0, 0},
				{2, 8, 0},
				{3, 15, 8},
			},
			ul:  blas.Lower,
			tA:  blas.NoTrans,
			d:   blas.Unit,
			x:   []float64{5, 6, 7},
			ans: []float64{5, -4, 52},
		},
		{
			n: 3,
			a: [][]float64{
				{1, 2, 3},
				{0, 8, 15},
				{0, 0, 8},
			},
			ul:  blas.Upper,
			tA:  blas.Trans,
			d:   blas.NonUnit,
			x:   []float64{5, 6, 7},
			ans: []float64{5, -0.5, -0.0625},
		},
		{
			n: 3,
			a: [][]float64{
				{1, 2, 3},
				{0, 8, 15},
				{0, 0, 8},
			},
			ul:  blas.Upper,
			tA:  blas.Trans,
			d:   blas.Unit,
			x:   []float64{5, 6, 7},
			ans: []float64{5, -4, 52},
		},
		{
			n: 3,
			a: [][]float64{
				{1, 0, 0},
				{2, 8, 0},
				{3, 15, 8},
			},
			ul:  blas.Lower,
			tA:  blas.Trans,
			d:   blas.NonUnit,
			x:   []float64{5, 6, 7},
			ans: []float64{4.15625, -0.890625, 0.875},
		},
		{
			n: 3,
			a: [][]float64{
				{1, 0, 0},
				{2, 1, 0},
				{3, 15, 1},
			},
			ul:  blas.Lower,
			tA:  blas.Trans,
			d:   blas.Unit,
			x:   []float64{5, 6, 7},
			ans: []float64{182, -99, 7},
		},
	} {
		incTest := func(incX, extra int) {
			aFlat := flatten(test.a)
			x := makeIncremented(test.x, incX, extra)
			blasser.Dtrsv(test.ul, test.tA, test.d, test.n, aFlat, test.n, x, incX)
			ans := makeIncremented(test.ans, incX, extra)
			if !floats.EqualApprox(x, ans, 1e-14) {
				t.Errorf("Case %v, incX = %v: Want %v, got %v.", i, incX, ans, x)
			}
		}
		incTest(1, 0)
		incTest(-2, 0)
		incTest(3, 0)
		incTest(-3, 8)
		incTest(4, 2)
	}
}