in Education by
If I understand correctly I can increase the performance of a numba function by adding a signature. Example: @njit(int32(int32, int32)) def f(x, y): # A somewhat trivial example return x + y Now I have function which takes two sets. What is the correct signature? @njit(int32(set(int32), set(int32))) def f(set_1, set_2): # A somewhat trivial example return x I thought the signature (int32(set(int32), set(int32))) could be correct but nothing is happening. print(numba.typeof(set_1)) returns reflected set(int32) JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
If I understand correctly I can increase the performance of a numba function by adding a signature. That's wrong - or only partially correct. With signature numba just compiles the function ahead-of-time instead of when called for the first time with these arguments. After the first call both should be equally fast. In some cases the function might be slightly faster without signature (especially with arrays where numba can use the array-alignment of the input). Now I have function which takes two sets. What is the correct signature? The correct signature for a Python set containing integers is: numba.types.Set(numba.int64, reflected=True) So the signature for a function taking two sets (and returning one) would be: import numba as nb reflected_int_set = nb.types.Set(nb.int64, reflected=True) @nb.njit(reflected_int_set(reflected_int_set, reflected_int_set)) def f(set_1, set_2): return set_1 >>> f({1,2,3}, {3,4,5}) {1, 2, 3} But since it (very likely) doesn't improve performance I wouldn't bother with the signature at all. Also a word of caution: numba will convert the Python set to a numba set internally so passing a Python set to a numba function or returning a set from a numba function to a Python context will copy the complete set. In most cases that overhead is much more significant than potential speed-ups that numba provides. In my experience sets and lists with numba only make sense if they are strictly confined to numba functions. So if you use them as arguments or return them (to non numba functions/contexts) you have to measure the performance and check if you really get speed-ups.

Related questions

0 votes
    I am trying to write a TDMA algorithm with numba in nopython mode. Here is my code: @jit(nopython ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    I'm using SafetyNet API for checking if device is rooted or not and using the below helpful code but ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 19, 2022 in Education by JackTerrance
0 votes
    I was coping with many problems to get stuck with this one. I have installed yum repository on server ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    icse blue j where is function signature?..show with example Is it possible to return 2 values from a method(function)?? Select the correct answer from above options...
asked Dec 24, 2021 in Education by JackTerrance
0 votes
    ______________ are difficult to identify as they keep on changing their type and signature. (a) Non-resident ... -Cyber Security:,Cyber Security-Jobs:,Cyber Security Applications...
asked Nov 1, 2021 in Education by JackTerrance
0 votes
    What is the process of defining more than one method in a class differentiated by method signature? (a) ... questions and answers pdf, java interview questions for beginners...
asked Oct 26, 2021 in Education by JackTerrance
0 votes
    What is the process of defining a method in a subclass having same name & type signature as a method ... questions and answers pdf, java interview questions for beginners...
asked Oct 26, 2021 in Education by JackTerrance
0 votes
    Digital Signature is implemented using the __________. (1)Symmetric key System (2)Keys are not used (3)Public key system...
asked Mar 19, 2021 in Technology by JackTerrance
0 votes
    How would you put your graduate degree on your signature block?...
asked Jan 27, 2021 in General by Editorial Staff
0 votes
    Which phase involves checking the signature of binaries? 1. Release 2. Operate 3. Deploy 4. Monitor...
asked Oct 28, 2020 in Technology by JackTerrance
0 votes
    Which of the following sets the size of the outer margins for the graph? (a) par(mfrow=c(nrow,mcol)) ... Regression of R Programming Select the correct answer from above options...
asked Feb 10, 2022 in Education by JackTerrance
0 votes
    How can I divide data into training and validation sets, Should I divide it 50%-50% for both or is there another ... advice me on this? Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    ________ is a type of intelligent technique that finds patterns and relationships in massive data sets too large for a ... to analyze. Select the correct answer from above options...
asked Dec 6, 2021 in Education by JackTerrance
...