forked from gorgonia/gorgonia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathequalities.go
128 lines (113 loc) · 1.85 KB
/
equalities.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package gorgonia
func scalarEq(a, b Scalar) bool {
switch at := a.(type) {
case *F64:
if bt, ok := b.(*F64); ok {
return *at == *bt
}
return false
case *F32:
if bt, ok := b.(*F32); ok {
return *at == *bt
}
return false
case *I:
if bt, ok := b.(*I); ok {
return *at == *bt
}
return false
case *I32:
if bt, ok := b.(*I32); ok {
return *at == *bt
}
return false
case *I64:
if bt, ok := b.(*I64); ok {
return *at == *bt
}
return false
case *U8:
if bt, ok := b.(*U8); ok {
return *at == *bt
}
return false
case *B:
if bt, ok := b.(*B); ok {
return *at == *bt
}
return false
}
return false
}
/*
func axesEq(a, b axes) bool {
if len(a) != len(b) {
return false
}
for i, s := range a {
if b[i] != s {
return false
}
}
return true
}
// yes it's exactly the same as axesEq
func coordEq(a, b coordinates) bool {
if len(a) != len(b) {
return false
}
for i, s := range a {
if b[i] != s {
return false
}
}
return true
}
*/
func constEq(a, b constant) (ok bool) {
switch at := a.(type) {
case constantScalar:
var bt constantScalar
if bt, ok = b.(constantScalar); !ok {
return
}
return bt == at
case constantTensor:
var bt constantTensor
if bt, ok = b.(constantTensor); !ok {
return
}
return at.v.Eq(bt.v)
default:
panic("Not yet implemented")
}
}
// fastest comparisons to least fastest
func nodeEq(a, b *Node) bool {
if a == b {
return true
}
if a.isInput() {
if !b.isInput() {
return false
}
return a.name == b.name
}
if b.isInput() {
return false
}
// hashcode is good for comparing Op (TODO: benchmark this vs reflect.DeepEq)
if a.op.Hashcode() != b.op.Hashcode() {
return false
}
if len(a.children) != len(b.children) {
return false
}
if a.t != b.t {
return false
}
if !a.shape.Eq(b.shape) {
return false
}
return true
}