@lantiga
Thank you for your replying.
There is a issue that two tensor of different sizes cannot be multiplied. but I can be aware of your idea.
The following is an example for 2-rank tensor,
a = torch.LongTensor([[1,2,3],[4,5,6]])
b = [torch.LongTensor([[1,1],[1,1]]), torch.LongTensor([[2,2],[4,4]]), torch.LongTensor([[3,3],[9,9]])]
b = torch.stack(b, dim=2)
a = a.view(a.size(0),1,a.size(1)).expand_as(b)

c = b.mul(a).sum(dim=2).view(b.size(0), b.size(1))

If anyone has better idea, please let me know.
Thanks.