docstr: Precomputes a data structure that can be used in the transform itself to speed things up
          
docstr_tok: ["Precomputes","a","data","structure","that","can","be","used","in","the","transform","itself","to","speed","things","up"]
code: def precompute(self, query, support):
      """Precomputes a data structure that can be used in the transform itself to speed things up"""
      pos_x, pos_y = query.pos, support.pos
      if hasattr(support, "batch"):
          batch_y = support.batch
      else:
          batch_y = torch.zeros((support.num_nodes,), dtype=torch.long)
      if hasattr(query, "batch"):
          batch_x = query.batch
      else:
          batch_x = torch.zeros((query.num_nodes,), dtype=torch.long)
  
      with torch.no_grad():
          assign_index = knn(
              pos_x, pos_y, self.k, batch_x=batch_x, batch_y=batch_y
          )
          y_idx, x_idx = assign_index
          diff = pos_x[x_idx] - pos_y[y_idx]
          squared_distance = (diff * diff).sum(dim=-1, keepdim=True)
          weights = 1.0 / torch.clamp(squared_distance, min=1e-16)
      normalisation = scatter_add(
          weights, y_idx, dim=0, dim_size=pos_y.size(0)
      )
  
      return Data(
          num_nodes=support.num_nodes,
          x_idx=x_idx,
          y_idx=y_idx,
          weights=weights,
          normalisation=normalisation,
      )
  
imports: import torch
  from torch_geometric.nn import knn_interpolate, knn
  from torch_scatter import scatter_add
  from torch_geometric.data import Data
label_desc: Use image node_id 2 for calling the KNNInterpolate obj's underlying member method code with example usage: obj.precompute(query, support) and returns: Data