<p dir="auto">For audio / scalar time series / 1d signals of shapes T or BxT, one currently has to unsqueeze at least to 3d tensor and then squeeze back.</p>
<p dir="auto">With PyTorch now used for everything and not just imaages, easy support for 1d signals would be great!</p>
<p dir="auto">Currently, <code class="notranslate">torch.nn.functional.interpolate</code> has dedicated implementation for 1d, 2d and 3d data, as well as for nearest, bilinear and bicubic interpolation. The set of different kernels that are dispatched can be seen <a href="https://github.com/pytorch/pytorch/blob/master/torch/nn/functional.py#L2050-L2079">here</a>.</p>
<p dir="auto">Those implementation are all very similar one to the other, and there is a lot of code duplication in there.<br>
Compare for example <a href="https://github.com/pytorch/pytorch/blob/master/aten/src/THNN/generic/SpatialUpSamplingNearest.c#L31-L95">nearest</a> with <a href="https://github.com/pytorch/pytorch/blob/master/aten/src/THNN/generic/SpatialUpSamplingBilinear.c#L33-L106">bilinear</a>.</p>
<p dir="auto">I believe it is possible to refactor the underlying implementation so that we can have a single C++ / CUDA codepath, with minimal  code duplication.</p>
<p dir="auto">This could be achieved in two independent steps (that could be done at the same time):</p>
<ul dir="auto">
<li>factor out the different kernel computations, so that we have a generic <code class="notranslate">filter</code> that is used to compute the interpolation, plus the size of the filter as a struct. For an example, <a href="https://github.com/python-pillow/Pillow/blob/master/src/libImaging/Resample.c#L9-L83">see how Pillow implements it</a>, and then the interpolation coefficients can be generically computed <a href="https://github.com/python-pillow/Pillow/blob/master/src/libImaging/Resample.c#L236">as in here</a>.</li>
<li>make the interpolate kernel separable (it is already separable in most cases). This means that we can have the user specify the dimensions he wants to interpolate as a list, and in the C++/CUDA code we have a loop over the dimensions. Something like <code class="notranslate">F.interpolate(image, dim=[-2, -1])</code> for spatial interpolation, or <code class="notranslate">F.interpolate(volume, dim=[-3, -2, -1])</code> for volumetric data. We can have reasonable defaults if <code class="notranslate">dim</code> is not specified (that depends on the shape of the input), to keep backwards compatibility.</li>
</ul>
<p dir="auto">The first point will allow us to fuse the <code class="notranslate">nearest</code> / <code class="notranslate">bilinear</code> / <code class="notranslate">bicubic</code> interpolation modes in a single file, while the second point will fuse <code class="notranslate">temporal</code> / <code class="notranslate">spatial</code> and <code class="notranslate">volumetric</code> into the same function.</p>