pymc-devs / pymc-devs/pytensor

Use `expand_dims` / `squeeze` in JAX implementation of `Dimshuffle`

Open
#847 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

beginner friendly jax
Dominant language
Python
Stars
644
Forks
208
Avg merge
2d 14h
Merged PRs (30d)
16

Description

https://github.com/pymc-devs/pytensor/blob/d3bd1f15a497c05a979a8e3e8be40883f669a0b6/pytensor/link/jax/dispatch/elemwise.py#L72-L89

The JAX docs of lax.reshape (which np.reshape uses) suggest this may be better for further optimizations: https://jax.readthedocs.io/en/latest/_autosummary/jax.lax.reshape.html#jax.lax.reshape

Relevant part:

For inserting/removing dimensions of size 1, prefer using lax.squeeze / lax.expand_dims. These preserve information about axis identity that may be useful for advanced transformation rules.

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 in pytensor/link/jax/dispatch/elemwise.py at lines 72-89, then read the linked JAX lax.reshape documentation and its guidance on lax.squeeze and lax.expand_dims. Done means the JAX implementation of Dimshuffle uses the recommended operations for inserting and removing size-one dimensions, with the existing behavior preserved.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Refactor
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.