Reshape

class Reshape<T : DType, V>(ctx: ExecutionContext, val newShape: Shape) : TensorTransform<T, V> (source)

Reshapes a tensor to a new shape without changing the data.

The total number of elements must remain the same.

Usage

val reshape = Reshape<FP32, Float>(ctx, Shape(1, 3, 224, 224))
val batched = reshape.apply(imageTensor) // Add batch dimension

Parameters

T

The tensor data type

V

The value type

ctx

The execution context for tensor operations

newShape

The target shape

Constructors

Link copied to clipboard
constructor(ctx: ExecutionContext, newShape: Shape)

Properties

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 getOutputShape(inputShape: Shape): Shape

By default, tensor transforms preserve the input shape. Override this method if the transform changes the shape.

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