gitee.com/quant1x/num@v0.3.2/internal/functions/min.go (about)

     1  package functions
     2  
     3  import (
     4  	"gitee.com/quant1x/num/internal/constraints"
     5  )
     6  
     7  func Min_Go[T constraints.Float](x []T) T {
     8  	minValue := x[0]
     9  	for _, v := range x[1:] {
    10  		if v < minValue {
    11  			minValue = v
    12  		}
    13  	}
    14  	return minValue
    15  }
    16  
    17  func ArgMin_Go[T constraints.Float](x []T) int {
    18  	minValue := x[0]
    19  	idx := 0
    20  	for i, v := range x[1:] {
    21  		if v < minValue {
    22  			minValue = v
    23  			idx = 1 + i
    24  		}
    25  	}
    26  	return idx
    27  }
    28  
    29  func Minimum_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 MinimumNumber_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  }