distance

package
v0.1.1-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 9, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package distance provides SIMD-accelerated vector distance computation.

Supported metrics: DotProduct (inner product), CosineSimilarity, L2Distance (Euclidean), and L2Squared (squared Euclidean). Normalize converts vectors to unit length in-place.

On amd64, AVX2 and AVX-512 are selected automatically at startup based on CPU capability. On arm64, NEON is always used. On other architectures, a scalar fallback is used.

All functions require len(a) == len(b). Passing mismatched lengths results in undefined behavior; callers must ensure equal lengths.

Requires Go 1.26+ with GOEXPERIMENT=simd for simd/archsimd support.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CosineSimilarity

func CosineSimilarity(a, b []float32) float32

func DotProduct

func DotProduct(a, b []float32) float32

func L2Distance

func L2Distance(a, b []float32) float32

func L2Squared

func L2Squared(a, b []float32) float32

func Normalize

func Normalize(v []float32)

Types

type MetricType

type MetricType int
const (
	L2 MetricType = iota
	Cosine
	InnerProduct
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL