gitee.com/quant1x/num@v0.3.2/internal/functions/max.go (about) 1 package functions 2 3 import ( 4 "gitee.com/quant1x/num/internal/constraints" 5 ) 6 7 func Max_Go[T constraints.Float](x []T) T { 8 maxValue := x[0] 9 for _, v := range x[1:] { 10 if v > maxValue { 11 maxValue = v 12 } 13 } 14 return maxValue 15 } 16 17 func ArgMax_Go[T constraints.Float](x []T) int { 18 maxValue := x[0] 19 idx := 0 20 for i, v := range x[1:] { 21 if v > maxValue { 22 maxValue = v 23 idx = 1 + i 24 } 25 } 26 return idx 27 } 28 29 func Maximum_Go[T constraints.Float](x, y []T) { 30 for i := 0; i < len(x); i++ { 31 if y[i] > x[i] { 32 x[i] = y[i] 33 } 34 } 35 } 36 37 func MaximumNumber_Go[T constraints.Float](x []T, a T) { 38 for i := 0; i < len(x); i++ { 39 if a > x[i] { 40 x[i] = a 41 } 42 } 43 }