Пример #1
0
func TestQRSmal(t *testing.T) {
	data := [][]float64{
		[]float64{12.0, -51.0, 4.0},
		[]float64{6.0, 167.0, -68.0},
		[]float64{-4.0, 24.0, -41.0}}

	A := matrix.FloatMatrixFromTable(data, matrix.RowOrder)
	T := matrix.FloatZeros(A.Cols(), A.Cols())
	T0 := T.Copy()

	M := A.Rows()
	//N := A.Cols()
	Tau := matrix.FloatZeros(M, 1)
	X, _ := DecomposeQR(A.Copy(), Tau, nil, 0)
	t.Logf("A\n%v\n", A)
	t.Logf("X\n%v\n", X)
	t.Logf("Tau\n%v\n", Tau)

	Tau0 := matrix.FloatZeros(M, 1)
	lapack.Geqrf(A, Tau0)
	t.Logf("lapack X\n%v\n", A)
	t.Logf("lapack Tau\n%v\n", Tau0)

	unblkQRBlockReflector(X, Tau, T)
	t.Logf("T:\n%v\n", T)

	V := TriLU(X.Copy())
	lapack.LarftFloat(V, Tau, T0)
	t.Logf("T0:\n%v\n", T0)

}
Пример #2
0
func TestQRT(t *testing.T) {
	M := 6
	N := 5

	var Tau matrix.FloatMatrix
	A := matrix.FloatUniform(M, N)
	T := matrix.FloatZeros(A.Cols(), A.Cols())
	T0 := T.Copy()

	X, _ := DecomposeQRT(A.Copy(), T, nil, 0)
	Tau.DiagOf(T)

	Tau0 := matrix.FloatZeros(M, 1)
	A0 := A.Copy()
	lapack.Geqrf(A0, Tau0)
	ok := X.AllClose(A0)
	okt := Tau.AllClose(Tau0)
	t.Logf("lapack QR == DecomposeQR: %v\n", ok && okt)
	if !ok || !okt {
		t.Logf("A0: %d, %d, %d\n", A0.Rows(), A0.Cols(), A0.LeadingIndex())
		t.Logf("A\n%v\n", A)
		t.Logf("X\n%v\n", X)
		t.Logf("Tau\n%v\n", &Tau)
		t.Logf("lapack X\n%v\n", A0)
		t.Logf("lapack Tau\n%v\n", Tau0)
	}

	// build block reflectors
	//unblkQRBlockReflector(X, Tau, T)
	V := TriLU(A0.Copy())
	lapack.LarftFloat(V, Tau0, T0)

	ok = T0.AllClose(T)
	t.Logf("lapack.dlarft == QRBlockReflector: %v\n", ok)
	if !ok {
		t.Logf("T:\n%v\n", T)
		t.Logf("lapack T0:\n%v\n", T0)
	}
}