simd

package
v2.0.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package simd is any-store's single home for vector distance math.

It wraps the vendored, hand-written SIMD kernels in internal/simd/asm (dot-product and L2 for amd64 AVX2/AVX512 and arm64 NEON/SVE, float32 and int8) behind a small, portable API. Runtime CPU dispatch happens once in an arch-specific init (dispatch_*.go); when no SIMD kernel is available — wasm, 386, or an x86 without AVX2 (e.g. pre-Haswell Ivy Bridge) — the pure-Go fallbacks in fallback.go are used, which beat a naive scalar loop.

This package replaces the former github.com/viterin/vek/vek32 dependency, which was amd64+AVX2-only and fell back to slow portable Go on arm64.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Accelerated

func Accelerated() bool

Accelerated reports whether a hand-written SIMD kernel (not the pure-Go fallback) was selected for this CPU. Mirrors the old vek32.Info().Acceleration.

func AcceleratedFloatByte

func AcceleratedFloatByte() bool

AcceleratedFloatByte reports whether a SIMD float×byte kernel is active (false on the pure-Go fallback path, and on arches where it is not wired).

func CosineSimilarity

func CosineSimilarity(a, b []float32) float32

CosineSimilarity returns the cosine similarity of a and b. For a zero-length operand it returns 0 (so a cosine distance of 1-sim is maximal, matching the previous behavior for degenerate vectors).

func Distance

func Distance(a, b []float32) float32

Distance returns the Euclidean distance. Kept as sqrt(L2Squared) so the returned/stored distance values stay identical to the previous vek32.Distance.

func Dot

func Dot(a, b []float32) float32

Dot returns the inner product of two equal-length vectors.

func DotFloatByte

func DotFloatByte(q []float32, u []byte) float32

DotFloatByte returns the inner product of a float32 vector q and a byte vector u, where each byte is interpreted as an UNSIGNED value 0..255 (matching the vendored weaviate kernels). Callers using offset-binary int8 storage recover the signed dot via scale·(DotFloatByte(q,u) − 128·Σq); see internal/vindex.

func L2Squared

func L2Squared(a, b []float32) float32

L2Squared returns the squared Euclidean distance (no sqrt).

func MulNumber_Into

func MulNumber_Into(dst, v []float32, s float32) []float32

MulNumber_Into writes dst = v * s and returns dst (which must have len(v)). Drop-in for vek32.MulNumber_Into. Cold path (per-vector normalize), so a plain loop the compiler can auto-vectorize is enough.

func Norm

func Norm(v []float32) float32

Norm returns the L2 norm (length) of v.

func NormalizeInto

func NormalizeInto(dst, v []float32) []float32

NormalizeInto writes the unit-normalized v into dst (reusing dst's capacity) and returns it. A zero vector is copied through unchanged (norm 0 -> leave as zeros). This is the single shared copy of the per-package normalizeInto that previously lived in both internal/vindex and internal/vivf.

func Sub_Into

func Sub_Into(dst, a, b []float32)

Sub_Into writes dst = a - b. Drop-in for vek32.Sub_Into.

Types

This section is empty.

Directories

Path Synopsis
asm only has amd64 specific implementations at the moment
asm only has amd64 specific implementations at the moment

Jump to

Keyboard shortcuts

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