1 Star 4 Fork 13

王布衣/pandas

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
argmin.go 1.28 KB
一键复制 编辑 原始数据 按行查看 历史
王布衣 提交于 2023-03-08 08:43 . !83#I6L2WO支持ARM框架
package stat
import (
"gitee.com/quant1x/vek"
"gitee.com/quant1x/vek/vek32"
)
// ArgMin Returns the indices of the minimum values along an axis.
//
// 返回轴上最小值的索引
func ArgMin[T Number](x []T) int {
ret := unaryOperations2[T, int](x, vek32.ArgMin, vek.ArgMin, __arg_min_go[T])
return ret
}
func ArgMin2[T BaseType](x []T) int {
var d int
switch vs := any(x).(type) {
case []float32:
d = ArgMin(vs)
case []float64:
d = ArgMin(vs)
case []int:
d = ArgMin(vs)
case []int8:
d = ArgMin(vs)
case []int16:
d = ArgMin(vs)
case []int32:
d = ArgMin(vs)
case []int64:
d = ArgMin(vs)
case []uint:
d = ArgMin(vs)
case []uint8:
d = ArgMin(vs)
case []uint16:
d = ArgMin(vs)
case []uint32:
d = ArgMin(vs)
case []uint64:
d = ArgMin(vs)
case []uintptr:
d = ArgMin(vs)
case []string:
d = __arg_min_go(vs)
case []bool:
d = __arg_min_go_bool(vs)
default:
// 其它类型原样返回
panic(Throw(any(x)))
}
return d
}
func __arg_min_go[T Ordered](x []T) int {
min := x[0]
idx := 0
for i, v := range x[1:] {
if v < min {
min = v
idx = 1 + i
}
}
return idx
}
func __arg_min_go_bool(x []bool) int {
min := BoolToInt(x[0])
idx := 0
for i, v := range x[1:] {
if BoolToInt(v) < min {
min = BoolToInt(v)
idx = 1 + i
}
}
return idx
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/quant1x/pandas.git
git@gitee.com:quant1x/pandas.git
quant1x
pandas
pandas
v0.9.14

搜索帮助