bartorch.interpolate

Contents

bartorch.interpolate#

bartorch.interpolate()#

Sample input at the voxel positions coord along axes.

out[..., q, ...] = sum_j input[..., j, ...] w(coord[q, i] - j_i) over the axes, where w is the kernel of order. Positions are array indices: coord = 2.0 is the sample input[2]. The grid is zero outside [0, n - 1], so a position within one kernel radius of the edge is weighted against zeros. BART’s interpolate.

Parameters:
  • input (torch.Tensor) – Array to sample.

  • coord (torch.Tensor) – Real positions (..., len(axes)): component i is the position along axes[i]. The leading shape aligns right against input.shape: the output size along each of axes, and one (shared positions) or the input’s size elsewhere. Along an axis before the last three, the output size must equal the input’s.

  • axes (int or tuple of int) – Axes interpolated over.

  • order ({0, 1, 3}, default=1) – Nearest neighbour (rounding half up), linear, or Keys cubic with a = -1/2.

Returns:

input.shape with each of axes replaced by coord’s size there.

Return type:

torch.Tensor

Raises:

ValueError – If coord does not match input as described.

Examples

>>> line = interpolate(image, torch.tensor([[1.5, 2.0]]), axes=(-2, -1))  # (1, 1)