ConvShapeUtils

Single source of truth for convolution output-shape arithmetic.

Both eager execution (VoidTensorOps) and graph emission (Conv{1,2,3}dOperation.inferOutputs) must produce identical shapes; keeping the formula here prevents the two paths from diverging.

Functions

Link copied to clipboard
fun conv1dOutputShape(inputShape: IntArray, weightShape: IntArray, stride: Int, padding: Int, dilation: Int): IntArray

Conv1d output shape: input (batch, in_channels, length), weight (out_channels, in_channels_per_group, kernel_length), result (batch, out_channels, out_length).

Link copied to clipboard
fun conv2dOutputShape(inputShape: IntArray, weightShape: IntArray, stride: Pair<Int, Int>, padding: Pair<Int, Int>, dilation: Pair<Int, Int>): IntArray

Conv2d output shape: input (batch, in_channels, height, width), weight (out_channels, in_channels_per_group, kernel_h, kernel_w), result (batch, out_channels, out_h, out_w).

Link copied to clipboard
fun conv3dOutputShape(inputShape: IntArray, weightShape: IntArray, stride: Triple<Int, Int, Int>, padding: Triple<Int, Int, Int>, dilation: Triple<Int, Int, Int>): IntArray

Conv3d output shape: input (batch, in_channels, depth, height, width), weight (out_channels, in_channels_per_group, kernel_d, kernel_h, kernel_w), result (batch, out_channels, out_d, out_h, out_w).

Link copied to clipboard
fun pool2dOutputShape(inputShape: IntArray, kernelSize: Pair<Int, Int>, stride: Pair<Int, Int>, padding: Pair<Int, Int>): IntArray

2D pool (max/avg) output shape: input (batch, channels, height, width), result (batch, channels, out_h, out_w). Channels are preserved.

Link copied to clipboard
fun upsample2dOutputShape(inputShape: IntArray, scale: Pair<Int, Int>): IntArray

2D upsample output shape: input (batch, channels, height, width), result (batch, channels, height * scale_h, width * scale_w).