本文整理汇总了Golang中github.com/hrautila/matrix.FloatMatrix类的典型用法代码示例。如果您正苦于以下问题:Golang FloatMatrix类的具体用法?Golang FloatMatrix怎么用?Golang FloatMatrix使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FloatMatrix类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GbtrsFloat
func GbtrsFloat(A, B *matrix.FloatMatrix, ipiv []int32, KL int, opts ...linalg.Option) error {
pars, err := linalg.GetParameters(opts...)
if err != nil {
return err
}
ind := linalg.GetIndexOpts(opts...)
ind.Kl = KL
err = checkGbtrs(ind, A, B, ipiv)
if err != nil {
return err
}
if ind.N == 0 || ind.Nrhs == 0 {
return nil
}
Aa := A.FloatArray()
Ba := B.FloatArray()
trans := linalg.ParamString(pars.Trans)
info := dgbtrs(trans, ind.N, ind.Kl, ind.Ku, ind.Nrhs,
Aa[ind.OffsetA:], ind.LDa, ipiv, Ba[ind.OffsetB:], ind.LDb)
if info != 0 {
return onError(fmt.Sprintf("Gbtrs: lapack error: %d", info))
}
return nil
}
示例2: sgemv
/*
Matrix-vector multiplication.
A is a matrix or spmatrix of size (m, n) where
N = dims['l'] + sum(dims['q']) + sum( k**2 for k in dims['s'] )
representing a mapping from R^n to S.
If trans is 'N':
y := alpha*A*x + beta * y (trans = 'N').
x is a vector of length n. y is a vector of length N.
If trans is 'T':
y := alpha*A'*x + beta * y (trans = 'T').
x is a vector of length N. y is a vector of length n.
The 's' components in S are stored in unpacked 'L' storage.
*/
func sgemv(A, x, y *matrix.FloatMatrix, alpha, beta float64, dims *sets.DimensionSet, opts ...la_.Option) error {
m := dims.Sum("l", "q") + dims.SumSquared("s")
n := la_.GetIntOpt("n", -1, opts...)
if n == -1 {
n = A.Cols()
}
trans := la_.GetIntOpt("trans", int(la_.PNoTrans), opts...)
offsetX := la_.GetIntOpt("offsetx", 0, opts...)
offsetY := la_.GetIntOpt("offsety", 0, opts...)
offsetA := la_.GetIntOpt("offseta", 0, opts...)
if trans == int(la_.PTrans) && alpha != 0.0 {
trisc(x, dims, offsetX)
//fmt.Printf("trisc x=\n%v\n", x.ConvertToString())
}
//fmt.Printf("alpha=%.4f beta=%.4f m=%d n=%d\n", alpha, beta, m, n)
//fmt.Printf("A=\n%v\nx=\n%v\ny=\n%v\n", A, x.ConvertToString(), y.ConvertToString())
err := blas.GemvFloat(A, x, y, alpha, beta, &la_.IOpt{"trans", trans},
&la_.IOpt{"n", n}, &la_.IOpt{"m", m}, &la_.IOpt{"offseta", offsetA},
&la_.IOpt{"offsetx", offsetX}, &la_.IOpt{"offsety", offsetY})
//fmt.Printf("gemv y=\n%v\n", y.ConvertToString())
if trans == int(la_.PTrans) && alpha != 0.0 {
triusc(x, dims, offsetX)
}
return err
}
示例3: 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
}
示例4: 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
}
示例5: 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
}
示例6: 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
}
示例7: unblkLowerLDLnoPiv
/*
* ( a11 a12 ) ( 1 0 )( d1 0 )( l l21.t )
* ( a21 A22 ) ( l21 L22 )( 0 A22 )( 0 L22.t )
*
* a11 = d1
* a21 = l21*d1 => l21 = a21/d1
* A22 = l21*d1*l21.t + L22*D2*L22.t => L22 = A22 - l21*d1*l21t
*/
func unblkLowerLDLnoPiv(A *matrix.FloatMatrix) (err error) {
var ATL, ATR, ABL, ABR matrix.FloatMatrix
var A00, a10, 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,
&a10, &a11, nil,
&A20, &a21, &A22, A, 1, pBOTTOMRIGHT)
// --------------------------------------------------------
// d11 = a11; no-op
// A22 = A22 - l21*d11*l21.T = A22 - a21*a21.T/a11; triangular update
err = MVUpdateTrm(&A22, &a21, &a21, -1.0/a11.Float(), LOWER)
// l21 = a21/a11
InvScale(&a21, a11.Float())
// ---------------------------------------------------------
continue3x3to2x2(
&ATL, &ATR,
&ABL, &ABR, &A00, &a11, &A22, A, pBOTTOMRIGHT)
}
return
}
示例8: blockedLUnoPiv
// blocked LU decomposition w/o pivots, FLAME LU nopivots variant 5
func blockedLUnoPiv(A *matrix.FloatMatrix, nb int) (err error) {
var ATL, ATR, ABL, ABR matrix.FloatMatrix
var A00, A01, A02, A10, A11, A12, A20, A21, A22 matrix.FloatMatrix
err = nil
partition2x2(
&ATL, &ATR,
&ABL, &ABR, A, 0, 0, pTOPLEFT)
for ATL.Rows() < A.Rows() {
repartition2x2to3x3(&ATL,
&A00, &A01, &A02,
&A10, &A11, &A12,
&A20, &A21, &A22, A, nb, pBOTTOMRIGHT)
// A00 = LU(A00)
unblockedLUnoPiv(&A11)
// A12 = trilu(A00)*A12.-1 (TRSM)
SolveTrm(&A12, &A11, 1.0, LEFT|LOWER|UNIT)
// A21 = A21.-1*triu(A00) (TRSM)
SolveTrm(&A21, &A11, 1.0, RIGHT|UPPER)
// A22 = A22 - A21*A12
Mult(&A22, &A21, &A12, -1.0, 1.0, NOTRANS)
continue3x3to2x2(
&ATL, &ATR,
&ABL, &ABR, &A00, &A11, &A22, A, pBOTTOMRIGHT)
}
return
}
示例9: 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
}
示例10: 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
}
示例11: 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
}
示例12: main
func main() {
blas.PanicOnError(true)
matrix.PanicOnError(true)
var data *matrix.FloatMatrix = nil
flag.Parse()
if len(dataVal) > 0 {
data, _ = matrix.FloatParse(dataVal)
if data == nil {
fmt.Printf("could not parse:\n%s\n", dataVal)
return
}
} else {
data = matrix.FloatNormal(20, 20)
}
if len(spPath) > 0 {
checkpnt.Reset(spPath)
checkpnt.Activate()
checkpnt.Verbose(spVerbose)
checkpnt.Format("%.7f")
}
sol, err := mcsdp(data)
if sol != nil && sol.Status == cvx.Optimal {
x := sol.Result.At("x")[0]
z := sol.Result.At("z")[0]
matrix.Reshape(z, data.Rows(), data.Rows())
fmt.Printf("x=\n%v\n", x.ToString("%.9f"))
//fmt.Printf("z=\n%v\n", z.ToString("%.9f"))
check(x, z)
} else {
fmt.Printf("status: %v\n", err)
}
}
示例13: 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
}
示例14: 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
}
示例15: 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 ---
}