本文整理匯總了Golang中github.com/hrautila/cmat.FloatMatrix.Get方法的典型用法代碼示例。如果您正苦於以下問題:Golang FloatMatrix.Get方法的具體用法?Golang FloatMatrix.Get怎麽用?Golang FloatMatrix.Get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/hrautila/cmat.FloatMatrix
的用法示例。
在下文中一共展示了FloatMatrix.Get方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: applyHouseholder2x1
/*
* Applies a real elementary reflector H to a real m by n matrix A,
* from either the left or the right. H is represented in the form
*
* H = I - tau * ( 1 ) * ( 1 v.T )
* ( v )
*
* where tau is a real scalar and v is a real vector.
*
* If tau = 0, then H is taken to be the unit cmat.
*
* A is /a1\ a1 := a1 - w1
* \A2/ A2 := A2 - v*w1
* w1 := tau*(a1 + A2.T*v) if side == LEFT
* := tau*(a1 + A2*v) if side == RIGHT
*
* Intermediate work space w1 required as parameter, no allocation.
*/
func applyHouseholder2x1(tau, v, a1, A2, w1 *cmat.FloatMatrix, flags int) *gomas.Error {
var err *gomas.Error = nil
tval := tau.Get(0, 0)
if tval == 0.0 {
return err
}
// shape oblivious vector copy.
blasd.Axpby(w1, a1, 1.0, 0.0)
if flags&gomas.LEFT != 0 {
// w1 = a1 + A2.T*v
err = blasd.MVMult(w1, A2, v, 1.0, 1.0, gomas.TRANSA)
} else {
// w1 = a1 + A2*v
err = blasd.MVMult(w1, A2, v, 1.0, 1.0, gomas.NONE)
}
// w1 = tau*w1
blasd.Scale(w1, tval)
// a1 = a1 - w1
blasd.Axpy(a1, w1, -1.0)
// A2 = A2 - v*w1
if flags&gomas.LEFT != 0 {
err = blasd.MVUpdate(A2, v, w1, -1.0)
} else {
err = blasd.MVUpdate(A2, w1, v, -1.0)
}
return err
}
示例2: TestPartition2D
func TestPartition2D(t *testing.T) {
var ATL, ATR, ABL, ABR, As cmat.FloatMatrix
var A00, a01, A02, a10, a11, a12, A20, a21, A22 cmat.FloatMatrix
csource := cmat.NewFloatConstSource(1.0)
A := cmat.NewMatrix(6, 6)
As.SubMatrix(A, 1, 1, 4, 4)
As.SetFrom(csource)
Partition2x2(&ATL, &ATR, &ABL, &ABR, &As, 0, 0, PTOPLEFT)
t.Logf("ATL:\n%v\n", &ATL)
t.Logf("n(ATL)=%d, n(As)=%d\n", n(&ATL), n(&As))
k := 0
for n(&ATL) < n(&As) && k < n(&As) {
Repartition2x2to3x3(&ATL,
&A00, &a01, &A02,
&a10, &a11, &a12,
&A20, &a21, &A22, &As, 1, PBOTTOMRIGHT)
t.Logf("n(A00)=%d, n(a01)=%d, n(A02)=%d\n", n(&A00), n(&a01), n(&A02))
t.Logf("n(a10)=%d, n(a11)=%d, n(a12)=%d\n", n(&a10), n(&a11), n(&a12))
t.Logf("n(A20)=%d, n(a21)=%d, n(A22)=%d\n", n(&A20), n(&a21), n(&A22))
//t.Logf("n(a12)=%d [%d], n(a11)=%d\n", n(&a12), a12.Len(), a11.Len())
a11.Set(0, 0, a11.Get(0, 0)+1.0)
addConst(&a21, -2.0)
Continue3x3to2x2(&ATL, &ATR, &ABL, &ABR, &A00, &a11, &A22, &As, PBOTTOMRIGHT)
t.Logf("n(ATL)=%d, n(As)=%d\n", n(&ATL), n(&As))
k += 1
}
t.Logf("A:\n%v\n", A)
}
示例3: unblockedLUnoPiv
// unblocked LU decomposition w/o pivots, FLAME LU nopivots variant 5
func unblockedLUnoPiv(A *cmat.FloatMatrix, conf *gomas.Config) *gomas.Error {
var ATL, ATR, ABL, ABR cmat.FloatMatrix
var A00, a01, A02, a10, a11, a12, A20, a21, A22 cmat.FloatMatrix
var err *gomas.Error = nil
util.Partition2x2(
&ATL, &ATR,
&ABL, &ABR, A, 0, 0, util.PTOPLEFT)
for m(&ATL) < m(A) {
util.Repartition2x2to3x3(&ATL,
&A00, &a01, &A02,
&a10, &a11, &a12,
&A20, &a21, &A22, A, 1, util.PBOTTOMRIGHT)
// a21 = a21/a11
blasd.InvScale(&a21, a11.Get(0, 0))
// A22 = A22 - a21*a12
blasd.MVUpdate(&A22, &a21, &a12, -1.0)
util.Continue3x3to2x2(
&ATL, &ATR,
&ABL, &ABR, &A00, &a11, &A22, A, util.PBOTTOMRIGHT)
}
return err
}
示例4: unblkReduceTridiagUpper
/*
* Reduce upper triangular matrix to tridiagonal.
*
* Elementary reflectors Q = H(n-1)...H(2)H(1) are stored on upper
* triangular part of A. Reflector H(n-1) saved at column A(n) and
* scalar multiplier to tau[n-1]. If parameter `tail` is true then
* this function is used to reduce tail part of partially reduced
* matrix and tau-vector partitioning is starting from last position.
*/
func unblkReduceTridiagUpper(A, tauq, W *cmat.FloatMatrix, tail bool) {
var ATL, ABR cmat.FloatMatrix
var A00, a01, a11, A22 cmat.FloatMatrix
var tqT, tqB, tq0, tauq1, tq2 cmat.FloatMatrix
var y21 cmat.FloatMatrix
var v0 float64
toff := 1
if tail {
toff = 0
}
util.Partition2x2(
&ATL, nil,
nil, &ABR, A, 0, 0, util.PBOTTOMRIGHT)
util.Partition2x1(
&tqT,
&tqB, tauq, toff, util.PBOTTOM)
for n(&ATL) > 0 {
util.Repartition2x2to3x3(&ATL,
&A00, &a01, nil,
nil, &a11, nil,
nil, nil, &A22, A, 1, util.PTOPLEFT)
util.Repartition2x1to3x1(&tqT,
&tq0,
&tauq1,
&tq2, tauq, 1, util.PTOP)
// set temp vectors for this round
y21.SetBuf(n(&A00), 1, n(&A00), W.Data())
// ------------------------------------------------------
// Compute householder to zero super-diagonal entries
computeHouseholderRev(&a01, &tauq1)
tauqv := tauq1.Get(0, 0)
// set superdiagonal to unit
v0 = a01.Get(-1, 0)
a01.Set(-1, 0, 1.0)
// y21 := A22*a12t
blasd.MVMultSym(&y21, &A00, &a01, tauqv, 0.0, gomas.UPPER)
// beta := tauq*a12t*y21
beta := tauqv * blasd.Dot(&a01, &y21)
// y21 := y21 - 0.5*beta*a125
blasd.Axpy(&y21, &a01, -0.5*beta)
// A22 := A22 - a12t*y21.T - y21*a12.T
blasd.MVUpdate2Sym(&A00, &a01, &y21, -1.0, gomas.UPPER)
// restore superdiagonal value
a01.Set(-1, 0, v0)
// ------------------------------------------------------
util.Continue3x3to2x2(
&ATL, nil,
nil, &ABR, &A00, &a11, &A22, A, util.PTOPLEFT)
util.Continue3x1to2x1(
&tqT,
&tqB, &tq0, &tauq1, tauq, util.PTOP)
}
}
示例5: blkReduceTridiagUpper
func blkReduceTridiagUpper(A, tauq, Y, W *cmat.FloatMatrix, lb int, conf *gomas.Config) {
var ATL, ABR cmat.FloatMatrix
var A00, A01, A11, A22 cmat.FloatMatrix
var YT, YB, Y0, Y1, Y2 cmat.FloatMatrix
var tqT, tqB, tq0, tauq1, tq2 cmat.FloatMatrix
var v0 float64
util.Partition2x2(
&ATL, nil,
nil, &ABR, A, 0, 0, util.PBOTTOMRIGHT)
util.Partition2x1(
&YT,
&YB, Y, 0, util.PBOTTOM)
util.Partition2x1(
&tqT,
&tqB, tauq, 1, util.PBOTTOM)
for m(&ATL)-lb > 0 {
util.Repartition2x2to3x3(&ATL,
&A00, &A01, nil,
nil, &A11, nil,
nil, nil, &A22, A, lb, util.PTOPLEFT)
util.Repartition2x1to3x1(&YT,
&Y0,
&Y1,
&Y2, Y, lb, util.PTOP)
util.Repartition2x1to3x1(&tqT,
&tq0,
&tauq1,
&tq2, tauq, lb, util.PTOP)
// ------------------------------------------------------
unblkBuildTridiagUpper(&ATL, &tauq1, &YT, W)
// set subdiagonal entry to unit
v0 = A01.Get(-1, 0)
A01.Set(-1, 0, 1.0)
// A22 := A22 - A01*Y0.T - Y0*A01.T
blasd.Update2Sym(&A00, &A01, &Y0, -1.0, 1.0, gomas.UPPER, conf)
// restore subdiagonal entry
A01.Set(-1, 0, v0)
// ------------------------------------------------------
util.Continue3x3to2x2(
&ATL, nil,
nil, &ABR, &A00, &A11, &A22, A, util.PTOPLEFT)
util.Continue3x1to2x1(
&YT,
&YB, &Y0, &Y1, Y, util.PTOP)
util.Continue3x1to2x1(
&tqT,
&tqB, &tq0, &tauq1, tauq, util.PTOP)
}
if m(&ATL) > 0 {
unblkReduceTridiagUpper(&ATL, &tqT, W, true)
}
}
示例6: unblkQLBlockReflector
/*
* like LAPACK/dlafrt.f
*
* Build block reflector T from HH reflector stored in TriLU(A) and coefficients
* in tau.
*
* Q = I - Y*T*Y.T; Householder H = I - tau*v*v.T
*
* T = | T z | z = -tau*T*Y.T*v
* | 0 c | c = tau
*
* Q = H(1)H(2)...H(k) building forward here.
*/
func unblkQLBlockReflector(T, A, tau *cmat.FloatMatrix) {
var ATL, ABR cmat.FloatMatrix
var A00, a01, a11, A02, a12, A22 cmat.FloatMatrix
var TTL, TBR cmat.FloatMatrix
var T00, t11, t21, T22 cmat.FloatMatrix
var tT, tB cmat.FloatMatrix
var t0, tau1, t2 cmat.FloatMatrix
util.Partition2x2(
&ATL, nil,
nil, &ABR, A, 0, 0, util.PBOTTOMRIGHT)
util.Partition2x2(
&TTL, nil,
nil, &TBR, T, 0, 0, util.PBOTTOMRIGHT)
util.Partition2x1(
&tT,
&tB, tau, 0, util.PBOTTOM)
for m(&ATL) > 0 && n(&ATL) > 0 {
util.Repartition2x2to3x3(&ATL,
&A00, &a01, &A02,
nil, &a11, &a12,
nil, nil, &A22, A, 1, util.PTOPLEFT)
util.Repartition2x2to3x3(&TTL,
&T00, nil, nil,
nil, &t11, nil,
nil, &t21, &T22, T, 1, util.PTOPLEFT)
util.Repartition2x1to3x1(&tT,
&t0,
&tau1,
&t2, tau, 1, util.PTOP)
// --------------------------------------------------
// t11 := tau
tauval := tau1.Get(0, 0)
if tauval != 0.0 {
t11.Set(0, 0, tauval)
// t21 := -tauval*(a12.T + &A02.T*a12)
blasd.Axpby(&t21, &a12, 1.0, 0.0)
blasd.MVMult(&t21, &A02, &a01, -tauval, -tauval, gomas.TRANSA)
// t21 := T22*t01
blasd.MVMultTrm(&t21, &T22, 1.0, gomas.LOWER)
}
// --------------------------------------------------
util.Continue3x3to2x2(
&ATL, nil,
nil, &ABR, &A00, &a11, &A22, A, util.PTOPLEFT)
util.Continue3x3to2x2(
&TTL, nil,
nil, &TBR, &T00, &t11, &T22, T, util.PTOPLEFT)
util.Continue3x1to2x1(
&tT,
&tB, &t0, &tau1, tau, util.PTOP)
}
}
示例7: unblkBlockReflectorRQ
/*
* like LAPACK/dlafrt.f
*
* Build block reflector T from HH reflector stored in TriLU(A) and coefficients
* in tau.
*
* Q = I - Y*T*Y.T; Householder H = I - tau*v*v.T
*
* T = | T 0 | z = -tau*T*Y.T*v
* | z c | c = tau
*
* Q = H(1)H(2)...H(k) building forward here.
*/
func unblkBlockReflectorRQ(T, A, tau *cmat.FloatMatrix) {
var ATL, ABR cmat.FloatMatrix
var A00, a10, A20, a11, a21, A22 cmat.FloatMatrix
var TTL, TBR cmat.FloatMatrix
var T00, t11, t21, T22 cmat.FloatMatrix
var tT, tB cmat.FloatMatrix
var t0, tau1, t2 cmat.FloatMatrix
util.Partition2x2(
&ATL, nil,
nil, &ABR /**/, A, 0, 0, util.PBOTTOMRIGHT)
util.Partition2x2(
&TTL, nil,
nil, &TBR /**/, T, 0, 0, util.PBOTTOMRIGHT)
util.Partition2x1(
&tT,
&tB /**/, tau, 0, util.PBOTTOM)
for m(&ATL) > 0 && n(&ATL) > 0 {
util.Repartition2x2to3x3(&ATL,
&A00, nil, nil,
&a10, &a11, nil,
&A20, &a21, &A22 /**/, A, 1, util.PTOPLEFT)
util.Repartition2x2to3x3(&TTL,
&T00, nil, nil,
nil, &t11, nil,
nil, &t21, &T22 /**/, T, 1, util.PTOPLEFT)
util.Repartition2x1to3x1(&tT,
&t0,
&tau1,
&t2 /**/, tau, 1, util.PTOP)
// --------------------------------------------------
// t11 := tau
tauval := tau1.Get(0, 0)
if tauval != 0.0 {
t11.Set(0, 0, tauval)
// t21 := -tauval*(a21 + A20*a10)
blasd.Axpby(&t21, &a21, 1.0, 0.0)
blasd.MVMult(&t21, &A20, &a10, -tauval, -tauval, gomas.NONE)
// t21 := T22*t21
blasd.MVMultTrm(&t21, &T22, 1.0, gomas.LOWER)
}
// --------------------------------------------------
util.Continue3x3to2x2(
&ATL, nil,
nil, &ABR /**/, &A00, &a11, &A22, A, util.PTOPLEFT)
util.Continue3x3to2x2(
&TTL, nil,
nil, &TBR /**/, &T00, &t11, &T22, T, util.PTOPLEFT)
util.Continue3x1to2x1(
&tT,
&tB /**/, &t0, &tau1, tau, util.PTOP)
}
}
示例8: unblkBlockReflectorLQ
/*
* like LAPACK/dlafrt.f
*
* Build block reflector T from HH reflector stored in TriLU(A) and coefficients
* in tau.
*
* Q = I - Y*T*Y.T; Householder H = I - tau*v*v.T
*
* T = | T z | z = -tau*T*Y.T*v
* | 0 c | c = tau
*
* Q = H(1)H(2)...H(k) building forward here.
*/
func unblkBlockReflectorLQ(T, A, tau *cmat.FloatMatrix) {
var ATL, ATR, ABL, ABR cmat.FloatMatrix
var A00, a01, A02, a11, a12, A22 cmat.FloatMatrix
var TTL, TTR, TBL, TBR cmat.FloatMatrix
var T00, t01, T02, t11, t12, T22 cmat.FloatMatrix
var tT, tB cmat.FloatMatrix
var t0, tau1, t2 cmat.FloatMatrix
util.Partition2x2(
&ATL, &ATR,
&ABL, &ABR, A, 0, 0, util.PTOPLEFT)
util.Partition2x2(
&TTL, &TTR,
&TBL, &TBR, T, 0, 0, util.PTOPLEFT)
util.Partition2x1(
&tT,
&tB, tau, 0, util.PTOP)
for m(&ABR) > 0 && n(&ABR) > 0 {
util.Repartition2x2to3x3(&ATL,
&A00, &a01, &A02,
nil, &a11, &a12,
nil, nil, &A22, A, 1, util.PBOTTOMRIGHT)
util.Repartition2x2to3x3(&TTL,
&T00, &t01, &T02,
nil, &t11, &t12,
nil, nil, &T22, T, 1, util.PBOTTOMRIGHT)
util.Repartition2x1to3x1(&tT,
&t0,
&tau1,
&t2, tau, 1, util.PBOTTOM)
// --------------------------------------------------
// t11 := tau
tauval := tau1.Get(0, 0)
if tauval != 0.0 {
t11.Set(0, 0, tauval)
// t01 := -tauval*(a01 + A02*a12)
blasd.Axpby(&t01, &a01, 1.0, 0.0)
blasd.MVMult(&t01, &A02, &a12, -tauval, -tauval, gomas.NONE)
// t01 := T00*t01
blasd.MVMultTrm(&t01, &T00, 1.0, gomas.UPPER)
}
// --------------------------------------------------
util.Continue3x3to2x2(
&ATL, &ATR,
&ABL, &ABR, &A00, &a11, &A22, A, util.PBOTTOMRIGHT)
util.Continue3x3to2x2(
&TTL, &TTR,
&TBL, &TBR, &T00, &t11, &T22, T, util.PBOTTOMRIGHT)
util.Continue3x1to2x1(
&tT,
&tB, &t0, &tau1, tau, util.PBOTTOM)
}
}
示例9: unblkReduceTridiagLower
/*
* Tridiagonal reduction of LOWER triangular symmetric matrix, zero elements below 1st
* subdiagonal:
*
* A = (1 - tau*u*u.t)*A*(1 - tau*u*u.T)
* = (I - tau*( 0 0 )) (a11 a12) (I - tau*( 0 0 ))
* ( ( 0 u*u.t)) (a21 A22) ( ( 0 u*u.t))
*
* a11, a12, a21 not affected
*
* from LEFT:
* A22 = A22 - tau*u*u.T*A22
* from RIGHT:
* A22 = A22 - tau*A22*u.u.T
*
* LEFT and RIGHT:
* A22 = A22 - tau*u*u.T*A22 - tau*(A22 - tau*u*u.T*A22)*u*u.T
* = A22 - tau*u*u.T*A22 - tau*A22*u*u.T + tau*tau*u*u.T*A22*u*u.T
* [x = tau*A22*u (vector)] (SYMV)
* A22 = A22 - u*x.T - x*u.T + tau*u*u.T*x*u.T
* [beta = tau*u.T*x (scalar)] (DOT)
* = A22 - u*x.T - x*u.T + beta*u*u.T
* = A22 - u*(x - 0.5*beta*u).T - (x - 0.5*beta*u)*u.T
* [w = x - 0.5*beta*u] (AXPY)
* = A22 - u*w.T - w*u.T (SYR2)
*
* Result of reduction for N = 5:
* ( d . . . . )
* ( e d . . . )
* ( v1 e d . . )
* ( v1 v2 e d . )
* ( v1 v2 v3 e d )
*/
func unblkReduceTridiagLower(A, tauq, W *cmat.FloatMatrix) {
var ATL, ABR cmat.FloatMatrix
var A00, a11, a21, A22 cmat.FloatMatrix
var tqT, tqB, tq0, tauq1, tq2 cmat.FloatMatrix
var y21 cmat.FloatMatrix
var v0 float64
util.Partition2x2(
&ATL, nil,
nil, &ABR, A, 0, 0, util.PTOPLEFT)
util.Partition2x1(
&tqT,
&tqB, tauq, 0, util.PTOP)
for m(&ABR) > 0 && n(&ABR) > 0 {
util.Repartition2x2to3x3(&ATL,
&A00, nil, nil,
nil, &a11, nil,
nil, &a21, &A22, A, 1, util.PBOTTOMRIGHT)
util.Repartition2x1to3x1(&tqT,
&tq0,
&tauq1,
&tq2, tauq, 1, util.PBOTTOM)
// set temp vectors for this round
y21.SetBuf(n(&A22), 1, n(&A22), W.Data())
// ------------------------------------------------------
// Compute householder to zero subdiagonal entries
computeHouseholderVec(&a21, &tauq1)
tauqv := tauq1.Get(0, 0)
// set subdiagonal to unit
v0 = a21.Get(0, 0)
a21.Set(0, 0, 1.0)
// y21 := tauq*A22*a21
blasd.MVMultSym(&y21, &A22, &a21, tauqv, 0.0, gomas.LOWER)
// beta := tauq*a21.T*y21
beta := tauqv * blasd.Dot(&a21, &y21)
// y21 := y21 - 0.5*beta*a21
blasd.Axpy(&y21, &a21, -0.5*beta)
// A22 := A22 - a21*y21.T - y21*a21.T
blasd.MVUpdate2Sym(&A22, &a21, &y21, -1.0, gomas.LOWER)
// restore subdiagonal
a21.Set(0, 0, v0)
// ------------------------------------------------------
util.Continue3x3to2x2(
&ATL, nil,
nil, &ABR, &A00, &a11, &A22, A, util.PBOTTOMRIGHT)
util.Continue3x1to2x1(
&tqT,
&tqB, &tq0, &tauq1, tauq, util.PBOTTOM)
}
}
示例10: unblockedQRT
/*
* Unblocked QR decomposition with block reflector T.
*/
func unblockedQRT(A, T, W *cmat.FloatMatrix) *gomas.Error {
var err *gomas.Error = nil
var ATL, ATR, ABL, ABR cmat.FloatMatrix
var A00, a10, a11, a12, A20, a21, A22 cmat.FloatMatrix
var TTL, TTR, TBL, TBR cmat.FloatMatrix
var T00, t01, T02, t11, t12, T22, w12 cmat.FloatMatrix
util.Partition2x2(
&ATL, &ATR,
&ABL, &ABR, A, 0, 0, util.PTOPLEFT)
util.Partition2x2(
&TTL, &TTR,
&TBL, &TBR, T, 0, 0, util.PTOPLEFT)
for m(&ABR) > 0 && n(&ABR) > 0 {
util.Repartition2x2to3x3(&ATL,
&A00, nil, nil,
&a10, &a11, &a12,
&A20, &a21, &A22, A, 1, util.PBOTTOMRIGHT)
util.Repartition2x2to3x3(&TTL,
&T00, &t01, &T02,
nil, &t11, &t12,
nil, nil, &T22, T, 1, util.PBOTTOMRIGHT)
// ------------------------------------------------------
computeHouseholder(&a11, &a21, &t11)
// H*[a12 A22].T
w12.SubMatrix(W, 0, 0, a12.Len(), 1)
applyHouseholder2x1(&t11, &a21, &a12, &A22, &w12, gomas.LEFT)
// update T
tauval := t11.Get(0, 0)
if tauval != 0.0 {
// t01 := -tauval*(a10.T + &A20.T*a21)
//a10.CopyTo(&t01)
blasd.Axpby(&t01, &a10, 1.0, 0.0)
blasd.MVMult(&t01, &A20, &a21, -tauval, -tauval, gomas.TRANSA)
// t01 := T00*t01
blasd.MVMultTrm(&t01, &T00, 1.0, gomas.UPPER)
}
// ------------------------------------------------------
util.Continue3x3to2x2(
&ATL, &ATR,
&ABL, &ABR, &A00, &a11, &A22, A, util.PBOTTOMRIGHT)
util.Continue3x3to2x2(
&TTL, &TTR,
&TBL, &TBR, &T00, &t11, &T22, T, util.PBOTTOMRIGHT)
}
return err
}
示例11: Amax
func Amax(X *cmat.FloatMatrix, confs ...*gomas.Config) float64 {
switch X.Len() {
case 0:
return 0.0
case 1:
return X.Get(0, 0)
}
ix := IAmax(X, confs...)
if ix == -1 {
return 0.0
}
return X.Get(ix, 0)
}
示例12: TestPartition1H
func TestPartition1H(t *testing.T) {
var AL, AR, A0, a1, A2 cmat.FloatMatrix
A := cmat.NewMatrix(1, 6)
Partition1x2(&AL, &AR, A, 0, PLEFT)
t.Logf("n(AL)=%d, n(AR)=%d\n", n(&AL), n(&AR))
for n(&AL) < n(A) {
addConst(&AR, 1.0)
t.Logf("n(AR)=%d; %v\n", n(&AR), &AR)
Repartition1x2to1x3(&AL, &A0, &a1, &A2, A, 1, PRIGHT)
t.Logf("n(A0)=%d, n(A2)=%d, a1=%.1f\n", n(&A0), n(&A2), a1.Get(0, 0))
Continue1x3to1x2(&AL, &AR, &A0, &a1, A, PRIGHT)
}
t.Logf("A:%v\n", A)
}
示例13: unblkBuildQL
/*
* Unblocked code for generating M by N matrix Q with orthogonal columns which
* are defined as the last N columns of the product of K first elementary
* reflectors.
*
* Parameter nk is last nk elementary reflectors that are not used in computing
* the matrix Q. Parameter mk length of the first unused elementary reflectors
* First nk columns are zeroed and subdiagonal mk-nk is set to unit.
*
* Compatible with lapack.DORG2L subroutine.
*/
func unblkBuildQL(A, Tvec, W *cmat.FloatMatrix, mk, nk int, mayClear bool) {
var ATL, ATR, ABL, ABR cmat.FloatMatrix
var A00, a01, a10, a11, a21, A22 cmat.FloatMatrix
var tT, tB cmat.FloatMatrix
var t0, tau1, t2, w12, D cmat.FloatMatrix
// (mk, nk) = (rows, columns) of upper left partition
util.Partition2x2(
&ATL, &ATR,
&ABL, &ABR, A, mk, nk, util.PTOPLEFT)
util.Partition2x1(
&tT,
&tB, Tvec, nk, util.PTOP)
// zero the left side
if nk > 0 && mayClear {
blasd.Scale(&ABL, 0.0)
blasd.Scale(&ATL, 0.0)
D.Diag(&ATL, nk-mk)
blasd.Add(&D, 1.0)
}
for m(&ABR) > 0 && n(&ABR) > 0 {
util.Repartition2x2to3x3(&ATL,
&A00, &a01, nil,
&a10, &a11, nil,
nil, &a21, &A22, A, 1, util.PBOTTOMRIGHT)
util.Repartition2x1to3x1(&tT,
&t0,
&tau1,
&t2, Tvec, 1, util.PBOTTOM)
// ------------------------------------------------------
w12.SubMatrix(W, 0, 0, a10.Len(), 1)
applyHouseholder2x1(&tau1, &a01, &a10, &A00, &w12, gomas.LEFT)
blasd.Scale(&a01, -tau1.Get(0, 0))
a11.Set(0, 0, 1.0-tau1.Get(0, 0))
// zero bottom elements
blasd.Scale(&a21, 0.0)
// ------------------------------------------------------
util.Continue3x3to2x2(
&ATL, &ATR,
&ABL, &ABR, &A00, &a11, &A22, A, util.PBOTTOMRIGHT)
util.Continue3x1to2x1(
&tT,
&tB, &t0, &tau1, Tvec, util.PBOTTOM)
}
}
示例14: unblkBuildLQ
/*
* Unblocked code for generating M by N matrix Q with orthogonal columns which
* are defined as the first N columns of the product of K first elementary
* reflectors.
*
* Parameters nk = n(A)-K, mk = m(A)-K define the initial partitioning of
* matrix A.
*
* Q = H(k)H(k-1)...H(1) , 0 < k <= M, where H(i) = I - tau*v*v.T
*
* Computation is ordered as H(k)*H(k-1)...*H(1)*I ie. from bottom to top.
*
* If k < M rows k+1:M are cleared and diagonal entries [k+1:M,k+1:M] are
* set to unit. Then the matrix Q is generated by right multiplying elements below
* of i'th elementary reflector H(i).
*
* Compatible to lapack.xORG2L subroutine.
*/
func unblkBuildLQ(A, Tvec, W *cmat.FloatMatrix, mk, nk int, mayClear bool) {
var ATL, ATR, ABL, ABR cmat.FloatMatrix
var A00, a10, a11, a12, a21, A22 cmat.FloatMatrix
var tT, tB cmat.FloatMatrix
var t0, tau1, t2, w12, D cmat.FloatMatrix
util.Partition2x2(
&ATL, &ATR,
&ABL, &ABR, A, mk, nk, util.PBOTTOMRIGHT)
util.Partition2x1(
&tT,
&tB, Tvec, mk, util.PBOTTOM)
// zero the bottom part
if mk > 0 && mayClear {
blasd.Scale(&ABL, 0.0)
blasd.Scale(&ABR, 0.0)
D.Diag(&ABR)
blasd.Add(&D, 1.0)
}
for m(&ATL) > 0 && n(&ATL) > 0 {
util.Repartition2x2to3x3(&ATL,
&A00, nil, nil,
&a10, &a11, &a12,
nil, &a21, &A22, A, 1, util.PTOPLEFT)
util.Repartition2x1to3x1(&tT,
&t0,
&tau1,
&t2, Tvec, 1, util.PTOP)
// ------------------------------------------------------
w12.SubMatrix(W, 0, 0, a21.Len(), 1)
applyHouseholder2x1(&tau1, &a12, &a21, &A22, &w12, gomas.RIGHT)
blasd.Scale(&a12, -tau1.Get(0, 0))
a11.Set(0, 0, 1.0-tau1.Get(0, 0))
// zero
blasd.Scale(&a10, 0.0)
// ------------------------------------------------------
util.Continue3x3to2x2(
&ATL, &ATR,
&ABL, &ABR, &A00, &a11, &A22, A, util.PTOPLEFT)
util.Continue3x1to2x1(
&tT,
&tB, &t0, &tau1, Tvec, util.PTOP)
}
}
示例15: findBKPivotUpper
func findBKPivotUpper(A *cmat.FloatMatrix) (int, int) {
var r, q int
var rcol, qrow cmat.FloatMatrix
if m(A) == 1 {
return 0, 1
}
lastcol := m(A) - 1
amax := math.Abs(A.Get(lastcol, lastcol))
// column above [A.Rows()-1, A.Rows()-1]
rcol.SubMatrix(A, 0, lastcol, lastcol, 1)
r = blasd.IAmax(&rcol)
// max off-diagonal on first column at index r
rmax := math.Abs(A.Get(r, lastcol))
if amax >= bkALPHA*rmax {
// no pivoting, 1x1 diagonal
return -1, 1
}
// max off-diagonal on r'th row at index q
// a) rest of the r'th row above diagonal
qmax := 0.0
if r > 0 {
qrow.SubMatrix(A, 0, r, r, 1)
q = blasd.IAmax(&qrow)
qmax = math.Abs(A.Get(q, r /*+1*/))
}
// b) elements right of diagonal
qrow.SubMatrix(A, r, r+1, 1, lastcol-r)
q = blasd.IAmax(&qrow)
qmax2 := math.Abs(qrow.Get(0, q))
if qmax2 > qmax {
qmax = qmax2
}
if amax >= bkALPHA*rmax*(rmax/qmax) {
// no pivoting, 1x1 diagonal
return -1, 1
}
if math.Abs(A.Get(r, r)) >= bkALPHA*qmax {
// 1x1 pivoting and interchange with k, r
return r, 1
} else {
// 2x2 pivoting and interchange with k+1, r
return r, 2
}
return 0, 1
}