# Why numpy ufunc is much faster?

**URL:** <https://numba.discourse.group/t/why-numpy-ufunc-is-much-faster/2277>\
**Category:** Support: How do I do ...?\
**Created:** [November 16, 2023, 12:01pm UTC](https://numba.discourse.group/t/why-numpy-ufunc-is-much-faster/2277 "2023-11-16T12:01:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mihkorz](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/mihkorz/32/935_2.png) [@Mihkorz](https://numba.discourse.group/u/Mihkorz)\
**Post date:** [November 16, 2023, 12:01pm UTC](https://numba.discourse.group/t/why-numpy-ufunc-is-much-faster/2277/1 "2023-11-16T12:01:32Z")

</div>

Hi all.  
I’m probably doing smth wrong, please help me figure out the root of the problem:

I was trying to apply np.log1p to a 2D array and speed this up with numba, but apparently it got ~2 times slower. Documentation states that numba has support for np.log1p function.  
I suppose that I misuse the ufunc, and will appreciate your help.

```auto
import numpy as np
from numba import jit, vectorize, f8, i8

def numpy_log1p(data):
    return np.log1p(data)

@jit("f8[:,:](i8[:, :])", nopython=True)
def numba_log1p_clean(data):
    return np.log1p(data)

@vectorize("f8(i8)", nopython=True)
def numba_vec_log1p(x):
    return np.log1p(x)

@jit("f8[:,:](i8[:, :])", nopython=True)
def numba_log1p(data):
    res = numba_vec_log1p(data)
    return res

dataX = np.random.randint(100, size=(1000, 20000))

%timeit numpy_log1p(dataX)
# 149 ms ± 4.07 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)

numba_log1p_clean(dataX)
%timeit numba_log1p_clean(dataX)
# 283 ms ± 3.31 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

numba_log1p(dataX)
%timeit numba_log1p(dataX)
# 264 ms ± 15.7 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

```

---

<div class="post-metadata">

**Author:** ![sschaer](https://avatars.discourse-cdn.com/v4/letter/s/5daacb/32.png) [@sschaer](https://numba.discourse.group/u/sschaer)\
**Post date:** [November 16, 2023, 5:03pm UTC](https://numba.discourse.group/t/why-numpy-ufunc-is-much-faster/2277/2 "2023-11-16T17:03:37Z")

</div>

Have you tried not specifying the signature? The point is that by specifying `type[:, :]` you are telling Numba that the array can have any layout. However, it is more efficient to work with contiguous arrays. If you do not specify the signature, Numba will choose the most precise one, which should be a C-contiguous array (`type[:, ::1]`).

Unless you have very good reasons to set the signature manually, I would definitely leave that to Numba.

PS: Your code does not run. You must specify `i4`, not `i8`.
