numba

Is there any good way to optimize the speed of this python code?

你离开我真会死。 提交于 2019-12-11 23:54:31
问题 I have a following piece of code, which basically evaluates some numerical expression, and use it to integrate over certain range of values. The current piece of code runs within about 8.6 s , but I am just using mock values, and my actual array is much larger. Especially, my actual size of freq_c= (3800, 101) and size of number_bin = (3800, 100) , which makes the following code really inefficient, as the total execution time will be close to 9 minutes for the actual array. One part of the

Passing functions to CUDA blocks with numba [closed]

我们两清 提交于 2019-12-11 16:38:56
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed last year . I am working in python with the numba library and wondered if there is a solution to write a parallel version of a previous work. I have a function f(X, S, F) where X and S are scalar arrays, and F is a list of functions. I am almost sure that passing an array of functions is not

Cannot coerce to or from object in nopython context: Error after python

做~自己de王妃 提交于 2019-12-11 16:31:47
问题 Following up from here, Numba is finally working (after weeks) on my machine, without any weird indentation errors. I've implemented it as in the solution to the linked question. However, I now get this string of errors from Numba, the last line being that it can't coerce to or from object in nopython context : Traceback (most recent call last): File "C:\Users\app\Documents\Python Scripts\gbc_classifier_train.py", line 19, in <module> import gentleboost_c_class_jit_v6_nolimit as gbc File "C:

Numba slows down my program instead of speeding it up

一笑奈何 提交于 2019-12-11 14:03:31
问题 I came across a piece of code which did the job I wanted it to do a lot quicker than my original code did. However, unlike my original code this one is slowed down by the numba jit function instead of sped up. Does anyone have an idea of why this is? This is the code without numba: def sum_factors(n): result = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: result.extend([i, n//i]) return sum(set(result)-set([n])) def amicable_pair(number): result = [] for x in range(1,number+1): y =

Amortized O(1) rolling minimum implemented in Python Numba/NumPy

こ雲淡風輕ζ 提交于 2019-12-11 12:19:37
问题 I am trying to implement a rolling minimum that has an amortized O(1) get_min() . The amortized O(1) algorithm comes from the accepted answer in this post Original function: import pandas as pd import numpy as np from numba import njit, prange def rolling_min_original(data, n): return pd.Series(data).rolling(n).min().to_numpy() My attempt to implement the amortized O(1) get_min() algorithm:(this function has decent performance for non-small n ) @njit def rollin_min(data, n): """ brief

@jit slowing down function

六眼飞鱼酱① 提交于 2019-12-11 08:43:30
问题 I'm developing an optimization code for a complex reservoir operations problem. Part of this requires me to calculate the objective function for a large number of potential solutions. I'm testing the optimizer on the Rosenbrock function and trying to improve its speed. I noticed when I profiled the code that calculating the objective function within a for loop was one of the code bottlenecks so I developed a way to do this in parallel for multiple sets of decision variables. I have two

Numba TypingError: Type of variable cannot be determined

我与影子孤独终老i 提交于 2019-12-11 07:49:34
问题 This question is the follow up of this question: Why this python class is not working with numba jitclass? Now the issue I am having that numba is unable to determine the types of the variable which I think I already explicitly defined in the specifications. Here is the code. I have updated it with a rnd function as numba doesn't allow np.round with only two parameters. import numpy as np import math from numba import jitclass from numba import float64,int64 spec =[ ('spacing',float64), ('n

Numba custom stack class and pop function failing in `nopython` mode

拜拜、爱过 提交于 2019-12-11 06:54:25
问题 Trying to solve the issue posted in the other question I posted: Numba jitclass not working with python List , I tried to implement the list of nodes to visit with a custom stack class. The code below is quite similar to that from the other question, but instead of using python lists inside the get_all , the nodes to visit are controled with the Stack class. import numba as nb import numpy as np INF = np.iinfo(np.int64).max node_type = nb.deferred_type() stack_type = nb.deferred_type() node

Basic trouble with Python lists in Numba; what's going on?

空扰寡人 提交于 2019-12-11 06:37:34
问题 I'm a beginner to Numba. For the life in me I can't get a Numba function to manipulate a simple list. Heck, I can't even figure out how to specify the signature. Here's the example. What's wrong? (What's a "reflected list"?) And how do I fix it? from numba import * from numba.types import * @jit(List(int64)(List(int64)), nopython=True) def foo(a): a[0] += a[0]; return a foo([1]) gives Traceback (most recent call last): File "<pyshell#5>", in <module> foo([1]) File "numba\dispatcher.py", line

Numba v0.44: cannot reflect element of reflected container

自作多情 提交于 2019-12-11 06:15:25
问题 I am new to numba and am struggling at every turn to get what I think is simple to work in nopython mode. For example, inspired by this question coalescing-ranges I have written the following function: @njit # @jit def coalesce(ranges): coalesced = [] for i, (label_a, start_a, stop_a) in enumerate(ranges): append_flag = True for j, (label_b, start_b, stop_b) in enumerate(coalesced): if label_a != label_b: # not of same type continue elif stop_a < start_b: # a does not start and then overlap b