本文整理匯總了Golang中github.com/henrylee2cn/algorithm/matrix.FloatMatrix.Copy方法的典型用法代碼示例。如果您正苦於以下問題:Golang FloatMatrix.Copy方法的具體用法?Golang FloatMatrix.Copy怎麽用?Golang FloatMatrix.Copy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/henrylee2cn/algorithm/matrix.FloatMatrix
的用法示例。
在下文中一共展示了FloatMatrix.Copy方法的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: 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)
}
}
示例3: 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
}
示例4: 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
}
示例5: 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
}
示例6: runRefTest
func runRefTest(A *matrix.FloatMatrix, ntest, LB int) time.Duration {
var flags matops.Flags
var mintime time.Duration
N := A.Rows()
ipiv := make([]int, N, N)
flags = matops.LOWER
if testUpper {
flags = matops.UPPER
}
W := matrix.FloatZeros(A.Rows(), LB+2)
fnc := func() {
_, ERRref = matops.DecomposeLDL(A, W, ipiv, flags, 0)
}
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: 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
}
示例8: 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
}
示例9: 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
}
示例10: columnDiffs
func columnDiffs(A, B *matrix.FloatMatrix) *matrix.FloatMatrix {
var c matrix.FloatMatrix
nrm := matrix.FloatZeros(A.Cols(), 1)
A0 := A.Copy()
A0.Minus(B)
for k := 0; k < A.Cols(); k++ {
A0.SubMatrix(&c, 0, k, A.Rows(), 1)
nrm.SetAt(k, 0, matops.Norm2(&c))
}
return nrm
}
示例11: rowDiffs
func rowDiffs(A, B *matrix.FloatMatrix) *matrix.FloatMatrix {
var r matrix.FloatMatrix
nrm := matrix.FloatZeros(A.Rows(), 1)
A0 := A.Copy()
A0.Minus(B)
for k := 0; k < A.Rows(); k++ {
A0.SubMatrix(&r, k, 0, 1, A.Cols())
nrm.SetAt(k, 0, matops.Norm2(&r))
}
return nrm
}
示例12: runCheck
// single invocation for matops and lapack functions
func runCheck(A *matrix.FloatMatrix, LB int) (bool, time.Duration, time.Duration) {
var flags matops.Flags
N := A.Rows()
ipiv := make([]int, N, N)
ipiv0 := make([]int32, N, N)
flags = matops.LOWER
lopt := linalg.OptLower
if testUpper {
flags = matops.UPPER
lopt = linalg.OptUpper
}
W := matrix.FloatZeros(A.Rows(), LB+2)
fnc := func() {
_, ERRmatops = matops.DecomposeBK(A, W, ipiv, flags, LB)
}
if verbose && N < 10 {
fmt.Fprintf(os.Stderr, "A start:\n%v\n", A)
}
A0 := A.Copy()
mperf.FlushCache()
time0 := mperf.Timeit(fnc)
if verbose && N < 10 {
fmt.Fprintf(os.Stderr, "ipiv:%v\n", ipiv)
fmt.Fprintf(os.Stderr, "A end:\n%v\n", A)
}
fn2 := func() {
ERRlapack = lapack.Sytrf(A0, ipiv0, lopt)
}
if verbose && N < 10 {
fmt.Fprintf(os.Stderr, "A0 start:\n%v\n", A0)
}
mperf.FlushCache()
time2 := mperf.Timeit(fn2)
if verbose && N < 10 {
fmt.Fprintf(os.Stderr, "ipiv0:%v\n", ipiv0)
fmt.Fprintf(os.Stderr, "A0 end:\n%v\n", A0)
}
// now A == A0 && ipiv == ipiv0
ok := A.AllClose(A0)
okip := checkIPIV(ipiv, ipiv0)
if !ok || !okip {
// save result to globals
Rlapack = A0
Rmatops = A
IPIVlapack = ipiv0
IPIVmatops = ipiv
}
return ok && okip, time0, time2
}
示例13: 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
}
示例14: runCheck
// single invocation for matops and lapack functions
func runCheck(A *matrix.FloatMatrix, LB int) (bool, time.Duration, time.Duration) {
M := A.Rows()
N := A.Cols()
nN := N
if M < N {
nN = M
}
ipiv := make([]int, nN, nN)
ipiv0 := make([]int32, nN, nN)
fnc := func() {
_, ERRmatops = matops.DecomposeLU(A, ipiv, LB)
}
if verbose && N < 10 {
fmt.Fprintf(os.Stderr, "A start:\n%v\n", A)
}
A0 := A.Copy()
mperf.FlushCache()
time0 := mperf.Timeit(fnc)
if verbose && N < 10 {
fmt.Fprintf(os.Stderr, "A end:\n%v\n", A)
fmt.Fprintf(os.Stderr, "ipiv:%v\n", ipiv)
}
fn2 := func() {
ERRlapack = lapack.Getrf(A0, ipiv0)
}
if verbose && N < 10 {
fmt.Fprintf(os.Stderr, "A0 start:\n%v\n", A0)
}
mperf.FlushCache()
time2 := mperf.Timeit(fn2)
if verbose && N < 10 {
fmt.Fprintf(os.Stderr, "A0 end:\n%v\n", A0)
fmt.Fprintf(os.Stderr, "ipiv0:%v\n", ipiv0)
}
// now A == A0 && ipiv == ipiv0
ok := A.AllClose(A0)
okip := checkIPIV(ipiv, ipiv0)
_ = okip
if !ok || !okip {
// save result to globals
Rlapack = A0
Rmatops = A
IPIVlapack = ipiv0
IPIVmatops = ipiv
}
return ok && okip, time0, time2
}
示例15: runCheck
// single invocation for matops and lapack functions
func runCheck(A *matrix.FloatMatrix, LB int) (bool, time.Duration, time.Duration) {
var W *matrix.FloatMatrix = nil
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)
}
if verbose && N < 10 {
fmt.Fprintf(os.Stderr, "A start:\n%v\n", A)
}
A0 := A.Copy()
tau0 := tau.Copy()
mperf.FlushCache()
time0 := mperf.Timeit(fnc)
if verbose && N < 10 {
fmt.Fprintf(os.Stderr, "A end:\n%v\n", A)
tau.SetSize(1, N, 1)
fmt.Fprintf(os.Stderr, "tau: %v\n", tau)
}
fn2 := func() {
ERRlapack = lapack.Geqrf(A0, tau0)
}
mperf.FlushCache()
time2 := mperf.Timeit(fn2)
if verbose && N < 10 {
fmt.Fprintf(os.Stderr, "A0 end:\n%v\n", A0)
tau0.SetSize(1, N, 1) // row vector
fmt.Fprintf(os.Stderr, "tau0: %v\n", tau0)
}
// now A == A0 && tau == tau0
ok := A.AllClose(A0)
oktau := tau.AllClose(tau0)
if !ok || !oktau {
// save result to globals
Rlapack = A0
Rmatops = A
TAUlapack = tau0
TAUmatops = tau
}
return ok && oktau, time0, time2
}