The dot product
# grade this stage (from your course directory)
npx theinference test --stage dot-product --watchThe dot product is the atom of everything that follows. a · b = Σ aᵢbᵢ — multiply elementwise, sum it up. Geometrically it measures alignment: big when two vectors point the same way, zero when perpendicular, negative when opposed.
a · b = a₀b₀ + a₁b₁ + … + a₍ₙ₋₁₎b₍ₙ₋₁₎
What to build
Implement dot
Implement dot(a, b) in src/vecmath.ts. Both are Float32Array of equal length; return their dot product as a number. One loop, one accumulator.
export function dot(a: Float32Array, b: Float32Array): number {
// Σ aᵢ·bᵢ
}
adapter — the harness calls your runDot (which calls dot) on a seeded vector pair and compares to the reference with allclose, atol=1e-5, rtol=1e-4. Your adapter wraps the scalar as [value]; that wiring is already done in tests/adapters.ts.
Float32Array elements are 32-bit, but a JS number is float64. Summing into a plain let s = 0 (float64) is exactly what the reference does — read each a[i]/b[i] as needed, but never truncate the running sum back to float32.