本文整理匯總了Golang中github.com/henrylee2cn/algorithm/matrix.FloatMatrix.LeadingIndex方法的典型用法代碼示例。如果您正苦於以下問題:Golang FloatMatrix.LeadingIndex方法的具體用法?Golang FloatMatrix.LeadingIndex怎麽用?Golang FloatMatrix.LeadingIndex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/henrylee2cn/algorithm/matrix.FloatMatrix
的用法示例。
在下文中一共展示了FloatMatrix.LeadingIndex方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: solveMVTest
func solveMVTest(t *testing.T, A, X0 *matrix.FloatMatrix, flags Flags, bN, bNB int) {
X1 := X0.Copy()
uplo := linalg.OptUpper
diag := linalg.OptNonUnit
if flags&LOWER != 0 {
uplo = linalg.OptLower
}
if flags&UNIT != 0 {
diag = linalg.OptUnit
}
blas.TrsvFloat(A, X0, uplo, diag)
Ar := A.FloatArray()
Xr := X1.FloatArray()
if bN == bNB {
DSolveUnblkMV(Xr, Ar, flags, 1, A.LeadingIndex(), bN)
} else {
DSolveBlkMV(Xr, Ar, flags, 1, A.LeadingIndex(), bN, bNB)
}
ok := X1.AllClose(X0)
t.Logf("X1 == X0: %v\n", ok)
if !ok && bN < 8 {
t.Logf("A=\n%v\n", A)
t.Logf("X0=\n%v\n", X0)
t.Logf("blas: X0\n%v\n", X0)
t.Logf("X1:\n%v\n", X1)
}
}
示例2: 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
}
示例3: Axpy
// Y := alpha * X + Y
func Axpy(Y, X *matrix.FloatMatrix, alpha float64) {
if X == nil || Y == nil {
return
}
if !isVector(X) {
return
}
if !isVector(Y) {
return
}
Xr := X.FloatArray()
incX := 1
if X.Cols() != 1 {
// Row vector
incX = X.LeadingIndex()
}
Yr := Y.FloatArray()
incY := 1
if Y.Cols() != 1 {
// Row vector
incY = Y.LeadingIndex()
}
calgo.DAxpy(Xr, Yr, alpha, incX, incY, X.NumElements())
return
}
示例4: syrkTest
func syrkTest(t *testing.T, C, A *matrix.FloatMatrix, flags Flags, vlen, nb int) bool {
//var B0 *matrix.FloatMatrix
P := A.Cols()
S := 0
E := C.Rows()
C0 := C.Copy()
trans := linalg.OptNoTrans
if flags&TRANSA != 0 {
trans = linalg.OptTrans
P = A.Rows()
}
uplo := linalg.OptUpper
if flags&LOWER != 0 {
uplo = linalg.OptLower
}
blas.SyrkFloat(A, C0, 1.0, 1.0, uplo, trans)
if A.Rows() < 8 {
//t.Logf("..A\n%v\n", A)
t.Logf(" BLAS C0:\n%v\n", C0)
}
Ar := A.FloatArray()
Cr := C.FloatArray()
DSymmRankBlk(Cr, Ar, 1.0, 1.0, flags, C.LeadingIndex(), A.LeadingIndex(),
P, S, E, vlen, nb)
result := C0.AllClose(C)
t.Logf(" C0 == C: %v\n", result)
if A.Rows() < 8 {
t.Logf(" DMRank C:\n%v\n", C)
}
return result
}
示例5: Swap
// Swap X and Y.
func Swap(X, Y *matrix.FloatMatrix) {
if X == nil || Y == nil {
return
}
if X.NumElements() == 0 || Y.NumElements() == 0 {
return
}
if !isVector(X) {
return
}
if !isVector(Y) {
return
}
Xr := X.FloatArray()
incX := 1
if X.Cols() != 1 {
// Row vector
incX = X.LeadingIndex()
}
Yr := Y.FloatArray()
incY := 1
if Y.Cols() != 1 {
// Row vector
incY = Y.LeadingIndex()
}
calgo.DSwap(Xr, Yr, incX, incY, X.NumElements())
}
示例6: SolveTrm
// Solve multiple right sides. If flags&UNIT then A diagonal is assumed to
// to unit and is not referenced. (blas.TRSM)
// alpha*B = A.-1*B if flags&LEFT
// alpha*B = A.-T*B if flags&(LEFT|TRANS)
// alpha*B = B*A.-1 if flags&RIGHT
// alpha*B = B*A.-T if flags&(RIGHT|TRANS)
//
// Matrix A is N*N triangular matrix defined with flags bits as follow
// LOWER non-unit lower triangular
// LOWER|UNIT unit lower triangular
// UPPER non-unit upper triangular
// UPPER|UNIT unit upper triangular
//
// Matrix B is N*P if flags&LEFT or P*N if flags&RIGHT.
//
func SolveTrm(B, A *matrix.FloatMatrix, alpha float64, flags Flags) error {
ok := true
empty := false
br, bc := B.Size()
ar, ac := A.Size()
switch flags & (LEFT | RIGHT) {
case LEFT:
empty = br == 0
ok = br == ac && ac == ar
case RIGHT:
empty = bc == 0
ok = bc == ar && ac == ar
}
if empty {
return nil
}
if !ok {
return onError("A, B size mismatch")
}
Ar := A.FloatArray()
ldA := A.LeadingIndex()
Br := B.FloatArray()
ldB := B.LeadingIndex()
E := bc
if flags&RIGHT != 0 {
E = br
}
// if more workers available can divide to tasks by B columns if flags&LEFT or by
// B rows if flags&RIGHT.
calgo.DSolveBlk(Br, Ar, alpha, calgo.Flags(flags), ldB, ldA, ac, 0, E, nB)
return nil
}
示例7: ScalePlus
// A = alpha*A + beta*B
// A = alpha*A + beta*B.T if flags&TRANSB
func ScalePlus(A, B *matrix.FloatMatrix, alpha, beta float64, flags Flags) error {
Ar := A.FloatArray()
ldA := A.LeadingIndex()
Br := B.FloatArray()
ldB := B.LeadingIndex()
S := 0
L := A.Cols()
R := 0
E := A.Rows()
calgo.DScalePlus(Ar, Br, alpha, beta, calgo.Flags(flags), ldA, ldB, S, L, R, E)
return nil
}
示例8: trmmTest
func trmmTest(t *testing.T, A *matrix.FloatMatrix, flags Flags, nb int) bool {
var B0 *matrix.FloatMatrix
N := A.Cols()
S := 0
E := A.Cols()
side := linalg.OptLeft
if flags&RIGHT != 0 {
B0 = matrix.FloatWithValue(2, A.Rows(), 2.0)
side = linalg.OptRight
E = B0.Rows()
} else {
B0 = matrix.FloatWithValue(A.Rows(), 2, 2.0)
E = B0.Cols()
}
B1 := B0.Copy()
trans := linalg.OptNoTrans
if flags&TRANSA != 0 {
trans = linalg.OptTransA
}
diag := linalg.OptNonUnit
if flags&UNIT != 0 {
diag = linalg.OptUnit
}
uplo := linalg.OptUpper
if flags&LOWER != 0 {
uplo = linalg.OptLower
}
blas.TrmmFloat(A, B0, 1.0, uplo, diag, trans, side)
if A.Rows() < 8 {
//t.Logf("..A\n%v\n", A)
t.Logf(" BLAS B0:\n%v\n", B0)
}
Ar := A.FloatArray()
Br := B1.FloatArray()
if nb != 0 {
DTrmmBlk(Br, Ar, 1.0, flags, B1.LeadingIndex(), A.LeadingIndex(),
N, S, E, nb)
} else {
DTrmmUnblk(Br, Ar, 1.0, flags, B1.LeadingIndex(), A.LeadingIndex(),
N, S, E, 0)
}
result := B0.AllClose(B1)
t.Logf(" B0 == B1: %v\n", result)
if A.Rows() < 8 {
t.Logf(" DTrmm B1:\n%v\n", B1)
}
return result
}
示例9: IAMax
// index of max |x|
func IAMax(X *matrix.FloatMatrix) int {
if X == nil {
return -1
}
if !isVector(X) {
return -1
}
Xr := X.FloatArray()
incX := 1
if X.Cols() != 1 {
// Row vector
incX = X.LeadingIndex()
}
return calgo.DIAMax(Xr, incX, X.NumElements())
}
示例10: Scale
// Scaling with scalar: X = alpha * X
func Scale(X *matrix.FloatMatrix, alpha float64) {
if X == nil || X.NumElements() == 0 {
return
}
if !isVector(X) {
return
}
Xr := X.FloatArray()
incX := 1
if X.Cols() != 1 {
// Row vector
incX = X.LeadingIndex()
}
calgo.DScal(Xr, alpha, incX, X.NumElements())
}
示例11: ASum
// sum(|x|)
func ASum(X *matrix.FloatMatrix) float64 {
if X == nil {
return math.NaN()
}
if !isVector(X) {
return math.NaN()
}
Xr := X.FloatArray()
incX := 1
if X.Cols() != 1 {
// Row vector
incX = X.LeadingIndex()
}
return calgo.DAsum(Xr, incX, X.NumElements())
}
示例12: MultDiag
/*
* Compute
* C = C*diag(D) flags & RIGHT == true
* C = diag(D)*C flags & LEFT == true
*
* Arguments
* C M-by-N matrix if flags&RIGHT == true or N-by-M matrix if flags&LEFT == true
*
* D N element column or row vector or N-by-N matrix
*
* flags Indicator bits, LEFT or RIGHT
*/
func MultDiag(C, D *matrix.FloatMatrix, flags Flags) {
var c, d0 matrix.FloatMatrix
if D.Cols() == 1 {
// diagonal is column vector
switch flags & (LEFT | RIGHT) {
case LEFT:
// scale rows; for each column element-wise multiply with D-vector
for k := 0; k < C.Cols(); k++ {
C.SubMatrix(&c, 0, k, C.Rows(), 1)
c.Mul(D)
}
case RIGHT:
// scale columns
for k := 0; k < C.Cols(); k++ {
C.SubMatrix(&c, 0, k, C.Rows(), 1)
// scale the column
c.Scale(D.GetAt(k, 0))
}
}
} else {
// diagonal is row vector
var d *matrix.FloatMatrix
if D.Rows() == 1 {
d = D
} else {
D.SubMatrix(&d0, 0, 0, 1, D.Cols(), D.LeadingIndex()+1)
d = &d0
}
switch flags & (LEFT | RIGHT) {
case LEFT:
for k := 0; k < C.Rows(); k++ {
C.SubMatrix(&c, k, 0, 1, C.Cols())
// scale the row
c.Scale(d.GetAt(0, k))
}
case RIGHT:
// scale columns
for k := 0; k < C.Cols(); k++ {
C.SubMatrix(&c, 0, k, C.Rows(), 1)
// scale the column
c.Scale(d.GetAt(0, k))
}
}
}
}
示例13: MVSymmUpdateUpper
// A = A + alpha*X*Y.T; A is N*N symmetric, X is row or column vector of length N.
func MVSymmUpdateUpper(A, X *matrix.FloatMatrix, alpha float64) error {
if X.Rows() != 1 && X.Cols() != 1 {
return errors.New("X not a vector.")
}
Ar := A.FloatArray()
ldA := A.LeadingIndex()
Xr := X.FloatArray()
incX := 1
if X.Rows() == 1 {
// row vector
incX = X.LeadingIndex()
}
// NOTE: This could diveded to parallel tasks per column.
calgo.DSymmRankMV(Ar, Xr, alpha, calgo.UPPER, ldA, incX, 0, A.Cols(), 0)
return nil
}
示例14: RankUpdateSym
// Rank update for symmetric lower or upper matrix (blas.SYRK)
// C = beta*C + alpha*A*A.T + alpha*A.T*A
func RankUpdateSym(C, A *matrix.FloatMatrix, alpha, beta float64, flags Flags) error {
if C.Rows() != C.Cols() {
return onError("C not a square matrix")
}
Ar := A.FloatArray()
ldA := A.LeadingIndex()
Cr := C.FloatArray()
ldC := C.LeadingIndex()
S := 0
E := C.Rows()
P := A.Cols()
if flags&TRANSA != 0 {
P = A.Rows()
}
// if more workers available C can be divided to blocks [S:E, S:E] along diagonal
// and updated in separate tasks.
calgo.DSymmRankBlk(Cr, Ar, alpha, beta, calgo.Flags(flags), ldC, ldA, P, S, E,
vpLen, nB)
return nil
}
示例15: MVMultTrm
// Tridiagonal multiplication; X = A*X
func MVMultTrm(X, A *matrix.FloatMatrix, flags Flags) error {
if A.Rows() == 0 || A.Cols() == 0 {
return nil
}
if X.Rows() != 1 && X.Cols() != 1 {
return errors.New("X not a vector.")
}
Ar := A.FloatArray()
ldA := A.LeadingIndex()
Xr := X.FloatArray()
incX := 1
if X.Rows() == 1 {
// row vector
incX = X.LeadingIndex()
}
calgo.DTrimvUnblkMV(Xr, Ar, calgo.Flags(flags), incX, ldA, A.Cols())
return nil
}