2 Star 2 Fork 9

王布衣/gox

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
aggregates_amd64.go 1.54 KB
一键复制 编辑 原始数据 按行查看 历史
package functions
import (
"gitee.com/quant1x/gox/num/partial"
"math"
"slices"
)
func Mean_AVX2_F64(x []float64) float64 {
return Sum_AVX2_F64(x) / float64(len(x))
}
func Mean_AVX2_F32(x []float32) float32 {
return Sum_AVX2_F32(x) / float32(len(x))
}
func Median_AVX2_F64(x []float64) float64 {
if len(x)%2 == 1 {
x = slices.Clone(x)
i := len(x) / 2
partial.TopK(x, i+1)
return x[i]
}
return Quantile_AVX2_F64(x, 0.5)
}
func Median_AVX2_F32(x []float32) float32 {
if len(x)%2 == 1 {
x = slices.Clone(x)
i := len(x) / 2
partial.TopK(x, i+1)
return x[i]
}
return Quantile_AVX2_F32(x, 0.5)
}
func Quantile_AVX2_F64(x []float64, q float64) float64 {
if len(x) == 1 {
return x[0]
}
if q == 0 {
return Min_AVX2_F64(x)
}
if q == 1 {
return Max_AVX2_F64(x)
}
x = slices.Clone(x)
f := float64(len(x)-1) * q
i := int(math.Floor(f))
if q < 0.5 {
partial.TopK(x, i+2)
a := Max_AVX2_F64(x[:i+1])
b := x[i+1]
return a + (b-a)*(f-float64(i))
} else {
partial.TopK(x, i+1)
a := x[i]
b := Min_AVX2_F64(x[i+1:])
return a + (b-a)*(f-float64(i))
}
}
func Quantile_AVX2_F32(x []float32, q float32) float32 {
if len(x) == 1 {
return x[0]
}
if q == 0 {
return Min_AVX2_F32(x)
}
if q == 1 {
return Max_AVX2_F32(x)
}
x = slices.Clone(x)
f := float32(len(x)-1) * q
i := int(math.Floor(float64(f)))
if q < 0.5 {
partial.TopK(x, i+2)
a := Max_AVX2_F32(x[:i+1])
b := x[i+1]
return a + (b-a)*(f-float32(i))
} else {
partial.TopK(x, i+1)
a := x[i]
b := Min_AVX2_F32(x[i+1:])
return a + (b-a)*(f-float32(i))
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/quant1x/gox.git
git@gitee.com:quant1x/gox.git
quant1x
gox
gox
v1.14.6

搜索帮助