-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.go
57 lines (49 loc) · 930 Bytes
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"fmt"
"bufio"
"os"
"strconv"
)
type MatDim struct {
rows int
cols int
}
func writeMat32(path string, arr []float32, dim MatDim) {
f, err := os.Create(path)
if err != nil {
fmt.Println("Failed to write matrix!")
panic(err)
}
defer f.Close()
w := bufio.NewWriter(f)
for row := 0; row < dim.rows; row++ {
line := ""
for col := 0; col < dim.cols; col++ {
line += strconv.FormatFloat(float64(arr[row * dim.rows + col]), 'E', -1, 32)
if col < dim.cols - 1 {
line += ","
}
}
line += "\n"
w.WriteString(line)
}
w.Flush()
return
}
func writeVec32(path string, arr [600]float32) {
f, err := os.Create(path)
if err != nil {
fmt.Println("Failed to write vector")
panic(err)
}
defer f.Close()
w := bufio.NewWriter(f)
txt := ""
for _, val := range arr {
txt += strconv.FormatFloat(float64(val), 'E', -1, 32) + "\n"
}
w.WriteString(txt)
w.Flush()
return
}