singa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [singa] dcslin edited a comment on issue #639: added support for matmul 3d 4d
Date Mon, 30 Mar 2020 05:44:56 GMT
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

Mime
View raw message