numba

Is there something like `inspect_types()` for a numba ' @jitclass`?

戏子无情 提交于 2019-12-11 06:11:24
问题 My numba @jitclass fails with a TypingError and an unhelpful error message, once I try to instantiate it: Can't infer type of variable '$0.1': list(undefined) . Which variable does that $0.1 correspond to (ok, probably the first one encountered, but in which function?). With normal functions, inspect_types() would be very helpful here. However, It doesn't seem to exist, neither on the jitclass, nor on it's methods. Is there something like that for jitclasses? I'm on numba 0.28.1 (currently

How can I pass string type in class in numba jitclass python?

a 夏天 提交于 2019-12-11 04:38:54
问题 while I added this before my class but I noticed that I passed a string to my class when I neglected to declare it for jitclass can't work and when i trying using string to be the same type can't use it. spec = [ ('filename', str), ('rows', int32), ('cls', int32), ('L', int32), ('H', int32), ('checking', int32[:]), ('enum_file', int32[:]), ('step', int32), ('slices', int32), ] @jitclass(spec) TypeError: spec values should be Numba type instances, got <class 'str'> ............................

TypeError when indexing numpy array using numba

左心房为你撑大大i 提交于 2019-12-11 04:35:02
问题 I need to sum up elements in a 1D numpy array (below: data ) based on another array with information on class memberships ( labels ). I use numba in the code below to speed it up. However, If I dot not explicitly cast with int() in the line ret[int(find(labels, g))] += y , I reveice an error message: TypeError: unsupported array index type ?int64 Is there a better workaround that explicit casting? import numpy as np from numba import jit labels = np.array([45, 85, 99, 89, 45, 86, 348, 764]) n

Find numpy.int_ in array of int_s using numba

前提是你 提交于 2019-12-11 03:56:12
问题 I am using numba (0.10.2-5-gda3e2bb-dirty) to speed up my code. Now I am trying the following: from numba import void, int_, double, jit import numpy as np @jit class bla(object) @void def my_fun k = np.int_(1) f = np.int_(np.array([1, 2 , 3, 4, 5])) if k in f: do something However numba appears to choke on the in command. If I type something like if k == 1: everything is fine. However with the in command numba won't compile. Any thoughts? Btw: I am running python 2.7 and numpy.version

Numba support for big integers?

ⅰ亾dé卋堺 提交于 2019-12-11 02:23:53
问题 I have a factorial lookup table that contains the first 30 integer factorials. This table is used in a function that is compiled with numba.njit . The issue is, above 20!, the number is larger than a 64-bit signed integer (9,223,372,036,854,775,807), which causes numba to raise a TypingError. If the table is reduced to only include the first 20 integer factorials the function runs fine. Is there a way to get around this in numba? Perhaps by declaring larger integer types in the jit compiled

Fail to implement Cardano method. Cube root of a complex number

旧巷老猫 提交于 2019-12-11 01:43:32
问题 In order to improve np.roots performance on cubic equation, I try to implement Cardan(o) Method : def cardan(a,b,c,d): #"resolve P=ax^3+bx^2+cx+d=0" #"x=z-b/a/3=z-z0 => P=z^3+pz+q" z0=b/3/a a2,b2 = a*a,b*b p=-b2/3/a2 +c/a q=(b/27*(2*b2/a2-9*c/a)+d)/a D=-4*p*p*p-27*q*q+0j r=sqrt(-D/27) J=-0.5+0.86602540378443871j # exp(2i*pi/3) u=((-q+r)/2)**(1/3) v=((-q-r)/2)**(1/3) return u+v-z0,u*J+v/J-z0,u/J+v*J-z0 It works well when roots are real: In [2]: P=poly1d([1,2,3],True) In [3]: roots(P) Out[3]:

Numba jitclass not working with python List

风格不统一 提交于 2019-12-11 01:09:54
问题 I am using python 3.6 and numba 0.36 . This question has a sister, where I approach the problem from another pov. But they are *not* the same issue. I'm implementing a r-tree structure and trying to boost the performance with Numba, but I'm facing some issues when I have to queue the nodes I have to visit during the search of items. Below I provide an example of the basic elements (nodes) and get_all function where I mimic a search in the tree (here I'm just getting all elements there in).

Numba `nogil` + dask threading backend results in no speed up (computation is slower!)

一曲冷凌霜 提交于 2019-12-11 00:19:30
问题 I'm trying to use Numba and Dask to speed up a slow computation that is similar to calculating the kernel density estimate of a huge collection of points. My plan was to write the computationally expensive logic in a jit ed function and then split the work among the CPU cores using dask . I wanted to use the nogil feature of numba.jit function so that I could use the dask threading backend so as to avoid unnecessary memory copies of the input data (which is very large). Unfortunately, Dask

Count the number of non zero values in a numpy array in Numba

China☆狼群 提交于 2019-12-10 22:08:06
问题 Very simple. I am trying to count the number of non-zero values in an array in NumPy jit compiled with Numba ( njit() ). The following I've tried is not allowed by Numba. a[a != 0].size np.count_nonzero(a) len(a[a != 0]) len(a) - len(a[a == 0]) I don't want to use for loops if there is still a faster, more pythonic and elegant way. For that commenter that wanted to see a full code example... import numpy as np from numba import njit @njit() def n_nonzero(a): return a[a != 0].size 回答1: You may

numba @jit slower that pure python?

一个人想着一个人 提交于 2019-12-10 19:29:37
问题 so i need to improve the execution time for a script that i have been working on. I started working with numba jit decorator to try parallel computing however it throws me KeyError: "Does not support option: 'parallel'" so i decided to test the nogil if it unlocks the whole capabilities from my cpu but it was slower than pure python i dont understand why this happened, and if someone can help me or guide me i will be very grateful import numpy as np from numba import * @jit(['float64[:,:]