INNER CODE UNIT · Go

DotProduct

takara-ai/go-attention · attention/attention.go:28

func DotProduct(v1, v2 Vector) (float64, error) {
	return bestDotProduct(v1, v2)
}

// BestDotProduct is an alias for DotProduct for API clarity
func BestDotProduct(v1, v2 Vector) (float64, error) {
	return DotProduct(v1, v2)
}

// bestDotProduct is the single, canonical implementation
func bestDotProduct(v1, v2 Vector) (float64, error) {
	if len(v1) != len(v2) {
		return 0, fmt.Errorf("vector dimensions mismatch: %d != %d", len(v1), len(v2))
	}
	// Loop unrolling for performance
	sum := 0.0
	n := len(v1)
	for i := 0; i < n-7; i += 8 {

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…