本文整理匯總了Golang中github.com/henrylee2cn/algorithm/matrix.FloatMatrix.Cols方法的典型用法代碼示例。如果您正苦於以下問題:Golang FloatMatrix.Cols方法的具體用法?Golang FloatMatrix.Cols怎麽用?Golang FloatMatrix.Cols使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/henrylee2cn/algorithm/matrix.FloatMatrix
的用法示例。
在下文中一共展示了FloatMatrix.Cols方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: runTest
func runTest(A *matrix.FloatMatrix, ntest, LB int) time.Duration {
var mintime time.Duration
M := A.Rows()
N := A.Cols()
nN := N
if M < N {
nN = M
}
ipiv := make([]int, nN, nN)
fnc := func() {
_, ERRmatops = matops.DecomposeLU(A, ipiv, 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
}
示例2: syrk2Test
func syrk2Test(t *testing.T, C, A, B *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.Syr2kFloat(A, B, 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()
Br := B.FloatArray()
Cr := C.FloatArray()
DSymmRank2Blk(Cr, Ar, Br, 1.0, 1.0, flags, C.LeadingIndex(), A.LeadingIndex(),
B.LeadingIndex(), P, S, E, vlen, nb)
result := C0.AllClose(C)
t.Logf(" C0 == C: %v\n", result)
if A.Rows() < 8 {
t.Logf(" DMRank2 C:\n%v\n", C)
}
return result
}
示例3: 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
}
示例4: 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 ---
}
示例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: 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
}
示例7: runTest
func runTest(A *matrix.FloatMatrix, ntest, LB int) time.Duration {
var W *matrix.FloatMatrix = nil
var mintime time.Duration
N := A.Cols()
tau := matrix.FloatZeros(N, 1)
if LB > 0 {
W = matrix.FloatZeros(A.Rows(), LB)
}
fnc := func() {
_, ERRmatops = matops.DecomposeQR(A, tau, W, LB)
}
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
}
if verbose {
fmt.Printf("%.4f ms\n", time0.Seconds()*1000.0)
}
}
return mintime
}
示例8: 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
}
示例9: 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
}
示例10: 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
}
示例11: Mult0
func Mult0(C, A, B *matrix.FloatMatrix, alpha, beta float64, flags Flags) error {
if A.Cols() != B.Rows() {
return errors.New("A.cols != B.rows: size mismatch")
}
psize := int64(C.NumElements()) * int64(A.Cols())
Ar := A.FloatArray()
ldA := A.LeadingIndex()
Br := B.FloatArray()
ldB := B.LeadingIndex()
Cr := C.FloatArray()
ldC := C.LeadingIndex()
if nWorker <= 1 || psize <= limitOne {
calgo.DMult0(Cr, Ar, Br, alpha, beta, calgo.Flags(flags), ldC, ldA, ldB, B.Rows(),
0, C.Cols(), 0, C.Rows(),
vpLen, nB, mB)
return nil
}
// here we have more than one worker available
worker := func(cstart, cend, rstart, rend int, ready chan int) {
calgo.DMult0(Cr, Ar, Br, alpha, beta, calgo.Flags(flags), ldC, ldA, ldB, B.Rows(),
cstart, cend, rstart, rend, vpLen, nB, mB)
ready <- 1
}
colworks, rowworks := divideWork(C.Rows(), C.Cols(), nWorker)
scheduleWork(colworks, rowworks, C.Cols(), C.Rows(), worker)
return nil
}
示例12: 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
}
示例13: runRefTest
func runRefTest(A *matrix.FloatMatrix, ntest, LB int) time.Duration {
var mintime time.Duration
M := A.Rows()
N := A.Cols()
nN := N
if M < N {
nN = M
}
ipiv := make([]int32, nN, nN)
fnc := func() {
ERRlapack = lapack.Getrf(A, ipiv)
}
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
}
示例14: Mult
// Generic matrix-matrix multpily. (blas.GEMM). Calculates
// C = beta*C + alpha*A*B (default)
// C = beta*C + alpha*A.T*B flags&TRANSA
// C = beta*C + alpha*A*B.T flags&TRANSB
// C = beta*C + alpha*A.T*B.T flags&(TRANSA|TRANSB)
//
// C is M*N, A is M*P or P*M if flags&TRANSA. B is P*N or N*P if flags&TRANSB.
//
func Mult(C, A, B *matrix.FloatMatrix, alpha, beta float64, flags Flags) error {
var ok, empty bool
// error checking must take in account flag values!
ar, ac := A.Size()
br, bc := B.Size()
cr, cc := C.Size()
switch flags & (TRANSA | TRANSB) {
case TRANSA | TRANSB:
empty = ac == 0 || br == 0
ok = cr == ac && cc == br && ar == bc
case TRANSA:
empty = ac == 0 || bc == 0
ok = cr == ac && cc == bc && ar == br
case TRANSB:
empty = ar == 0 || br == 0
ok = cr == ar && cc == br && ac == bc
default:
empty = ar == 0 || bc == 0
ok = cr == ar && cc == bc && ac == br
}
if empty {
return nil
}
if !ok {
return errors.New("Mult: size mismatch")
}
psize := int64(C.NumElements()) * int64(A.Cols())
Ar := A.FloatArray()
ldA := A.LeadingIndex()
Br := B.FloatArray()
ldB := B.LeadingIndex()
Cr := C.FloatArray()
ldC := C.LeadingIndex()
// matrix A, B common dimension
P := A.Cols()
if flags&TRANSA != 0 {
P = A.Rows()
}
if nWorker <= 1 || psize <= limitOne {
calgo.DMult(Cr, Ar, Br, alpha, beta, calgo.Flags(flags), ldC, ldA, ldB, P,
0, C.Cols(), 0, C.Rows(),
vpLen, nB, mB)
return nil
}
// here we have more than one worker available
worker := func(cstart, cend, rstart, rend int, ready chan int) {
calgo.DMult(Cr, Ar, Br, alpha, beta, calgo.Flags(flags), ldC, ldA, ldB, P,
cstart, cend, rstart, rend, vpLen, nB, mB)
ready <- 1
}
colworks, rowworks := divideWork(C.Rows(), C.Cols(), nWorker)
scheduleWork(colworks, rowworks, C.Cols(), C.Rows(), worker)
return nil
}
示例15: unblkQRBlockReflector
/*
* 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 unblkQRBlockReflector(T, A, tau *matrix.FloatMatrix) {
var ATL, ATR, ABL, ABR matrix.FloatMatrix
var A00, a10, a11, A20, a21, A22 matrix.FloatMatrix
var TTL, TTR, TBL, TBR matrix.FloatMatrix
var T00, t01, T02, t11, t12, T22 matrix.FloatMatrix
var tT, tB matrix.FloatMatrix
var t0, tau1, t2 matrix.FloatMatrix
partition2x2(
&ATL, &ATR,
&ABL, &ABR, A, 0, 0, pTOPLEFT)
partition2x2(
&TTL, &TTR,
&TBL, &TBR, T, 0, 0, pTOPLEFT)
partition2x1(
&tT,
&tB, tau, 0, pTOP)
for ABR.Rows() > 0 && ABR.Cols() > 0 {
repartition2x2to3x3(&ATL,
&A00, nil, nil,
&a10, &a11, nil,
&A20, &a21, &A22, A, 1, pBOTTOMRIGHT)
repartition2x2to3x3(&TTL,
&T00, &t01, &T02,
nil, &t11, &t12,
nil, nil, &T22, T, 1, pBOTTOMRIGHT)
repartition2x1to3x1(&tT,
&t0,
&tau1,
&t2, tau, 1, pBOTTOM)
// --------------------------------------------------
// t11 := tau
tauval := tau1.GetAt(0, 0)
if tauval != 0.0 {
t11.SetAt(0, 0, tauval)
// t01 := a10.T + &A20.T*a21
a10.CopyTo(&t01)
MVMult(&t01, &A20, &a21, -tauval, -tauval, TRANSA)
// t01 := T00*t01
MVMultTrm(&t01, &T00, UPPER)
//t01.Scale(-tauval)
}
// --------------------------------------------------
continue3x3to2x2(
&ATL, &ATR,
&ABL, &ABR, &A00, &a11, &A22, A, pBOTTOMRIGHT)
continue3x3to2x2(
&TTL, &TTR,
&TBL, &TBR, &T00, &t11, &T22, T, pBOTTOMRIGHT)
continue3x1to2x1(
&tT,
&tB, &t0, &tau1, tau, pBOTTOM)
}
}