numr 0.16.0

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
// Phase angle of real numbers shader
// entry point: angle_real_f32
// angle(x) = 0 if x >= 0, π if x < 0

struct Params {
    numel: u32,
}

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

// PI constant (WGSL has no standard math library, so this is defined literally)
// Value matches std::f32::consts::PI exactly (f32 precision: ~7 significant digits)
const PI: f32 = 3.14159265f;

@compute @workgroup_size(256)
fn angle_real_f32(
    @builtin(global_invocation_id) gid: vec3<u32>,
    @builtin(num_workgroups) nwg: vec3<u32>,
) {
    let idx = gid.x + gid.y * nwg.x * 256u;
    if (idx < params.numel) {
        let val = input[idx];
        output[idx] = select(0.0, PI, val < 0.0);  // 0 if x >= 0, π if x < 0
    }
}