DriftTexture · function

evalNetworkHalf

Evaluate the network as a device with enable f16 would, writing shape.outputs values into out.

Explained in DriftTexture.

function evalNetworkHalf(shape: NetworkShape, weights: Uint16Array, input: Float32Array, out: Float32Array, scratch: Float64Array, contract?: boolean): void
import { evalNetworkHalf } from '@driftengine/texture';

Parameters

ParameterTypeDescription
shapeNetworkShape
weightsUint16Array
inputFloat32Array
outFloat32Array
scratchFloat64Array
contract?boolean

In depth

Every multiply and every add is rounded, because that is what a sixteen-bit adder does, and the arithmetic is in doubles so the rounding is the only approximation. The order is the device's: the weighted inputs summed in index order, then the bias, then the rectifier — render/shaders/network.wgsl.ts in @driftengine/core is written to match it.

weights are half-precision bits, as halfWeights produces and an NNET chunk stores. Inputs are rounded to half precision on the way in. scratch holds at least twice the widest layer.