Missing basic read of write simplification

Open
#2,691 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@aaronanish-t is already working on this.

Since Nov 19, 2026.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
57/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
python

Research direction

The example builds a SetSubtensor followed by Subtensor, but the issue does not name implementation files or tests. Start by searching the indexing rewrite and optimization tests for analogous advanced-index simplifications; confirm how basic slice writes are represented. Done means the shown expression simplifies to the equivalent read from v and a focused test verifies it.

Written by the indexing model from the issue text.

Description

graph rewriting indexing
Description

We likely have something that works for advanced indices already but not for basic ones as in this example.

import pytensor
import pytensor.tensor as pt

x = pt.zeros(4)
v = pt.vector("v", shape=(2,))
y = x[1:3].set(v)[2]  # Equivalent to v[1]

fn = pytensor.function([v], y)
fn.dprint(print_shape=True)
# Subtensor{i} [id A] shape=() 2
#  ├─ SetSubtensor{start:stop} [id B] shape=(4,) 1
#  │  ├─ Alloc [id C] shape=(4,) 0
#  │  │  ├─ 0.0 [id D] shape=()
#  │  │  └─ 4 [id E] shape=()
#  │  ├─ v [id F] shape=(2,)
#  │  ├─ 1 [id G] shape=()
#  │  └─ 3 [id H] shape=()
#  └─ 2 [id I] shape=()
Dominant language
Python
Stars
655
Forks
266
Avg merge
3d 23h
Merged PRs (30d)
43

Getting set up

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.

More from pymc-devs/pytensor

All issues in pymc-devs/pytensor

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.