protocol NumKongDot 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
DotOutputThe type the dot product is returned in, at least as wide as Self.
associatedtype DotOutput dotComputes the dot product of two vectors.
static func dot<A, B>(
_ a: A,
_ b: B
) -> DotOutput? where Self == A.Element, A : Sequence, B : Sequence, A.Element == B.Element Parameters
a | The first vector. | |
|---|---|---|
b | The 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.