func runRefTest(A *matrix.FloatMatrix, ntest, LB int) time.Duration { var mintime time.Duration N := A.Cols() tau := matrix.FloatZeros(N, 1) fnc := func() { ERRlapack = lapack.Geqrf(A, tau) } A0 := A.Copy() for n := 0; n < ntest; n++ { if n > 0 { // restore original A A0.CopyTo(A) tau.Scale(0.0) } mperf.FlushCache() time0 := mperf.Timeit(fnc) if n == 0 || time0 < mintime { mintime = time0 } } return mintime }
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) }
// single invocation for matops and lapack functions func runCheck(A *matrix.FloatMatrix, LB int) (bool, time.Duration, time.Duration) { var W *matrix.FloatMatrix = nil N := A.Cols() tau := matrix.FloatZeros(N, 1) if LB > 0 { W = matrix.FloatZeros(A.Rows(), LB) } fnc := func() { _, ERRmatops = matops.DecomposeQR(A, tau, W, LB) } if verbose && N < 10 { fmt.Fprintf(os.Stderr, "A start:\n%v\n", A) } A0 := A.Copy() tau0 := tau.Copy() mperf.FlushCache() time0 := mperf.Timeit(fnc) if verbose && N < 10 { fmt.Fprintf(os.Stderr, "A end:\n%v\n", A) tau.SetSize(1, N, 1) fmt.Fprintf(os.Stderr, "tau: %v\n", tau) } fn2 := func() { ERRlapack = lapack.Geqrf(A0, tau0) } mperf.FlushCache() time2 := mperf.Timeit(fn2) if verbose && N < 10 { fmt.Fprintf(os.Stderr, "A0 end:\n%v\n", A0) tau0.SetSize(1, N, 1) // row vector fmt.Fprintf(os.Stderr, "tau0: %v\n", tau0) } // now A == A0 && tau == tau0 ok := A.AllClose(A0) oktau := tau.AllClose(tau0) if !ok || !oktau { // save result to globals Rlapack = A0 Rmatops = A TAUlapack = tau0 TAUmatops = tau } return ok && oktau, time0, time2 }
func TestQRBlk(t *testing.T) { M := 8 N := 6 nb := 2 A := matrix.FloatUniform(M, N) Tau := matrix.FloatZeros(M, 1) Tz := matrix.FloatZeros(N, N) Tx := matrix.FloatZeros(N, N) DecomposeBlockSize(0) Z, _ := DecomposeQRT(A.Copy(), Tz, nil, 0) _ = Z DecomposeBlockSize(nb) //X, _ := DecomposeQR(A.Copy(), Tau, nil) X, _ := DecomposeQRT(A.Copy(), Tx, nil, nb) Tau0 := matrix.FloatZeros(M, 1) A0 := A.Copy() lapack.Geqrf(A0, Tau0) ok := X.AllClose(A0) var dx matrix.FloatMatrix dx.DiagOf(Tx) //okt := Tau.AllClose(Tau0) okt := true _ = Tau t.Logf("lapack QR == DecomposeQR: %v\n", ok && okt) if !ok || !okt || true { 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("Tz\n%v\n", Tz) t.Logf("Tx\n%v\n", Tx) t.Logf("Tau\n%v\n", &dx) t.Logf("lapack X\n%v\n", A0) t.Logf("lapack Tau\n%v\n", Tau0) } }
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) } }