Skip to content

Instantly share code, notes, and snippets.

@5kg

5kg/-

Created April 27, 2015 12:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 5kg/d027df1455eb1c4c7ebb to your computer and use it in GitHub Desktop.
Save 5kg/d027df1455eb1c4c7ebb to your computer and use it in GitHub Desktop.
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)]
@5kg
Copy link
Author

5kg commented Apr 27, 2015

Output

m: 1000, n: 2000, k: 10
Took 754.997378ms
Tot: 9972

m: 1000, n: 2000, k: 10
Took 884.45471ms
Tot: 9972

@5kg
Copy link
Author

5kg commented Apr 27, 2015

In `julia'

julia> tic(); rand(1000,10)*rand(10,2000); toc()
elapsed time: 0.012591754 seconds

@BaiGang
Copy link

BaiGang commented Apr 30, 2015

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