Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!
Installation¶
numba can be installed using the following command.
:::bash
pip3 install numbaIf you need CUDA support, you have to install CUDA drivers.
:::bash
sudo apt-get install cuda-10-1Instead of going through the hassle of configuring numba for GPU,
a better way is to run numba in a Nvidia Docker container.
The Docker image nvidia
from __future__ import division
import time
import random
data = []
data_length = 100000
ma_length = 500
test_times = 10
for i in range(data_length):
data.append(random.randint(1, 100))import numba
@numba.jit
def ma_numba(data, ma_length):
ma = []
data_window = data[:ma_length]
test_data = data[ma_length:]
for new_tick in test_data:
data_window.pop(0)
data_window.append(new_tick)
sum_tick = 0
for tick in data_window:
sum_tick += tick
ma.append(sum_tick / ma_length)
return ma
start = time.time()
for i in range(test_times):
result = ma_numba(data, ma_length)
time_per_test = (time.time() - start) / test_times
time_per_point = time_per_test / (data_length - ma_length)
print("time_per_test:%sS" % time_per_test)
print("time_per_point:%sMS" % (time_per_point * 1000000))/workspace/.pip-modules/lib/python3.7/site-packages/numba/ir_utils.py:1969: NumbaPendingDeprecationWarning:
Encountered the use of a type that is scheduled for deprecation: type 'reflected list' found for argument 'data' of function 'ma_numba'.
For more information visit http://numba.pydata.org/numba-doc/latest/reference/deprecation.html#deprecation-of-reflection-for-list-and-set-types
File "<ipython-input-2-72e6018139c1>", line 4:
@numba.jit
def ma_numba(data, ma_length):
^
warnings.warn(NumbaPendingDeprecationWarning(msg, loc=loc))
time_per_test:0.4571639060974121S
time_per_point:4.594612121582031MS
Deprecation Notices¶
Reflection for List and Set types will be deprecated in Numba.
You should use numba.typed.List and numba.typed.Set instead.
Tutorials¶
Numba - Tell Those C++ Bullies to Get Lost | SciPy 2017 Tutorial | Gil Forsyth & Lorena Barba
References¶
Speed Up your Algorithms Part 2— Numba
https://
https://
https://
https://numba.pydata.org/numba-doc/dev/user/5minguide.html?highlight=target cuda
https://numba.pydata.org/numba-doc/dev/reference/jit-compilation.html?highlight=target cuda