(a)
| 11 | |
| 12 | @jit(nopython=True) # Set "nopython" mode for best performance, equivalent to @njit |
| 13 | def go_fast(a): # Function is compiled to machine code when called the first time |
| 14 | trace = 0.0 |
| 15 | for i in range(a.shape[0]): # Numba likes loops |
| 16 | trace += np.tanh(a[i, i]) # Numba likes NumPy functions |
| 17 | return a + trace # Numba likes NumPy broadcasting |
| 18 | |
| 19 | self.assertEqual(10, go_fast(x).shape[0]) |
| 20 |