forked from sugarme/gotch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
func.go
42 lines (33 loc) · 907 Bytes
/
func.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
package nn
// Layers defined by closure
import (
"github.com/nullbull/gotch/ts"
)
type Func struct {
f func(*ts.Tensor) *ts.Tensor
}
func NewFunc(fn func(*ts.Tensor) *ts.Tensor) (retVal Func) {
return Func{f: fn}
}
// Implement Module interface for Func:
// ====================================
func (fn Func) Forward(xs *ts.Tensor) (retVal *ts.Tensor) {
return fn.f(xs)
}
// ForwardT implements ModuleT for Func object as well.
//
// NOTE: train param will not be used.
func (fn Func) ForwardT(xs *ts.Tensor, train bool) (retVal *ts.Tensor) {
return fn.f(xs)
}
type FuncT struct {
f func(*ts.Tensor, bool) *ts.Tensor
}
func NewFuncT(fn func(*ts.Tensor, bool) *ts.Tensor) (retVal FuncT) {
return FuncT{f: fn}
}
// Implement Module interface for Func:
// ====================================
func (fn FuncT) ForwardT(xs *ts.Tensor, train bool) (retVal *ts.Tensor) {
return fn.f(xs, train)
}