I wish to apply a nn.Linear() layer only to a part of a Variable. How to go about it?
As an example consider a Variable feat of type torch.cuda.FloatTensor of size 256x20x51, stored in a batch–first representation. I wish to apply the linear layer on just one of 20 (1x51 vectors) for each batch_number.
So for example if the feat variable is something like:
Variable containing:
(0 ,.,.) = 
   0   1   2   3
   4   5   6   7
   8   9  10  11

(1 ,.,.) = 
  12  13  14  15
  16  17  18  19
  20  21  22  23
[torch.FloatTensor of size 2x3x4]

I need to convert this into
Variable containing:
(0 ,.,.) = 
   0   1   2   3
   4   5   6   7
   fc([8   9  10  11])

(1 ,.,.) = 
  12  13  14  15
  fc([16  17  18  19])
  20  21  22  23
[torch.FloatTensor of size 2x3x4]

where idx = [2, 1], corresponding to the rows I wish to apply the linear layer to in each batch_no; and fc = nn.Linear(4, 4).
Also, is the following method correct?
for each batch_i and corresponding idx_i
feat.data[batch_i][idx_i] = fc(feat[batch_i][idx_i]).data.
Does it mess up the autograd procedure in any way?