Exemple #1
0
func TestSolveBKLowerBig(t *testing.T) {
	N := 427
	normsrc := cmat.NewFloatNormSource(5.0, 10.0)
	A := cmat.NewMatrix(N, N)
	A.SetFrom(normsrc, cmat.LOWER)

	X := cmat.NewMatrix(N, 2)
	X.SetFrom(normsrc)
	B := cmat.NewCopy(X)
	blasd.MultSym(B, A, X, 1.0, 0.0, gomas.LOWER|gomas.LEFT)

	ipiv := lapackd.NewPivots(N)

	conf := gomas.NewConf()
	conf.LB = 16
	W := lapackd.Workspace(lapackd.BKFactorWork(A, conf))
	lapackd.BKFactor(A, W, ipiv, gomas.LOWER, conf)

	lapackd.BKSolve(B, A, ipiv, gomas.LOWER, conf)
	ok := B.AllClose(X)
	t.Logf("N=%d unblk.BK(X) == A.-1*B : %v\n", N, ok)
	blasd.Plus(B, X, 1.0, -1.0, gomas.NONE)
	nrm := lapackd.NormP(B, lapackd.NORM_ONE)
	t.Logf("  ||X - A.-1*B||_1: %.4e\n", nrm)

}
Exemple #2
0
func TestRowPivot(t *testing.T) {
	N := 7
	K := 3
	B := cmat.NewMatrix(N, K)
	B0 := cmat.NewMatrix(N, K)
	ipv := lapackd.NewPivots(7)
	for k, _ := range ipv {
		ipv[k] = k + 1
	}
	ipv[0] = 3
	ipv[3] = 7
	ipv[5] = 7
	t.Logf("pivots: %v\n", ipv)
	rowsetter := func(i, j int, v float64) float64 {
		return float64(i + 1)
	}
	B.Map(&cmat.FloatEvaluator{rowsetter})
	B0.Copy(B)

	lapackd.ApplyRowPivots(B, ipv, lapackd.FORWARD)
	t.Logf("pivot forward ...\n")
	lapackd.ApplyRowPivots(B, ipv, lapackd.BACKWARD)
	t.Logf("pivot backward ...\n")
	ok := B.AllClose(B0)
	t.Logf("result is original: %v\n", ok)
}
Exemple #3
0
func TestBKLowerBig(t *testing.T) {
	N := 411
	normsrc := cmat.NewFloatNormSource(5.0, 10.0)
	A := cmat.NewMatrix(N, N)
	A.SetFrom(normsrc, cmat.LOWER)
	A0 := cmat.NewCopy(A)

	ipiv := lapackd.NewPivots(N)
	ipiv0 := lapackd.NewPivots(N)

	conf := gomas.NewConf()
	conf.LB = 0

	// unblocked
	W := lapackd.Workspace(lapackd.BKFactorWork(A, conf))
	err := lapackd.BKFactor(A, W, ipiv, gomas.LOWER, conf)
	if err != nil {
		t.Logf("unblk.err: %v\n", err)
	}

	// blocked
	conf.LB = 8
	W = lapackd.Workspace(lapackd.BKFactorWork(A0, conf))
	err = lapackd.BKFactor(A0, W, ipiv0, gomas.LOWER, conf)
	if err != nil {
		t.Logf("blk.err: %v\n", err)
	}
	ok := A.AllClose(A0)
	t.Logf("N=%d unblk.A == blk.A : %v\n", N, ok)

	if !ok {
		r, c := errorLoc(A, A0)
		t.Logf("unblk.A != blk.A at: %d, %d\n", r, c)
		for k, _ := range ipiv {
			t.Logf("%3d  %3d  %3d\n", k, ipiv[k], ipiv0[k])
		}
	}
}
Exemple #4
0
func TestLU(t *testing.T) {
	N := 119
	K := 41
	nb := 0

	A := cmat.NewMatrix(N, N)
	A0 := cmat.NewMatrix(N, N)
	B := cmat.NewMatrix(N, K)
	X := cmat.NewMatrix(N, K)

	unitrand := cmat.NewFloatUniformSource()
	A.SetFrom(unitrand)
	A0.Copy(A)
	B.SetFrom(unitrand)
	X.Copy(B)
	piv := lapackd.NewPivots(N)

	conf := gomas.DefaultConf()
	conf.LB = nb

	// R = lu(A) = P*L*U
	lapackd.LUFactor(A, piv, conf)
	// X = A.-1*B = U.-1*(L.-1*B)
	lapackd.LUSolve(X, A, piv, gomas.NONE)
	// B = B - A*X
	blasd.Mult(B, A0, X, -1.0, 1.0, gomas.NONE)
	nrm := lapackd.NormP(B, lapackd.NORM_ONE)
	t.Logf("Unblocked decomposition: nb=%d\n", conf.LB)
	t.Logf("N=%d  ||B - A*X||_1: %e\n", N, nrm)

	// blocked
	conf.LB = 16
	A.Copy(A0)
	B.SetFrom(unitrand)
	X.Copy(B)
	// lu(A) = P*L*U
	lapackd.LUFactor(A, piv, conf)
	// X = A.-1*B = U.-1*(L.-1*B)
	lapackd.LUSolve(X, A, piv, gomas.NONE)
	// B = B - A*X
	blasd.Mult(B, A0, X, -1.0, 1.0, gomas.NONE)
	nrm = lapackd.NormP(B, lapackd.NORM_ONE)
	t.Logf("Blocked decomposition: nb=%d\n", conf.LB)
	t.Logf("N=%d  ||B - A*X||_1: %e\n", N, nrm)
}