UNPKG

@thi.ng/vectors

Version:

Optimized 2d/3d/4d and arbitrary length vector operations, support for memory mapping/layouts

18 lines (17 loc) 452 B
import { compile } from "./compile/emit.js"; import { DOT, SARGS_V } from "./compile/templates.js"; const dotS = (a, b, n, ia = 0, ib = 0, sa = 1, sb = 1) => { let sum = 0; for (; n-- > 0; ia += sa, ib += sb) sum += a[ia] * b[ib]; return sum; }; const $ = (dim) => compile(dim, DOT, `o,a,${SARGS_V}`, "o,a", "", "+", "return ", ";", true); const dotS2 = $(2); const dotS3 = $(3); const dotS4 = $(4); export { dotS, dotS2, dotS3, dotS4 };