Spatial tensor utilities #
Padding, indexing, and window-extraction operations used by convolution and pooling specifications.
The signatures use Tensor directly; channels-first layout is visible in each shape rather than
hidden behind a second family of tensor aliases.
Choose the input-space pivot whose scaled value beta * pivot is maximal.
Selecting a maximum for positive beta and a minimum for negative beta avoids forming
beta * x before the log-sum-exp shift. Both fixed-rank and dimension-polymorphic smooth pooling
use this operation.
Instances For
Read position (x, y) from a rank-two tensor, returning 0 when out of bounds.
This helper is used by window-extraction and padding utilities for conv/pooling specs.
Instances For
getValueAtPosition agrees with the generic list-indexing helper get_at_or_zero.
In particular, reading a scalar via the specialized (x, y) accessor is the same as reading
with indices [x, y], where both return 0 out of bounds.
Extract a kH × kW patch from an image starting at (start_i, start_j).
Out-of-bounds pixels are treated as 0, matching the behavior of getValueAtPosition. This is
spec-level "im2col"-style logic (cf. PyTorch nn.Unfold, conceptually).
Instances For
Zero-pad a channels-first image by padding pixels on each spatial axis.
This is the spec analogue of torch.nn.functional.pad (with constant 0 padding). The output
shape is [inC, inH + 2*padding, inW + 2*padding].
Instances For
Characterization lemma for pad_multi_channel under list-indexing (get_at_or_zero).
Reading the padded tensor at [c, p, q] yields 0 in the top/left padding region, and otherwise
reads the original tensor at [c, p - padding, q - padding] (with out-of-bounds falling back to
0 on both sides).
Index-shift lemma for pad_multi_channel.
If (i, j) is in-bounds for the original image, then reading the padded image at
(i + padding, j + padding) returns the same value.
Extract a kH × kW window from each channel of a channels-first image.
The input is typically a padded image, and the result has shape [inC, kH, kW].
Instances For
Increase the channel dimension by zero-padding extra channels.
This is used in some ResNet-style skip connections when inChannels < outChannels. Existing
channels are copied; newly introduced channels are identically zero.
Instances For
Write a value at pixel (x, y) if it is in-bounds; otherwise return the original image.
This uses update_tensor_spec under the hood and is intended for small spec-level utilities.
Instances For
Add value to pixel (x, y) if it is in-bounds; otherwise return the original image.
This is a small helper for accumulation-style specs (e.g. naive convolution).