-
Notifications
You must be signed in to change notification settings - Fork 4
/
relu.go
58 lines (47 loc) · 1.47 KB
/
relu.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
package opset13
import (
"github.com/advancedclimatesystems/gonnx/onnx"
"github.com/advancedclimatesystems/gonnx/ops"
"gorgonia.org/tensor"
)
// Relu represents the ONNX relu operator.
type Relu struct{}
// newRelu creates a new relu operator.
func newRelu() ops.Operator {
return &Relu{}
}
// Init initializes the relu operator.
func (r *Relu) Init(*onnx.NodeProto) error {
return nil
}
// Apply applies the relu operator.
func (r *Relu) Apply(inputs []tensor.Tensor) ([]tensor.Tensor, error) {
out, err := ops.ReLU(inputs[0])
if err != nil {
return nil, err
}
return []tensor.Tensor{out}, nil
}
// ValidateInputs validates the inputs that will be given to Apply for this operator.
func (r *Relu) ValidateInputs(inputs []tensor.Tensor) ([]tensor.Tensor, error) {
return ops.ValidateInputs(r, inputs)
}
// GetMinInputs returns the minimum number of input tensors this operator expects.
func (r *Relu) GetMinInputs() int {
return 1
}
// GetMaxInputs returns the maximum number of input tensors this operator expects.
func (r *Relu) GetMaxInputs() int {
return 1
}
// GetInputTypeConstraints returns a list. Every element represents a set of allowed tensor dtypes
// for the corresponding input tensor.
func (r *Relu) GetInputTypeConstraints() [][]tensor.Dtype {
return [][]tensor.Dtype{
{tensor.Float32, tensor.Float64},
}
}
// String implements the stringer interface, and can be used to format errors or messages.
func (r *Relu) String() string {
return "relu operator"
}