本文整理匯總了Golang中github.com/hrautila/gomas/blasd.Plus函數的典型用法代碼示例。如果您正苦於以下問題:Golang Plus函數的具體用法?Golang Plus怎麽用?Golang Plus使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Plus函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: updateLeftRQ
// compute:
// Q.T*C = (I -Y*T*Y.T).T*C == C - Y*(C.T*Y*T).T
// or
// Q*C = (I -Y*T*Y.T)*C == C - Y*(C.T*Y*T.T).T
//
//
// where C = ( C2 ) Y = ( Y2 Y1 )
// ( C1 )
//
// C1 is nb*K, C2 is P*K, Y1 is nb*nb triuu, Y2 is nb*P, T is nb*nb
// W = K*nb
func updateLeftRQ(C1, C2, Y1t, Y2t, T, W *cmat.FloatMatrix, transpose bool, conf *gomas.Config) {
// W = C1.T
blasd.Plus(W, C1, 0.0, 1.0, gomas.TRANSB)
// W = C1.T*Y1.T
blasd.MultTrm(W, Y1t, 1.0, gomas.RIGHT|gomas.LOWER|gomas.UNIT|gomas.TRANSA, conf)
// W = W + C2.T*Y2.T
blasd.Mult(W, C2, Y2t, 1.0, 1.0, gomas.TRANSA|gomas.TRANSB, conf)
// --- here: W == C.T*Y == C1.T*Y1.T + C2.T*Y2.T ---
tflags := gomas.RIGHT | gomas.LOWER
if !transpose {
tflags |= gomas.TRANSA
}
// W = W*T or W*T.T
blasd.MultTrm(W, T, 1.0, tflags, conf)
// --- here: W == C.T*Y*T or C.T*Y*T.T ---
// C2 = C2 - Y2*W.T
blasd.Mult(C2, Y2t, W, -1.0, 1.0, gomas.TRANSA|gomas.TRANSB, conf)
// W = Y1*W.T ==> W.T = W*Y1
blasd.MultTrm(W, Y1t, 1.0, gomas.RIGHT|gomas.LOWER|gomas.UNIT, conf)
// C1 = C1 - W.T
blasd.Plus(C1, W, 1.0, -1.0, gomas.TRANSB)
// --- here: C = (I - Y*T*Y.T).T * C ---
}
示例2: updateRightRQ
// compute:
// C*Q.T = C*(I -Y*T*Y.T).T == C - C*Y*T.T*Y.T
// or
// C*Q = (I -Y*T*Y.T)*C == C - C*Y*T*Y.T
//
//
// where C = ( C2 C1 ), Y = ( Y2 Y1 )
//
// C1 is K*nb, C2 is K*P, Y1 is nb*nb triuu, Y2 is nb*P, T is nb*nb
// W = K*nb
func updateRightRQ(C1, C2, Y1t, Y2t, T, W *cmat.FloatMatrix, transpose bool, conf *gomas.Config) {
// -- compute: W = C*Y = C1*Y1 + C2*Y2
// W = C1
blasd.Plus(W, C1, 0.0, 1.0, gomas.NONE)
// W = C1*Y1t.T
blasd.MultTrm(W, Y1t, 1.0, gomas.RIGHT|gomas.LOWER|gomas.UNIT|gomas.TRANSA, conf)
// W = W + C2*Y2t.T
blasd.Mult(W, C2, Y2t, 1.0, 1.0, gomas.TRANSB, conf)
// --- here: W == C*Y ---
tflags := gomas.RIGHT | gomas.LOWER
if transpose {
tflags |= gomas.TRANSA
}
// W = W*T or W*T.T
blasd.MultTrm(W, T, 1.0, tflags, conf)
// --- here: W == C*Y*T or C*Y*T.T ---
// C2 = C2 - W*Y2t
blasd.Mult(C2, W, Y2t, -1.0, 1.0, gomas.NONE, conf)
// C1 = C1 - W*Y1t
// W = W*Y1
blasd.MultTrm(W, Y1t, 1.0, gomas.RIGHT|gomas.LOWER|gomas.UNIT, conf)
// C1 = C1 - W
blasd.Plus(C1, W, 1.0, -1.0, gomas.NONE)
// --- here: C = (I - Y*T*Y.T).T * C ---
}
示例3: TestTrdMultUpper
func TestTrdMultUpper(t *testing.T) {
var dt, et, da, ea cmat.FloatMatrix
N := 843
nb := 48
conf := gomas.NewConf()
conf.LB = nb
A := cmat.NewMatrix(N, N)
tau := cmat.NewMatrix(N, 1)
src := cmat.NewFloatNormSource()
// create symmetric matrix
A.SetFrom(src, cmat.SYMM)
A0 := cmat.NewCopy(A)
W := lapackd.Workspace(lapackd.TRDReduceWork(A, conf))
lapackd.TRDReduce(A, tau, W, gomas.UPPER, conf)
// make tridiagonal matrix T
T0 := cmat.NewMatrix(N, N)
dt.Diag(T0)
da.Diag(A)
blasd.Copy(&dt, &da)
ea.Diag(A, 1)
et.Diag(T0, 1)
blasd.Copy(&et, &ea)
et.Diag(T0, -1)
blasd.Copy(&et, &ea)
T1 := cmat.NewCopy(T0)
// compute Q*T*Q.T (unblocked)
conf.LB = 0
lapackd.TRDMult(T0, A, tau, W, gomas.LEFT|gomas.UPPER, conf)
lapackd.TRDMult(T0, A, tau, W, gomas.RIGHT|gomas.TRANS|gomas.UPPER, conf)
blasd.Plus(T0, A0, 1.0, -1.0, gomas.NONE)
nrm := lapackd.NormP(T0, lapackd.NORM_ONE)
t.Logf("N=%d, unblk.||A - Q*T*Q.T||_1: %e\n", N, nrm)
// compute Q*T*Q.T (blocked)
conf.LB = nb
W = lapackd.Workspace(lapackd.TRDMultWork(A, gomas.LEFT|gomas.UPPER, conf))
lapackd.TRDMult(T1, A, tau, W, gomas.LEFT|gomas.UPPER, conf)
lapackd.TRDMult(T1, A, tau, W, gomas.RIGHT|gomas.TRANS|gomas.UPPER, conf)
blasd.Plus(T1, A0, 1.0, -1.0, gomas.NONE)
nrm = lapackd.NormP(T1, lapackd.NORM_ONE)
t.Logf("N=%d, blk.||A - Q*T*Q.T||_1: %e\n", N, nrm)
}
示例4: TestBidiagReduceUnblocked
func TestBidiagReduceUnblocked(t *testing.T) {
N := 217
M := 269
conf := gomas.NewConf()
conf.LB = 0
zeromean := cmat.NewFloatNormSource()
A := cmat.NewMatrix(M, N)
A.SetFrom(zeromean)
tauq := cmat.NewMatrix(N, 1)
taup := cmat.NewMatrix(N, 1)
At := cmat.NewMatrix(N, M)
blasd.Transpose(At, A)
tauqt := cmat.NewMatrix(N, 1)
taupt := cmat.NewMatrix(N, 1)
W := lapackd.Workspace(M + N)
lapackd.BDReduce(A, tauq, taup, W, conf)
lapackd.BDReduce(At, tauqt, taupt, W, conf)
// BiRed(A) == BiRed(A.T).T
blasd.Plus(At, A, 1.0, -1.0, gomas.TRANSB)
blasd.Axpy(tauqt, taup, -1.0)
blasd.Axpy(taupt, tauq, -1.0)
nrm := lapackd.NormP(At, lapackd.NORM_ONE)
t.Logf("M=%d, N=%d || BiRed(A) - BiRed(A.T).T||_1 : %e\n", M, N, nrm)
nrm = lapackd.NormP(taupt, lapackd.NORM_ONE)
t.Logf(" || BiRed(A).tauq - BiRed(A.T).taup||_1 : %e\n", nrm)
nrm = lapackd.NormP(tauqt, lapackd.NORM_ONE)
t.Logf(" || BiRed(A).taup - BiRed(A.T).tauq||_1 : %e\n", nrm)
}
示例5: TestReduceHess
// test: unblk.ReduceHess(A) == blk.ReduceHess(A)
func TestReduceHess(t *testing.T) {
N := 375
nb := 16
conf := gomas.NewConf()
conf.LB = nb
A := cmat.NewMatrix(N, N)
tau := cmat.NewMatrix(N, 1)
zeromean := cmat.NewFloatNormSource()
A.SetFrom(zeromean)
A0 := cmat.NewCopy(A)
tau0 := cmat.NewCopy(tau)
// blocked reduction
W := lapackd.Workspace(lapackd.HessReduceWork(A, conf))
lapackd.HessReduce(A, tau, W, conf)
// unblocked reduction
conf.LB = 0
lapackd.HessReduce(A0, tau0, W, conf)
ok := A.AllClose(A0)
t.Logf("blk.ReduceHess(A) == unblk.ReduceHess(A): %v\n", ok)
ok = tau0.AllClose(tau)
t.Logf("blk HessQ.tau == unblk HessQ.tau: %v\n", ok)
// ||A - A0||_1
blasd.Plus(A, A0, 1.0, -1.0, gomas.NONE)
nrm := lapackd.NormP(A, lapackd.NORM_ONE)
t.Logf("||H - H0||_1: %e\n", nrm)
}
示例6: TestLeastSquaresLQ
// test: min || B - A.T*X ||
func TestLeastSquaresLQ(t *testing.T) {
M := 723
N := 811
K := 273
nb := 32
conf := gomas.NewConf()
conf.LB = nb
tau := cmat.NewMatrix(M, 1)
A := cmat.NewMatrix(M, N)
src := cmat.NewFloatNormSource()
A.SetFrom(src)
B0 := cmat.NewMatrix(M, K)
B0.SetFrom(src)
B := cmat.NewMatrix(N, K)
// B = A.T*B0
blasd.Mult(B, A, B0, 1.0, 0.0, gomas.TRANSA, conf)
W := lapackd.Workspace(lapackd.LQFactorWork(A, conf))
lapackd.LQFactor(A, tau, W, conf)
// B' = A.-1*B
lapackd.LQSolve(B, A, tau, W, gomas.TRANS, conf)
// expect B[0:M,0:K] == B0[0:M,0:K], B[M:N,0:K] == 0
var X cmat.FloatMatrix
X.SubMatrix(B, 0, 0, M, K)
blasd.Plus(&X, B0, 1.0, -1.0, gomas.NONE)
nrm := lapackd.NormP(&X, lapackd.NORM_ONE)
t.Logf("M=%d, N=%d ||B0 - min( ||A.T*X - B0|| ) ||_1: %e\n", M, N, nrm)
}
示例7: TestLQFactor
func TestLQFactor(t *testing.T) {
M := 611
N := 715
nb := 32
conf := gomas.NewConf()
A := cmat.NewMatrix(M, N)
src := cmat.NewFloatNormSource()
A.SetFrom(src)
tau := cmat.NewMatrix(M, 1)
A1 := cmat.NewCopy(A)
tau1 := cmat.NewCopy(tau)
conf.LB = 0
W := cmat.NewMatrix(M+N, 1)
lapackd.LQFactor(A, tau, W, conf)
conf.LB = nb
W1 := lapackd.Workspace(lapackd.LQFactorWork(A1, conf))
lapackd.LQFactor(A1, tau1, W1, conf)
blasd.Plus(A1, A, 1.0, -1.0, gomas.NONE)
nrm := lapackd.NormP(A1, lapackd.NORM_ONE)
t.Logf("M=%d, N=%d ||blk.LQ(A) - unblk.LQ(A)||_1: %e\n", M, N, nrm)
}
示例8: TestUnblkQRMultLeft
// QR decompose A, then compute ||A - Q*R||_1, should be small
func TestUnblkQRMultLeft(t *testing.T) {
M := 711
N := 593
A := cmat.NewMatrix(M, N)
tau := cmat.NewMatrix(N, 1)
zeromean := cmat.NewFloatNormSource()
A.SetFrom(zeromean)
A0 := cmat.NewCopy(A)
conf := gomas.NewConf()
conf.LB = 0
// QR = A = Q*R
W := lapackd.Workspace(lapackd.QRFactorWork(A, conf))
lapackd.QRFactor(A, tau, W, conf)
// C = TriU(QR) = R
C := cmat.TriU(cmat.NewCopy(A), cmat.NONE)
// C = Q*C
W = lapackd.Workspace(lapackd.QRMultWork(C, gomas.LEFT, conf))
err := lapackd.QRMult(C, A, tau, W, gomas.LEFT, conf)
if err != nil {
t.Logf("err: %v\n", err)
}
// A = A - QR
blasd.Plus(A0, C, 1.0, -1.0, gomas.NONE)
// ||A - Q*R||_1
nrm := lapackd.NormP(A0, lapackd.NORM_ONE)
t.Logf("M=%d,N=%d ||A - Q*R||_1: %e\n", M, N, nrm)
}
示例9: TestQRTMultLeftIdent
// m > n: A[m,n], I[m,m] --> A == I*A == Q*Q.T*A
func TestQRTMultLeftIdent(t *testing.T) {
M := 411
N := 399
nb := 16
A := cmat.NewMatrix(M, N)
T := cmat.NewMatrix(nb, N)
zeromean := cmat.NewFloatNormSource()
A.SetFrom(zeromean)
A0 := cmat.NewCopy(A)
C := cmat.NewCopy(A)
conf := gomas.NewConf()
conf.LB = nb
//t.Logf("A0:\n%v\n", A0)
// QR = A = Q*R
W := lapackd.Workspace(lapackd.QRTFactorWork(A, conf))
lapackd.QRTFactor(A, T, W, conf)
//t.Logf("T:\n%v\n", T)
// C = Q.T*A
W = lapackd.Workspace(lapackd.QRTMultWork(C, T, gomas.LEFT, conf))
lapackd.QRTMult(C, A, T, W, gomas.LEFT|gomas.TRANS, conf)
// C = Q*C == Q*Q.T*A
lapackd.QRTMult(C, A, T, W, gomas.LEFT, conf)
//t.Logf("A*Q*Q.T:\n%v\n", C)
// A = A - Q*Q.T*A
blasd.Plus(A0, C, 1.0, -1.0, gomas.NONE)
// ||A - Q*Q.T*A||_1
nrm := lapackd.NormP(A0, lapackd.NORM_ONE)
t.Logf("M=%d,N=%d ||A - Q*Q.T*A||_1: %e\n", M, N, nrm)
}
示例10: TestUnblkQRMultRight
// QR decompose A, then compute ||A - (R.T*Q.T).T||_1, should be small
func TestUnblkQRMultRight(t *testing.T) {
M := 711
N := 593
A := cmat.NewMatrix(M, N)
C := cmat.NewMatrix(N, M)
tau := cmat.NewMatrix(N, 1)
zeromean := cmat.NewFloatNormSource()
A.SetFrom(zeromean)
A0 := cmat.NewCopy(A)
conf := gomas.NewConf()
conf.LB = 0
// QR = A = Q*R
W := lapackd.Workspace(lapackd.QRFactorWork(A, conf))
lapackd.QRFactor(A, tau, W, conf)
// C = transpose(TriU(QR)) = R.T
C.Transpose(cmat.TriU(cmat.NewCopy(A), cmat.NONE))
// C = C*Q.T = R.T*Q.T
W = lapackd.Workspace(lapackd.QRMultWork(C, gomas.RIGHT, conf))
err := lapackd.QRMult(C, A, tau, W, gomas.RIGHT|gomas.TRANS, conf)
if err != nil {
t.Logf("err: %v\n", err)
}
// A = A - QR
blasd.Plus(A0, C, 1.0, -1.0, gomas.TRANSB)
// ||A - Q*R||_1
nrm := lapackd.NormP(A0, lapackd.NORM_ONE)
t.Logf("M=%d,N=%d ||A - (R.T*Q.T).T||_1: %e\n", M, N, nrm)
}
示例11: TestBlockedQRMultRightIdent
// m > n: A[m,n], I[m,m] --> A.T == A.T*I == A.T*Q*Q.T
func TestBlockedQRMultRightIdent(t *testing.T) {
M := 511
N := 489
A := cmat.NewMatrix(M, N)
C := cmat.NewMatrix(N, M)
tau := cmat.NewMatrix(N, 1)
zeromean := cmat.NewFloatNormSource()
A.SetFrom(zeromean)
A0 := cmat.NewCopy(A)
C.Transpose(A)
conf := gomas.NewConf()
conf.LB = 32
// QR = A = Q*R
W := lapackd.Workspace(lapackd.QRFactorWork(A, conf))
lapackd.QRFactor(A, tau, W, conf)
// C = A.T*Q
W = lapackd.Workspace(lapackd.QRMultWork(C, gomas.RIGHT, conf))
lapackd.QRMult(C, A, tau, W, gomas.RIGHT, conf)
// C = C*Q.T == A.T*Q*Q.T
lapackd.QRMult(C, A, tau, W, gomas.RIGHT|gomas.TRANS, conf)
//t.Logf("A*Q*Q.T:\n%v\n", C)
// A = A - (A.T*Q*Q.T).T
blasd.Plus(A0, C, 1.0, -1.0, gomas.TRANSB)
// ||A - (A.T*Q*Q.T).T||_1
nrm := lapackd.NormP(A0, lapackd.NORM_ONE)
t.Logf("M=%d,N=%d ||A - (A.T*Q*Q.T).T||_1: %e\n", M, N, nrm)
}
示例12: TestGivensLQ
// Simple and slow LQ decomposition with Givens rotations
func TestGivensLQ(t *testing.T) {
var d cmat.FloatMatrix
M := 149
N := 167
A := cmat.NewMatrix(M, N)
A1 := cmat.NewCopy(A)
ones := cmat.NewFloatConstSource(1.0)
src := cmat.NewFloatNormSource()
A.SetFrom(src)
A0 := cmat.NewCopy(A)
Qt := cmat.NewMatrix(N, N)
d.Diag(Qt)
d.SetFrom(ones)
// R = G(n)...G(2)G(1)*A; Q = G(1).T*G(2).T...G(n).T ; Q.T = G(n)...G(2)G(1)
for i := 0; i < M; i++ {
// zero elements right of diagonal
for j := N - 2; j >= i; j-- {
c, s, r := lapackd.ComputeGivens(A.Get(i, j), A.Get(i, j+1))
A.Set(i, j, r)
A.Set(i, j+1, 0.0)
// apply rotation to this column starting from row i+1
lapackd.ApplyGivensRight(A, j, j+1, i+1, M-i-1, c, s)
// update Qt = G(k)*Qt
lapackd.ApplyGivensRight(Qt, j, j+1, 0, N, c, s)
}
}
// A = L*Q
blasd.Mult(A1, A, Qt, 1.0, 0.0, gomas.TRANSB)
blasd.Plus(A0, A1, 1.0, -1.0, gomas.NONE)
nrm := lapackd.NormP(A0, lapackd.NORM_ONE)
t.Logf("M=%d, N=%d ||A - L*G(1)..G(n)||_1: %e\n", M, N, nrm)
}
示例13: TestTriRedUpper
func TestTriRedUpper(t *testing.T) {
N := 843
nb := 48
conf := gomas.NewConf()
conf.LB = 0
A := cmat.NewMatrix(N, N)
tau := cmat.NewMatrix(N, 1)
src := cmat.NewFloatNormSource()
A.SetFrom(src, cmat.UPPER)
A1 := cmat.NewCopy(A)
tau1 := cmat.NewCopy(tau)
_ = A1
W := lapackd.Workspace(N)
W1 := lapackd.Workspace(N * nb)
lapackd.TRDReduce(A, tau, W, gomas.UPPER, conf)
conf.LB = nb
lapackd.TRDReduce(A1, tau1, W1, gomas.UPPER, conf)
blasd.Plus(A, A1, -1.0, 1.0, gomas.NONE)
nrm := lapackd.NormP(A, lapackd.NORM_ONE)
t.Logf("N=%d, ||unblk.Trired(A) - blk.Trired(A)||_1: %e\n", N, nrm)
blasd.Axpy(tau, tau1, -1.0)
nrm = blasd.Nrm2(tau)
t.Logf(" ||unblk.Trired(tau) - blk.Trired(tau)||_1: %e\n", nrm)
}
示例14: TestSolveBKLowerBig
func TestSolveBKLowerBig(t *testing.T) {
N := 427
normsrc := cmat.NewFloatNormSource(5.0, 10.0)
A := cmat.NewMatrix(N, N)
A.SetFrom(normsrc, cmat.LOWER)
X := cmat.NewMatrix(N, 2)
X.SetFrom(normsrc)
B := cmat.NewCopy(X)
blasd.MultSym(B, A, X, 1.0, 0.0, gomas.LOWER|gomas.LEFT)
ipiv := lapackd.NewPivots(N)
conf := gomas.NewConf()
conf.LB = 16
W := lapackd.Workspace(lapackd.BKFactorWork(A, conf))
lapackd.BKFactor(A, W, ipiv, gomas.LOWER, conf)
lapackd.BKSolve(B, A, ipiv, gomas.LOWER, conf)
ok := B.AllClose(X)
t.Logf("N=%d unblk.BK(X) == A.-1*B : %v\n", N, ok)
blasd.Plus(B, X, 1.0, -1.0, gomas.NONE)
nrm := lapackd.NormP(B, lapackd.NORM_ONE)
t.Logf(" ||X - A.-1*B||_1: %.4e\n", nrm)
}
示例15: TestBiredWide
func TestBiredWide(t *testing.T) {
N := 811
M := 693
nb := 32
conf := gomas.NewConf()
conf.LB = 0
ediag := -1
zeromean := cmat.NewFloatNormSource()
A := cmat.NewMatrix(M, N)
A.SetFrom(zeromean)
A0 := cmat.NewCopy(A)
tauq := cmat.NewMatrix(N, 1)
taup := cmat.NewMatrix(N, 1)
W := lapackd.Workspace(M + N)
lapackd.BDReduce(A, tauq, taup, W, conf)
var D, E, Bd, Be cmat.FloatMatrix
D.Diag(A)
E.Diag(A, ediag)
B := cmat.NewMatrix(M, N)
Bd.Diag(B)
Be.Diag(B, ediag)
blasd.Copy(&Bd, &D)
blasd.Copy(&Be, &E)
Bt := cmat.NewMatrix(N, M)
blasd.Transpose(Bt, B)
conf.LB = nb
W0 := lapackd.Workspace(lapackd.BDMultWork(B, conf))
lapackd.BDMult(B, A, tauq, W0, gomas.MULTQ|gomas.LEFT, conf)
lapackd.BDMult(Bt, A, tauq, W0, gomas.MULTQ|gomas.RIGHT|gomas.TRANS, conf)
lapackd.BDMult(B, A, taup, W0, gomas.MULTP|gomas.RIGHT|gomas.TRANS, conf)
lapackd.BDMult(Bt, A, taup, W0, gomas.MULTP|gomas.LEFT, conf)
blasd.Plus(B, A0, 1.0, -1.0, gomas.NONE)
nrm := lapackd.NormP(B, lapackd.NORM_ONE)
t.Logf("M=%d, N=%d ||A - Q*B*P.T||_1 : %e\n", M, N, nrm)
blasd.Plus(Bt, A0, 1.0, -1.0, gomas.TRANSB)
nrm = lapackd.NormP(Bt, lapackd.NORM_ONE)
t.Logf("M=%d, N=%d ||A.T - P*B.T*Q.T||_1 : %e\n", M, N, nrm)
}