forked from hybridgroup/gocv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
svd_test.go
69 lines (54 loc) · 1.18 KB
/
svd_test.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
package gocv
import (
"testing"
)
func TestSVDCompute(t *testing.T) {
var resultW = []float32{6.167493, 3.8214223}
var resultU = []float32{-0.1346676, -0.99089086, 0.9908908, -0.1346676}
var resultVt = []float32{0.01964448, 0.999807, -0.999807, 0.01964448}
checkFunc := func(a []float32, b []float32) bool {
if len(a) != len(b) {
return false
}
for i := range a {
if a[i] != b[i] {
return false
}
}
return true
}
src := NewMatWithSize(2, 2, MatTypeCV32F)
src.SetFloatAt(0, 0, 3.76956568)
src.SetFloatAt(0, 1, -0.90478725)
src.SetFloatAt(1, 0, 0.634576)
src.SetFloatAt(1, 1, 6.10002347)
defer src.Close()
w := NewMat()
defer w.Close()
u := NewMat()
defer u.Close()
vt := NewMat()
defer vt.Close()
SVDCompute(src, &w, &u, &vt)
dataW, err := w.DataPtrFloat32()
if err != nil {
t.Error(err)
}
if !checkFunc(resultW, dataW) {
t.Error("w value is incorrect")
}
dataU, err := u.DataPtrFloat32()
if err != nil {
t.Error(err)
}
if !checkFunc(resultU, dataU) {
t.Error("u value is incorrect")
}
dataVt, err := vt.DataPtrFloat32()
if err != nil {
t.Error(err)
}
if !checkFunc(resultVt, dataVt) {
t.Error("vt value is incorrect")
}
}