Created
April 30, 2021 17:43
-
-
Save nschloe/33b3c93b9bc0768394ba9edee1fda2bc to your computer and use it in GitHub Desktop.
dot vs einsum for 1D
This file contains hidden or 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 numpy as np | |
| import perfplot | |
| def dot(xy): | |
| x, y = xy | |
| return np.dot(x, y) | |
| def einsum(xy): | |
| x, y = xy | |
| return np.einsum("i...,i...->...", x, y) | |
| b = perfplot.bench( | |
| setup=lambda n: np.random.rand(2, n), | |
| kernels=[dot, einsum], | |
| n_range=[2 ** k for k in range(25)], | |
| ) | |
| b.save("out.svg") | |
| b.show() |
nschloe
commented
Apr 30, 2021
Author

Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment