Skip to content

WasmGPU.compute.ndarray.wgslScalarType

Summary

WasmGPU.compute.ndarray.wgslScalarType reports the WGSL scalar type mapping for the ndarray dtype. Supported mappings include "i32", "u32", "f32", and "f64"; unsupported byte/half-width dtypes return null. Use this when generating shader code dynamically based on ndarray dtype. This is a dtype-level property and does not depend on shape or strides.

Syntax

WasmGPU.compute.ndarray.wgslScalarType: DTypeInfo["wgslScalarType"]
const scalarType = ndarray.wgslScalarType;

Parameters

This API does not take parameters.

Returns

"i32" | "u32" | "f32" | "f64" | null - WGSL scalar type for this ndarray dtype.

Example

const canvas = document.querySelector("canvas");
const wgpu = await WasmGPU.create(canvas);

const a = wgpu.compute.CPUndarray.empty("f32", { shape: [16] });
console.log(a.wgslScalarType);

See Also