Go · Dot Products

Dot Products

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

Dot products cover float64, float32, int8, and uint8.

package main

import (
	"fmt"

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

func main() {
	a64 := []float64{1, 2, 3}
	b64 := []float64{4, 5, 6}
	fmt.Println(nk.DotF64(a64, b64))

	a32 := []float32{1, 2, 3}
	b32 := []float32{4, 5, 6}
	fmt.Println(nk.DotF32(a32, b32)) // widened to float64

	a8 := []int8{1, 2, 3, 4}
	b8 := []int8{4, 3, 2, 1}
	fmt.Println(nk.DotI8(a8, b8)) // widened to int32

	au := []uint8{1, 2, 3, 4}
	bu := []uint8{4, 3, 2, 1}
	fmt.Println(nk.DotU8(au, bu)) // widened to uint32
}

DotF32 returns float64. DotI8 returns int32. DotU8 returns uint32. Those widened outputs are deliberate.

API

Functions

DotF32DotF32 computes the dot product of two float32 vectors.
numkong.go:28 ↗
func DotF32(a, b []float32) float64

Both slices must have the same length.

DotF64DotF64 computes the dot product of two float64 vectors.
numkong.go:14 ↗
func DotF64(a, b []float64) float64

Both slices must have the same length.

DotI8DotI8 computes the dot product of two int8 vectors.
numkong.go:42 ↗
func DotI8(a, b []int8) int32

Both slices must have the same length.

DotU8DotU8 computes the dot product of two uint8 vectors.
numkong.go:56 ↗
func DotU8(a, b []uint8) uint32

Both slices must have the same length.