File: dspr.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 (75 lines) | stat: -rw-r--r-- 1,480 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
// 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"
)

type Dsprer interface {
	Dspr(ul blas.Uplo, n int, alpha float64, x []float64, incX int, a []float64)
}

func DsprTest(t *testing.T, blasser Dsprer) {
	for i, test := range []struct {
		ul    blas.Uplo
		n     int
		a     [][]float64
		x     []float64
		alpha float64
		ans   [][]float64
	}{
		{
			ul: blas.Upper,
			n:  4,
			a: [][]float64{
				{10, 2, 0, 1},
				{0, 1, 2, 3},
				{0, 0, 9, 15},
				{0, 0, 0, -6},
			},
			x:     []float64{1, 2, 0, 5},
			alpha: 8,
			ans: [][]float64{
				{18, 18, 0, 41},
				{0, 33, 2, 83},
				{0, 0, 9, 15},
				{0, 0, 0, 194},
			},
		},
		{
			ul: blas.Lower,
			n:  3,
			a: [][]float64{
				{10, 2, 0},
				{4, 1, 2},
				{2, 7, 9},
			},
			x:     []float64{3, 0, 5},
			alpha: 8,
			ans: [][]float64{
				{82, 2, 0},
				{4, 1, 2},
				{122, 7, 209},
			},
		},
	} {
		incTest := func(incX, extra int) {
			xnew := makeIncremented(test.x, incX, extra)
			aFlat := flattenTriangular(test.a, test.ul)
			ans := flattenTriangular(test.ans, test.ul)
			blasser.Dspr(test.ul, test.n, test.alpha, xnew, incX, aFlat)
			if !dSliceTolEqual(aFlat, ans) {
				t.Errorf("Case %v, idx %v: Want %v, got %v.", i, incX, ans, aFlat)
			}
		}
		incTest(1, 3)
		incTest(1, 0)
		incTest(3, 2)
		incTest(-2, 2)
	}
}