Support for tensordot


(Shijie Wu) #1

Numpy and Theano support tensordot. It would be nice that Pytorch also have this feature.


(Roman Pearah) #2

If numpy supports it, PyTorch supports it, through the use of numpy():

import torch
import numpy as np

M = torch.randn(3, 3, 4)
v = torch.randn(2, 2, 3)

out = torch.Tensor(np.tensordot(v.numpy(), M.numpy(), axes=[[2], [0]]))

Not as concise, but it’s there.


(Miguel Varela Ramos) #3

Not exactly true, because if you want to backprop through it, you will break the graph…


(Roman Pearah) #4

Ah, yes, that’s true and that would be important under most circumstances.


#5

So, is there any workaround for tensordot in pytorch?


(Dean Mark) #6

I adapted the numpy tensordot implementation to pytorch: pytorch tensordot


(Thomas V) #7

You could use einsum.