Reference
API reference
An index of the public API used in current examples. See the source declarations for exact overloads and options.
Device and Tensor lifecycle
const device = await nn.device({ device: "auto" });
const x = device.tensor([1, 2, 3, 4], { shape: [2, 2] });
const y = x.relu().softmax();
const values = await y.data();
await y.disposeGraph();
await device.dispose();device(options?)Open a Device using auto, cpu, webgpu, or webgl2 selection.Device.tensor(values, { shape })Create an input tensor with a checked shape.Tensor.data()Materialize the requested graph result and return host values.Tensor.disposeGraph(preserve?)Release graph tensors while retaining selected values.Device.dispose()Wait for pending work and release runtime resources.
Tensor operations
Linear algebra
matmul(other, options?)
Rank-2 matrix multiply with transpose options.
Elementwise
add, sub, mul, div, maximum, minimum, pow, and supported activations.
Reduction and normalization
sum, mean, max, min, argMax, softmax, and logSoftmax.
Loss and gradients
softmaxCrossEntropyWithLogits, backward(), and selected Tensor graph gradient rules.
Modules and optimizers
ModuleRegister child layers, expose parameters, switch train/eval mode.Sequential,Linear,Flatten,ReLU,DropoutCore building blocks shown by current examples.optim.SGD,optim.AdamUpdate parameter gradients on CPU or through GPU kernels, depending on Device tier.CrossEntropyLossLoss module for logits and integer class labels in the MNIST path.
TypeShade's pure-function shadeGrad is separate from TypeNN Tensor graph autograd.