You could adjust the following code that performs backward-warping for optical flow.

  
      github.com
  
  
    sniklaus/pytorch-spynet/blob/master/run.py#L127 53

					torchHorizontal = torch.linspace(-1.0, 1.0, variableInput.size(3)).view(1, 1, 1, variableInput.size(3)).expand(variableInput.size(0), 1, variableInput.size(2), variableInput.size(3))
					torchVertical = torch.linspace(-1.0, 1.0, variableInput.size(2)).view(1, 1, variableInput.size(2), 1).expand(variableInput.size(0), 1, variableInput.size(2), variableInput.size(3))


					self.tensorGrid = torch.cat([ torchHorizontal, torchVertical ], 1).cuda()
				# end


				variableGrid = torch.autograd.Variable(data=self.tensorGrid, volatile=not self.training)


				variableFlow = torch.cat([ variableFlow[:, 0:1, :, :] / ((variableInput.size(3) - 1.0) / 2.0), variableFlow[:, 1:2, :, :] / ((variableInput.size(2) - 1.0) / 2.0) ], 1)


				return torch.nn.functional.grid_sample(input=variableInput, grid=(variableGrid + variableFlow).permute(0, 2, 3, 1), mode='bilinear', padding_mode='border')
			# end
		# end


		self.modulePreprocess = Preprocess()


		self.moduleBasic = torch.nn.ModuleList([ Basic(intLevel) for intLevel in range(6) ])


		self.moduleBackward = Backward()
	# end





  
  
    
    
  
  


Disparity is essentially just optical flow without vertical motion.