How is a parrot different from Numba? Since I have not seen any improvements in some NumPy expressions

I am wondering if any of the key differences between a parrot and Numba jit know? I'm curious because I compared Numexpr with Numba and parakeet, and for that particular expression (which I expected to do very well on Numexpr, because that was what is mentioned in its documentation)

Thus, the results

enter image description here

and the functions I tested (through timeit - at least 3 repetitions and 10 cycles per function)

import numpy as np
import numexpr as ne
from numba import jit as numba_jit
from parakeet import jit as para_jit


def numpy_complex_expr(A, B):
    return(A*B-4.1*A > 2.5*B)

def numexpr_complex_expr(A, B):
    return ne.evaluate('A*B-4.1*A > 2.5*B')

@numba_jit
def numba_complex_expr(A, B):
    return A*B-4.1*A > 2.5*B

@para_jit
def parakeet_complex_expr(A, B):
    return A*B-4.1*A > 2.5*B

I can also capture IPython nb if you want to double check the results on your computer.

If someone wonders if Numba is installed correctly ... I think it performed as expected in my previous test:

enter image description here

+4
1

Numba ( ) ufuncs @jit. , @vectorize :

import numpy as np
from numba import jit, vectorize
import numexpr as ne

def numpy_complex_expr(A, B):
    return(A*B+4.1*A > 2.5*B)

def numexpr_complex_expr(A, B):
    return ne.evaluate('A*B+4.1*A > 2.5*B')

@jit
def numba_complex_expr(A, B):
    return A*B+4.1*A > 2.5*B

@vectorize(['u1(float64, float64)'])
def numba_vec(A,B):
    return A*B+4.1*A > 2.5*B

n = 1000
A = np.random.rand(n,n)
B = np.random.rand(n,n)

:

%timeit numba_complex_expr(A,B)
1 loops, best of 3: 49.8 ms per loop

%timeit numpy_complex_expr(A,B)
10 loops, best of 3: 43.5 ms per loop

%timeit numexpr_complex_expr(A,B)
100 loops, best of 3: 3.08 ms per loop

%timeit numba_vec(A,B)
100 loops, best of 3: 9.8 ms per loop

numba, :

@jit
def numba_unroll2(A, B):
    C = np.empty(A.shape, dtype=np.uint8)
    for i in xrange(A.shape[0]):
        for j in xrange(A.shape[1]):
            C[i,j] = A[i,j]*B[i,j] + 4.1*A[i,j] > 2.5*B[i,j]

    return C

%timeit numba_unroll2(A,B)
100 loops, best of 3: 5.96 ms per loop

, , numexpr 1, , , :

ne.set_num_threads(1)
%timeit numexpr_complex_expr(A,B)
100 loops, best of 3: 8.87 ms per loop

numexpr ne.detect_number_of_cores() . 8.

+5

Source: https://habr.com/ru/post/1541382/


All Articles