numba | numba provides functions to convert integers | Code Quality library
kandi X-RAY | numba Summary
kandi X-RAY | numba Summary
Package numba provides functions to convert integers to various human friendly formats.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Abbreviate converts a number to a short string
- OrdinalSuffix returns alphabet suffix of n .
- Ordinal returns the ordinal of n .
numba Key Features
numba Examples and Code Snippets
Community Discussions
Trending Discussions on numba
QUESTION
I need to pass dates into numba function.
Passing them in as .astype('datetime64[D]') works well. But I need to create an epoch date inside function too.
...ANSWER
Answered 2021-Jun-09 at 23:36Your problem is likely related to this documented issue with numba
.
A first workaround would be to define epoch
outside of your jit
function:
QUESTION
Here is my code.
...ANSWER
Answered 2021-Jun-09 at 20:59There are several problems to handle: first, you've commented out the @jit
decorator of your first function, stopF_w
.
If you uncomment it, you'll resolve your current error. Unfortunately, you will immediately run into several other errors. if your numba version is up to date, you'll see an error pertaining to "reflected lists".
Basically, your inputs b_wi
and f_wi
are lists of variable length lists, which cannot be converted into uniform numpy arrays. E.g.: if instead of [[1,2,3,4],[6,7,8,9,10,11]]
, if b_wi
was something like [[1,2,3, 4, 6], [7, 8, 9, 10, 11]]
(easily convertible to an array of shape (2, 5) then it would work without any problems. To get your variable length lists to work with numba, you need to rely on a Typed List, which is a bit cumbersome.
QUESTION
I am trying to replicate the technique descrived in the paragraph 1. of the selected answer to another question: How to pass additional parameters to numba cfunc passed as LowLevelCallable to scipy.integrate.quad.
However, I don't know how to modify the implementation so that xx[1] is an array of float and not a unique float.
...ANSWER
Answered 2021-Jun-08 at 07:45I solved the issue by modifiying the code by Jacques Gaudin in https://stackoverflow.com/a/49732825/3925704 to:
QUESTION
I have the following code:
...ANSWER
Answered 2021-Jun-01 at 12:51Flawr is correct. B[..., k]
returns a np.view()
into B
, but does not actually copy any data. In memory, two neighbouring elements of the view have a distance of B.strides[1]
, which evaluates to B.shape[-1]*B.itemsize
and is greater than B.itemsize
. Consequentially, your array is not contiguous.
The best optimization is to vectorize the dotplus
loop and write
QUESTION
I have a 498-frames-long image sequence for which I calculated optical flow using cv2.calcOpticalFlowFarneback. Therefore now I have 497 vector maps representing my motion vectors, and these vector are described by magnitude and direction.
What I need to do is to generate a histogram where on the x-axis I have angle ranges in degrees. More specifically, I have 12 bins where the first bin contains all the vectors with direction 0 < angle < 30
, the second one 30 < angle < 60
and so on. On the y-axis, instead, I need to have the sum of the modulus of those vectors contained in each bin.
The problem here is that doing all of this using simple for
loops and if
statements takes ages:
ANSWER
Answered 2021-Jun-01 at 01:10Conditionals are slow. You should avoid them as much as possible. Also Numpy vectorization and Numba JIT help to speed up such a code by a large margin. Here is an untested example:
QUESTION
I run the following code with fastmath
option enabled and disabled.
ANSWER
Answered 2021-May-31 at 19:29There are a few things missing to get the SIMD vectorization working. For maximum performance it is also necessary to avoid costly temporary arrays, which may not be optimized away if you use a partly vectorized function.
- Function calls have to be inlined
- The memory access pattern must be known at compile time. In the following example this is done with
assert vectors.shape[2]==2
. Generally the shape of the last array could also be larger than two, which would be much more complicated to SIMD-vectorize. - Division by zero checks can also avoid SIMD-vectorization, and are slow if they are not optimized away. I do this manually by calculating
div_pi=1/np.pi
once and than a simple multiplication inside the loop. If a repeated division is not avoidable you can useerror_model="numpy"
to avoid the division by zero check.
Example
QUESTION
Edit: Forgot to run numba more than once (oops!)
Ive looked at the numba versions of namedtuple and Dict as potential solutions but they seem much slower (about 10000x slower) in comparison to their python counterparts.
...ANSWER
Answered 2021-May-31 at 03:48The biggest issue is the fact that you are measuring the first execution of build_params_numba
, which includes the compilation (it is compiled Just-In-Time, just as you requested). This is like measuring the time-to-dinner between a classic meal and a microwave meal, but you're including the time to buy and install a microwave oven as part of the latter. Measure the second invocation of build_params_numba
, when the compilation has been already completed, to see how the compiled function performs.
The second issue is that numba
might not be of much help with your code. AFAIK it is designed to speed up numerical algorithms and numpy code. By necessity, namedtuple
and dict
are Python data structures and numba
has to treat them as such; so even though you requested nopython mode, Numba cannot oblige, as it only works when a native data type can be detected for all values in your code (I think — not 100% sure on this point though).
QUESTION
Using pandas/python, I want to calculate the longest increasing subsequence of tuples for each DTE
group, but efficiently with 13M rows. Right now, using apply/iteration, takes about 10 hours.
Here's roughly my problem:
DTE Strike Bid Ask 1 100 10 11 1 200 16 17 1 300 17 18 1 400 11 12 1 500 12 13 1 600 13 14 2 100 10 30 2 200 15 20 2 300 16 21 ...ANSWER
Answered 2021-May-27 at 13:27What is the complexity of your algorithm of finding the longest increasing subsequence?
This article provides an algorithm with the complexity of O(n log n).
Upd: doesn't work.
You don't even need to modify the code, because in python comparison works for tuples: assert (1, 2) < (3, 4)
QUESTION
I have a class with an attribute sources
that can or cannot be defined. Before using numba, I set the variable sources
to None
when it was undefined, otherwise it was a numpy array.
Now, it seems that this behavior is not allowed by numba. Is this correct? I though to use a boolean variable as a workaround, but this messes up with the signature of the function (property) source
:
ANSWER
Answered 2021-May-28 at 13:23The error you get has nothing to do with None and typing. It is due to self.sources
in the member function sources
not being declared nor initialized while self._sources
is and should be used instead.
Note Numba actually supports None
values using optional
types. You can find more information in the Numba documentation.
QUESTION
I am a beginner in Numba. I have difficulty in re-arranging the rows of an array in GPU.
In Numba CPU, for example, this can be done by
...ANSWER
Answered 2021-May-27 at 14:52You are correct that those slice operators are not supported on the device in Numba. The underlying problem is that slice operation requires an intermediate array construction and the Numba compiler currently can't do that.
There are probably two alternative ways to do this:
- Use a single thread to copy a row of the data between the source and destination (
numba_gpu1
shown below) - Use a single block to copy a row of the data between the source and destination. This can exploit a strided loop design pattern which improves memory coalescing and cache coherency and should perform better at non-trivial sizes (
numba_gpu2
shown below for row major ordered data).
In from numba import cuda import numpy as np
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install numba
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page