Global constant dictionaries

Hello,

What is the best way to use global constant dictionaries in numba? I know that using a numba typed Dict doesn’t work, because it cannot be made constant, and thus its values cannot be known at the time of computing function closure during compilation.

Similarly, I have seen the existence of LiteralStrKeyDict but it is not obvious if they can be explicitly defined.

It is trivial of course to wrap all constants in a structure and pass it as argument to numba code, but certain projects make heavy use of dictionaries (for example certain properties given a cell type, or simply to store the genetic code) and it is more readable to have those as simply constants.

Many thanks!

You can try following the example here that uses a global dictionary variable _work_registry. It follows, in turn, the approach developed by Daniel Weitekamp here.

1 Like