# Numba typed lists with homogeneous-signature functions

**URL:** <https://numba.discourse.group/t/numba-typed-lists-with-homogeneous-signature-functions/1322>\
**Category:** Support: How do I do ...?\
**Created:** [April 27, 2022, 6:52am UTC](https://numba.discourse.group/t/numba-typed-lists-with-homogeneous-signature-functions/1322 "2022-04-27T06:52:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![7vn](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/7vn/32/587_2.png) [@7vn](https://numba.discourse.group/u/7vn)\
**Post date:** [April 27, 2022, 6:52am UTC](https://numba.discourse.group/t/numba-typed-lists-with-homogeneous-signature-functions/1322/1 "2022-04-27T06:52:48Z")

</div>

I have some numba-jitted event functions with equal signature, i.e.:

```python
from numba import jit

@jit("Tuple((float64,float64))(float64[::1])", nopython=True)
def event_1(y): 
    return 1.1, 1.2 # (random values for this example)

@jit("Tuple((float64,float64))(float64[::1])", nopython=True)
def event_2(y): 
    return 2.1, 2.2 # (random values for this example)

```

My goal is to create a jitted-function which returns a List of event functions. The event\_handler output is supposed to be the input of another cache-compiled jitted-function and so its signature must be fixed:

```python
from numba.typed import List
@jit("ListType(FunctionType(Tuple((float64, float64))(float64[::1])))()", nopython=True)
def event_handler(): 
    return List([event_1, event_2])

```

However, the code above only works if the List returned by `event_handler` has at least two different event functions. If the List has only 1 event-function item, or multiple items of the same function (e.g., either `List([event_1])` or `List([event_1, event_1])` ), the code above cannot compile and produces the following error:

```auto
No conversion from ListType[type(CPUDispatcher(<function event_1 at 0x7f83c2a22430>))] to ListType[FunctionType[UniTuple(float64 x 2)(array(float64, 1d, C))]]

```

I believe the reason is because in the latter case the List item-type is set equal to the function CPUDispatcher rather than the typed function signature. I’ve already tried the solution in the topic named “_typed list of jitted functions in jitclass_” (I am unable to add links) to initialise the list but unfortunately it does not work when the list is passed from one function to another.

How can I solve this issue? It seems strange to me that the list type is inferred correctly when two different functions are provided but suddendly inherits a `CPUDispatcher` type whenever a single item is given.

---

<div class="post-metadata">

**Author:** ![nelson2005](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/nelson2005/32/47_2.png) [@nelson2005](https://numba.discourse.group/u/nelson2005)\
**Post date:** [April 28, 2022, 2:57am UTC](https://numba.discourse.group/t/numba-typed-lists-with-homogeneous-signature-functions/1322/2 "2022-04-28T02:57:53Z")

</div>

Does [this](https://numba.discourse.group/t/constructing-typed-list-slow/1301) example with explicit typing help work around the problem at all?

---

<div class="post-metadata">

**Author:** ![7vn](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/7vn/32/587_2.png) [@7vn](https://numba.discourse.group/u/7vn)\
**Post date:** [April 28, 2022, 12:50pm UTC](https://numba.discourse.group/t/numba-typed-lists-with-homogeneous-signature-functions/1322/4 "2022-04-28T12:50:11Z")

</div>

Actually, it did help solve the problem, thank you!  
I’m posting here the solution for anyone who stumbles upon the same issue. With reference to my original post, I can initialize the List with the `empty_list` method, passing as argument its signature (defined outside the scope of any jitted function):

```python
from numba import types
from numba.typed import List

vector_sig = types.Array(dtype=types.float64, ndim=1, layout="C")
function_sig = types.FunctionType(types.Tuple((types.float64, types.float64))(vector_sig))

@jit("ListType(FunctionType(Tuple((float64, float64))(float64[::1])))()", nopython=True)
def event_handler(): 
    event_list = List.empty_list(function_sig)
    event_list.append(event_1)
    return event_list

```
