title: Bicubic interpolation in pytorch
body: <p>I'm trying to do bicubic interpolation on a <code>torch.Tensor</code>.</p>
  
  <p>I know about <code>torch.nn.functional.interpolate</code>, but that method doesn't support bicubic interpolation yet.</p>
  
  <p>I know that <code>PIL</code> images support bicubic interpolation, so I created this snippet (part of torch.nn.Module).</p>
  
  <pre><code>def build_transform(self, shape):
      h, w = shape[2] * self.scale_factor, shape[3] * self.scale_factor
      return Compose([
          ToPILImage(),
          Resize((h, w), interpolation=PIL.Image.BICUBIC),
          ToTensor()
        ])
  
  def forward(self, x: Tensor):
      if self.transform is None:
          self.transform = self.build_transform(x.shape)
  
      shape = x.shape[0], x.shape[1], x.shape[2] * self.scale_factor, x.shape[3] * self.scale_factor
      new = Tensor(size=shape, device=x.device)
  
      for i in range(x.shape[0]):
          new[i] = self.transform(x[i])
      new.requires_grad_()
  
      return new
  </code></pre>
  
  <p>My assumption is that this method is slower than interpolating the <code>Tensor</code> in one pass.</p>
  
  <p><strong>My Question:</strong> Is there no other way to compute this without the loop? I assume that the difference would be noticeable (correct me if I'm wrong).</p>