Last active
          December 14, 2020 12:16 
        
      - 
      
- 
        Save nschloe/d9c1d872a3ab8b47ff22d97d103be266 to your computer and use it in GitHub Desktop. 
  
    
      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 | |
| 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)], | |
| ) | 
      
      
  Author
  
  
        
      
            nschloe
  
      
      
      commented 
        Dec 14, 2020 
      
    
  

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