Thanks a lot. I already stripped down much of libtorch machinery and resorted back to the old plain for loops and got around 3x speed up!
Having that part jit scripted should in theory at least help in performance, as I believe (and expect) the instructions are optimized as well by the engine) at least this is what I hoped for.
I guess I’ll be able to hopefully extract a bit more performance out of it (making it around 4x faster), but thats still no way around the performance I get in Python!
I’m not sure if this is because something is wrong with libtorch’s cartesian_prod implementation that takes too much compared to its counterpart (Python’s product) or some thing else that I’m missing completely. I know the implementation posted above is not efficient by any means, but I really didn’t expect this to be this slow!
To give you an impression, Python code runs around 20,30 ms while this takes around 350!450 ms!
(after my last changes, it now runs at 70~100ms )but still way slower than Python!