Beispiel #1
0
func runTest(A *matrix.FloatMatrix, ntest, LB int) time.Duration {

	var mintime time.Duration

	M := A.Rows()
	N := A.Cols()
	nN := N
	if M < N {
		nN = M
	}
	ipiv := make([]int, nN, nN)

	fnc := func() {
		_, ERRmatops = matops.DecomposeLU(A, ipiv, LB)
	}

	A0 := A.Copy()
	for n := 0; n < ntest; n++ {
		if n > 0 {
			// restore original A
			A0.CopyTo(A)
		}
		mperf.FlushCache()
		time0 := mperf.Timeit(fnc)
		if n == 0 || time0 < mintime {
			mintime = time0
		}
		if verbose {
			fmt.Printf("%.4f ms\n", time0.Seconds()*1000.0)
		}
	}
	return mintime
}
Beispiel #2
0
// single invocation for matops and lapack functions
func runCheck(A *matrix.FloatMatrix, LB int) (bool, time.Duration, time.Duration) {

	M := A.Rows()
	N := A.Cols()
	nN := N
	if M < N {
		nN = M
	}
	ipiv := make([]int, nN, nN)
	ipiv0 := make([]int32, nN, nN)
	fnc := func() {
		_, ERRmatops = matops.DecomposeLU(A, ipiv, LB)
	}

	if verbose && N < 10 {
		fmt.Fprintf(os.Stderr, "A start:\n%v\n", A)
	}
	A0 := A.Copy()
	mperf.FlushCache()
	time0 := mperf.Timeit(fnc)
	if verbose && N < 10 {
		fmt.Fprintf(os.Stderr, "A end:\n%v\n", A)
		fmt.Fprintf(os.Stderr, "ipiv:%v\n", ipiv)
	}

	fn2 := func() {
		ERRlapack = lapack.Getrf(A0, ipiv0)
	}
	if verbose && N < 10 {
		fmt.Fprintf(os.Stderr, "A0 start:\n%v\n", A0)
	}
	mperf.FlushCache()
	time2 := mperf.Timeit(fn2)
	if verbose && N < 10 {
		fmt.Fprintf(os.Stderr, "A0 end:\n%v\n", A0)
		fmt.Fprintf(os.Stderr, "ipiv0:%v\n", ipiv0)
	}
	// now A == A0 && ipiv == ipiv0

	ok := A.AllClose(A0)
	okip := checkIPIV(ipiv, ipiv0)
	_ = okip
	if !ok || !okip {
		// save result to globals
		Rlapack = A0
		Rmatops = A
		IPIVlapack = ipiv0
		IPIVmatops = ipiv
	}
	return ok && okip, time0, time2
}