-
Notifications
You must be signed in to change notification settings - Fork 0
/
dim.go
41 lines (30 loc) · 970 Bytes
/
dim.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
package vs
import "fmt"
type Dim interface {
Len() int
}
// Dim stores a tensor size.
type Dim2 [2]int
// Len returns the total number of elements.
func (d Dim2) Len() int { return d[0] * d[1] }
func (d Dim2) String() string { return tupleStr(d[:]) }
type Dim3 [3]int
// Len returns the total number of elements.
func (d Dim3) Len() int { return d[0] * d[1] * d[2] }
func (d Dim3) String() string { return tupleStr(d[:]) }
type Dim4 [4]int
// Len returns the total number of elements.
func (d Dim4) Len() int { return d[0] * d[1] * d[2] * d[3] }
func (d Dim4) String() string { return tupleStr(d[:]) }
type Dim5 [5]int
// Len returns the total number of elements.
func (d Dim5) Len() int { return d[0] * d[1] * d[2] * d[3] * d[4] }
func (d Dim5) String() string { return tupleStr(d[:]) }
func tupleStr(d []int) string {
str := fmt.Sprint("(", d[0])
for _, v := range d[1:] {
str += fmt.Sprint(",", v)
}
str += ")"
return str
}