Skip to content

Commit e0e8de4

Browse files
committed
.gitignore and dummy numba
1 parent e26c1f4 commit e0e8de4

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
__pycache__
2+
*.txt
3+
*.pkl

numba.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"""Provide dummy alternative for `numba.jit`.
2+
3+
The python package `numba <http://numba.pydata.org/>` provides just-in-time compilation,
4+
which can often give a huge speed-up. However, it is not included into the python standard library.
5+
Although e.g. the python distributions provided by anaconda already come with numba, it might not
6+
be available on your laptops, so we provide a "dummy" alternative for the "@jit" decorator used
7+
in some of the python scripts.
8+
Moreover, this dummy is also usefull for debugging, since the "@jit" often leads to confusing,
9+
lengthy tracebacks and error messages.
10+
11+
If you get an "ImportError: No module named 'numba'" or want to disable the @jit for debugging,
12+
simply copy this file in the folder where you run the scripts.
13+
Note that you need might need to restart the kernel to force a new import, simply calling the cell
14+
with the "import" is not enough.
15+
16+
17+
Example
18+
-------
19+
The usage is as with the jit decorator of the "real" numba package,
20+
but the @jit simply doesn't do anything::
21+
22+
from numba import jit
23+
24+
@jit
25+
def example_function(a, b):
26+
return a + b
27+
28+
@jit(nopython=True)
29+
def another_example_function(a, b):
30+
return a * b
31+
32+
"""
33+
warnings.warn("did not import numba, but dummy jit. Code will work but run slowly!")
34+
35+
def jit(*args, **kwargs):
36+
"""Dummy decorator, doing nothing, for replacing numba.jit if not available"""
37+
if len(args) > 0:
38+
return args[0]
39+
else:
40+
def dummy_decorator(func):
41+
"""Dummy decorator"""
42+
return func
43+
return dummy_decorator

0 commit comments

Comments
 (0)