pymc-devs / pymc-devs/pytensor

Reshape should take each shape dimension as a separate input

Open
#881 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

maintenance Op implementation
Dominant language
Python
Stars
644
Forks
208
Avg merge
2d 14h
Merged PRs (30d)
16

Description

Description

Reshape has only two inputs, x, and a vector of the output shape. This is cumbersome because many times we want to analyze the individual dimensions to rewrite Reshape as expand_dims or get rid of useless Reshape. Also the Reshape Op needs to be parametrized with the output length, because historically we didn't have static shapes, and couldn't always guess how many entries the shape vector had.

Most times Reshape is used to concatenate dimensions, so we end up with stuff like [x.shape[0], ..., x.shape[n] * x.shape[m], ..., x.shape[-1]], wrapped in a MakeVector. This makes Resahpe rewrites harder because they have to handle the case where things are joined in a MakeVector or may have been constant folded into a single tensor.

https://github.com/pymc-devs/pytensor/blob/bf73f8a06be2adf1d30e4f59e30c2dfa49c5204e/pytensor/tensor/rewriting/shape.py#L921-L926

SpecifyShape already works with a variable number of inputs and we haven't any trouble with it.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the shape rewrite at pytensor/tensor/rewriting/shape.py around lines 921-926, then inspect the existing Reshape and SpecifyShape interfaces. Determine how Reshape can accept separate dimension inputs while preserving an explicit output length, and verify that shape rewrites no longer depend on MakeVector handling.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.