Go · Dense Distances

Dense Distances

import "github.com/ashvardanian/NumKong" 8.0.0-rc.1 · b1f866ab

The dense distance family includes squared Euclidean, Euclidean, and angular distance. Each metric supports float64, float32, int8, and uint8.

package main

import (
	"fmt"

	nk "github.com/ashvardanian/NumKong/golang"
)

func main() {
	a := []float64{1, 2, 3, 4}
	b := []float64{4, 3, 2, 1}

	fmt.Println(nk.SqEuclideanF64(a, b))
	fmt.Println(nk.EuclideanF64(a, b))
	fmt.Println(nk.AngularF64(a, b))
}

The int8 and uint8 families widen their outputs. AngularF32 and EuclideanF32 return float64. AngularI8, AngularU8, EuclideanI8, EuclideanU8 return float32. SqEuclideanI8 and SqEuclideanU8 return uint32.

API

Functions

AngularF32AngularF32 computes the angular distance between two float32 vectors.
numkong.go:30 ↗
func AngularF32(a, b []float32) float64

Both slices must have the same length.

AngularF64AngularF64 computes the angular distance between two float64 vectors.
numkong.go:16 ↗
func AngularF64(a, b []float64) float64

Both slices must have the same length.

AngularI8AngularI8 computes the angular distance between two int8 vectors.
numkong.go:44 ↗
func AngularI8(a, b []int8) float32

Both slices must have the same length.

AngularU8AngularU8 computes the angular distance between two uint8 vectors.
numkong.go:58 ↗
func AngularU8(a, b []uint8) float32

Both slices must have the same length.

EuclideanF32EuclideanF32 computes the Euclidean distance between two float32 vectors.
numkong.go:90 ↗
func EuclideanF32(a, b []float32) float64

Both slices must have the same length.

EuclideanF64EuclideanF64 computes the Euclidean distance between two float64 vectors.
numkong.go:76 ↗
func EuclideanF64(a, b []float64) float64

Both slices must have the same length.

EuclideanI8EuclideanI8 computes the Euclidean distance between two int8 vectors.
numkong.go:104 ↗
func EuclideanI8(a, b []int8) float32

Both slices must have the same length.

EuclideanU8EuclideanU8 computes the Euclidean distance between two uint8 vectors.
numkong.go:118 ↗
func EuclideanU8(a, b []uint8) float32

Both slices must have the same length.

SqEuclideanF32SqEuclideanF32 computes the squared Euclidean distance between two float32 vectors.
numkong.go:150 ↗
func SqEuclideanF32(a, b []float32) float64

Both slices must have the same length.

SqEuclideanF64SqEuclideanF64 computes the squared Euclidean distance between two float64 vectors.
numkong.go:136 ↗
func SqEuclideanF64(a, b []float64) float64

Both slices must have the same length.

SqEuclideanI8SqEuclideanI8 computes the squared Euclidean distance between two int8 vectors.
numkong.go:164 ↗
func SqEuclideanI8(a, b []int8) uint32

Both slices must have the same length.

SqEuclideanU8SqEuclideanU8 computes the squared Euclidean distance between two uint8 vectors.
numkong.go:178 ↗
func SqEuclideanU8(a, b []uint8) uint32

Both slices must have the same length.