Exemplo n.º 1
0
func _TestBlkCHOLUpLo(t *testing.T) {
	N := 10
	nb := 4
	L := matrix.FloatUniformSymmetric(N, matrix.Lower)
	A := matrix.Times(L, L.Transpose())
	DecomposeCHOL(A, LOWER, nb)
	Ld := TriL(A)
	ok := L.AllClose(Ld)
	t.Logf("result L == Ld: %v\n", ok)
	if !ok {
		t.Logf("L:\n%v\n", L)
		t.Logf("Ld:\n%v\n", Ld)
	}

	U := matrix.FloatUniformSymmetric(N, matrix.Upper)
	A = matrix.Times(U.Transpose(), U)
	DecomposeCHOL(A, UPPER, nb)
	Ud := TriU(A)
	ok = U.AllClose(Ud)
	t.Logf("result U == Ud: %v\n", ok)

	//lapack.Potrf(A0)
	//t.Logf("lapack result:\n%v\n", A0)
	//t.Logf("A == A0: %v\n", A0.AllClose(A))
}
Exemplo n.º 2
0
func _TestCHOLUpLo(t *testing.T) {
	N := 10
	L := matrix.FloatUniformSymmetric(N, matrix.Lower)
	A := matrix.Times(L, L.Transpose())
	DecomposeCHOL(A, LOWER, 0)
	Ld := TriL(A)
	t.Logf("result L == Ld: %v\n", L.AllClose(Ld))

	U := matrix.FloatUniformSymmetric(N, matrix.Upper)
	A = matrix.Times(U.Transpose(), U)
	DecomposeCHOL(A, UPPER, 0)
	Ud := TriU(A)
	t.Logf("result U == Ud: %v\n", U.AllClose(Ud))
}
Exemplo n.º 3
0
func _TestUnblkLUnoPiv(t *testing.T) {
	N := 6
	L := matrix.FloatUniformSymmetric(N, matrix.Lower)
	U := matrix.FloatUniformSymmetric(N, matrix.Upper)
	// Set L diagonal to 1.0
	L.Diag().SetIndexes(1.0)

	A := matrix.Times(L, U)
	t.Logf("A\n%v\n", A)
	DecomposeBlockSize(0)
	R, _ := DecomposeLUnoPiv(A.Copy(), 0)
	Ld := TriLU(R.Copy())
	Ud := TriU(R)
	t.Logf("A == L*U: %v\n", A.AllClose(matrix.Times(Ld, Ud)))
}
Exemplo n.º 4
0
func _TestBlkLUPiv(t *testing.T) {
	N := 10
	nb := 4
	L := matrix.FloatUniformSymmetric(N, matrix.Lower)
	U := matrix.FloatUniformSymmetric(N, matrix.Upper)
	// Set L diagonal to 1.0
	L.Diag().SetIndexes(1.0)

	A := matrix.Times(L, U)
	A0 := A.Copy()
	piv := make([]int, N, N)
	DecomposeBlockSize(nb)
	R, _ := DecomposeLU(A.Copy(), piv, 0)
	t.Logf("piv: %v\n", piv)

	piv0 := make([]int32, N, N)
	lapack.Getrf(A0, piv0)
	t.Logf("lapack result: piv0 %v\n", piv0)
	t.Logf("R == A0: %v\n", A0.AllClose(R))
}
Exemplo n.º 5
0
func TestInvLower(t *testing.T) {
	N := 36
	nb := 12
	A := matrix.FloatUniformSymmetric(N, matrix.Lower)
	I := matrix.FloatDiagonal(N, 1.0)
	I0 := matrix.FloatZeros(N, N)

	A0 := A.Copy()
	// A0 = A.-1
	InverseTrm(A0, LOWER, 0)
	Mult(I0, A, A0, 1.0, 0.0, NOTRANS)
	I0.Minus(I)
	nrm := NormP(I0, NORM_ONE)
	t.Logf("unblk: ||I - A*A.-1||_1 : %e\n", nrm)

	A0 = A.Copy()
	// A0 = A.-1
	InverseTrm(A0, LOWER, nb)
	Mult(I0, A, A0, 1.0, 0.0, NOTRANS)
	I0.Minus(I)
	nrm = NormP(I0, NORM_ONE)
	t.Logf("blk:   ||I - A*A.-1||_1 : %e\n", nrm)
}