Skip to content
fn

pack

void pack(const int * src, int * dst, const int & shape, const int & stride, int elem)

Packs a strided view into dst, dense and row-major. src points at the view's first element.

This walked every element recursively with a memcpy each — 4.6 ms to make a 1024 x 1024 float transpose contiguous, where copying the same bytes takes 0.08 — and every CPU op that reads a view comes through here. Now the axes are merged first, and the innermost run moves as a memcpy when it is contiguous, a fill when it is broadcast, and a typed strided loop otherwise; a view that merges to a 2-D transpose is copied in tiles, so both sides stay in cache.