-
Notifications
You must be signed in to change notification settings - Fork 21
/
utils.go
56 lines (47 loc) · 977 Bytes
/
utils.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
package agogo
import (
"bytes"
"fmt"
"github.com/pkg/errors"
"gorgonia.org/tensor"
)
type slicer struct {
v tensor.View
err error
}
func (s *slicer) Slice(a *tensor.Dense, slices ...tensor.Slice) *tensor.Dense {
if s.err != nil {
return nil
}
if s.v, s.err = a.Slice(slices...); s.err != nil {
s.err = errors.Wrapf(s.err, "Slicer failed") // get a stack trace
return nil
}
return s.v.(*tensor.Dense)
}
type rs struct {
start, end, step int
}
func (s rs) Start() int { return s.start }
func (s rs) End() int { return s.end }
func (s rs) Step() int { return s.step }
// s creates a ranged slice. It takes an optional step param.
func sli(start, end int, opts ...int) rs {
step := 1
if len(opts) > 0 {
step = opts[0]
}
return rs{
start: start,
end: end,
step: step,
}
}
type manyErr []error
func (err manyErr) Error() string {
var buf bytes.Buffer
for _, e := range err {
fmt.Fprintln(&buf, e.Error())
}
return buf.String()
}