-
Notifications
You must be signed in to change notification settings - Fork 4
/
sinh.go
75 lines (60 loc) · 1.79 KB
/
sinh.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
package opset13
import (
"math"
"github.com/advancedclimatesystems/gonnx/onnx"
"github.com/advancedclimatesystems/gonnx/ops"
"gorgonia.org/tensor"
)
// Sinh represents the ONNX sinh operator.
type Sinh struct{}
// newSin creates a new sinh operator.
func newSinh() ops.Operator {
return &Sinh{}
}
// Init initializes the sinh operator.
func (s *Sinh) Init(*onnx.NodeProto) error {
return nil
}
// Apply applies the sinh operator.
func (s *Sinh) Apply(inputs []tensor.Tensor) ([]tensor.Tensor, error) {
var (
out tensor.Tensor
err error
)
switch inputs[0].Dtype() {
case tensor.Float32:
out, err = inputs[0].Apply(sinh[float32])
case tensor.Float64:
out, err = inputs[0].Apply(sinh[float64])
default:
return nil, ops.ErrInvalidInputType(0, inputs[0].Dtype().String(), s)
}
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 (s *Sinh) ValidateInputs(inputs []tensor.Tensor) ([]tensor.Tensor, error) {
return ops.ValidateInputs(s, inputs)
}
// GetMinInputs returns the minimum number of input tensors this operator expects.
func (s *Sinh) GetMinInputs() int {
return 1
}
// GetMaxInputs returns the maximum number of input tensors this operator expects.
func (s *Sinh) GetMaxInputs() int {
return 1
}
// GetInputTypeConstraints returns a list. Every element represents a set of allowed tensor dtypes
// for the corresponding input tensor.
func (s *Sinh) 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 (s *Sinh) String() string {
return "sinh operator"
}
func sinh[T ops.FloatType](x T) T {
return T(math.Sinh(float64(x)))
}