/
dlacpy.go
90 lines (83 loc) · 1.75 KB
/
dlacpy.go
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
// Copyright ©2015 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"
"golang.org/x/exp/rand"
"gonum.org/v1/gonum/blas"
)
type Dlacpyer interface {
Dlacpy(uplo blas.Uplo, m, n int, a []float64, lda int, b []float64, ldb int)
}
func DlacpyTest(t *testing.T, impl Dlacpyer) {
rnd := rand.New(rand.NewSource(1))
for _, uplo := range []blas.Uplo{blas.Upper, blas.Lower, blas.All} {
for _, test := range []struct {
m, n, lda, ldb int
}{
{3, 5, 0, 0},
{5, 5, 0, 0},
{7, 5, 0, 0},
{3, 5, 10, 12},
{5, 5, 10, 12},
{7, 5, 10, 12},
} {
m := test.m
n := test.n
lda := test.lda
if lda == 0 {
lda = n
}
ldb := test.ldb
if ldb == 0 {
ldb = n
}
a := make([]float64, m*lda)
for i := range a {
a[i] = rnd.Float64()
}
b := make([]float64, m*ldb)
for i := range b {
b[i] = rnd.Float64()
}
impl.Dlacpy(uplo, m, n, a, lda, b, ldb)
equal := true
switch uplo {
case blas.Upper:
for i := 0; i < m; i++ {
for j := i; j < n; j++ {
if b[i*ldb+j] != a[i*lda+j] {
equal = false
goto DoneCheck
}
}
}
case blas.Lower:
for i := 0; i < m; i++ {
for j := 0; j < min(i, n); j++ {
if b[i*ldb+j] != a[i*lda+j] {
equal = false
goto DoneCheck
}
}
}
case blas.All:
for i := 0; i < m; i++ {
for j := 0; j < n; j++ {
if b[i*ldb+j] != a[i*lda+j] {
equal = false
goto DoneCheck
}
}
}
}
DoneCheck:
if !equal {
fmt.Println(blas.Lower)
t.Errorf("Matrices not equal after copy. Uplo = %d, m = %d, n = %d", uplo, m, n)
}
}
}
}