Multi-Dimension Matrix Matmul Rule

52 Views Asked by At

Can I safely assume that when

X = torch.rand([a,b,c,d ... n-1,n]) and Y = torch.rand([e,f,...k-1,k])
if X[n] = Y[k-1] then X and Y can execute torch.matmul calculation

or when Y only has one dimension Y[k]

if X[n] = Y[k] then X and Y can execute torch.matmul calculation

for example: In 2 dimension matrix

X = torch.rand([a,b]), Y = torch.rand([e,f])
it's very easy to tell whether X and Y can do torch.matmul() calculations
If b = e, then yes otherwise no. 

In 3 dimension matrix

X = torch.rand([a,b,c]), Y = torch.rand([e,f,g])
if c = f then result = torch.matmul(X,Y) is valid otherwise no. 

In 4 dimensions matrix

Scenario 1:
X = torch.rand([a,b,c,d]), Y = torch.rand([e,f,g,h])
if d = g then result = torch.matmul(X,Y) is valid otherwise no.

Scenario 2:
X = torch.rand([a,b,c,d]), Y = torch.rand([e,f,g])
if d = f then result = torch.matmul(X,Y) is valid otherwise no.

Scenario 2:
X = torch.rand([a,b,c,d]), Y = torch.rand([e,f,g])
if d = f then result = torch.matmul(X,Y) is valid otherwise no.

Scenario 3:
X = torch.rand([a,b,c,d]), Y = torch.rand([e,f])
if d = e then result = torch.matmul(X,Y) is valid otherwise no.

Scenario 4:
X = torch.rand([a,b,c,d]), Y = torch.rand([e])
if d = e then result = torch.matmul(X,Y) is valid otherwise no.
0

There are 0 best solutions below