本文整理匯總了Golang中github.com/hrautila/cmat.NewMatrix函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewMatrix函數的具體用法?Golang NewMatrix怎麽用?Golang NewMatrix使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewMatrix函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestSolveQR
// test: min ||X|| s.t A.T*X = B
func TestSolveQR(t *testing.T) {
M := 799
N := 711
K := 241
nb := 32
conf := gomas.NewConf()
conf.LB = nb
tau := cmat.NewMatrix(N, 1)
A := cmat.NewMatrix(M, N)
src := cmat.NewFloatNormSource()
A.SetFrom(src)
A0 := cmat.NewCopy(A)
B0 := cmat.NewMatrix(M, K)
B0.SetFrom(src)
B := cmat.NewCopy(B0)
W := lapackd.Workspace(lapackd.QRFactorWork(A, conf))
lapackd.QRFactor(A, tau, W, conf)
lapackd.QRSolve(B, A, tau, W, gomas.TRANS, conf)
var Bmin cmat.FloatMatrix
Bmin.SubMatrix(B0, 0, 0, N, K)
blasd.Mult(&Bmin, A0, B, 1.0, -1.0, gomas.TRANSA, conf)
nrm := lapackd.NormP(&Bmin, lapackd.NORM_ONE)
t.Logf("M=%d, N=%d ||B - A.T*X||_1: %e\n", M, N, nrm)
}
示例2: TestDTrmmLower
func TestDTrmmLower(t *testing.T) {
N := 563
K := 171
nofail := true
A := cmat.NewMatrix(N, N)
B := cmat.NewMatrix(N, K)
B0 := cmat.NewMatrix(N, K)
C := cmat.NewMatrix(N, K)
ones := cmat.NewFloatConstSource(1.0)
zeromean := cmat.NewFloatNormSource()
A.SetFrom(zeromean, cmat.LOWER)
B.SetFrom(ones)
B0.SetFrom(ones)
// B = A*B
blasd.MultTrm(B, A, 1.0, gomas.LOWER|gomas.LEFT)
blasd.Mult(C, A, B0, 1.0, 0.0, gomas.NONE)
ok := C.AllClose(B)
nofail = nofail && ok
t.Logf("trmm(B, A, L|L|N) == gemm(C, TriL(A), B) : %v\n", ok)
B.SetFrom(ones)
// B = A.T*B
blasd.MultTrm(B, A, 1.0, gomas.LOWER|gomas.LEFT|gomas.TRANSA)
blasd.Mult(C, A, B0, 1.0, 0.0, gomas.TRANSA)
ok = C.AllClose(B)
nofail = nofail && ok
t.Logf("trmm(B, A, L|L|T) == gemm(C, TriL(A).T, B) : %v\n", ok)
}
示例3: __TestZeroQLSweep
func __TestZeroQLSweep(t *testing.T) {
N := 5
D0 := cmat.NewMatrix(1, N)
E0 := cmat.NewMatrix(1, N-1)
D1 := cmat.NewMatrix(1, N)
E1 := cmat.NewMatrix(1, N-1)
for k := 0; k < N; k++ {
D0.SetAt(N-k-1, float64(k+1))
D1.SetAt(N-k-1, float64(k+1))
if k < N-1 {
E0.SetAt(k, 1.0)
E1.SetAt(k, 1.0)
}
}
f := D0.GetAt(4)
g := E0.GetAt(3)
lapackd.BDQLsweep(D0, E0, f, g)
lapackd.BDQLzero(D1, E1)
t.Logf("D0.std :%v\n", D0)
t.Logf("D1.zero:%v\n", D1)
t.Logf("E0.std :%v\n", E0)
t.Logf("E1.zero:%v\n", E1)
}
示例4: __TestSweep
func __TestSweep(t *testing.T) {
N := 5
D0 := cmat.NewMatrix(1, N)
E0 := cmat.NewMatrix(1, N-1)
D1 := cmat.NewMatrix(1, N)
E1 := cmat.NewMatrix(1, N-1)
for k := 0; k < N; k++ {
D0.SetAt(k, float64(k+1))
D1.SetAt(N-1-k, float64(k+1))
if k < N-1 {
E0.SetAt(k, 1.0)
E1.SetAt(k, 1.0)
}
}
f := 0.5
g := -0.45
lapackd.BDQRsweep(D0, E0, f, g)
lapackd.BDQLsweep(D1, E1, f, g)
t.Logf("D0:%v\n", D0)
t.Logf("D1:%v\n", D1)
t.Logf("E0:%v\n", E0)
t.Logf("E1:%v\n", E1)
}
示例5: 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)
}
示例6: TestBlockedDecomposeCHOL
func TestBlockedDecomposeCHOL(t *testing.T) {
N := 119
nb := 16
conf := gomas.NewConf()
conf.LB = nb
Z := cmat.NewMatrix(N, N)
AL := cmat.NewMatrix(N, N)
AU := cmat.NewMatrix(N, N)
unitrand := cmat.NewFloatUniformSource()
Z.SetFrom(unitrand)
blasd.Mult(AL, Z, Z, 1.0, 0.0, gomas.TRANSB)
AU.Copy(AL)
eu := lapackd.CHOLFactor(AU, gomas.UPPER, conf)
el := lapackd.CHOLFactor(AL, gomas.LOWER, conf)
_, _ = eu, el
Z.Transpose(AU)
if N < 10 {
t.Logf("AU.T:\n%v\n", Z)
t.Logf("AL:\n%v\n", AL)
}
ok := AL.AllClose(Z)
t.Logf("Decompose(AL) == Decompose(AU).T: %v\n", ok)
}
示例7: 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)
}
示例8: TestDecomposeQRT
// test that unblocked and blocked QRT are equal
func TestDecomposeQRT(t *testing.T) {
M := 615
N := 591
nb := 16
conf := gomas.NewConf()
conf.LB = nb
A := cmat.NewMatrix(M, N)
T := cmat.NewMatrix(nb, N)
zeromean := cmat.NewFloatNormSource()
A.SetFrom(zeromean)
A0 := cmat.NewCopy(A)
T0 := cmat.NewMatrix(N, N)
// blocked: QR = A = Q*R
W := lapackd.Workspace(lapackd.QRTFactorWork(A, conf))
lapackd.QRTFactor(A, T, W, conf)
conf.LB = 0
lapackd.QRTFactor(A0, T0, W, conf)
ok := A.AllClose(A0)
t.Logf("blk.DecomposeQRT(A) == unblk.DecomposeQRT(A): %v\n", ok)
}
示例9: TestDSyr1
func TestDSyr1(t *testing.T) {
const N = 911
A := cmat.NewMatrix(N, N)
X := cmat.NewMatrix(N, 1)
B := cmat.NewMatrix(N, N)
//ones := cmat.NewFloatConstSource(1.0)
zeromean := cmat.NewFloatUniformSource(0.5, 2.0)
A.SetFrom(zeromean, cmat.LOWER)
X.SetFrom(zeromean)
B.Copy(A)
// B = A*B
blasd.MVUpdate(B, X, X, 1.0)
cmat.TriL(B, cmat.NONE)
blasd.MVUpdateSym(A, X, 1.0, gomas.LOWER)
ok := B.AllClose(A)
t.Logf("MVUpdateSym(A, X, L) == TriL(MVUpdate(A, X, X)) : %v\n", ok)
A.SetFrom(zeromean, cmat.UPPER)
cmat.TriU(A, cmat.NONE)
B.Copy(A)
blasd.MVUpdate(B, X, X, 1.0)
cmat.TriU(B, cmat.NONE)
blasd.MVUpdateSym(A, X, 1.0, gomas.UPPER)
ok = B.AllClose(A)
t.Logf("MVUpdateSym(A, X, U) == TriU(MVUpdate(A, X, X)) : %v\n", ok)
}
示例10: TestDTrmmUnitUpper
func TestDTrmmUnitUpper(t *testing.T) {
var d cmat.FloatMatrix
N := 563
K := 171
A := cmat.NewMatrix(N, N)
B := cmat.NewMatrix(N, K)
B0 := cmat.NewMatrix(N, K)
C := cmat.NewMatrix(N, K)
zeros := cmat.NewFloatConstSource(0.0)
ones := cmat.NewFloatConstSource(1.0)
zeromean := cmat.NewFloatNormSource()
A.SetFrom(zeromean, cmat.UPPER|cmat.UNIT)
B.SetFrom(ones)
B0.SetFrom(ones)
// B = A*B
blasd.MultTrm(B, A, 1.0, gomas.UPPER|gomas.LEFT|gomas.UNIT)
d.Diag(A).SetFrom(ones)
blasd.Mult(C, A, B0, 1.0, 0.0, gomas.NONE)
ok := C.AllClose(B)
t.Logf("trmm(B, A, L|U|N|U) == gemm(C, TriUU(A), B) : %v\n", ok)
B.SetFrom(ones)
// B = A.T*B
d.Diag(A).SetFrom(zeros)
blasd.MultTrm(B, A, 1.0, gomas.UPPER|gomas.LEFT|gomas.TRANSA|gomas.UNIT)
d.Diag(A).SetFrom(ones)
blasd.Mult(C, A, B0, 1.0, 0.0, gomas.TRANSA)
ok = C.AllClose(B)
t.Logf("trmm(B, A, L|U|T|U) == gemm(C, TriUU(A).T, B) : %v\n", ok)
}
示例11: 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)
}
示例12: TestDTrmmUnitUpperRight
func TestDTrmmUnitUpperRight(t *testing.T) {
var d cmat.FloatMatrix
N := 563
K := 171
A := cmat.NewMatrix(N, N)
B := cmat.NewMatrix(K, N)
B0 := cmat.NewMatrix(K, N)
C := cmat.NewMatrix(K, N)
zeros := cmat.NewFloatConstSource(0.0)
ones := cmat.NewFloatConstSource(1.0)
zeromean := cmat.NewFloatNormSource()
A.SetFrom(zeromean, cmat.UPPER|cmat.UNIT)
B.SetFrom(ones)
B0.SetFrom(ones)
// B = B*A
blasd.MultTrm(B, A, 1.0, gomas.UPPER|gomas.RIGHT|gomas.UNIT)
d.Diag(A).SetFrom(ones)
blasd.Mult(C, B0, A, 1.0, 0.0, gomas.NONE)
ok := C.AllClose(B)
t.Logf("trmm(B, A, R|U|N|U) == gemm(C, B, TriUU(A)) : %v\n", ok)
B.SetFrom(ones)
// B = B*A.T
d.SetFrom(zeros)
blasd.MultTrm(B, A, 1.0, gomas.UPPER|gomas.RIGHT|gomas.TRANSA|gomas.UNIT)
d.SetFrom(ones)
blasd.Mult(C, B0, A, 1.0, 0.0, gomas.TRANSB)
ok = C.AllClose(B)
t.Logf("trmm(B, A, R|U|T|U) == gemm(C, B, TriUU(A).T) : %v\n", ok)
}
示例13: 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)
}
示例14: TestDTrsm1
func TestDTrsm1(t *testing.T) {
nofail := true
const N = 31
const K = 4
A := cmat.NewMatrix(N, N)
B := cmat.NewMatrix(N, K)
B0 := cmat.NewMatrix(N, K)
ones := cmat.NewFloatConstSource(1.0)
zeromean := cmat.NewFloatUniformSource(1.0, -0.5)
A.SetFrom(zeromean, cmat.LOWER)
B.SetFrom(ones)
B0.Copy(B)
// B = A*B
blasd.MultTrm(B, A, 1.0, gomas.LOWER|gomas.LEFT)
blasd.SolveTrm(B, A, 1.0, gomas.LOWER|gomas.LEFT)
ok := B0.AllClose(B)
nofail = nofail && ok
t.Logf("B == trsm(trmm(B, A, L|L|N), A, L|L|N) : %v\n", ok)
if !ok {
t.Logf("B|B0:\n%v\n", cmat.NewJoin(cmat.AUGMENT, B, B0))
}
B.Copy(B0)
// B = A.T*B
blasd.MultTrm(B, A, 1.0, gomas.LOWER|gomas.LEFT|gomas.TRANSA)
blasd.SolveTrm(B, A, 1.0, gomas.LOWER|gomas.LEFT|gomas.TRANSA)
ok = B0.AllClose(B)
nofail = nofail && ok
t.Logf("B == trsm(trmm(B, A, L|L|T), A, L|L|T) : %v\n", ok)
}
示例15: TestQRFactor
// test that unblocked QR and QRT are equal
func TestQRFactor(t *testing.T) {
M := 411
N := 375
nb := 16
conf := gomas.NewConf()
conf.LB = nb
A := cmat.NewMatrix(M, N)
//W := cmat.NewMatrix(N, nb)
tau := cmat.NewMatrix(N, 1)
zeromean := cmat.NewFloatNormSource()
A.SetFrom(zeromean)
A0 := cmat.NewCopy(A)
tau0 := cmat.NewCopy(tau)
// blocked: QR = A = Q*R
W := lapackd.Workspace(lapackd.QRFactorWork(A, conf))
lapackd.QRFactor(A, tau, W, conf)
conf.LB = 0
lapackd.QRFactor(A0, tau0, W, conf)
ok := A.AllClose(A0)
t.Logf("blk.QRFactor(A) == unblk.QRFactor(A): %v\n", ok)
ok = tau0.AllClose(tau)
t.Logf("blk QR.tau == unblk QR.tau: %v\n", ok)
}