Esempio n. 1
0
func TestLUFact_Solve_t(t *testing.T) {
	n := 100
	// Random square matrix.
	a := randMat(n, n)
	// Random vector.
	want := randVec(n)

	// Factorize.
	lu, err := LU(a)
	if err != nil {
		t.Fatal(err)
	}

	// Solve un-transposed system.
	b := cmat.MulVec(a, want)
	got, err := lu.Solve(false, b)
	if err != nil {
		t.Fatal(err)
	}
	testSliceEq(t, want, got)

	// Then solve conjugate-transpose system.
	b = cmat.MulVec(cmat.H(a), want)
	got, err = lu.Solve(true, b)
	if err != nil {
		t.Fatal(err)
	}
	testSliceEq(t, want, got)
}
Esempio n. 2
0
func TestSolveSquare(t *testing.T) {
	n := 100
	a := randMat(n, n)
	want := randVec(n)
	b := cmat.MulVec(a, want)

	got, err := SolveSquare(a, b)
	if err != nil {
		t.Fatal(err)
	}
	testSliceEq(t, want, got)
}
Esempio n. 3
0
func TestSolvePosDef(t *testing.T) {
	n := 100
	// Random symmetric positive definite matrix.
	a := randMat(2*n, n)
	a = cmat.Mul(cmat.H(a), a)
	// Random vector.
	want := randVec(n)
	b := cmat.MulVec(a, want)

	got, err := SolvePosDef(a, b)
	if err != nil {
		t.Fatal(err)
	}
	testSliceEq(t, want, got)
}
Esempio n. 4
0
func overDetProb(m, n int) (a *cmat.Mat, b, x []complex128, err error) {
	if m < n {
		panic("expect m >= n")
	}

	a = randMat(m, n)
	b = randVec(m)

	// Compute pseudo-inverse explicitly.
	// y <- (A' A) \ b
	x, err = SolveHerm(cmat.Mul(cmat.H(a), a), cmat.MulVec(cmat.H(a), b))
	if err != nil {
		return nil, nil, nil, err
	}
	return
}
Esempio n. 5
0
func underDetProb(m, n int) (a *cmat.Mat, b, x []complex128, err error) {
	if m > n {
		panic("expect m <= n")
	}

	a = randMat(m, n)
	b = randVec(m)

	// Compute pseudo-inverse explicitly.
	// y <- (A A') \ b
	y, err := SolveHerm(cmat.Mul(a, cmat.H(a)), b)
	if err != nil {
		return nil, nil, nil, err
	}
	// x <- A' y
	x = cmat.MulVec(cmat.H(a), y)
	return
}
Esempio n. 6
0
func TestLUFact_Solve(t *testing.T) {
	n := 100
	// Random square matrix.
	a := randMat(n, n)
	// Random vector.
	want := randVec(n)
	b := cmat.MulVec(a, want)

	lu, err := LU(a)
	if err != nil {
		t.Fatal(err)
	}
	got, err := lu.Solve(false, b)
	if err != nil {
		t.Fatal(err)
	}
	testSliceEq(t, want, got)
}
Esempio n. 7
0
func TestLDLFact_Solve(t *testing.T) {
	n := 100
	// Random symmetric matrix.
	a := randMat(n, n)
	a = cmat.Plus(a, cmat.H(a))
	// Random vector.
	want := randVec(n)
	b := cmat.MulVec(a, want)

	ldl, err := LDL(a)
	if err != nil {
		t.Fatal(err)
	}

	got, err := ldl.Solve(b)
	if err != nil {
		t.Fatal(err)
	}
	testSliceEq(t, want, got)
}
Esempio n. 8
0
func TestCholFact_Solve(t *testing.T) {
	n := 100
	// Random symmetric positive definite matrix.
	a := randMat(2*n, n)
	a = cmat.Mul(cmat.H(a), a)
	// Random vector.
	want := randVec(n)
	b := cmat.MulVec(a, want)

	// Factorize matrix.
	chol, err := Chol(a)
	if err != nil {
		t.Fatal(err)
	}

	got, err := chol.Solve(b)
	if err != nil {
		t.Fatal(err)
	}
	testSliceEq(t, want, got)
}