本文整理匯總了Golang中github.com/henrylee2cn/algorithm/matrix.FloatMatrix類的典型用法代碼示例。如果您正苦於以下問題:Golang FloatMatrix類的具體用法?Golang FloatMatrix怎麽用?Golang FloatMatrix使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了FloatMatrix類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: unblockedInverseUnitLower
// Inverse UNIT diagonal tridiagonal matrix
func unblockedInverseUnitLower(A *matrix.FloatMatrix) (err error) {
var ATL, ATR, ABL, ABR matrix.FloatMatrix
var A00, a10t, a11, A20, a21, A22 matrix.FloatMatrix
err = nil
partition2x2(
&ATL, &ATR,
&ABL, &ABR, A, 0, 0, pTOPLEFT)
for ATL.Rows() < A.Rows() {
repartition2x2to3x3(&ATL,
&A00, nil, nil,
&a10t, &a11, nil,
&A20, &a21, &A22, A, 1, pBOTTOMRIGHT)
// -------------------------------------------------
// a21 = -a21
Scale(&a21, -1.0)
// A20 = A20 + a21*a10.t
MVRankUpdate(&A20, &a21, &a10t, 1.0)
// -------------------------------------------------
continue3x3to2x2(
&ATL, &ATR,
&ABL, &ABR, &A00, &a11, &A22, A, pBOTTOMRIGHT)
}
return
}
示例2: InverseTrm
func InverseTrm(A *matrix.FloatMatrix, flags Flags, nb int) (*matrix.FloatMatrix, error) {
var err error = nil
if nb == 0 || A.Cols() < nb {
if flags&UNIT != 0 {
if flags&LOWER != 0 {
err = unblockedInverseUnitLower(A)
} else {
err = unblockedInverseUnitUpper(A)
}
} else {
if flags&LOWER != 0 {
err = unblockedInverseLower(A)
} else {
err = unblockedInverseUpper(A)
}
}
} else {
if flags&LOWER != 0 {
err = blockedInverseLower(A, flags, nb)
} else {
err = blockedInverseUpper(A, flags, nb)
}
}
return A, err
}
示例3: unblockedInverseUpper
// Inverse NON-UNIT diagonal tridiagonal matrix
func unblockedInverseUpper(A *matrix.FloatMatrix) (err error) {
var ATL, ATR, ABL, ABR matrix.FloatMatrix
var A00, a01, A02, a11, a12t, A22 matrix.FloatMatrix
err = nil
partition2x2(
&ATL, &ATR,
&ABL, &ABR, A, 0, 0, pTOPLEFT)
for ATL.Rows() < A.Rows() {
repartition2x2to3x3(&ATL,
&A00, &a01, &A02,
nil, &a11, &a12t,
nil, nil, &A22, A, 1, pBOTTOMRIGHT)
// -------------------------------------------------
aval := a11.Float()
// a12 = -a12/a11
InvScale(&a12t, -aval)
// A02 = A02 + a01*a12
MVRankUpdate(&A02, &a01, &a12t, 1.0)
// a01 = a01/a11
InvScale(&a01, aval)
// a11 = 1.0/a11
a11.SetAt(0, 0, 1.0/aval)
// -------------------------------------------------
continue3x3to2x2(
&ATL, &ATR,
&ABL, &ABR, &A00, &a11, &A22, A, pBOTTOMRIGHT)
}
return
}
示例4: blockedInverseUpper
func blockedInverseUpper(A *matrix.FloatMatrix, flags Flags, nb int) (err error) {
var ATL, ATR, ABL, ABR matrix.FloatMatrix
var A00, A01, A02, A11, A12, A22 matrix.FloatMatrix
err = nil
partition2x2(
&ATL, &ATR,
&ABL, &ABR, A, 0, 0, pTOPLEFT)
for ATL.Rows() < A.Rows() {
repartition2x2to3x3(&ATL,
&A00, &A01, &A02,
nil, &A11, &A12,
nil, nil, &A22, A, nb, pBOTTOMRIGHT)
// -------------------------------------------------
// libflame, variant 1
// A01 = A00*A01
MultTrm(&A01, &A00, 1.0, flags)
// A01 = -A01 / triu(A11)
SolveTrm(&A01, &A11, -1.0, flags|RIGHT)
// A11 = inv(A11)
if flags&UNIT != 0 {
unblockedInverseUnitUpper(&A11)
} else {
unblockedInverseUpper(&A11)
}
// -------------------------------------------------
continue3x3to2x2(
&ATL, &ATR,
&ABL, &ABR, &A00, &A11, &A22, A, pBOTTOMRIGHT)
}
return
}
示例5: runRefTest
func runRefTest(A *matrix.FloatMatrix, ntest, LB int) time.Duration {
var mintime time.Duration
N := A.Cols()
tau := matrix.FloatZeros(N, 1)
fnc := func() {
ERRlapack = lapack.Geqrf(A, tau)
}
A0 := A.Copy()
for n := 0; n < ntest; n++ {
if n > 0 {
// restore original A
A0.CopyTo(A)
tau.Scale(0.0)
}
mperf.FlushCache()
time0 := mperf.Timeit(fnc)
if n == 0 || time0 < mintime {
mintime = time0
}
}
return mintime
}
示例6: TestSolveLeastSquaresQRT
func TestSolveLeastSquaresQRT(t *testing.T) {
M := 60
N := 40
K := 30
nb := 12
A := matrix.FloatUniform(M, N)
B := matrix.FloatZeros(M, K)
X0 := matrix.FloatUniform(N, K)
// B = A*X0
Mult(B, A, X0, 1.0, 0.0, NOTRANS)
W := matrix.FloatZeros(N, nb)
T := matrix.FloatZeros(N, N)
QR, err := DecomposeQRT(A, T, W, nb)
if err != nil {
t.Logf("decompose error: %v\n", err)
}
// B' = A.-1*B
err = SolveQRT(B, QR, T, W, NOTRANS, nb)
// expect B[0:N, 0:K] == X0, B[N:M, 0:K] == 0.0
var Xref matrix.FloatMatrix
Bref := matrix.FloatZeros(M, K)
Bref.SubMatrix(&Xref, 0, 0, N, K)
Xref.Plus(X0)
Bref.Minus(B)
t.Logf("\nmin ||B - A*X0||\n\twhere B = A*X0\n")
t.Logf("||B - A*X0||_1 ~~ 0.0: %e\n", NormP(Bref, NORM_ONE))
}
示例7: updateBlas
func updateBlas(t *testing.T, Y1, Y2, C1, C2, T, W *matrix.FloatMatrix) {
if W.Rows() != C1.Cols() {
panic("W.Rows != C1.Cols")
}
// W = C1.T
ScalePlus(W, C1, 0.0, 1.0, TRANSB)
//fmt.Printf("W = C1.T:\n%v\n", W)
// W = C1.T*Y1
blas.TrmmFloat(Y1, W, 1.0, linalg.OptLower, linalg.OptUnit, linalg.OptRight)
t.Logf("W = C1.T*Y1:\n%v\n", W)
// W = W + C2.T*Y2
blas.GemmFloat(C2, Y2, W, 1.0, 1.0, linalg.OptTransA)
t.Logf("W = W + C2.T*Y2:\n%v\n", W)
// --- here: W == C.T*Y ---
// W = W*T
blas.TrmmFloat(T, W, 1.0, linalg.OptUpper, linalg.OptRight)
t.Logf("W = C.T*Y*T:\n%v\n", W)
// --- here: W == C.T*Y*T ---
// C2 = C2 - Y2*W.T
blas.GemmFloat(Y2, W, C2, -1, 1.0, linalg.OptTransB)
t.Logf("C2 = C2 - Y2*W.T:\n%v\n", C2)
// W = Y1*W.T ==> W.T = W*Y1.T
blas.TrmmFloat(Y1, W, 1.0, linalg.OptLower,
linalg.OptUnit, linalg.OptRight, linalg.OptTrans)
t.Logf("W.T = W*Y1.T:\n%v\n", W)
// C1 = C1 - W.T
ScalePlus(C1, W, 1.0, -1.0, TRANSB)
//fmt.Printf("C1 = C1 - W.T:\n%v\n", C1)
// --- here: C = (I - Y*T*Y.T).T * C ---
}
示例8: runTest
func runTest(A *matrix.FloatMatrix, ntest, LB int) time.Duration {
var flags matops.Flags
var mintime time.Duration
flags = matops.LOWER
if testUpper {
flags = matops.UPPER
}
fnc := func() {
_, ERRmatops = matops.DecomposeCHOL(A, 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
}
示例9: setDiagonal
func setDiagonal(M *matrix.FloatMatrix, srow, scol, erow, ecol int, val float64) {
for i := srow; i < erow; i++ {
if i < ecol {
M.SetAt(i, i, val)
}
}
}
示例10: AMax
// max |x|
func AMax(X *matrix.FloatMatrix) float64 {
ix := IAMax(X)
if ix == -1 {
return math.NaN()
}
return X.GetIndex(ix)
}
示例11: SyrkFloat
// See function Syrk.
func SyrkFloat(A, C *matrix.FloatMatrix, alpha, beta float64, opts ...linalg.Option) (err error) {
params, e := linalg.GetParameters(opts...)
if e != nil {
err = e
return
}
ind := linalg.GetIndexOpts(opts...)
err = check_level3_func(ind, fsyrk, A, nil, C, params)
if e != nil || err != nil {
return
}
if ind.N == 0 {
return
}
Aa := A.FloatArray()
Ca := C.FloatArray()
uplo := linalg.ParamString(params.Uplo)
trans := linalg.ParamString(params.Trans)
//diag := linalg.ParamString(params.Diag)
dsyrk(uplo, trans, ind.N, ind.K, alpha, Aa[ind.OffsetA:], ind.LDa, beta,
Ca[ind.OffsetC:], ind.LDc)
return
}
示例12: runRefTest
func runRefTest(A *matrix.FloatMatrix, ntest, LB int) time.Duration {
var mintime time.Duration
lopt := linalg.OptLower
if testUpper {
lopt = linalg.OptUpper
}
fnc := func() {
ERRlapack = lapack.Potrf(A, lopt)
}
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
}
示例13: pack
/*
Copy x to y using packed storage.
The vector x is an element of S, with the 's' components stored in
unpacked storage. On return, x is copied to y with the 's' components
stored in packed storage and the off-diagonal entries scaled by
sqrt(2).
*/
func pack(x, y *matrix.FloatMatrix, dims *sets.DimensionSet, opts ...la_.Option) (err error) {
/*DEBUGGED*/
err = nil
mnl := la_.GetIntOpt("mnl", 0, opts...)
offsetx := la_.GetIntOpt("offsetx", 0, opts...)
offsety := la_.GetIntOpt("offsety", 0, opts...)
nlq := mnl + dims.At("l")[0] + dims.Sum("q")
blas.Copy(x, y, &la_.IOpt{"n", nlq}, &la_.IOpt{"offsetx", offsetx},
&la_.IOpt{"offsety", offsety})
iu, ip := offsetx+nlq, offsety+nlq
for _, n := range dims.At("s") {
for k := 0; k < n; k++ {
blas.Copy(x, y, &la_.IOpt{"n", n - k}, &la_.IOpt{"offsetx", iu + k*(n+1)},
&la_.IOpt{"offsety", ip})
y.SetIndex(ip, (y.GetIndex(ip) / math.Sqrt(2.0)))
ip += n - k
}
iu += n * n
}
np := dims.SumPacked("s")
blas.ScalFloat(y, math.Sqrt(2.0), &la_.IOpt{"n", np}, &la_.IOpt{"offset", offsety + nlq})
return
}
示例14: trmvTest
func trmvTest(t *testing.T, A *matrix.FloatMatrix, flags Flags, nb int) bool {
N := A.Cols()
//S := 0
//E := A.Cols()
X0 := matrix.FloatWithValue(A.Rows(), 1, 2.0)
X1 := X0.Copy()
trans := linalg.OptNoTrans
if flags&TRANS != 0 {
trans = linalg.OptTrans
}
diag := linalg.OptNonUnit
if flags&UNIT != 0 {
diag = linalg.OptUnit
}
uplo := linalg.OptUpper
if flags&LOWER != 0 {
uplo = linalg.OptLower
}
blas.TrmvFloat(A, X0, uplo, diag, trans)
Ar := A.FloatArray()
Xr := X1.FloatArray()
if nb == 0 {
DTrimvUnblkMV(Xr, Ar, flags, 1, A.LeadingIndex(), N)
}
result := X0.AllClose(X1)
t.Logf(" X0 == X1: %v\n", result)
if !result && A.Rows() < 8 {
t.Logf(" BLAS TRMV X0:\n%v\n", X0)
t.Logf(" DTrmv X1:\n%v\n", X1)
}
return result
}
示例15: pack2
// In-place version of pack(), which also accepts matrix arguments x.
// The columns of x are elements of S, with the 's' components stored
// in unpacked storage. On return, the 's' components are stored in
// packed storage and the off-diagonal entries are scaled by sqrt(2).
//
func pack2(x *matrix.FloatMatrix, dims *sets.DimensionSet, mnl int) (err error) {
if len(dims.At("s")) == 0 {
return nil
}
const sqrt2 = 1.41421356237309504880
iu := mnl + dims.Sum("l", "q")
ip := iu
row := matrix.FloatZeros(1, x.Cols())
//fmt.Printf("x.size = %d %d\n", x.Rows(), x.Cols())
for _, n := range dims.At("s") {
for k := 0; k < n; k++ {
cnt := n - k
row = x.GetRow(iu+(n+1)*k, row)
//fmt.Printf("%02d: %v\n", iu+(n+1)*k, x.FloatArray())
x.SetRow(ip, row)
for i := 1; i < n-k; i++ {
row = x.GetRow(iu+(n+1)*k+i, row)
//fmt.Printf("%02d: %v\n", iu+(n+1)*k+i, x.FloatArray())
x.SetRow(ip+i, row.Scale(sqrt2))
}
ip += cnt
}
iu += n * n
}
return nil
}