I'm currently experimenting with numba functions and especially vectorized , so I created a vectorized sum function (because it is easy to compare with np.sum .
import numpy as np import numba as nb @nb.vectorize([nb.float64(nb.float64, nb.float64)]) def numba_sum(element1, element2): return element1 + element2 @nb.vectorize([nb.float64(nb.float64, nb.float64)], target='parallel') def numba_sum_parallel(element1, element2): return element1 + element2 array = np.ones(elements) np.testing.assert_almost_equal(numba_sum.reduce(array), np.sum(array)) np.testing.assert_almost_equal(numba_sum_parallel.reduce(array), np.sum(array))
Depending on the number of elements parallel code does not return the same number as the target cpu code. I think it is due to something related to the usual problems with threads (but why? Is it a bug in Numba or something that just happens when using parallel execution?). Itβs funny that sometimes it works, sometimes itβs not. Sometimes it fails with elements=1000 , sometimes it starts crashing with elements=100000 .
For example:
AssertionError: Arrays are not almost equal to 7 decimals ACTUAL: 93238.0 DESIRED: 100000.0
and if I run it again
AssertionError: Arrays are not almost equal to 7 decimals ACTUAL: 83883.0 DESIRED: 100000.0
Now my question is: why do I need a parallel vector function? I understand that the purpose of the vectorized function is to provide numpy-ufunc features , but I tested reduce and accumulate and they stop working on some (variable) number of elements and want an unreliable function?
I am using numba 0.23.1 , numpy 1.10.1 with python 3.5.1 .
python numpy parallel-processing numba
Mseifert
source share