Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Split shows up in the graph of Join. It's just a fancy sequence of slice operations.
np.split
is just a thin wrapper that does this:https://github.com/numpy/numpy/blob/e7a123b2d3eca9897843791dd698c1803d9a39c2/numpy/lib/_shape_base_impl.py#L789-L796
If it was not for the possible dynamic axis (which Join also supports) we wouldn't need Split at all.
We may still want it for the second order derivatives of join graphs. The gradient over Split is more clean than the eager gradient over multiple subtensors, it's just the reverse join on the output gradients.
I added a specialization rewrite that converts Split to the respective Subtensor graph. I see speedups in all backends.
The C backend wasn't really capable of returning a view of the inputs, so this optimization avoids as many copies as there are splits:
📚 Documentation preview 📚: https://pytensor--1334.org.readthedocs.build/en/1334/