pymc-devs / pymc-devs/pytensor
Useless `dimshuffle("x","x")`
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 644
- Forks
- 208
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 16
Description
Description
import pytensor
import pytensor.tensor as pt
x = pt.tensor("x", shape=(None, None))
y = x.dimshuffle("x", "x")
pytensor.function([x], y).dprint()
# DeepCopyOp [id A] 1
# └─ DimShuffle{order=[x,x]} [id B] 0
# └─ x [id C]
Whenever a DimShuffle only has x and it has as many entries as the inputs, it's basically a specify_shape(x, (1,) * x.type.ndim). If the dimensions were known to be length1, the DimShuffle would be removed correctly
This is a low priority one since the DimShuffle is little more expensive than the specify_shape
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the Python reproducer in the issue and inspecting the DimShuffle optimization entry point. Trace the case where the order contains only "x" and matches the input dimensionality. Done means the graph uses the specified-shape form instead of retaining the redundant DimShuffle, with the existing known-length-one behavior preserved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers, performance
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100