Ejemplo n.º 1
0
func _TestRankSmall(t *testing.T) {
	bM := 5
	bN := 5
	//bP := 5
	Adata := [][]float64{
		[]float64{1.0, 1.0, 1.0, 1.0, 1.0},
		[]float64{2.0, 2.0, 2.0, 2.0, 2.0},
		[]float64{3.0, 3.0, 3.0, 3.0, 3.0},
		[]float64{4.0, 4.0, 4.0, 4.0, 4.0},
		[]float64{5.0, 5.0, 5.0, 5.0, 5.0}}

	A := matrix.FloatMatrixFromTable(Adata, matrix.RowOrder)
	A0 := matrix.FloatMatrixFromTable(Adata, matrix.RowOrder)
	X := matrix.FloatVector([]float64{1.0, 2.0, 3.0, 4.0, 5.0})
	Y := matrix.FloatWithValue(bN, 1, 2.0)

	Ar := A.FloatArray()
	Xr := X.FloatArray()
	Yr := Y.FloatArray()

	blas.GerFloat(X, Y, A0, 1.0)

	DRankMV(Ar, Xr, Yr, 1.0, A.LeadingIndex(), 1, 1, 0, bN, 0, bM, 4, 4)
	ok := A0.AllClose(A)
	t.Logf("A0 == A1: %v\n", ok)
	if !ok {
		t.Logf("blas ger:\n%v\n", A0)
		t.Logf("A1: \n%v\n", A)
	}
}
Ejemplo n.º 2
0
func TestTrsmUnblk(t *testing.T) {
	//bN := 7
	Udata3 := [][]float64{
		[]float64{2.0, 2.0, 2.0},
		[]float64{0.0, 3.0, 3.0},
		[]float64{0.0, 0.0, 4.0}}
	U3 := matrix.FloatMatrixFromTable(Udata3, matrix.RowOrder)
	_ = U3

	Ldata3 := [][]float64{
		[]float64{1.0, 0.0, 0.0},
		[]float64{1.0, 2.0, 0.0},
		[]float64{1.0, 2.0, 3.0}}
	L3 := matrix.FloatMatrixFromTable(Ldata3, matrix.RowOrder)
	_ = L3

	bN := 10
	nP := 7
	nb := 4
	L := matrix.FloatNormalSymmetric(bN, matrix.Lower)

	//t.Logf("-- TRSM-UPPER, TRANS, RIGHT, NON_UNIT --")
	//trsmSolve(t, U3, UPPER|TRANSA|RIGHT, false, 2, 0)
	//t.Logf("-- TRSM-UPPER, TRANS, RIGHT, UNIT --")
	//trsmSolve(t, U3, UPPER|TRANSA|UNIT|RIGHT, false, 2, 0)

	t.Logf("-- UNBLK TRSM-LOWER, TRANS, RIGHT, NON-UNIT --")
	trsmSolve(t, L, LOWER|TRANSA|RIGHT, false, nP, 0)
	t.Logf("-- BLK   TRSM-LOWER, TRANS, RIGHT, NON-UNIT --")
	trsmSolve(t, L, LOWER|TRANSA|RIGHT, false, nP, nb)

}
Ejemplo n.º 3
0
func _TestSyrk2Small(t *testing.T) {
	//bN := 7
	Udata3 := [][]float64{
		[]float64{2.0, 2.0, 2.0},
		[]float64{0.0, 3.0, 3.0},
		[]float64{0.0, 0.0, 4.0}}

	Udata := [][]float64{
		[]float64{1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0},
		[]float64{0.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0},
		[]float64{0.0, 0.0, 3.0, 3.0, 3.0, 3.0, 3.0},
		[]float64{0.0, 0.0, 0.0, 4.0, 4.0, 4.0, 4.0},
		[]float64{0.0, 0.0, 0.0, 0.0, 5.0, 5.0, 5.0},
		[]float64{0.0, 0.0, 0.0, 0.0, 0.0, 6.0, 6.0},
		[]float64{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 7.0}}
	U := matrix.FloatMatrixFromTable(Udata, matrix.RowOrder)
	U3 := matrix.FloatMatrixFromTable(Udata3, matrix.RowOrder)
	_ = U
	_ = U3

	Ldata3 := [][]float64{
		[]float64{1.0, 0.0, 0.0},
		[]float64{1.0, 2.0, 0.0},
		[]float64{1.0, 2.0, 3.0}}

	Ldata := [][]float64{
		[]float64{1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
		[]float64{1.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0},
		[]float64{1.0, 2.0, 3.0, 0.0, 0.0, 0.0, 0.0},
		[]float64{1.0, 2.0, 3.0, 4.0, 0.0, 0.0, 0.0},
		[]float64{1.0, 2.0, 3.0, 4.0, 5.0, 0.0, 0.0},
		[]float64{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 0.0},
		[]float64{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0}}
	L := matrix.FloatMatrixFromTable(Ldata, matrix.RowOrder)
	L3 := matrix.FloatMatrixFromTable(Ldata3, matrix.RowOrder)
	_ = L
	_ = L3

	Adata := [][]float64{
		[]float64{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0},
		[]float64{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0}}
	Bdata := [][]float64{
		[]float64{7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0},
		[]float64{7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0}}
	_ = Bdata
	A := matrix.FloatMatrixFromTable(Adata)
	//B := matrix.FloatMatrixFromTable(Bdata);
	B := matrix.FloatNormal(7, 2)
	t.Logf("-- SYR2K UPPER --")
	syrk2Test(t, U.Copy(), A, B, UPPER, 4, 2)
	t.Logf("-- SYR2K LOWER --")
	syrk2Test(t, L.Copy(), A, B, LOWER, 4, 2)
	t.Logf("-- SYR2K UPPER, TRANSA --")
	//t.Logf("A: \n%v\n", A.Transpose())
	syrk2Test(t, U.Copy(), A.Transpose(), B.Transpose(), UPPER|TRANSA, 4, 2)
	t.Logf("-- SYR2K LOWER, TRANS --")
	syrk2Test(t, L.Copy(), A.Transpose(), B.Transpose(), LOWER|TRANSA, 4, 2)
}
Ejemplo n.º 4
0
func _TestBKpivot1(t *testing.T) {
	Ldata := [][]float64{
		[]float64{1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
		[]float64{1.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0},
		[]float64{1.0, 2.0, 3.0, 0.0, 0.0, 0.0, 0.0},
		[]float64{1.0, 2.0, 3.0, 4.0, 0.0, 0.0, 0.0},
		[]float64{1.0, 5.0, 3.0, 4.0, 5.0, 0.0, 0.0},
		[]float64{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 0.0},
		[]float64{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0}}

	Bdata := [][]float64{
		[]float64{10.0, 20.0},
		[]float64{10.0, 20.0},
		[]float64{10.0, 20.0},
		[]float64{10.0, 20.0},
		[]float64{10.0, 20.0},
		[]float64{10.0, 20.0},
		[]float64{10.0, 20.0}}

	A := matrix.FloatMatrixFromTable(Ldata, matrix.RowOrder)
	X := matrix.FloatMatrixFromTable(Bdata, matrix.RowOrder)
	N := A.Rows()
	B := matrix.FloatZeros(N, 2)
	MultSym(B, A, X, 1.0, 0.0, LOWER|LEFT)
	t.Logf("initial B:\n%v\n", B)
	//N := 8
	//A := matrix.FloatUniformSymmetric(N)
	nb := 0

	W := matrix.FloatWithValue(A.Rows(), 5, 0.0)

	ipiv := make([]int, N, N)
	L, _ := DecomposeBK(A.Copy(), W, ipiv, LOWER, nb)
	t.Logf("ipiv: %v\n", ipiv)
	t.Logf("L:\n%v\n", L)

	ipiv0 := make([]int, N, N)
	nb = 4
	L0, _ := DecomposeBK(A.Copy(), W, ipiv0, LOWER, nb)
	t.Logf("ipiv: %v\n", ipiv0)
	t.Logf("L:\n%v\n", L0)
	B0 := B.Copy()
	SolveBK(B0, L0, ipiv0, LOWER)
	t.Logf("B0:\n%v\n", B0)

	ipiv2 := make([]int32, N, N)
	lapack.SytrfFloat(A, ipiv2, linalg.OptLower)
	t.Logf("ipiv2: %v\n", ipiv2)
	t.Logf("lapack A:\n%v\n", A)
	lapack.Sytrs(A, B, ipiv2, linalg.OptLower)
	t.Logf("lapack B:\n%v\n", B)
	t.Logf("B == B0: %v\n", B.AllClose(B0))
}
Ejemplo n.º 5
0
func _TestBKpivot2n2U(t *testing.T) {
	Ldata := [][]float64{
		[]float64{1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0},
		[]float64{1.0, 2.0, 2.0, 2.0, 5.0, 2.0, 2.0},
		[]float64{1.0, 2.0, 3.0, 3.0, 3.0, 3.0, 3.0},
		[]float64{1.0, 2.0, 3.0, 4.0, 4.0, 4.0, 10.0},
		[]float64{1.0, 5.0, 3.0, 4.0, 5.0, 9.0, 5.0},
		[]float64{1.0, 2.0, 3.0, 4.0, 9.0, 6.0, 6.0},
		[]float64{1.0, 2.0, 3.0, 10.0, 5.0, 6.0, 7.0}}

	Bdata := [][]float64{
		[]float64{10.0, 20.0},
		[]float64{10.0, 20.0},
		[]float64{10.0, 20.0},
		[]float64{10.0, 20.0},
		[]float64{10.0, 20.0},
		[]float64{10.0, 20.0},
		[]float64{10.0, 20.0}}

	A := matrix.FloatMatrixFromTable(Ldata, matrix.RowOrder)
	X := matrix.FloatMatrixFromTable(Bdata, matrix.RowOrder)
	N := A.Rows()
	B := matrix.FloatZeros(N, 2)
	MultSym(B, A, X, 1.0, 0.0, UPPER|LEFT)
	//t.Logf("initial B:\n%v\n", B)

	nb := 0
	W := matrix.FloatWithValue(A.Rows(), 5, 0.0)
	ipiv := make([]int, N, N)
	L, _ := DecomposeBK(A.Copy(), W, ipiv, UPPER, nb)
	t.Logf("ipiv: %v\n", ipiv)
	t.Logf("L:\n%v\n", L)

	//ipiv0 := make([]int, N, N)
	//nb = 4
	//L0, _ := DecomposeBK(A.Copy(), W, ipiv0, UPPER, nb)
	//t.Logf("ipiv: %v\n", ipiv0)
	//t.Logf("L:\n%v\n", L0)
	//B0 := B.Copy()
	//SolveBK(B0, L0, ipiv0, UPPER)
	//t.Logf("B0:\n%v\n", B0)

	ipiv2 := make([]int32, N, N)
	lapack.SytrfFloat(A, ipiv2, linalg.OptUpper)
	t.Logf("ipiv2: %v\n", ipiv2)
	t.Logf("lapack A:\n%v\n", A)
	//lapack.Sytrs(A, B, ipiv2, linalg.OptUpper)
	//t.Logf("lapack B:\n%v\n", B)
	//t.Logf("B == B0: %v\n", B.AllClose(B0))
}
Ejemplo n.º 6
0
func _TestTrmmUnblkSmall(t *testing.T) {

	U := matrix.FloatMatrixFromTable(upper7, matrix.RowOrder)
	U3 := matrix.FloatMatrixFromTable(upper3, matrix.RowOrder)
	_ = U
	_ = U3

	L := matrix.FloatMatrixFromTable(lower7, matrix.RowOrder)
	L3 := matrix.FloatMatrixFromTable(lower3, matrix.RowOrder)
	_ = L

	t.Logf("-- TRMM-UPPER, NON-UNIT ---")
	fail(t, trmmTest(t, U3, UPPER, 0))
	t.Logf("-- TRMM-UPPER, UNIT ---")
	fail(t, trmmTest(t, U3, UPPER|UNIT, 0))
	t.Logf("-- TRMM-UPPER, NON-UNIT, TRANSA ---")
	fail(t, trmmTest(t, U3, UPPER|TRANSA, 0))
	t.Logf("-- TRMM-UPPER, UNIT, TRANSA ---")
	fail(t, trmmTest(t, U3, UPPER|TRANSA|UNIT, 0))
	t.Logf("-- TRMM-LOWER, NON-UNIT ---")
	fail(t, trmmTest(t, L3, LOWER, 0))
	t.Logf("-- TRMM-LOWER, UNIT ---")
	fail(t, trmmTest(t, L3, LOWER|UNIT, 0))
	t.Logf("-- TRMM-LOWER, NON-UNIT, TRANSA ---")
	fail(t, trmmTest(t, L3, LOWER|TRANSA, 0))
	t.Logf("-- TRMM-LOWER, UNIT, TRANSA ---")
	fail(t, trmmTest(t, L3, LOWER|TRANSA|UNIT, 0))

	t.Logf("-- TRMM-UPPER, NON-UNIT, RIGHT ---")
	fail(t, trmmTest(t, U3, UPPER|RIGHT, 0))
	t.Logf("-- TRMM-UPPER, UNIT, RIGHT ---")
	fail(t, trmmTest(t, U3, UPPER|UNIT|RIGHT, 0))

	t.Logf("-- TRMM-LOWER, NON-UNIT, RIGHT ---")
	fail(t, trmmTest(t, L3, LOWER|RIGHT, 0))
	t.Logf("-- TRMM-LOWER, UNIT, RIGHT ---")
	fail(t, trmmTest(t, L3, LOWER|UNIT|RIGHT, 0))

	t.Logf("-- TRMM-UPPER, NON-UNIT, RIGHT, TRANSA ---")
	fail(t, trmmTest(t, U3, UPPER|RIGHT|TRANSA, 0))
	t.Logf("-- TRMM-UPPER, UNIT, RIGHT, TRANSA ---")
	fail(t, trmmTest(t, U3, UPPER|UNIT|RIGHT|TRANSA, 0))

	t.Logf("-- TRMM-LOWER, NON-UNIT, RIGHT, TRANSA ---")
	fail(t, trmmTest(t, L3, LOWER|RIGHT|TRANSA, 0))
	t.Logf("-- TRMM-LOWER, UNIT, RIGHT, TRANSA ---")
	fail(t, trmmTest(t, L3, LOWER|UNIT|RIGHT|TRANSA, 0))

}
Ejemplo n.º 7
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)

}
Ejemplo n.º 8
0
func TestTrmvSmall(t *testing.T) {

	L := matrix.FloatMatrixFromTable(lower5, matrix.RowOrder)
	U := L.Transpose()
	nb := 0

	t.Logf("-- TRMV, LOWER --")
	trmvTest(t, L, LOWER, nb)
	t.Logf("-- TRMV, UPPER --")
	trmvTest(t, U, UPPER, nb)

	t.Logf("-- TRMV, LOWER, UNIT --")
	trmvTest(t, L, LOWER|UNIT, nb)
	t.Logf("-- TRMV, UPPER, UNIT --")
	trmvTest(t, U, UPPER|UNIT, nb)

	t.Logf("-- TRMV, LOWER, TRANS --")
	trmvTest(t, L, LOWER|TRANS, nb)
	t.Logf("-- TRMV, UPPER, TRANS --")
	trmvTest(t, U, UPPER|TRANS, nb)

	t.Logf("-- TRMV, LOWER, TRANS, UNIT --")
	trmvTest(t, L, LOWER|UNIT|TRANS, nb)
	t.Logf("-- TRMV, UPPER, TRANS, UNIT --")
	trmvTest(t, U, UPPER|UNIT|TRANS, nb)
}
Ejemplo n.º 9
0
func _TestSolveBlockedSmall(t *testing.T) {

	L := matrix.FloatMatrixFromTable(lower5, matrix.RowOrder)
	N := L.Rows()
	nb := 4

	U := L.Transpose()
	X0 := matrix.FloatWithValue(L.Rows(), 1, 1.0)
	X1 := X0.Copy()
	xsum := 0.0
	for i := 0; i < N; i++ {
		xsum += float64(i)
		X0.Add(xsum, i)
		X1.Add(xsum, -(i + 1))
	}

	t.Logf("-- SOLVE LOWER, NON-UNIT ---\n")
	solveMVTest(t, L, X0.Copy(), LOWER, N, nb)
	t.Logf("-- SOLVE UPPER, NON-UNIT ---\n")
	solveMVTest(t, U, X1.Copy(), UPPER, N, nb)

	t.Logf("-- SOLVE LOWER, UNIT ---\n")
	solveMVTest(t, L, X0.Copy(), LOWER|UNIT, N, nb)
	t.Logf("-- SOLVE UPPER, UNIT ---\n")
	solveMVTest(t, U, X1.Copy(), UPPER|UNIT, N, nb)
}
Ejemplo n.º 10
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))
}
Ejemplo n.º 11
0
func _TestViewUpdate(t *testing.T) {
	Adata2 := [][]float64{
		[]float64{4.0, 2.0, 2.0},
		[]float64{6.0, 4.0, 2.0},
		[]float64{4.0, 6.0, 1.0},
	}

	A := matrix.FloatMatrixFromTable(Adata2, matrix.RowOrder)
	N := A.Rows()

	// simple LU decomposition without pivoting
	var A11, a10, a01, a00 matrix.FloatMatrix
	for k := 1; k < N; k++ {
		a00.SubMatrixOf(A, k-1, k-1, 1, 1)
		a01.SubMatrixOf(A, k-1, k, 1, A.Cols()-k)
		a10.SubMatrixOf(A, k, k-1, A.Rows()-k, 1)
		A11.SubMatrixOf(A, k, k)
		//t.Logf("A11: %v  a01: %v\n", A11, a01)
		a10.Scale(1.0 / a00.Float())
		MVRankUpdate(&A11, &a10, &a01, -1.0)
	}

	Ld := TriLU(A.Copy())
	Ud := TriU(A)
	t.Logf("Ld:\n%v\nUd:\n%v\n", Ld, Ud)
	An := matrix.FloatZeros(N, N)
	Mult(An, Ld, Ud, 1.0, 1.0, NOTRANS)
	t.Logf("A == Ld*Ud: %v\n", An.AllClose(An))
}
Ejemplo n.º 12
0
func _TestMultSymmLowerSmall(t *testing.T) {
	//bM := 5
	bN := 7
	bP := 7
	Adata := [][]float64{
		[]float64{1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
		[]float64{1.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0},
		[]float64{1.0, 2.0, 3.0, 0.0, 0.0, 0.0, 0.0},
		[]float64{1.0, 2.0, 3.0, 4.0, 0.0, 0.0, 0.0},
		[]float64{1.0, 2.0, 3.0, 4.0, 5.0, 0.0, 0.0},
		[]float64{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 0.0},
		[]float64{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0}}

	A := matrix.FloatMatrixFromTable(Adata, matrix.RowOrder)
	B := matrix.FloatNormal(bN, bP)
	C0 := matrix.FloatZeros(bN, bP)
	C1 := matrix.FloatZeros(bN, bP)

	Ar := A.FloatArray()
	Br := B.FloatArray()
	C1r := C1.FloatArray()

	blas.SymmFloat(A, B, C0, 1.0, 1.0, linalg.OptLower, linalg.OptRight)

	DMultSymm(C1r, Ar, Br, 1.0, 1.0, LOWER|RIGHT, bN, A.LeadingIndex(), bN,
		bN, 0, bP, 0, bN, 2, 2, 2)
	ok := C0.AllClose(C1)
	t.Logf("C0 == C1: %v\n", ok)
	if !ok {
		t.Logf("A=\n%v\n", A)
		t.Logf("blas: C=A*B\n%v\n", C0)
		t.Logf("C1: C1 = A*X\n%v\n", C1)
	}
}
Ejemplo n.º 13
0
func _TestBKSolve(t *testing.T) {
	Ldata := [][]float64{
		[]float64{1.0, 2.0, 3.0, 4.0},
		[]float64{2.0, 2.0, 3.0, 4.0},
		[]float64{3.0, 3.0, 3.0, 4.0},
		[]float64{4.0, 4.0, 4.0, 4.0}}
	Xdata := [][]float64{
		[]float64{1.0, 2.0},
		[]float64{1.0, 2.0},
		[]float64{1.0, 2.0},
		[]float64{1.0, 2.0}}

	A := matrix.FloatMatrixFromTable(Ldata, matrix.RowOrder)
	X := matrix.FloatMatrixFromTable(Xdata, matrix.RowOrder)
	N := A.Rows()
	B := matrix.FloatZeros(N, 2)
	Mult(B, A, X, 1.0, 0.0, NOTRANS)
	S := matrix.FloatZeros(N, 2)
	MultSym(S, A, X, 1.0, 0.0, LOWER|LEFT)
	t.Logf("B:\n%v\n", B)
	t.Logf("S:\n%v\n", S)
	//N := 8
	//A := matrix.FloatUniformSymmetric(N)
	nb := 0

	W := matrix.FloatWithValue(A.Rows(), 5, 0.0)

	ipiv := make([]int, N, N)
	L, _ := DecomposeBK(A.Copy(), W, ipiv, LOWER, nb)
	t.Logf("ipiv: %v\n", ipiv)
	t.Logf("L:\n%v\n", L)
	B0 := B.Copy()
	SolveBK(B0, L, ipiv, LOWER)
	t.Logf("B0:\n%v\n", B0)

	ipiv2 := make([]int32, N, N)
	lapack.Sytrf(A, ipiv2, linalg.OptLower)
	t.Logf("ipiv2: %v\n", ipiv2)
	t.Logf("lapack A:\n%v\n", A)
	lapack.Sytrs(A, B, ipiv2, linalg.OptLower)
	t.Logf("lapack B:\n%v\n", B)
}
Ejemplo n.º 14
0
func _TestTrmmBlkSmall(t *testing.T) {
	//bN := 7
	Udata := [][]float64{
		[]float64{1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0},
		[]float64{0.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0},
		[]float64{0.0, 0.0, 3.0, 3.0, 3.0, 3.0, 3.0},
		[]float64{0.0, 0.0, 0.0, 4.0, 4.0, 4.0, 4.0},
		[]float64{0.0, 0.0, 0.0, 0.0, 5.0, 5.0, 5.0},
		[]float64{0.0, 0.0, 0.0, 0.0, 0.0, 6.0, 6.0},
		[]float64{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 7.0}}
	U := matrix.FloatMatrixFromTable(Udata, matrix.RowOrder)
	_ = U

	Ldata := [][]float64{
		[]float64{1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
		[]float64{1.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0},
		[]float64{1.0, 2.0, 3.0, 0.0, 0.0, 0.0, 0.0},
		[]float64{1.0, 2.0, 3.0, 4.0, 0.0, 0.0, 0.0},
		[]float64{1.0, 2.0, 3.0, 4.0, 5.0, 0.0, 0.0},
		[]float64{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 0.0},
		[]float64{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0}}
	L := matrix.FloatMatrixFromTable(Ldata, matrix.RowOrder)
	_ = L

	t.Logf("-- TRMM-UPPER, NON-UNIT ---")
	fail(t, trmmTest(t, U, UPPER, 2))
	t.Logf("-- TRMM-UPPER, NON-UNIT, TRANSA ---")
	fail(t, trmmTest(t, U, UPPER|TRANSA, 2))
	t.Logf("-- TRMM-LOWER, NON-UNIT ---")
	fail(t, trmmTest(t, L, LOWER, 2))
	t.Logf("-- TRMM-LOWER, NON-UNIT, TRANSA ---")
	fail(t, trmmTest(t, L, LOWER|TRANSA, 2))
	t.Logf("-- TRMM-UPPER, RIGHT, NON-UNIT ---")
	fail(t, trmmTest(t, U, UPPER|RIGHT, 2))
	t.Logf("-- TRMM-UPPER, RIGHT, NON-UNIT, TRANSA ---")
	fail(t, trmmTest(t, U, UPPER|RIGHT|TRANSA, 2))
	t.Logf("-- TRMM-LOWER, RIGHT, NON-UNIT ---")
	fail(t, trmmTest(t, U, LOWER|RIGHT, 2))
	t.Logf("-- TRMM-LOWER, RIGHT, NON-UNIT, TRANSA ---")
	fail(t, trmmTest(t, U, LOWER|RIGHT|TRANSA, 2))
}
Ejemplo n.º 15
0
func _TestLU2x2NoPiv(t *testing.T) {
	Adata2 := [][]float64{
		[]float64{4.0, 3.0},
		[]float64{6.0, 3.0}}

	A := matrix.FloatMatrixFromTable(Adata2, matrix.RowOrder)
	DecomposeBlockSize(0)
	DecomposeLUnoPiv(A, 0)
	t.Logf("A\n%v\n", A)
	Ld := TriLU(A.Copy())
	Ud := TriU(A)
	t.Logf("L*U\n%v\n", matrix.Times(Ld, Ud))
}
Ejemplo n.º 16
0
func _TestCHOL3x3(t *testing.T) {
	Ldata2 := [][]float64{
		[]float64{3.0, 0.0, 0.0},
		[]float64{6.0, 4.0, 0.0},
		[]float64{4.0, 6.0, 3.0},
	}
	L := matrix.FloatMatrixFromTable(Ldata2, matrix.RowOrder)
	A := matrix.Times(L, L.Transpose())
	DecomposeBlockSize(0)
	DecomposeCHOL(A, LOWER, 0)
	Ld := TriL(A.Copy())
	t.Logf("Ld:\n%v\n", Ld)
	t.Logf("result L == Ld: %v\n", L.AllClose(Ld))
}
Ejemplo n.º 17
0
func _TestBK2(t *testing.T) {
	Bdata := [][]float64{
		[]float64{10.0, 20.0},
		[]float64{10.0, 20.0},
		[]float64{10.0, 20.0},
		[]float64{10.0, 20.0},
		[]float64{10.0, 20.0},
		[]float64{10.0, 20.0},
		[]float64{10.0, 20.0}}

	N := 7

	A0 := matrix.FloatNormal(N, N)
	A := matrix.FloatZeros(N, N)
	// A is symmetric, posivite definite
	Mult(A, A0, A0, 1.0, 1.0, TRANSB)

	X := matrix.FloatMatrixFromTable(Bdata, matrix.RowOrder)
	B := matrix.FloatZeros(N, 2)
	MultSym(B, A, X, 1.0, 0.0, LOWER|LEFT)
	t.Logf("initial B:\n%v\n", B)

	nb := 0
	W := matrix.FloatWithValue(A.Rows(), 5, 1.0)
	A.SetAt(4, 1, A.GetAt(4, 1)+1.0)
	A.SetAt(1, 4, A.GetAt(4, 1))

	ipiv := make([]int, N, N)
	L, _ := DecomposeBK(A.Copy(), W, ipiv, LOWER, nb)
	t.Logf("ipiv: %v\n", ipiv)
	t.Logf("L:\n%v\n", L)

	ipiv0 := make([]int, N, N)
	nb = 4
	L0, _ := DecomposeBK(A.Copy(), W, ipiv0, LOWER, nb)
	t.Logf("ipiv: %v\n", ipiv0)
	t.Logf("L:\n%v\n", L0)
	B0 := B.Copy()
	SolveBK(B0, L0, ipiv0, LOWER)
	t.Logf("B0:\n%v\n", B0)

	ipiv2 := make([]int32, N, N)
	lapack.Sytrf(A, ipiv2, linalg.OptLower)
	t.Logf("ipiv2: %v\n", ipiv2)
	t.Logf("lapack A:\n%v\n", A)
	lapack.Sytrs(A, B, ipiv2, linalg.OptLower)
	t.Logf("lapack B:\n%v\n", B)
	t.Logf("B == B0: %v\n", B.AllClose(B0))
}
Ejemplo n.º 18
0
func TestAcent(t *testing.T) {
	// matrix string in row order presentation
	Adata := [][]float64{
		[]float64{-7.44e-01, 1.11e-01, 1.29e+00, 2.62e+00, -1.82e+00},
		[]float64{4.59e-01, 7.06e-01, 3.16e-01, -1.06e-01, 7.80e-01},
		[]float64{-2.95e-02, -2.22e-01, -2.07e-01, -9.11e-01, -3.92e-01},
		[]float64{-7.75e-01, 1.03e-01, -1.22e+00, -5.74e-01, -3.32e-01},
		[]float64{-1.80e+00, 1.24e+00, -2.61e+00, -9.31e-01, -6.38e-01}}

	bdata := []float64{
		8.38e-01, 9.92e-01, 9.56e-01, 6.14e-01, 6.56e-01,
		3.57e-01, 6.36e-01, 5.08e-01, 8.81e-03, 7.08e-02}

	// these are solution obtained from running cvxopt acent.py with above data
	solData := []float64{-11.59728373909344512, -1.35196389161339936,
		7.21894899350256303, -3.29159917142051528, 4.90454147385329176}

	ntData := []float64{
		1.5163484265903457, 1.2433928210771914, 1.0562922103520955, 0.8816246051011607,
		0.7271128861543598, 0.42725003346248974, 0.0816777301914883, 0.0005458037072843131,
		1.6259980735305693e-10}

	b := matrix.FloatVector(bdata)
	Al := matrix.FloatMatrixFromTable(Adata, matrix.RowOrder)
	Au := matrix.Scale(Al, -1.0)
	A := matrix.FloatZeros(2*Al.Rows(), Al.Cols())
	A.SetSubMatrix(0, 0, Al)
	A.SetSubMatrix(Al.Rows(), 0, Au)

	x, nt, err := acent(A, b, 10)
	if err != nil {
		t.Logf("Acent error: %s", err)
		t.Fail()
	}
	solref := matrix.FloatVector(solData)
	ntref := matrix.FloatVector(ntData)
	soldf := matrix.Minus(x, solref)
	ntdf := matrix.Minus(matrix.FloatVector(nt), ntref)
	solNrm := blas.Nrm2Float(soldf)
	ntNrm := blas.Nrm2Float(ntdf)
	t.Logf("x  [diff=%.2e]:\n%v\n", solNrm, x)
	t.Logf("nt [diff=%.2e]:\n%v\n", ntNrm, nt)

	if solNrm > TOL {
		t.Log("solution deviates too much from expected\n")
		t.Fail()
	}
}
Ejemplo n.º 19
0
func _TestLU3x3NoPiv(t *testing.T) {
	Adata2 := [][]float64{
		[]float64{4.0, 2.0, 2.0},
		[]float64{6.0, 4.0, 2.0},
		[]float64{4.0, 6.0, 1.0},
	}

	A := matrix.FloatMatrixFromTable(Adata2, matrix.RowOrder)
	A0 := A.Copy()
	DecomposeBlockSize(0)
	DecomposeLUnoPiv(A, 0)
	t.Logf("A\n%v\n", A)
	Ld := TriLU(A.Copy())
	Ud := TriU(A.Copy())
	t.Logf("A == L*U: %v\n", A0.AllClose(matrix.Times(Ld, Ud)))
}
Ejemplo n.º 20
0
// The small GP of section 9.3 (Geometric programming).
func TestGp(t *testing.T) {

	xref := []float64{1.06032641296944741, 1.75347359157296845, 2.44603683900611868}

	aflr := 1000.0
	awall := 100.0
	alpha := 0.5
	beta := 2.0
	gamma := 0.5
	delta := 2.0

	fdata := [][]float64{
		[]float64{-1.0, 1.0, 1.0, 0.0, -1.0, 1.0, 0.0, 0.0},
		[]float64{-1.0, 1.0, 0.0, 1.0, 1.0, -1.0, 1.0, -1.0},
		[]float64{-1.0, 0.0, 1.0, 1.0, 0.0, 0.0, -1.0, 1.0}}

	gdata := []float64{1.0, 2.0 / awall, 2.0 / awall, 1.0 / aflr, alpha, 1.0 / beta, gamma, 1.0 / delta}

	g := matrix.FloatNew(8, 1, gdata).Log()
	F := matrix.FloatMatrixFromTable(fdata)
	K := []int{1, 2, 1, 1, 1, 1, 1}

	var solopts SolverOptions
	solopts.MaxIter = 40
	solopts.ShowProgress = false
	solopts.KKTSolverName = "ldl"
	sol, err := Gp(K, F, g, nil, nil, nil, nil, &solopts)
	if sol != nil && sol.Status == Optimal {
		x := sol.Result.At("x")[0]
		r := matrix.Exp(x)
		h := r.GetIndex(0)
		w := r.GetIndex(1)
		d := r.GetIndex(2)
		t.Logf("x=\n%v\n", x.ToString("%.9f"))
		t.Logf("h = %f,  w = %f, d = %f.\n", h, w, d)
		xe, _ := nrmError(matrix.FloatVector(xref), x)
		if xe > TOL {
			t.Logf("x differs [%.3e] from exepted too much.", xe)
			t.Fail()
		}
	} else {
		t.Logf("status: %v\n", err)
		t.Fail()
	}
}
Ejemplo n.º 21
0
func _TestUpdate(t *testing.T) {
	Tdata := [][]float64{
		[]float64{1.37e+00, 3.77e-01},
		[]float64{0.00e+00, 1.39e+00}}

	C1data := [][]float64{
		[]float64{2.54e-01, 9.77e-01, 8.01e-01, 9.08e-02},
		[]float64{2.82e-01, 7.43e-02, 7.30e-01, 4.93e-01}}

	C2data := [][]float64{
		[]float64{7.89e-01, 2.22e-01, 1.83e-01, 9.27e-01},
		[]float64{3.62e-01, 6.81e-01, 4.28e-01, 9.55e-01},
		[]float64{8.81e-01, 2.42e-01, 8.97e-01, 3.48e-01},
		[]float64{2.97e-01, 3.12e-01, 6.83e-01, 6.91e-01},
		[]float64{8.94e-01, 9.33e-01, 9.79e-01, 7.11e-01},
		[]float64{9.75e-02, 7.42e-01, 9.22e-01, 5.64e-01}}

	Y1data := [][]float64{
		[]float64{-1.41e+00, -1.11e+00},
		[]float64{1.46e-02, -7.04e-01}}

	Y2data := [][]float64{
		[]float64{8.19e-02, 2.62e-02},
		[]float64{3.14e-01, -2.57e-02},
		[]float64{5.05e-01, -3.73e-01},
		[]float64{4.11e-02, 2.09e-01},
		[]float64{3.08e-01, -1.34e-01},
		[]float64{3.06e-02, 4.86e-01}}

	Wdata := [][]float64{
		[]float64{1.62e+00, 3.81e-01},
		[]float64{2.28e+00, 1.01e+00},
		[]float64{2.42e+00, 1.84e+00},
		[]float64{1.24e+00, 1.30e+00}}

	T := matrix.FloatMatrixFromTable(Tdata, matrix.RowOrder)
	C1 := matrix.FloatMatrixFromTable(C1data, matrix.RowOrder)
	Y1 := matrix.FloatMatrixFromTable(Y1data, matrix.RowOrder)
	C2 := matrix.FloatMatrixFromTable(C2data, matrix.RowOrder)
	Y2 := matrix.FloatMatrixFromTable(Y2data, matrix.RowOrder)
	W := matrix.FloatMatrixFromTable(Wdata, matrix.RowOrder)
	_, _, _ = C2, Y2, W
	_, _, _ = T, C1, Y1

	C1b := C1.Copy()
	C2b := C2.Copy()
	update(t, Y1, Y2, C1, C2, T, W)
	t.Logf("C1:\n%v\n", C1)
	updateBlas(t, Y1, Y2, C1b, C2b, T, W)
	t.Logf("C1b:\n%v\n", C1b)

}
Ejemplo n.º 22
0
// The analytic centering with cone constraints example of section 9.1
// (Problems with nonlinear objectives).
func TestCp(t *testing.T) {

	xref := []float64{0.41132359189354400, 0.55884774432611484, -0.72007090016957931}

	F := &acenterProg{3, 1}

	gdata := [][]float64{
		[]float64{0., -1., 0., 0., -21., -11., 0., -11., 10., 8., 0., 8., 5.},
		[]float64{0., 0., -1., 0., 0., 10., 16., 10., -10., -10., 16., -10., 3.},
		[]float64{0., 0., 0., -1., -5., 2., -17., 2., -6., 8., -17., -7., 6.}}

	G := matrix.FloatMatrixFromTable(gdata)
	h := matrix.FloatVector(
		[]float64{1.0, 0.0, 0.0, 0.0, 20., 10., 40., 10., 80., 10., 40., 10., 15.})

	var solopts SolverOptions
	solopts.MaxIter = 40
	solopts.ShowProgress = false

	dims := sets.NewDimensionSet("l", "q", "s")
	dims.Set("l", []int{0})
	dims.Set("q", []int{4})
	dims.Set("s", []int{3})

	sol, err := Cp(F, G, h, nil, nil, dims, &solopts)
	if err == nil && sol.Status == Optimal {
		x := sol.Result.At("x")[0]
		t.Logf("x = \n%v\n", x.ToString("%.9f"))
		xe, _ := nrmError(matrix.FloatVector(xref), x)
		if xe > TOL {
			t.Logf("x differs [%.3e] from exepted too much.", xe)
			t.Fail()
		}
	} else {
		t.Logf("result: %v\n", err)
		t.Fail()
	}
}
Ejemplo n.º 23
0
func _TestBlkQRUT(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)

	M := A.Rows()
	N := A.Cols()
	var d matrix.FloatMatrix
	//nb := 0
	T := matrix.FloatZeros(N, N)
	Q := matrix.FloatZeros(M, M)
	X, _ := DecomposeQRUT(A.Copy(), T)
	t.Logf("A\n%v\n", A)
	Y := TriLU(X.Copy())
	R := TriU(X.Copy())
	t.Logf("R\n%v\n", R)
	t.Logf("Y\n%v\n", Y)
	t.Logf("T\n%v\n", T)
	_ = Q
	_ = d
}
Ejemplo n.º 24
0
func TestConeQp(t *testing.T) {
	adata := [][]float64{
		[]float64{0.3, -0.4, -0.2, -0.4, 1.3},
		[]float64{0.6, 1.2, -1.7, 0.3, -0.3},
		[]float64{-0.3, 0.0, 0.6, -1.2, -2.0}}

	// reference values from cvxopt coneqp.py
	xref := []float64{0.72558318685981904, 0.61806264311119252, 0.30253527966423444}
	sref := []float64{
		0.72558318685981904, 0.61806264311119263,
		0.30253527966423449, 1.00000000000041678,
		-0.72558318686012169, -0.61806264311145032,
		-0.30253527966436067}
	zref := []float64{
		0.00000003332583626, 0.00000005116586239,
		0.00000009993673262, 0.56869648433154019,
		0.41264857754144563, 0.35149286573190930,
		0.17201618570052318}

	A := matrix.FloatMatrixFromTable(adata, matrix.ColumnOrder)
	b := matrix.FloatVector([]float64{1.5, 0.0, -1.2, -0.7, 0.0})

	_, n := A.Size()
	N := n + 1 + n

	h := matrix.FloatZeros(N, 1)
	h.SetIndex(n, 1.0)

	I0 := matrix.FloatDiagonal(n, -1.0)
	I1 := matrix.FloatIdentity(n)
	G, _ := matrix.FloatMatrixStacked(matrix.StackDown, I0, matrix.FloatZeros(1, n), I1)

	At := A.Transpose()
	P := matrix.Times(At, A)
	q := matrix.Times(At, b).Scale(-1.0)

	dims := sets.DSetNew("l", "q", "s")
	dims.Set("l", []int{n})
	dims.Set("q", []int{n + 1})

	var solopts SolverOptions
	solopts.MaxIter = 10
	solopts.ShowProgress = false
	sol, err := ConeQp(P, q, G, h, nil, nil, dims, &solopts, nil)
	if err == nil {
		fail := false
		x := sol.Result.At("x")[0]
		s := sol.Result.At("s")[0]
		z := sol.Result.At("z")[0]
		t.Logf("Optimal\n")
		t.Logf("x=\n%v\n", x.ToString("%.9f"))
		t.Logf("s=\n%v\n", s.ToString("%.9f"))
		t.Logf("z=\n%v\n", z.ToString("%.9f"))
		xe, _ := nrmError(matrix.FloatVector(xref), x)
		if xe > TOL {
			t.Logf("x differs [%.3e] from exepted too much.", xe)
			fail = true
		}
		se, _ := nrmError(matrix.FloatVector(sref), s)
		if se > TOL {
			t.Logf("s differs [%.3e] from exepted too much.", se)
			fail = true
		}
		ze, _ := nrmError(matrix.FloatVector(zref), z)
		if ze > TOL {
			t.Logf("z differs [%.3e] from exepted too much.", ze)
			fail = true
		}
		if fail {
			t.Fail()
		}
	}

}
Ejemplo n.º 25
0
func _TestTrsmSmall(t *testing.T) {
	//bN := 7
	Udata3 := [][]float64{
		[]float64{2.0, 2.0, 2.0},
		[]float64{0.0, 3.0, 3.0},
		[]float64{0.0, 0.0, 4.0}}

	Udata := [][]float64{
		[]float64{1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0},
		[]float64{0.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0},
		[]float64{0.0, 0.0, 3.0, 3.0, 3.0, 3.0, 3.0},
		[]float64{0.0, 0.0, 0.0, 4.0, 4.0, 4.0, 4.0},
		[]float64{0.0, 0.0, 0.0, 0.0, 5.0, 5.0, 5.0},
		[]float64{0.0, 0.0, 0.0, 0.0, 0.0, 6.0, 6.0},
		[]float64{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 7.0}}
	U := matrix.FloatMatrixFromTable(Udata, matrix.RowOrder)
	U3 := matrix.FloatMatrixFromTable(Udata3, matrix.RowOrder)
	_ = U
	_ = U3

	Ldata3 := [][]float64{
		[]float64{1.0, 0.0, 0.0},
		[]float64{1.0, 2.0, 0.0},
		[]float64{1.0, 2.0, 3.0}}

	Ldata := [][]float64{
		[]float64{1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
		[]float64{1.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0},
		[]float64{1.0, 2.0, 3.0, 0.0, 0.0, 0.0, 0.0},
		[]float64{1.0, 2.0, 3.0, 4.0, 0.0, 0.0, 0.0},
		[]float64{1.0, 2.0, 3.0, 4.0, 5.0, 0.0, 0.0},
		[]float64{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 0.0},
		[]float64{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0}}
	L := matrix.FloatMatrixFromTable(Ldata, matrix.RowOrder)
	L3 := matrix.FloatMatrixFromTable(Ldata3, matrix.RowOrder)
	_ = L
	_ = L3

	nP := 2
	nb := 0
	t.Logf("-- TRSM-LOWER, NON-UNIT --")
	trsmSolve(t, L3, LOWER|LEFT, false, nP, nb)
	//trsmSolve(t, L, LOWER, false, nP, nb)
	//trsmSolve(t, L, LOWER, true, nP, nb)

	t.Logf("- TRSM-LOWER, UNIT --")
	trsmSolve(t, L3, LOWER|LEFT|UNIT, false, nP, nb)

	t.Logf("-- TRSM-UPPER, NON-UNIT --")
	trsmSolve(t, U3, UPPER|LEFT, false, nP, nb)
	//trsmSolve(t, U, UPPER, false, nP, nb)
	//trsmSolve(t, U, UPPER, true, nP, nb)

	t.Logf("-- TRSM-UPPER, UNIT --")
	trsmSolve(t, U3, UPPER|LEFT|UNIT, false, nP, nb)

	t.Logf("-- TRSM-UPPER, TRANS, NON_UNIT --")
	trsmSolve(t, U3, UPPER|LEFT|TRANSA, false, nP, nb)

	t.Logf("-- TRSM-UPPER, TRANS, UNIT --")
	trsmSolve(t, U3, UPPER|LEFT|TRANSA|UNIT, false, nP, nb)

	t.Logf("-- TRSM-LOWER, TRANS, NON-UNIT --")
	trsmSolve(t, L3, LOWER|LEFT|TRANSA, false, nP, nb)

	t.Logf("-- TRSM-LOWER, TRANS, UNIT --")
	trsmSolve(t, L3, LOWER|LEFT|TRANSA|UNIT, false, nP, nb)

	t.Logf("-- TRSM-UPPER, NON-UNIT, RIGHT ---")
	trsmSolve(t, U3, UPPER|RIGHT, false, nP, nb)

	t.Logf("-- TRSM-UPPER, UNIT, RIGHT ---")
	trsmSolve(t, U3, UPPER|UNIT|RIGHT, false, nP, nb)

	t.Logf("-- TRSM-LOWER, NON-UNIT, RIGHT ---")
	trsmSolve(t, L3, LOWER|RIGHT, false, nP, nb)

	t.Logf("-- TRSM-LOWER, UNIT, RIGHT ---")
	trsmSolve(t, L3, LOWER|UNIT|RIGHT, false, nP, nb)

	t.Logf("-- TRSM-UPPER, NON-UNIT, RIGHT, TRANS ---")
	trsmSolve(t, U3, UPPER|RIGHT|TRANSA, false, nP, nb)

	t.Logf("-- TRSM-UPPER, UNIT, RIGHT, TRANS ---")
	trsmSolve(t, U3, UPPER|UNIT|RIGHT|TRANSA, false, nP, nb)

	t.Logf("-- TRSM-LOWER, NON-UNIT, RIGHT, TRANS ---")
	trsmSolve(t, L3, LOWER|RIGHT|TRANSA, false, nP, nb)

	t.Logf("-- TRSM-LOWER, UNIT, RIGHT, TRANS ---")
	trsmSolve(t, L3, LOWER|UNIT|RIGHT|TRANSA, false, nP, nb)

	nP = 4
	nb = 2
	t.Logf("-- BLK TRSM-UPPER, NON-UNIT ---")
	//trsmSolve(t, U, UPPER, false, 2)
	trsmSolve(t, U, UPPER, true, nP, nb)

	t.Logf("-- BLK TRSM-UPPER, UNIT ---")
	//trsmSolve(t, U, UPPER, false, nP, nb)
	trsmSolve(t, U, UPPER|UNIT, true, nP, nb)

	t.Logf("-- BLK TRSM-LOWER, NON-UNIT ---")
	//trsmSolve(t, L, LOWER, false, nP, nb)
	trsmSolve(t, L, LOWER, true, nP, nb)

	t.Logf("-- BLK TRSM-LOWER, UNIT ---")
	//trsmSolve(t, L, LOWER, false, nP, nb)
	trsmSolve(t, L, LOWER|UNIT, true, nP, nb)

	t.Logf("-- BLK TRSM-UPPER, NON-UNIT, TRANS ---")
	//trsmSolve(t, U, UPPER|TRANSA, false, nP, nb)
	trsmSolve(t, U, UPPER|TRANSA, true, nP, nb)

	t.Logf("-- BLK TRSM-LOWER, NON-UNIT, TRANS ---")
	//trsmSolve(t, L, LOWER|TRANSA, false, nP, nb)
	trsmSolve(t, L, LOWER|TRANSA, true, nP, nb)

	t.Logf("-- BLK TRSM-UPPER, NON-UNIT, RIGHT ---")
	trsmSolve(t, U, UPPER|RIGHT, true, nP, nb)

	t.Logf("-- BLK TRSM-UPPER, UNIT, RIGHT ---")
	trsmSolve(t, U, UPPER|UNIT|RIGHT, true, nP, nb)

	t.Logf("-- BLK TRSM-UPPER, NON-UNIT, RIGHT, TRANSA ---")
	trsmSolve(t, U, UPPER|RIGHT|TRANSA, true, nP, nb)

	t.Logf("-- BLK TRSM-LOWER, NON-UNIT, RIGHT ---")
	trsmSolve(t, L, LOWER|RIGHT, true, nP, nb)

	t.Logf("-- BLK TRSM-LOWER, UNIT, RIGHT ---")
	trsmSolve(t, L, LOWER|UNIT|RIGHT, true, nP, nb)

	t.Logf("-- BLK TRSM-LOWER, NON-UNIT, RIGHT, TRANSA ---")
	trsmSolve(t, L, LOWER|RIGHT|TRANSA, true, nP, nb)
}
Ejemplo n.º 26
0
func TestConeLp(t *testing.T) {

	gdata := [][]float64{
		[]float64{16., 7., 24., -8., 8., -1., 0., -1., 0., 0., 7.,
			-5., 1., -5., 1., -7., 1., -7., -4.},
		[]float64{-14., 2., 7., -13., -18., 3., 0., 0., -1., 0., 3.,
			13., -6., 13., 12., -10., -6., -10., -28.},
		[]float64{5., 0., -15., 12., -6., 17., 0., 0., 0., -1., 9.,
			6., -6., 6., -7., -7., -6., -7., -11.}}

	hdata := []float64{-3., 5., 12., -2., -14., -13., 10., 0., 0., 0., 68.,
		-30., -19., -30., 99., 23., -19., 23., 10.}

	// these reference values obtained from running cvxopt conelp.py example
	xref := []float64{-1.22091525026262993, 0.09663323966626469, 3.57750155386611057}

	sref := []float64{
		0.00000172588537019, 13.35314040819201864,
		94.28805677232460880, -53.44110853283719109,
		18.97172963929198275, -75.32834138499130461,
		10.00000013568614321, -1.22091525026262993,
		0.09663323966626476, 3.57750155386611146,
		44.05899318373081286, -58.82581769017131990,
		4.26572401145687596, -58.82581769017131990,
		124.10382738701650851, 40.46243652188705653,
		4.26572401145687596, 40.46243652188705653,
		47.17458693781828316}

	zref := []float64{
		0.09299833991484617, 0.00000001060210894,
		0.23532251654806322, 0.13337937743566930,
		-0.04734875722474355, 0.18800192060450249,
		0.00000001245876667, 0.00000000007816348,
		-0.00000000039584268, -0.00000000183463577,
		0.12558704894101563, 0.08777794737598217,
		-0.08664401207348003, 0.08777794737598217,
		0.06135161787371416, -0.06055906182304811,
		-0.08664401207348003, -0.06055906182304811,
		0.05977675078191153}

	c := matrix.FloatVector([]float64{-6., -4., -5.})
	G := matrix.FloatMatrixFromTable(gdata)
	h := matrix.FloatVector(hdata)

	dims := sets.DSetNew("l", "q", "s")
	dims.Set("l", []int{2})
	dims.Set("q", []int{4, 4})
	dims.Set("s", []int{3})

	var solopts SolverOptions
	solopts.MaxIter = 30
	solopts.ShowProgress = false
	sol, err := ConeLp(c, G, h, nil, nil, dims, &solopts, nil, nil)
	if err == nil {
		fail := false
		x := sol.Result.At("x")[0]
		s := sol.Result.At("s")[0]
		z := sol.Result.At("z")[0]
		t.Logf("Optimal\n")
		t.Logf("x=\n%v\n", x.ToString("%.9f"))
		t.Logf("s=\n%v\n", s.ToString("%.9f"))
		t.Logf("z=\n%v\n", z.ToString("%.9f"))
		xe, _ := nrmError(matrix.FloatVector(xref), x)
		if xe > TOL {
			t.Logf("x differs [%.3e] from exepted too much.", xe)
			fail = true
		}
		se, _ := nrmError(matrix.FloatVector(sref), s)
		if se > TOL {
			t.Logf("s differs [%.3e] from exepted too much.", se)
			fail = true
		}
		ze, _ := nrmError(matrix.FloatVector(zref), z)
		if ze > TOL {
			t.Logf("z differs [%.3e] from exepted too much.", ze)
			fail = true
		}
		if fail {
			t.Fail()
		}
	} else {
		t.Logf("status: %s\n", err)
		t.Fail()
	}
}
Ejemplo n.º 27
0
func TestMultMVTransASmall(t *testing.T) {
	data6 := [][]float64{
		[]float64{-1.59e+00, 6.56e-02, 2.14e-01, 6.79e-01, 2.93e-01, 5.24e-01},
		[]float64{4.28e-01, 1.57e-01, 3.81e-01, 2.19e-01, 2.97e-01, 2.83e-02},
		[]float64{3.02e-01, 9.70e-02, 3.18e-01, 2.03e-01, 7.53e-01, 1.58e-01},
		[]float64{1.99e-01, 3.01e-01, 4.69e-01, 3.61e-01, 2.07e-01, 6.07e-01},
		[]float64{1.93e-01, 5.15e-01, 2.83e-01, 5.71e-01, 8.65e-01, 9.75e-01},
		[]float64{3.13e-01, 8.14e-01, 2.93e-01, 8.62e-01, 6.97e-01, 7.95e-02}}
	data5 := [][]float64{
		[]float64{1.57e-01, 3.81e-01, 2.19e-01, 2.97e-01, 2.83e-02},
		[]float64{9.70e-02, 3.18e-01, 2.03e-01, 7.53e-01, 1.58e-01},
		[]float64{3.01e-01, 4.69e-01, 3.61e-01, 2.07e-01, 6.07e-01},
		[]float64{5.15e-01, 2.83e-01, 5.71e-01, 8.65e-01, 9.75e-01},
		[]float64{8.14e-01, 2.93e-01, 8.62e-01, 6.97e-01, 7.95e-02}}
	data2 := []float64{4.28e-01, 3.02e-01, 1.99e-01, 1.93e-01, 3.13e-01}

	bM := 5
	bN := 4
	nb := 2
	//A := matrix.FloatNormal(bN, bM)
	//X := matrix.FloatWithValue(bN, 1, 1.0)

	A := matrix.FloatMatrixFromTable(data5, matrix.RowOrder)
	X := matrix.FloatNew(5, 1, data2)
	bM = A.Rows()
	bN = A.Cols()
	Ym := matrix.FloatZeros(3, bM)
	Y1 := matrix.FloatZeros(bM, 1)
	Y0 := matrix.FloatZeros(bM, 1)

	Ar := A.FloatArray()
	Xr := X.FloatArray()
	Y1r := Y1.FloatArray()

	blas.GemvFloat(A, X, Y0, 1.0, 1.0, linalg.OptTrans)

	DMultMV(Y1r, Ar, Xr, 1.0, 1.0, TRANSA, 1, A.LeadingIndex(), 1, 0, bN, 0, bM, nb, nb)
	ok := Y0.AllClose(Y1)
	t.Logf("Y0 == Y1: %v\n", ok)
	if ok || !ok {
		t.Logf("blas: Y=A.T*X\n%v\n", Y0)
		t.Logf("Y1: Y1 = A*X\n%v\n", Y1)
	}

	// zero Y0, Y1
	Y0.Scale(0.0)
	Y1.Scale(0.0)

	// test with matrix view; A is view
	var A0 matrix.FloatMatrix
	A6 := matrix.FloatMatrixFromTable(data6, matrix.RowOrder)
	A0.SubMatrixOf(A6, 1, 1)

	blas.GemvFloat(&A0, X, Y0, 1.0, 1.0, linalg.OptTrans)

	Ar = A0.FloatArray()
	DMultMV(Y1r, Ar, Xr, 1.0, 1.0, TRANSA, 1, A0.LeadingIndex(), 1, 0, bN, 0, bM, nb, nb)
	ok = Y0.AllClose(Y1)
	t.Logf("lda>rows: Y0 == Y1: %v\n", ok)
	if ok || !ok {
		t.Logf("blas: Y=A.T*X\n%v\n", Y0)
		t.Logf("Y1: Y1 = A*X\n%v\n", Y1)
	}

	// Y is view too.
	Y1.SubMatrixOf(Ym, 0, 0, 1, bM)
	Y1r = Y1.FloatArray()
	DMultMV(Y1r, Ar, Xr, 1.0, 1.0, TRANSA, Y1.LeadingIndex(), A0.LeadingIndex(), 1, 0, bN, 0, bM, nb, nb)
	ok = Y0.AllClose(Y1.Transpose())
	t.Logf("Y0 == Y1 row: %v\n", ok)
	t.Logf("row Y1: %v\n", Y1)
}