代码拉取完成,页面将自动刷新
package functions
import (
"github.com/chewxy/math32"
"golang.org/x/exp/constraints"
"math"
)
func Dot_Go[T constraints.Float](x, y []T) T {
res := T(0)
for i := 0; i < len(x); i++ {
res += x[i] * y[i]
}
return res
}
func Norm_Go_F64(x []float64) float64 {
res := float64(0)
for i := 0; i < len(x); i++ {
res += x[i] * x[i]
}
return math.Sqrt(res)
}
func Norm_Go_F32(x []float32) float32 {
res := float32(0)
for i := 0; i < len(x); i++ {
res += x[i] * x[i]
}
return math32.Sqrt(res)
}
func Distance_Go_F64(x, y []float64) float64 {
res := float64(0)
for i := 0; i < len(x); i++ {
res += (x[i] - y[i]) * (x[i] - y[i])
}
return math.Sqrt(res)
}
func Distance_Go_F32(x, y []float32) float32 {
res := float32(0)
for i := 0; i < len(x); i++ {
res += (x[i] - y[i]) * (x[i] - y[i])
}
return math32.Sqrt(res)
}
func ManhattanNorm_Go_F64(x []float64) float64 {
res := float64(0)
for i := 0; i < len(x); i++ {
res += math.Abs(x[i])
}
return res
}
func ManhattanNorm_Go_F32(x []float32) float32 {
res := float32(0)
for i := 0; i < len(x); i++ {
res += math32.Abs(x[i])
}
return res
}
func ManhattanDistance_Go_F64(x, y []float64) float64 {
res := float64(0)
for i := 0; i < len(x); i++ {
res += math.Abs(x[i] - y[i])
}
return res
}
func ManhattanDistance_Go_F32(x, y []float32) float32 {
res := float32(0)
for i := 0; i < len(x); i++ {
res += math32.Abs(x[i] - y[i])
}
return res
}
func CosineSimilarity_Go_F64(x, y []float64) float64 {
dp := float64(0)
xdp := float64(0)
ydp := float64(0)
for i := 0; i < len(x); i++ {
dp += x[i] * y[i]
xdp += x[i] * x[i]
ydp += y[i] * y[i]
}
return dp / math.Sqrt(xdp*ydp)
}
func CosineSimilarity_Go_F32(x, y []float32) float32 {
dp := float32(0)
xdp := float32(0)
ydp := float32(0)
for i := 0; i < len(x); i++ {
dp += x[i] * y[i]
xdp += x[i] * x[i]
ydp += y[i] * y[i]
}
return dp / math32.Sqrt(xdp*ydp)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。