Slicing an array inside a JIT compiled function vs using sliced arrays as inputs to JIT compiled function #18319
-
Hello, I have a function as follows that needs to update the values of
Here I have simplified my original function quite a bit, but the gist is that I have these repeated calls to Since I have O(50) such
and then rewriting the function as follows:
Since the updates happen in a single array-based computation, I figured this would be a more efficient jit-compiled function. But rather this is much slower in the compilation step and seems to crash the Jupyter kernel likely due to memory issues. I suspect the culprit is the slicing of the array Regards, |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
Okay, I found that the problem is only when I use a wrapper function to call the
If I call |
Beta Was this translation helpful? Give feedback.
-
Okay, found the solution, if I define the wrapper function with
But if I just remove
I keep the I am still curios for the explanation behind this, so I will keep the discussion open for now. It is possibly a new update, since I recently upgraded to v0.4.19 from v0.4.6. Also curios as to why the jit-compiled |
Beta Was this translation helpful? Give feedback.
-
I'm not sure offhand what might be causing the slow execution. A minimal reproducible example would help in being able to better answer the question (it's much easier to debug behavior when you can see it yourself!). One possible idea: rather than a |
Beta Was this translation helpful? Give feedback.
Oh I see – the difference is that when you compile
func
, you are passing all the arguments past the first one as arguments to the function, and so they are treated as runtime traced values. When you compilefunc_wrapper
, you are closing over all the variables after the first one, and their global values are stored as numpy arrays, so they are being treated as compile-time constants. This changes the compilation characteristics: in particular the compiler can often specialize execution if a value is a constant, but sometimes this can lead to longer compilation times because the compiler has more flexibility, and more potential optimizations to explore. Does that answer your question?