# Check if a function is jitted

**URL:** <https://numba.discourse.group/t/check-if-a-function-is-jitted/337>\
**Category:** Support: How do I do ...?\
**Created:** [November 12, 2020, 4:35am UTC](https://numba.discourse.group/t/check-if-a-function-is-jitted/337 "2020-11-12T04:35:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hgrecco](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/hgrecco/32/132_2.png) [@hgrecco](https://numba.discourse.group/u/hgrecco)\
**Post date:** [November 12, 2020, 4:35am UTC](https://numba.discourse.group/t/check-if-a-function-is-jitted/337/1 "2020-11-12T04:35:39Z")

</div>

I am currently doing `hasattr(func, "inspect_llvm")` to find out is a function is jitted. It works but …

1. What is the recommended way to do it?
2. And to check if was jitted in `object` or `nopython` mode?

---

<div class="post-metadata">

**Author:** ![esc](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/esc/32/49_2.png) [@esc](https://numba.discourse.group/u/esc)\
**Post date:** [November 12, 2020, 1:42pm UTC](https://numba.discourse.group/t/check-if-a-function-is-jitted/337/2 "2020-11-12T13:42:38Z")

</div>

Perhaps you could use the `signatures` attribute of the dispatcher:

```auto
In [1]: import numba as nb

In [2]: @nb.njit
   ...: def foo():
   ...: acc = 0
   ...: for i in range(100):
   ...: acc += i
   ...: return acc
   ...:

In [3]: foo
Out[3]: CPUDispatcher(<function foo at 0x7fbf7572ab80>)

In [4]: foo.signatures
Out[4]: []

In [5]: foo()
Out[5]: 4950

In [6]: foo.signatures
Out[6]: [()]

```

---

<div class="post-metadata">

**Author:** ![esc](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/esc/32/49_2.png) [@esc](https://numba.discourse.group/u/esc)\
**Post date:** [November 12, 2020, 2:08pm UTC](https://numba.discourse.group/t/check-if-a-function-is-jitted/337/3 "2020-11-12T14:08:22Z")

</div>

Or maybe this is even better: [https://github.com/numba/numba/blob/master/numba/core/extending.py#L526](https://github.com/numba/numba/blob/master/numba/core/extending.py#L526)

---

<div class="post-metadata">

**Author:** ![hgrecco](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/hgrecco/32/132_2.png) [@hgrecco](https://numba.discourse.group/u/hgrecco)\
**Post date:** [November 13, 2020, 2:09pm UTC](https://numba.discourse.group/t/check-if-a-function-is-jitted/337/4 "2020-11-13T14:09:37Z")

</div>

Thanks @esc I was not aware of this. Do you know if there is a way to distinguish between jitted and nijitted functions?

---

<div class="post-metadata">

**Author:** ![stuartarchibald](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/stuartarchibald/32/10_2.png) [@stuartarchibald](https://numba.discourse.group/u/stuartarchibald)\
**Post date:** [November 13, 2020, 2:33pm UTC](https://numba.discourse.group/t/check-if-a-function-is-jitted/337/5 "2020-11-13T14:33:39Z")

</div>

> [@esc](#):
>
> Or maybe this is even better: [https://github.com/numba/numba/blob/master/numba/core/extending.py#L526](https://github.com/numba/numba/blob/master/numba/core/extending.py#L526)

This is now documented: [Document numba.extending.is\_jitted by stuartarchibald · Pull Request #6472 · numba/numba · GitHub](https://github.com/numba/numba/pull/6472)

RE: differentiating between `nopython` vs “some sort of jit”, there’s two attributes on the dispatcher object:

1. `signatures` which is a list of all compiled signatures
2. `nopython_signatures` which is a list of `nopython` mode compiled signatures.

Small demo:

```pycon
In [1]: from numba import jit

In [2]: @jit
   ...: def foo(x):
   ...: if x.ndim == 1:
   ...: object()
   ...: return 10
   ...: else:
   ...: return 4
   ...: 

In [3]: import numpy as np

In [4]: a = np.array([1])

In [5]: foo(a)
<ipython-input-2-bd094eb34546>:1: NumbaWarning: 
Compilation is falling back to object mode WITH looplifting enabled because Function "foo" failed type inference due to: Untyped global name 'object': cannot determine Numba type of <class 'type'>

File "<ipython-input-2-bd094eb34546>", line 4:
def foo(x):
    <source elided>
    if x.ndim == 1:
        object()
        ^

  @jit
<path>/numba/core/object_mode_passes.py:178: NumbaWarning: Function "foo" was compiled in object mode without forceobj=True.

File "<ipython-input-2-bd094eb34546>", line 2:
@jit
def foo(x):
^

  state.func_ir.loc))
<path>/numba/core/object_mode_passes.py:188: NumbaDeprecationWarning: 
Fall-back from the nopython compilation path to the object mode compilation path has been detected, this is deprecated behaviour.

For more information visit http://numba.pydata.org/numba-doc/latest/reference/deprecation.html#deprecation-of-object-mode-fall-back-behaviour-when-using-jit

File "<ipython-input-2-bd094eb34546>", line 2:
@jit
def foo(x):
^

  state.func_ir.loc))
Out[5]: 10

In [6]: b = np.array([[1]])

In [7]: foo(b)
Out[7]: 4

In [8]: foo.signatures
Out[8]: [(array(int64, 1d, C),), (array(int64, 2d, C),)]

In [9]: foo.nopython_signatures
Out[9]: [(array(int64, 2d, C),) -> Literal[int](4)]

```
