ScaleAndShift
class ScaleAndShift<T : DType, V>(ctx: ExecutionContext, val scale: Float = 1.0f, val offset: Float = 0.0f) : TensorTransform<T, V> (source)
Scales and shifts tensor values: output = input * scale + offset
This is a more general form of rescaling that supports both multiplication and addition operations.
Usage
// Convert from [0, 255] to [-1, 1]
val transform = ScaleAndShift<FP32, Float>(ctx, scale = 2f/255f, offset = -1f)
val result = transform.apply(imageData)Content copied to clipboard
Parameters
T
The tensor data type
V
The value type
ctx
The execution context for tensor operations
scale
The value to multiply by
offset
The value to add after scaling