title: Counting arithmetic operations
body: <p>Is there a way to evalute the number of numeric operations (+, -, /, *) in a function/expression? </p>
  
  <p>In example, lets take a simple linear algebra problem (<code>Ax = b</code>):</p>
  
  <pre><code>A_data = np.array([[1, -4, 1],
                    [1, 6, -1],
                    [2, -1, 2]], dtype=float)
  
  b_data = np.array([[7],
                    [13],
                    [5]], dtype=float)
  </code></pre>
  
  <p>Next, lets apply Gauss elimination procedure:</p>
  
  <pre><code>def gauss_elim(A, b):
      Ab = np.column_stack((A, b))
      for k, pivot_row in enumerate(Ab[:-1]):
          for row in Ab[k+1:]:
              if pivot_row[k] != 0:
                  row[k:] = row[k:] - pivot_row[k:] * row[k]/pivot_row[k]
      return Ab
  </code></pre>
  
  <p>The result is:</p>
  
  <pre><code>array([[  1. ,  -4. ,   1. ,   7. ],
         [  0. ,  10. ,  -2. ,   6. ],
         [  0. ,   0. ,   1.4, -13.2]])
  </code></pre>
  
  <p>How could I count the operations?</p>
  
  <p>Note: I know the number of operations can be evaluated mathematically beforehand (i.e. for <a href="https://en.wikipedia.org/wiki/Gaussian_elimination#Computational_efficiency" rel="nofollow">Gaussian elimination</a> it is O(n^3)).</p>