本文整理匯總了Golang中github.com/henrylee2cn/algorithm/matrix.FloatMatrix.Mul方法的典型用法代碼示例。如果您正苦於以下問題:Golang FloatMatrix.Mul方法的具體用法?Golang FloatMatrix.Mul怎麽用?Golang FloatMatrix.Mul使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/henrylee2cn/algorithm/matrix.FloatMatrix
的用法示例。
在下文中一共展示了FloatMatrix.Mul方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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))
}
}
}
}