示例#1
0
func TestBidiagReduceUnblocked(t *testing.T) {

	N := 217
	M := 269
	conf := gomas.NewConf()
	conf.LB = 0

	zeromean := cmat.NewFloatNormSource()
	A := cmat.NewMatrix(M, N)
	A.SetFrom(zeromean)
	tauq := cmat.NewMatrix(N, 1)
	taup := cmat.NewMatrix(N, 1)

	At := cmat.NewMatrix(N, M)
	blasd.Transpose(At, A)
	tauqt := cmat.NewMatrix(N, 1)
	taupt := cmat.NewMatrix(N, 1)

	W := lapackd.Workspace(M + N)

	lapackd.BDReduce(A, tauq, taup, W, conf)
	lapackd.BDReduce(At, tauqt, taupt, W, conf)

	// BiRed(A) == BiRed(A.T).T
	blasd.Plus(At, A, 1.0, -1.0, gomas.TRANSB)
	blasd.Axpy(tauqt, taup, -1.0)
	blasd.Axpy(taupt, tauq, -1.0)

	nrm := lapackd.NormP(At, lapackd.NORM_ONE)
	t.Logf("M=%d, N=%d || BiRed(A) - BiRed(A.T).T||_1 : %e\n", M, N, nrm)
	nrm = lapackd.NormP(taupt, lapackd.NORM_ONE)
	t.Logf("  || BiRed(A).tauq - BiRed(A.T).taup||_1 : %e\n", nrm)
	nrm = lapackd.NormP(tauqt, lapackd.NORM_ONE)
	t.Logf("  || BiRed(A).taup - BiRed(A.T).tauq||_1 : %e\n", nrm)
}
示例#2
0
func TestBiredWide(t *testing.T) {
	N := 811
	M := 693
	nb := 32
	conf := gomas.NewConf()
	conf.LB = 0
	ediag := -1

	zeromean := cmat.NewFloatNormSource()
	A := cmat.NewMatrix(M, N)
	A.SetFrom(zeromean)
	A0 := cmat.NewCopy(A)

	tauq := cmat.NewMatrix(N, 1)
	taup := cmat.NewMatrix(N, 1)

	W := lapackd.Workspace(M + N)
	lapackd.BDReduce(A, tauq, taup, W, conf)

	var D, E, Bd, Be cmat.FloatMatrix
	D.Diag(A)
	E.Diag(A, ediag)

	B := cmat.NewMatrix(M, N)
	Bd.Diag(B)
	Be.Diag(B, ediag)
	blasd.Copy(&Bd, &D)
	blasd.Copy(&Be, &E)

	Bt := cmat.NewMatrix(N, M)
	blasd.Transpose(Bt, B)

	conf.LB = nb
	W0 := lapackd.Workspace(lapackd.BDMultWork(B, conf))
	lapackd.BDMult(B, A, tauq, W0, gomas.MULTQ|gomas.LEFT, conf)
	lapackd.BDMult(Bt, A, tauq, W0, gomas.MULTQ|gomas.RIGHT|gomas.TRANS, conf)

	lapackd.BDMult(B, A, taup, W0, gomas.MULTP|gomas.RIGHT|gomas.TRANS, conf)
	lapackd.BDMult(Bt, A, taup, W0, gomas.MULTP|gomas.LEFT, conf)

	blasd.Plus(B, A0, 1.0, -1.0, gomas.NONE)
	nrm := lapackd.NormP(B, lapackd.NORM_ONE)
	t.Logf("M=%d, N=%d ||A - Q*B*P.T||_1   : %e\n", M, N, nrm)
	blasd.Plus(Bt, A0, 1.0, -1.0, gomas.TRANSB)
	nrm = lapackd.NormP(Bt, lapackd.NORM_ONE)
	t.Logf("M=%d, N=%d ||A.T - P*B.T*Q.T||_1 : %e\n", M, N, nrm)
}
示例#3
0
文件: lq_test.go 项目: hrautila/gomas
// test: ||C - Q*Q.T*C||_1 ~= 0;
//   multipling from left requires: m(C) == n(A) [n(Q)]
func TestLQMultLeft(t *testing.T) {
	M := 771
	N := 813
	nb := 16
	conf := gomas.NewConf()

	A := cmat.NewMatrix(M, N)
	src := cmat.NewFloatNormSource()
	A.SetFrom(src)
	// C0 := A
	C0 := cmat.NewCopy(A)
	C1t := cmat.NewMatrix(N, M)
	blasd.Transpose(C1t, C0)
	C2t := cmat.NewCopy(C1t)

	tau := cmat.NewMatrix(M, 1)
	W := cmat.NewMatrix(M+N, 1)

	conf.LB = 0
	lapackd.LQFactor(A, tau, W, conf)

	// A0 := Q.T*A0
	conf.LB = 0
	lapackd.LQMult(C2t, A, tau, W, gomas.LEFT, conf)
	lapackd.LQMult(C2t, A, tau, W, gomas.LEFT|gomas.TRANS, conf)

	// A0 := Q.T*A0
	conf.LB = nb
	W1 := lapackd.Workspace(lapackd.LQMultWork(C1t, gomas.LEFT, conf))
	lapackd.LQMult(C1t, A, tau, W1, gomas.LEFT, conf)
	lapackd.LQMult(C1t, A, tau, W1, gomas.LEFT|gomas.TRANS, conf)

	blasd.Plus(C0, C1t, 1.0, -1.0, gomas.TRANSB)
	nrm := lapackd.NormP(C0, lapackd.NORM_ONE)
	t.Logf("M=%d, N=%d, ||C - Q*Q*T*C||_1: %e\n", M, N, nrm)

	blasd.Plus(C1t, C2t, 1.0, -1.0, gomas.NONE)
	nrm = lapackd.NormP(C1t, lapackd.NORM_ONE)
	t.Logf("M=%d, N=%d, ||unblk(Q*Q.T*C) - blk(Q*Q*T*C)||_1: %e\n", M, N, nrm)
}