Exemplo n.º 1
0
func runTest(A *matrix.FloatMatrix, ntest, LB int) time.Duration {

	var flags matops.Flags
	var mintime time.Duration

	N := A.Rows()
	ipiv := make([]int, N, N)
	flags = matops.LOWER
	if testUpper {
		flags = matops.UPPER
	}

	W := matrix.FloatZeros(A.Rows(), LB+2)
	fnc := func() {
		_, ERRmatops = matops.DecomposeBK(A, W, ipiv, flags, 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
}
Exemplo n.º 2
0
// single invocation for matops and lapack functions
func runCheck(A *matrix.FloatMatrix, LB int) (bool, time.Duration, time.Duration) {

	var flags matops.Flags
	N := A.Rows()
	ipiv := make([]int, N, N)
	ipiv0 := make([]int32, N, N)
	flags = matops.LOWER
	lopt := linalg.OptLower
	if testUpper {
		flags = matops.UPPER
		lopt = linalg.OptUpper
	}
	W := matrix.FloatZeros(A.Rows(), LB+2)
	fnc := func() {
		_, ERRmatops = matops.DecomposeBK(A, W, ipiv, flags, 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, "ipiv:%v\n", ipiv)
		fmt.Fprintf(os.Stderr, "A end:\n%v\n", A)
	}

	fn2 := func() {
		ERRlapack = lapack.Sytrf(A0, ipiv0, lopt)
	}
	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, "ipiv0:%v\n", ipiv0)
		fmt.Fprintf(os.Stderr, "A0 end:\n%v\n", A0)
	}
	// now A == A0 && ipiv == ipiv0

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