-
Notifications
You must be signed in to change notification settings - Fork 2
/
route_layer.go
38 lines (31 loc) · 913 Bytes
/
route_layer.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
package yologo
import (
"fmt"
"github.com/pkg/errors"
"gorgonia.org/gorgonia"
)
type routeLayer struct {
firstLayerIdx int
secondLayerIdx int
}
func (l *routeLayer) String() string {
if l.secondLayerIdx != -1 {
return fmt.Sprintf("Route layer: Start->%[1]d End->%[2]d", l.firstLayerIdx, l.secondLayerIdx)
}
return fmt.Sprintf("Route layer: Start->%[1]d", l.firstLayerIdx)
}
func (l *routeLayer) Type() string {
return "route"
}
func (l *routeLayer) ToNode(g *gorgonia.ExprGraph, inputs ...*gorgonia.Node) (*gorgonia.Node, error) {
concatNodes := []*gorgonia.Node{}
concatNodes = append(concatNodes, inputs[l.firstLayerIdx])
if l.secondLayerIdx > 0 {
concatNodes = append(concatNodes, inputs[l.secondLayerIdx])
}
routeNode, err := gorgonia.Concat(1, concatNodes...)
if err != nil {
return &gorgonia.Node{}, errors.Wrap(err, "Can't prepare route operation")
}
return routeNode, nil
}