How can i compute 3D tensor * 2D tensor multiplication?
In PyTorch, i can do this as below. <SCODE>result = torch.mm(X.view(-1, C), Y)
result = result.view(-1, B, D)
<ECODE> Is there simpler way to handle this?
yunjey
<SCODE>Y.unsqueeze(0).expand_as(X) * X<ECODE>
chenyuntc
Y.unsqueeze(0) has a shape (1, C, D) so that it can not be expanded as X which has a shape (A, B, C). What i want to do is to broadcast 2D matrix multiplication as below. <SCODE>def matmul(X, Y):
    results = [] 
    for i in range(X.size(0)):
        result = torch.mm(X[i], Y)
        results.append(result)
    return torch.cat(results)<ECODE>
yunjey
smth
Ok, I got it. Thanks.
yunjey
result = torch.mm(X.resize_(A*B,C), Y).resize_(A,B,D)
alexis-jacq
My mistake, I was careless
chenyuntc
jphoward
Also, you be able to do that with batched matrix multiply: <SCODE>result = torch.bmm(X, Y.unsqueeze(0).expand(X.size(0), *Y.size()))
<ECODE> We’ll be adding broadcasting very soon.
apaszke
apaszke
ngimel
o2h4n