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)

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

Constructors

Link copied to clipboard
constructor(ctx: ExecutionContext, scale: Float = 1.0f, offset: Float = 0.0f)

Properties

Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
open override fun apply(input: Tensor<T, V>): Tensor<T, V>

Applies this transformation to the given input.

Link copied to clipboard
open override fun toString(): String