|
|
|
|
|
by rickard
1830 days ago
|
|
I recently (last week) started using numba, for similar reasons to why the author seems to like Julia. I tested translating his example to numba: @numba.njit(parallel=True, fastmath=True)
def w(M, a):
n = len(a)
for i in numba.prange(n):
for j in range(n):
M[i,j] = np.exp(1j*k * np.sqrt(a[i]**2 + a[j]**2))
and timed it like this: %%timeit
n = len(a)
M = np.zeros((n,n), dtype=complex)
w(M, a)
On my 8-core system, this ends up more than 10x as fast as the numpy version he listed (which seems to lack the sqrt, though), which would place it close to the multithreaded Julia, even considering that ran it on a 4-core system. As an added bonus, it can also pretty much automatically translate to GPU as well. |
|
yet Numba basically makes your python code not python. It doesn't support so many things: pandas dataframe, or even as simple as a dict(), which means you often have to manually feed your numba function separate arguments.
To separate a complicated calculation into numba-infer-able parts and the not ones is not fun and sometimes just impossible.