Sometimes Advanced Indexing is Slow

I found that sometimes index_select is much faster than advanced indexing. For a toy example it is 10x faster. Checking with the profiler reveals that many more ops are used for advanced indexing, whereas index_select is a single op.

Is this behavior intentional? Could advanced indexing easily check if it can use index_select instead? I imagine quite a few projects could benefit from using index_select.

Here’s the behavior reproduced on CPU:

Note: I somewhat recall that index_select required more memory than advanced indexing, which is what leads me to believe that this isn’t really a bug and there are cases where advanced indexing makes sense to use (maybe when you are indexing many dimensions simultaneously).

2 Likes