A python dictionary all_bars[x] = foo(x)
gets you value specialization, even if it’s partially outside jitted code
This is what I have been doing so far as a workaround. Not optimal as it requires either to pass arguments that matter™ to an init function in Pythonland to generate the right specialisations or you have to hardcode those.
To give you an idea of why hardcoding is not appealing to me, if interested... click here
I’m writing a small library to perform a specific analysis on density maps. Those maps can be of any dimension (1D, 2D, 3D, 100D, etc.) however for any specific application, people will use a single dimension (or very few of them). Like, I use mainly 3D and, for a very weird reason, 11D. So the number of specialisations is not expected to explode but having to hardcode them prior to using them is a major thorn on my side.
All is good when I use the density map itself: ndim
is enough and can be passed around as a Literal
. However some functions, used in other contexts, expect an array of shape (N, ndim)
or (N, ndim, ndim)
and so far I have resorted to pass around ndim
as a Literal
or the original density map itself (but just for the type information which looks a bit nuts).
in theory generated_jit
plus literal types could produce a form of value specialization, right?
If you use literally
, yes because any unspecialised implementation would raise an error, forcing the compiler to become more specific.
otherwise compilation time would explode.
I am very aware of that.
(see justification above)
Now I was just thinking, is there a way to force specific unboxing/boxing processes when jitting besides wrapping my native python types into specialised ones?
I saw the Array
subclassing tutorial in numba-examples
. Would be neat to be able to tell jit
to unbox an input array into MyArrayType
and to box it into a normal array once it gets back to Pythonland (or continue using MyArrayType
as long as it stays in Numbaland).
I believe this would provide just enough flexibility without making it worse for everyone by default. (talking about arrays but could be applied to anything, now that it’s documented)