I found the solution.

  
      gist.github.com
  
  
    https://gist.github.com/lantiga/a78581e6c6c0ad1534065950e204ce9d 67
README.md

# Indexed convolutions

A convolution operator over a 1D tensor (BxCxL), where a list of neighbors for each element is provided through a indices tensor (LxK), where K is the size of the convolution kernel. Each row of indices specifies the indices of the K neighbors of the corresponding element in the input. A -1 is handled like for zero padding.

Note that the neighbors specified in indices are not relative, but rather absolute. They have to be specified for each of the elements of the output.

A use case is for convolutions over non-square lattices, such as images on hexagonal lattices coming from Cherenkov telescopes (http://www.isdc.unige.ch/%7Elyard/FirstLight/FirstLight_slowHD.mov).

Example:
This file has been truncated. show original
indexed_conv.py
import torch
from torch.autograd import Variable

def prepare_mask(indices):

    padded = indices == -1
    indices[padded] = 0

    mask = torch.FloatTensor([1,0])
    mask = mask[..., padded.t().long()]
This file has been truncated. show original