Skip to content

compute.kernels.scaleRemap

Summary

compute.kernels.scaleRemap applies a scale transform independently to each scalar and preserves the ndarray shape. Use the output as colormap coordinates when scalar extraction and range selection happen separately.

Syntax

scaleRemap(x: GPUndarray, opts: ScaleRemapOptions): GPUndarray
const coordinates = kernels.scaleRemap(x, { transform });

Parameters

Name Type Required Description
x GPUndarray Yes Live f32 array of any supported shape and layout.
opts ScaleRemapOptions Yes Resolved transform and kernel output and dispatch settings.

Returns

GPUndarray - f32 coordinates in [0, 1] with the input shape. Non-finite input values map to zero. An empty input yields an empty result.

Type Details

type ScaleRemapOptions = KernelOutputOptions & { transform: ScaleTransform };

Use scale.createTransform to create the transform. The kernel operates on scalar elements, so use scaleExtract first when you need component selection or magnitude. For percentile clamping, provide the resolved range in the transform.

Example

const wgpu = await WasmGPU.create(document.querySelector("canvas"));
const { ndarray: nd, kernels } = wgpu.compute;
const input = nd.fromArray("f32", [3], [1, 10, 100], { residency: "gpu" });
const transform = wgpu.scale.createTransform({ mode: "log", domainMin: 1, domainMax: 100 });
const result = kernels.scaleRemap(input, { transform });
const cpu = await nd.toCPU(result);
console.log(cpu.data()); // approximately [0, 0.5, 1]
for (const array of [cpu, result, input]) array.destroy();

See Also