You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@singa.apache.org by GitBox <gi...@apache.org> on 2020/03/30 05:44:56 UTC

[GitHub] [singa] dcslin edited a comment on issue #639: added support for matmul 3d 4d

dcslin edited a comment on issue #639: added support for matmul 3d 4d
URL: https://github.com/apache/singa/pull/639#issuecomment-605793210
 
 
   > is matmul different to tensordot?
   > why not call tensordot to implement it?
   
   Batch matmul could not be implemented by tensordot, as batch matmul is not really tensor dot.
   Batch matmul could be illustrated by einsum:
   ``` python
   >>> x1.shape
   (2, 3, 4, 5)
   >>> x2.shape
   (2, 3, 5, 6)
   >>> np.testing.assert_almost_equal(np.matmul(x1,x2), np.einsum('ijkl,ijlm->ijkm',x1,x2))
   # output is (2,3,4,6)
   ```
   
   
   Boardcasting matmul could be implemented by tensordot:
   ```
   >>> x1.shape
   (2, 3, 4, 5)
   >>> x3.shape
   (5, 6)
   >>> np.testing.assert_almost_equal(np.matmul(x1,x3), np.tensordot(x1,x3,axes=([3],[0])))
   # output is (2,3,4,6)
   ```

----------------------------------------------------------------
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