Created
August 15, 2022 02:04
-
-
Save qpwo/a39bd54eb317d442ef18b855db25793b to your computer and use it in GitHub Desktop.
as_strided matrix multiplication
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch as t | |
l = 2 | |
n = 3 | |
m = 5 | |
a = t.randint(0,100,(l,n)) | |
b = t.randint(0,100,(n,m)) | |
print("matmul:", a.matmul(b)) | |
print("with strides:", (a.as_strided((l,n,m), (n,1,0)) * b.as_strided((l, n, m), (0, m, 1))).sum(1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment