gorgonia.org/gorgonia@v0.9.17/slice.go (about) 1 package gorgonia 2 3 import "gorgonia.org/tensor" 4 5 // sli is slice. It's named sli to prevent confusion over naming 6 type sli struct { 7 start, end, step int 8 } 9 10 // S creates a tensor.Slice. 11 // end is optional. It should be passed in as the first param of the optionals. 12 // step is optional. It should be passed in as the second param of the optionals. 13 // 14 // Default end is start+1. Default step is 1, unless end == step+1, then it defaults to 0 15 func S(start int, opt ...int) tensor.Slice { 16 var end, step int 17 if len(opt) > 0 { 18 end = opt[0] 19 } else { 20 end = start + 1 21 } 22 23 step = 1 24 if len(opt) > 1 { 25 step = opt[1] 26 } else if end == start+1 { 27 step = 0 28 } 29 30 return &sli{ 31 start: start, 32 end: end, 33 step: step, 34 } 35 } 36 37 func (s *sli) Start() int { return s.start } 38 func (s *sli) End() int { return s.end } 39 func (s *sli) Step() int { return s.step }