# How to register an existing builtin function

**URL:** <https://numba.discourse.group/t/how-to-register-an-existing-builtin-function/350>\
**Category:** Support: How do I do ...?\
**Created:** [November 18, 2020, 12:23pm UTC](https://numba.discourse.group/t/how-to-register-an-existing-builtin-function/350 "2020-11-18T12:23:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rpopovici](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/rpopovici/32/86_2.png) [@rpopovici](https://numba.discourse.group/u/rpopovici)\
**Post date:** [November 18, 2020, 12:23pm UTC](https://numba.discourse.group/t/how-to-register-an-existing-builtin-function/350/1 "2020-11-18T12:23:00Z")

</div>

Let’s say I have a function with the following signature:

```auto
float fractal(vector position, float H , float lacunarity , int octaves, string type)

```

and I want to register this buitin function in order to use it from njit functions  
How do I do that?

---

<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 18, 2020, 12:29pm UTC](https://numba.discourse.group/t/how-to-register-an-existing-builtin-function/350/2 "2020-11-18T12:29:35Z")

</div>

Hi @rpopovici

I’m not quite sure what you are asking. If you have a function `fractal` that is already jit compatible then just `@numba.njit` decorate it? If you are referring to `fractal` as a prototype from an external API and you wish to replicate the functionality with `@jit`, then I suggest using `@numba.extending.overload` [docs are here](https://numba.readthedocs.io/en/stable/extending/high-level.html#implementing-functions) and a [user guide is here](https://numba.readthedocs.io/en/stable/extending/overloading-guide.html).

Hope this helps?

---

<div class="post-metadata">

**Author:** ![rpopovici](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/rpopovici/32/86_2.png) [@rpopovici](https://numba.discourse.group/u/rpopovici)\
**Post date:** [November 18, 2020, 12:59pm UTC](https://numba.discourse.group/t/how-to-register-an-existing-builtin-function/350/3 "2020-11-18T12:59:40Z")

</div>

@stuartarchibald The function is already implemented in C and exported as a builtin for python. Basicaly, I am trying to call this builtin from an njit but I get:

```auto
Untyped global name 'hybrid_multi_fractal': Cannot determine Numba type of <class 'builtin_function_or_method'>

```

---

<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 18, 2020, 1:10pm UTC](https://numba.discourse.group/t/how-to-register-an-existing-builtin-function/350/4 "2020-11-18T13:10:44Z")

</div>

If it’s an exported C symbol then perhaps user Numba’s `ctypes` support. Example of binding to `libm`'s `cos` function.

```auto
In [1]: import ctypes

In [2]: from numba import njit

In [3]: libm = ctypes.CDLL('libm.so')

In [4]: libm.cos.restype = ctypes.c_double # define return type

In [5]: libm.cos.argtypes = (ctypes.c_double,) # define arg type(s)

In [6]: cos_binding = libm.cos # bind directly to the function so that numba can resolve it

In [7]: @njit
   ...: def foo(x):
   ...: return cos_binding(x)
   ...: 

In [8]: cos_binding(3.14159) # Call ctypes binding directly
Out[8]: -0.9999999999964793

In [9]: foo(3.14159) # Call ctypes binding from jit code
Out[9]: -0.9999999999964793

```

If `cython` is used for creating or exporting the function then this might help too: [https://numba.readthedocs.io/en/stable/extending/high-level.html#importing-cython-functions](https://numba.readthedocs.io/en/stable/extending/high-level.html#importing-cython-functions)

---

<div class="post-metadata">

**Author:** ![rpopovici](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/rpopovici/32/86_2.png) [@rpopovici](https://numba.discourse.group/u/rpopovici)\
**Post date:** [November 18, 2020, 5:16pm UTC](https://numba.discourse.group/t/how-to-register-an-existing-builtin-function/350/5 "2020-11-18T17:16:48Z")

</div>

@stuartarchibald that’s the thing. This function is statically linked to the main executable. There is no dll to load with ctypes. I don’t know if it’s possible to convert the imported python wrapper to a ctypes function call…

---

<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 18, 2020, 8:24pm UTC](https://numba.discourse.group/t/how-to-register-an-existing-builtin-function/350/6 "2020-11-18T20:24:02Z")

</div>

Without a library symbol to bind to there’s not a lot of options available for use by python (as a raw function call) or anything else? I suspect it will not be possible to convert the wrapper to a `ctype`s call, the wrapper will expect `PyObject` instances and return the same so it’s not suitable. Options available are to either try and find a way to get hold of that symbol, translate the compiled code into Python and JIT it, or use an [`objmode` block](https://numba.readthedocs.io/en/latest/user/withobjmode.html) and accept the performance penalty for doing so.
