singa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [singa] dcslin commented on issue #634: cannot do matmul for high-dim tensors
Date Tue, 24 Mar 2020 11:41:23 GMT
dcslin commented on issue #634: cannot do matmul for high-dim tensors
URL: https://github.com/apache/singa/issues/634#issuecomment-603190533
 
 
   Hi @joddiy , for tensor mul >2d, please use `tensor.tensordot`, it depends on which
axis to perform the `tensordot`
   ```python
       def test_4d_tensor_dot(self):
           for dev in [cpu_dev, gpu_dev]:
               x1 = np.random.randn(1, 12, 256, 64).astype(np.float32)
               x2 = np.random.randn(1, 12, 64, 256).astype(np.float32)
               x1 = tensor.from_numpy(x1)
               x1.to_device(dev)
               x2 = tensor.from_numpy(x2)
               x2.to_device(dev)
   
               y = tensor.tensordot(x1, x2, axes=([3],[2]))
               print(y.shape)
   
               y = tensor.tensordot(x1, x2, axes=([2,3],[3,2]))
               print(y.shape)
   
   ```
   output:
   ```
   (1, 12, 256, 1, 12, 256)
   (1, 12, 1, 12)
   (1, 12, 256, 1, 12, 256)
   (1, 12, 1, 12)
   ...........................
   ----------------------------------------------------------------------
   Ran 27 tests in 0.121s
   
   OK
   ```
   
   reference: https://docs.scipy.org/doc/numpy/reference/generated/numpy.tensordot.html

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message