Signature for ndarray of strings in numba decorator @njit with nopython mode

Viewed 283

I'm trying to use signature for an array of texts in numba decorator @ njit. For example, this no-sense function:

import numpy as np
import numba as nb
@nb.njit(nb.int64
         (nb.types.unicode_type, nb.int8[:], nb.types.unicode_type[:]),
         error_model='numpy')
def foo(paramText, paramArrayOfInts, paramArrayOfTexts):
    print(paramText)
    return 1

a = 'Hello'
b = np.array([1, 2], dtype=np.int8)
c = np.array(['dog', 'cat', 'me'], dtype=np.dtype('U3'))
aNumber = foo(a, b, c)
print(aNumber)

Shows this error:

  File "C:\OSGeo4W64\apps\Python37\Lib\site-packages\numba\dispatcher.py", line 574, in _explain_matching_error
    raise TypeError(msg) TypeError: No matching definition for argument type(s) unicode_type, array(int8, 1d, C), array([unichr x 3], 1d, C)

There is a solution if I insist in using decorators with:

nb.typeof(np.array(['1', '2'], dtype='U3'))

instead of:

nb.types.unicode_type[:]

It works, but is't not what I'm looking for.

Versions: python 3.7 numpy: 1.18.3 numba: 0.48.0

1 Answers
Related