Skip to main content

dot

Function dot 

Source
pub fn dot<A, B, R, OpA, OpB>(
    a: &StridedView<'_, A, OpA>,
    b: &StridedView<'_, B, OpB>,
) -> Result<R>
where A: Copy + Mul<B, Output = R> + MaybeSendSync + 'static, B: Copy + MaybeSendSync + 'static, R: Copy + Zero + Add<Output = R> + MaybeSendSync + MaybeSimdOps + 'static, OpA: ElementOp<A>, OpB: ElementOp<B>,
Expand description

Dot product: sum(OpA::apply(a[i]) * OpB::apply(b[i])).

Operands may have different element types. Result type R must be A * B. SIMD fast path fires only when A == B == R (same type) and both Identity ops.

A widening dot — f32 operands with an f64 accumulator — is not expressible here because R is pinned to A * B; use zip_reduce with a |x, y| x as f64 * y as f64 map instead.

§Evaluation order

This entry takes no parallel branch, so its result does not depend on the ambient pool width at all: it is computed on the calling thread whatever the execution policy is. The homogeneous contiguous fast path folds with the SIMD lane scheme of the element type; every other layout folds a single accumulator along the traversal order of the fused plan, which is left to right over each unit-stride run. Neither is guaranteed to be bitwise equal across machines or target features.

§Allocation

At rank ≤ INLINE_RANK the view metadata and the traversal plan are stored inline, so a call performs no heap allocation.