How to pass string argument to numba njit python function from inside another whilst specifying signature type?

Viewed 324

numba 0.51.2

I'm trying to pass a string argument to a njit function inside another njit function. For example:

import numba as nb    
from numba import njit, types

@njit(nb.void(types.unicode_type))
def bar(string):
    pass

@njit(nb.void(types.unicode_type))
def foo1(string):
    bar(string)

@njit(nb.void(types.unicode_type))
def foo2(string):
    bar("Testing")

I can call foo1("Test") fine, however, foo2("Test") fails with error:

TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Invalid use of type(CPUDispatcher(<function bar at 0x00000258625F0678>)) with parameters (Literal[str](Testing))
Known signatures:
 * (unicode_type,) -> none
 * parameterized
[1] During: resolving callee type: type(CPUDispatcher(<function bar at 0x00000258625F0678>))
[2] During: typing of call at <ipython-input-4-62a1e466b1c1> (14)


File "<ipython-input-4-62a1e466b1c1>", line 14:
def foo2(string):
    bar("Testing")
    ^

I don't have any issues running either function when I try and run the njit function without specifying the signature, however, I intend to use the numba.pycc ahead-of-time compiler which, as far as I'm aware, requires the signatures.

Any help would be greatly appreciated!

Edit - As a work around I've been able to pass the string through by creating a typed.List with signature types.ListType(types.unicode_type) and indexing the first element. Is there a better way?

0 Answers
Related