-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmatrix_factorization_test.go
More file actions
87 lines (70 loc) · 2.56 KB
/
matrix_factorization_test.go
File metadata and controls
87 lines (70 loc) · 2.56 KB
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
package methods
import (
"reflect"
"testing"
m "github.com/NumberXNumbers/types/gc/matrices"
mops "github.com/NumberXNumbers/types/gc/matrices/ops"
v "github.com/NumberXNumbers/types/gc/vectors"
)
func TestLU(t *testing.T) {
testVectorAa := v.MakeVector(v.RowSpace, 0, 0, -1, 1)
testVectorAb := v.MakeVector(v.RowSpace, 1, 1, -1, 2)
testVectorAc := v.MakeVector(v.RowSpace, -1, -1, 2, 0)
testVectorAd := v.MakeVector(v.RowSpace, 1, 2, 0, 2)
testVectorsA := v.MakeVectors(v.RowSpace, testVectorAa, testVectorAb, testVectorAc, testVectorAd)
testMatrixA := m.MakeMatrixAlt(testVectorsA)
L, U, P, errA := LU(testMatrixA)
if errA != nil {
t.Error("Unexpected Error")
}
P.Trans()
A := mops.MustMultSimple(mops.MustMultSimple(P, L), U)
if !reflect.DeepEqual(testMatrixA, A) {
t.Errorf("Expected %+v, received %+v", testMatrixA, A)
}
testVectorsB := v.MakeVectors(v.RowSpace, testVectorAa, testVectorAb, testVectorAc)
testMatrixB := m.MakeMatrixAlt(testVectorsB)
_, _, _, errB := LU(testMatrixB)
if errB == nil {
t.Error("Expected Error")
}
testVectorCa := v.MakeVector(v.RowSpace, 0, 0, -1)
testVectorCb := v.MakeVector(v.RowSpace, 0, 1, -1)
testVectorCc := v.MakeVector(v.RowSpace, 0, -1, 2)
testVectorsC := v.MakeVectors(v.RowSpace, testVectorCa, testVectorCb, testVectorCc)
testMatrixC := m.MakeMatrixAlt(testVectorsC)
_, _, _, errC := LU(testMatrixC)
if errC == nil {
t.Error("Expected Error")
}
}
func TestLDLtrans(t *testing.T) {
testVectorAa := v.MakeVector(v.RowSpace, 4, -1, 1)
testVectorAb := v.MakeVector(v.RowSpace, -1, 4.25, 2.75)
testVectorAc := v.MakeVector(v.RowSpace, 1, 2.75, 3.5)
testVectorsA := v.MakeVectors(v.RowSpace, testVectorAa, testVectorAb, testVectorAc)
testMatrixA := m.MakeMatrixAlt(testVectorsA)
L, D, errA := LDLt(testMatrixA)
if errA != nil {
t.Error("Unexpected Error")
}
A := mops.MustMultSimple(mops.MustMultSimple(L, D), m.MakeTransMatrix(L))
if !reflect.DeepEqual(testMatrixA, A) {
t.Errorf("Expected %+v, received %+v", testMatrixA, A)
}
testVectorsB := v.MakeVectors(v.RowSpace, testVectorAa, testVectorAb)
testMatrixB := m.MakeMatrixAlt(testVectorsB)
_, _, errB := LDLt(testMatrixB)
if errB == nil {
t.Error("Expected Error")
}
testVectorCa := v.MakeVector(v.RowSpace, 0, -1, 0)
testVectorCb := v.MakeVector(v.RowSpace, -1, 0, 2.75)
testVectorCc := v.MakeVector(v.RowSpace, 0, 2.75, 0)
testVectorsC := v.MakeVectors(v.RowSpace, testVectorCa, testVectorCb, testVectorCc)
testMatrixC := m.MakeMatrixAlt(testVectorsC)
_, _, errC := LDLt(testMatrixC)
if errC == nil {
t.Error("Expected Error")
}
}