Created
April 16, 2015 09:00
-
-
Save 5kg/12648d9cccaef1dbc1bd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| package main | |
| import ( | |
| "fmt" | |
| "github.com/golang/protobuf/proto" | |
| pb "github.com/taskgraph/taskgraph/example/bwmf/proto" | |
| "io/ioutil" | |
| "os" | |
| "strconv" | |
| ) | |
| const nRow = 2000 | |
| const nColumn = 1000 | |
| const nTask = 4 | |
| func main() { | |
| in, _ := os.Open(os.Args[1]) | |
| mat := make([][]float32, nRow) | |
| for i := 0; i < nRow; i++ { | |
| mat[i] = make([]float32, nColumn) | |
| for j := 0; j < nColumn; j++ { | |
| var z float32 | |
| fmt.Fscanf(in, "%f", &z) | |
| mat[i][j] = z | |
| } | |
| } | |
| for iter := 0; iter < nTask; iter++ { | |
| m := nColumn / nTask | |
| v := &pb.SparseMatrixShard{Row: make([]*pb.SparseMatrixShard_SparseRow, m)} | |
| for c := 0; c < m; c++ { | |
| v.Row[c] = &pb.SparseMatrixShard_SparseRow{At: make(map[int32]float32)} | |
| for r := 0; r < nRow; r++ { | |
| z := mat[r][iter*m+c] | |
| if z == 0 { | |
| continue | |
| } | |
| v.Row[c].At[int32(r)] = z | |
| } | |
| } | |
| buf, err := proto.Marshal(v) | |
| if err != nil { | |
| fmt.Println("marshaling error: ", err) | |
| } | |
| ioutil.WriteFile("20ng_column_shard.t.dat."+strconv.Itoa(iter), buf, 0644) | |
| } | |
| } |
This file contains hidden or 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
| package main | |
| import ( | |
| "fmt" | |
| "os" | |
| // "testing" | |
| "github.com/golang/protobuf/proto" | |
| pb "github.com/taskgraph/taskgraph/example/bwmf/proto" | |
| "io/ioutil" | |
| "strconv" | |
| ) | |
| const nRow = 2000 | |
| const nColumn = 1000 | |
| const nTask = 4 | |
| func main() { | |
| in, _ := os.Open(os.Args[1]) | |
| for iter := 0; iter < nTask; iter++ { | |
| n := nRow/nTask | |
| v := &pb.SparseMatrixShard{Row: make([]*pb.SparseMatrixShard_SparseRow, n)} | |
| for i := 0; i < n; i++ { | |
| v.Row[i] = &pb.SparseMatrixShard_SparseRow{At: make(map[int32]float32)} | |
| for j := 0; j < nColumn; j++ { | |
| var z float32 | |
| fmt.Fscanf(in, "%f", &z) | |
| if z == 0 { | |
| continue | |
| } | |
| v.Row[i].At[int32(j)] = z | |
| } | |
| } | |
| buf, err := proto.Marshal(v) | |
| if err != nil { | |
| fmt.Println("marshaling error: ", err) | |
| } | |
| ioutil.WriteFile("20ng_row_shard.dat."+strconv.Itoa(iter), buf, 0644) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment