Skip to content

Instantly share code, notes, and snippets.

@nschloe
Last active December 14, 2020 12:16
Show Gist options
  • Save nschloe/d9c1d872a3ab8b47ff22d97d103be266 to your computer and use it in GitHub Desktop.
Save nschloe/d9c1d872a3ab8b47ff22d97d103be266 to your computer and use it in GitHub Desktop.
import numpy
import perfplot
def setup(n):
pts = numpy.random.rand(3, n, 2)
e = numpy.array([
pts[2] - pts[1],
pts[0] - pts[2],
pts[1] - pts[0],
])
return e
def test1(data):
numpy.einsum("...k, ...k->...", data, data)
w = numpy.einsum("...k, ...k->...", data[[1, 2, 0]], data[[2, 0, 1]])
return w
def test2(data):
v = numpy.einsum("...k, ...k->...", data, data)
w = v - numpy.sum(v, axis=0) / 2
return w
perfplot.save(
"out.png",
setup=setup,
kernels=[test1, test2],
n_range=[2 ** k for k in range(23)],
)
@nschloe
Copy link
Author

nschloe commented Dec 14, 2020

out

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