pymc-devs / pymc-devs/pytensor
Simplify dots with 1
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 644
- Forks
- 208
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 16
Description
Description
We have a local_0_dot_x that removes useless dots with zero'd inputs. We don't seem to have anything for dots with ones as reported in https://github.com/pymc-devs/pytensor/discussions/637#discussioncomment-8405862
import pytensor
import pytensor.tensor as pt
from pytensor.compile.mode import get_default_mode
x = tn.col('x')
f = x @ [[1.]]
with pytensor.config.change_flags(optimizer_verbose=True):
fn = pytensor.function([x], f, mode=get_default_mode().excluding("BlasOpt"))
pytensor.dprint(fn)
dot [id A] 0
├─ x [id B]
└─ [[1.]] [id C]
I excluded the BlasOpt just to have a simpler graph, but it will still not rewrite it away with those, just add the more complex Blas Op.
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 with the existing zero-input dot rewrite in pytensor/tensor/rewriting/math.py at the linked section, then run the reproduction using x @ [[1.]] with BlasOpt excluded. Done means the resulting graph no longer contains the redundant dot operation for one-valued inputs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- performance
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 43/100