numr 0.15.2

Numerical computing and tensor library for Rust, in the role of NumPy: n-dimensional arrays, linear algebra, FFT, statistics and autograd on CPU, CUDA and WebGPU
Documentation
// masked_fill operations for f32

const WORKGROUP_SIZE: u32 = 256u;

struct MaskedFillParams {
    numel: u32,
    fill_value: f32,
}

@group(0) @binding(0) var<storage, read_write> input: array<f32>;
@group(0) @binding(1) var<storage, read_write> mask: array<u32>;
@group(0) @binding(2) var<storage, read_write> output: array<f32>;
@group(0) @binding(3) var<uniform> params: MaskedFillParams;

@compute @workgroup_size(256)
fn masked_fill_f32(
    @builtin(global_invocation_id) gid: vec3<u32>,
    @builtin(num_workgroups) nwg: vec3<u32>,
) {
    let idx = gid.x + gid.y * nwg.x * WORKGROUP_SIZE;
    if (idx >= params.numel) {
        return;
    }

    if (mask[idx] != 0u) {
        output[idx] = f32(params.fill_value);
    } else {
        output[idx] = input[idx];
    }
}