forked from gorgonia/gorgonia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
op_infidel.go
68 lines (56 loc) · 3.17 KB
/
op_infidel.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
package gorgonia
import (
"hash"
"hash/fnv"
"github.com/chewxy/gorgonia/tensor"
"github.com/chewxy/hm"
)
/*
This file contains code for Ops that aren't really functions in the sense that they aren't pure.
Since they're not adherents to the Church of Lambda, they are INFIDELS! A fatwa will be issued on them shortly
*/
type stmtOp interface {
Op
isStmt() bool
}
// letOp is not really a function. It's more of a binding statement.
// However, it's implemented as a Op so that it can be counted for register allocation and liveness
type letOp struct{}
func (op letOp) Arity() int { return 0 }
func (op letOp) Type() hm.Type { return nil }
func (op letOp) ReturnsPtr() bool { return true }
func (op letOp) OverwritesInput() int { return 0 }
func (op letOp) CallsExtern() bool { return false }
func (op letOp) InferShape(...DimSizer) (tensor.Shape, error) { return nil, nil }
func (op letOp) DiffWRT(int) []bool { return nil }
func (op letOp) SymDiff(inputs Nodes, outputNode, gradNode *Node) (Nodes, error) { return nil, nil }
func (op letOp) Do(vals ...Value) (Value, error) { return nil, nil }
func (op letOp) String() string { return "=" }
func (op letOp) WriteHash(h hash.Hash) { h.Write([]byte("let")) }
func (op letOp) Hashcode() uint32 {
h := fnv.New32a()
op.WriteHash(h)
return h.Sum32()
}
func (op letOp) isStmt() bool { return true }
// readOp reads a value off the input. This op ensures that a value used, and hence codegen'd out
type readOp struct {
into *Value // no, it's not a mistake. It's a pointer to a Value (which is an interface{} type)
}
func (op readOp) Arity() int { return 0 }
func (op readOp) Type() hm.Type { return nil }
func (op readOp) ReturnsPtr() bool { return true }
func (op readOp) OverwritesInput() int { return 0 }
func (op readOp) CallsExtern() bool { return false }
func (op readOp) InferShape(...DimSizer) (tensor.Shape, error) { return nil, nil }
func (op readOp) DiffWRT(int) []bool { return nil }
func (op readOp) SymDiff(inputs Nodes, outputNode, gradNode *Node) (Nodes, error) { return nil, nil }
func (op readOp) Do(vals ...Value) (Value, error) { return nil, nil }
func (op readOp) String() string { return "print" }
func (op readOp) WriteHash(h hash.Hash) { h.Write([]byte("print")) }
func (op readOp) Hashcode() uint32 {
h := fnv.New32a()
op.WriteHash(h)
return h.Sum32()
}
func (op readOp) isStmt() bool { return true }