Example #1
0
func TestEigSymm(t *testing.T) {
	n := 100
	a := randMat(n, n)
	a = mat.Plus(a, mat.T(a))

	// Take eigen decomposition.
	v, d, err := EigSymm(a)
	if err != nil {
		t.Fatal(err)
	}

	got := mat.Mul(mat.Mul(v, mat.NewDiag(d)), mat.T(v))
	testMatEq(t, a, got)
}
Example #2
0
func TestSVD(t *testing.T) {
	m, n := 150, 100
	want := randMat(m, n)

	// Take singular value decomposition.
	u, s, vt, err := SVD(want)
	if err != nil {
		t.Fatal(err)
	}

	// Check that A = U S V'.
	got := mat.Mul(u, mat.Mul(mat.NewDiag(s), vt))
	testMatEq(t, want, got)
}