Swift · Dot Products

Dot Products

import NumKong 8.0.0-rc.1 · b1f866ab

Dot products follow a collection-first shape.

import NumKong

let a: [UInt8] = [1, 2, 3, 4]
let b: [UInt8] = [4, 3, 2, 1]

let dot = a.dot(b) // widened to UInt32, not UInt8
print(dot as Any)

For Float32, the scalar result widens to Float64. For Float16, it widens to Float32. For Int8, it widens to Int32. For UInt8, it widens to UInt32.

API

ProtocolNumKongDotA type that can compute SIMD-accelerated dot products with output type widening.2
Scalar.swift:13 ↗
protocol NumKongDot

Conforming types

DotOutputThe type the dot product is returned in, at least as wide as Self.
Scalar.swift:15 ↗
associatedtype DotOutput
dotComputes the dot product of two vectors.
Scalar.swift:23 ↗
static func dot<A, B>(
    _ a: A,
    _ b: B
) -> DotOutput? where Self == A.Element, A : Sequence, B : Sequence, A.Element == B.Element

Parameters

aThe first vector.
bThe second vector, as long as a.

Returns

The dot product, or nil if the sequences are empty, differ in length, or the kernel reports an error.