Example #1
0
// m > n: A[m,n], I[m,m] --> A.T == A.T*I == A.T*Q*Q.T
func TestBlockedQRMultRightIdent(t *testing.T) {
	M := 511
	N := 489
	A := cmat.NewMatrix(M, N)
	C := cmat.NewMatrix(N, M)
	tau := cmat.NewMatrix(N, 1)

	zeromean := cmat.NewFloatNormSource()
	A.SetFrom(zeromean)
	A0 := cmat.NewCopy(A)
	C.Transpose(A)
	conf := gomas.NewConf()
	conf.LB = 32

	// QR = A = Q*R
	W := lapackd.Workspace(lapackd.QRFactorWork(A, conf))
	lapackd.QRFactor(A, tau, W, conf)

	// C = A.T*Q
	W = lapackd.Workspace(lapackd.QRMultWork(C, gomas.RIGHT, conf))
	lapackd.QRMult(C, A, tau, W, gomas.RIGHT, conf)

	// C = C*Q.T == A.T*Q*Q.T
	lapackd.QRMult(C, A, tau, W, gomas.RIGHT|gomas.TRANS, conf)
	//t.Logf("A*Q*Q.T:\n%v\n", C)

	// A = A - (A.T*Q*Q.T).T
	blasd.Plus(A0, C, 1.0, -1.0, gomas.TRANSB)
	// ||A - (A.T*Q*Q.T).T||_1
	nrm := lapackd.NormP(A0, lapackd.NORM_ONE)
	t.Logf("M=%d,N=%d  ||A - (A.T*Q*Q.T).T||_1: %e\n", M, N, nrm)
}
Example #2
0
// m > n: A[m,n], I[m,m] --> A == I*A == Q*Q.T*A
func TestBlkQRMultLeftIdent(t *testing.T) {
	M := 411
	N := 399
	A := cmat.NewMatrix(M, N)
	tau := cmat.NewMatrix(N, 1)

	zeromean := cmat.NewFloatNormSource()
	A.SetFrom(zeromean)
	A0 := cmat.NewCopy(A)
	C := cmat.NewCopy(A)
	conf := gomas.NewConf()
	conf.LB = 32

	// QR = A = Q*R
	W := lapackd.Workspace(lapackd.QRFactorWork(A, conf))
	lapackd.QRFactor(A, tau, W, conf)
	//t.Logf("T:\n%v\n", T)

	// C = Q.T*A
	W = lapackd.Workspace(lapackd.QRMultWork(C, gomas.LEFT, conf))
	lapackd.QRMult(C, A, tau, W, gomas.LEFT|gomas.TRANS, conf)

	// C = Q*C == Q*Q.T*A
	lapackd.QRMult(C, A, tau, W, gomas.LEFT, conf)
	//t.Logf("A*Q*Q.T:\n%v\n", C)

	// A = A - Q*Q.T*A
	blasd.Plus(A0, C, 1.0, -1.0, gomas.NONE)
	// ||A - Q*Q.T*A||_1
	nrm := lapackd.NormP(A0, lapackd.NORM_ONE)
	t.Logf("M=%d,N=%d  ||A - Q*Q.T*A||_1: %e\n", M, N, nrm)
}
Example #3
0
// QR decompose A, then compute ||A - (R.T*Q.T).T||_1, should be small
func TestUnblkQRMultRight(t *testing.T) {
	M := 711
	N := 593
	A := cmat.NewMatrix(M, N)
	C := cmat.NewMatrix(N, M)
	tau := cmat.NewMatrix(N, 1)

	zeromean := cmat.NewFloatNormSource()
	A.SetFrom(zeromean)
	A0 := cmat.NewCopy(A)

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

	// QR = A = Q*R
	W := lapackd.Workspace(lapackd.QRFactorWork(A, conf))
	lapackd.QRFactor(A, tau, W, conf)

	// C = transpose(TriU(QR)) = R.T
	C.Transpose(cmat.TriU(cmat.NewCopy(A), cmat.NONE))

	// C = C*Q.T = R.T*Q.T
	W = lapackd.Workspace(lapackd.QRMultWork(C, gomas.RIGHT, conf))
	err := lapackd.QRMult(C, A, tau, W, gomas.RIGHT|gomas.TRANS, conf)
	if err != nil {
		t.Logf("err: %v\n", err)
	}

	// A = A - QR
	blasd.Plus(A0, C, 1.0, -1.0, gomas.TRANSB)
	// ||A - Q*R||_1
	nrm := lapackd.NormP(A0, lapackd.NORM_ONE)
	t.Logf("M=%d,N=%d  ||A - (R.T*Q.T).T||_1: %e\n", M, N, nrm)
}
Example #4
0
// QR decompose A, then compute ||A - Q*R||_1, should be small
func TestUnblkQRMultLeft(t *testing.T) {
	M := 711
	N := 593
	A := cmat.NewMatrix(M, N)
	tau := cmat.NewMatrix(N, 1)

	zeromean := cmat.NewFloatNormSource()
	A.SetFrom(zeromean)
	A0 := cmat.NewCopy(A)

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

	// QR = A = Q*R
	W := lapackd.Workspace(lapackd.QRFactorWork(A, conf))
	lapackd.QRFactor(A, tau, W, conf)

	// C = TriU(QR) = R
	C := cmat.TriU(cmat.NewCopy(A), cmat.NONE)

	// C = Q*C
	W = lapackd.Workspace(lapackd.QRMultWork(C, gomas.LEFT, conf))
	err := lapackd.QRMult(C, A, tau, W, gomas.LEFT, conf)
	if err != nil {
		t.Logf("err: %v\n", err)
	}

	// A = A - QR
	blasd.Plus(A0, C, 1.0, -1.0, gomas.NONE)
	// ||A - Q*R||_1
	nrm := lapackd.NormP(A0, lapackd.NORM_ONE)
	t.Logf("M=%d,N=%d  ||A - Q*R||_1: %e\n", M, N, nrm)
}