permute_copy_f32
void permute_copy_f32(const float * in, float * out, const int & in_shape, const int & perm)Copies a single-precision tensor into a permuted, densely-packed output buffer using the supplied axis permutation.
The implementation iterates the output in flat row-major order and, for
each output flat index, back-computes its N-D coordinate and reads from
the matching input position via the inverse permutation expressed through
the input's C-order strides. No intermediate allocation beyond two stride
vectors of size ndim is performed. This is an out-of-place layout
transform — there is no in-place fast path.
Shape
out_shape[d] == in_shape[perm[d]] for every d.
See Also
permute_copy_f64, permute_copy_i32, permute_copy_i64 : Same operation for other element types.
Parameters
inconst float*in_shape.outfloat*numel(in_shape) * sizeof(float) bytes. May not alias in.in_shapeconst std::vector<int64_t>&permconst std::vector<int>&in_shape.size(). perm[d] names the source axis whose extent becomes output axis d. Must be a valid permutation of [0, ndim).Notes
Cost is O(numel * ndim) due to per-element coordinate back-projection.
For frequently used permutations (e.g. matrix transpose) consider a
dimension-specialised kernel; this routine is the generic fallback used by
CpuBackend and the GPU tensordot pre-layout path.
Examples
perm = {2, 0, 1} over in_shape = {H, W, C} yields a CHW output.
perm = {0, 2, 3, 1} over in_shape = {N, C, H, W} performs an NHWC
re-layout.