Example #1
0
func runRefTest(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([]int32, nN, nN)

	fnc := func() {
		ERRlapack = lapack.Getrf(A, ipiv)
	}

	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
		}
	}
	return mintime
}
Example #2
0
func _TestLU3x3Piv(t *testing.T) {
	Adata2 := [][]float64{
		[]float64{3.0, 2.0, 2.0},
		[]float64{6.0, 4.0, 1.0},
		[]float64{4.0, 6.0, 3.0},
	}
	A := matrix.FloatMatrixFromTable(Adata2, matrix.RowOrder)
	piv := make([]int, A.Rows())
	piv0 := make([]int32, A.Rows())
	A0 := A.Copy()
	t.Logf("start A\n%v\n", A)
	DecomposeBlockSize(0)
	DecomposeLU(A, piv, 0)
	Ld := TriLU(A.Copy())
	Ud := TriU(A.Copy())
	t.Logf("A\n%v\n", A)
	t.Logf("Ld:\n%v\n", Ld)
	t.Logf("Ud:\n%v\n", Ud)
	t.Logf("piv: %v\n", piv)
	t.Logf("result:\n%v\n", matrix.Times(Ld, Ud))
	//t.Logf("A == L*U: %v\n", A0.AllClose(matrix.Times(Ld, Ud)))
	lapack.Getrf(A0, piv0)
	t.Logf("lapack result: piv0 %v\n%v\n", piv0, A0)
	t.Logf("A == A0: %v\n", A0.AllClose(A))
}
Example #3
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
}
Example #4
0
func _TestBlkLUPiv(t *testing.T) {
	N := 10
	nb := 4
	L := matrix.FloatUniformSymmetric(N, matrix.Lower)
	U := matrix.FloatUniformSymmetric(N, matrix.Upper)
	// Set L diagonal to 1.0
	L.Diag().SetIndexes(1.0)

	A := matrix.Times(L, U)
	A0 := A.Copy()
	piv := make([]int, N, N)
	DecomposeBlockSize(nb)
	R, _ := DecomposeLU(A.Copy(), piv, 0)
	t.Logf("piv: %v\n", piv)

	piv0 := make([]int32, N, N)
	lapack.Getrf(A0, piv0)
	t.Logf("lapack result: piv0 %v\n", piv0)
	t.Logf("R == A0: %v\n", A0.AllClose(R))
}