Skip to content

Instantly share code, notes, and snippets.

@nschloe
Last active October 26, 2020 12:57
Show Gist options
  • Save nschloe/8bc015cc1a9e5c56374945ddd711df7b to your computer and use it in GitHub Desktop.
Save nschloe/8bc015cc1a9e5c56374945ddd711df7b to your computer and use it in GitHub Desktop.
einsum is faster if the tail survives
import perfplot
import numpy
def setup(n):
a = numpy.random.rand(n, 3)
b = numpy.ascontiguousarray(a.T)
return a, b
def einsum_i(data):
return numpy.einsum("ij,ij->i", data[0], data[0])
def einsum_j(data):
return numpy.einsum("ij,ij->j", data[1], data[1])
perfplot.show(
setup=setup,
kernels=[einsum_i, einsum_j],
n_range=[2 ** k for k in range(26)],
relative_to=1,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment