# How to specify the type signature of funtion pointers to jitclass member function

**URL:** <https://numba.discourse.group/t/how-to-specify-the-type-signature-of-funtion-pointers-to-jitclass-member-function/2181>\
**Category:** Support: How do I do ...?\
**Created:** [October 3, 2023, 3:40am UTC](https://numba.discourse.group/t/how-to-specify-the-type-signature-of-funtion-pointers-to-jitclass-member-function/2181 "2023-10-03T03:40:44Z")\
**Posts on this page:** 1\
**Showing post:** 11

<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:** [October 6, 2023, 7:13am UTC](https://numba.discourse.group/t/how-to-specify-the-type-signature-of-funtion-pointers-to-jitclass-member-function/2181/11 "2023-10-06T07:13:59Z")

</div>

It depends. How important is caching and short compilation time for you? If it’s not of high priority, you can use something like this without sacrificing performance:

```auto
import numba as nb 
import numpy as np 

@nb.njit
def kernel_linear(x1, x2):
    s = 0
    for i in range(x1.shape[0]):
        s += (x1[i] * x2[i])
    return s

@nb.njit
def kernel_rbf(x1, x2, gamma):
    s = 0
    for i in range(x1.shape[0]):
        s += (x1[i] - x2[i]) ** 2
    return np.exp(-gamma * s)

@nb.njit
def test(x, kernel_func, *kernel_params):
    out = np.empty(x.shape[0], x.dtype)
    for i in range(x.shape[0]):
        for j in range(x.shape[0]):
            out[i] = kernel_func(x[i], x[j], *kernel_params)
    return out

x = np.random.rand(5_000, 3)

test(x, kernel_linear)
test(x, kernel_rbf, 1.0)

```

I just checked, and we discussed the pros and cons of various alternatives for such problems in the thread I posted above:

> [@Any numba equivalent for casting a raw pointer to a StructRef, Dict, List etc?](https://numba.discourse.group/t/any-numba-equivalent-for-casting-a-raw-pointer-to-a-structref-dict-list-etc/351/25):
>
> Dear @DannyWeitekamp First of all, thank you for sharing so much of your experience. That’s very valuable knowledge to me and likey many others too. I have used a similar implementation to store a set of callbacks in an array to then call them repeatedly in a loop. And from a performance standpoint, there is a difference between retrieving a function from its address and passing the function directly. The main differences I noticed were: Calling a jitted function that takes another jitted fu…

---

_[View the full topic](https://numba.discourse.group/t/how-to-specify-the-type-signature-of-funtion-pointers-to-jitclass-member-function/2181)._
