I am currently trying to use numba to speed up a calculation for me where a TypedDict stores either 1 tuple w/ 2 float64 or array w/ 2 float64. At some point, I look up in the typedDict to see if a key exists - if it does not, I have it return the default (-1.0, -2.0)
I have the njit functions as mentioned below. If I return the vp_item
from the Numba function, I can access all of the values. However, I can't seem to access any of the tuple values inside of the Numba function.
import numba as nb
# Must declare return outside
njit_float_array = nb.types.Tuple([nb.core.types.float64, nb.core.types.float64])
@jit( nopython=True)
def test(price):
vp = nb.typed.Dict.empty(
key_type=nb.core.types.int64,
value_type=njit_float_array
)
vp_item = vp.get(0, (-1.0, -2.0))
vp_item[0] = vp_item[0] + 1.0
return vp_item
This produces the error:
numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
No implementation of function Function(<built-in function setitem>) found for signature:
>>> setitem(OptionalType(UniTuple(float64 x 2)), Literal[int](0), float64)
There are 16 candidate implementations:
- Of which 16 did not match due to:
Overload of function 'setitem': File: <numerous>: Line N/A.
With argument(s): '(OptionalType(UniTuple(float64 x 2)), int64, float64)':
No match.
During: typing of staticsetitem at numba-test.py (34)
File "processor/2024/numba-test.py", line 34:
def test(price):
<source elided>
vp_item = vp.get(0, (-1.0, -2.0))
vp_item[0] = vp_item[0] + 1.0
^
Is there some other way I should define the value of this typed_dict? The error message is confusing me.
Thank you!