-
-
Save 5kg/d027df1455eb1c4c7ebb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/example/bwmf/kldiv_loss.go b/example/bwmf/kldiv_loss.go | |
index 764a46d..3dbd771 100644 | |
--- a/example/bwmf/kldiv_loss.go | |
+++ b/example/bwmf/kldiv_loss.go | |
@@ -3,6 +3,8 @@ package bwmf | |
import ( | |
"math" | |
"sort" | |
+ "time" | |
+ "fmt" | |
pb "github.com/taskgraph/taskgraph/example/bwmf/proto" | |
"github.com/taskgraph/taskgraph/op" | |
@@ -57,6 +59,28 @@ func (l *KLDivLoss) Evaluate(param op.Parameter, gradient op.Parameter) float32 | |
H := param | |
op.Fill(gradient, 0.0) | |
value := float32(0.0) | |
+ start := time.Now() | |
+ | |
+ fmt.Printf("m: %d, n: %d, k: %d\n", l.m, l.n, l.k) | |
+ for i := 0; i < l.m; i++ { | |
+ for j := 0; j < l.n; j++ { | |
+ wRow := l.GetWRow(i) | |
+ wh := float32(0.0) | |
+ for k, wk := range *wRow { | |
+ wh += wk * H.Get(j*l.k+int(k)) | |
+ } | |
+ } | |
+ } | |
+ | |
+ elapsed := time.Since(start) | |
+ fmt.Printf("Took %s\n", elapsed) | |
+ | |
+ tot := 0 | |
+ for i := 0; i < l.m; i++ { | |
+ tot += len(*l.GetWRow(i)) | |
+ } | |
+ fmt.Printf("Tot: %d\n", tot) | |
+ | |
for i := 0; i < l.m; i++ { | |
for j := 0; j < l.n; j++ { | |
v, ve := l.V.GetRow()[j].At[int32(i)] |
In `julia'
julia> tic(); rand(1000,10)*rand(10,2000); toc()
elapsed time: 0.012591754 seconds
We can make it parallel by using a fixed num of goroutines, which each takes charge of a proportion of the matrix.
CC @xiaoyunwu
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output