pymc-devs / pymc-devs/pytensor

Rewrite homogenous repeat vector

Open
#1,620 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

graph rewriting performance
Dominant language
Python
Stars
644
Forks
208
Avg merge
2d 14h
Merged PRs (30d)
16

Description

Description

If the number of repetitions in pt.repeat is homogeneous, we could replace it by repeat(x, unique_value). Under the hood this ends up as an alloc, skipping the non-C Op altogether

import numpy as np

x = np.arange(600)
r1 = np.array(2, dtype=int)
r2 = np.array([2] * 600, dtype=int)
np.testing.assert_allclose(np.repeat(x, r1), np.repeat(x, r2))
%timeit np.repeat(x, r1)  # 1.32 μs ± 3.21 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)
%timeit np.repeat(x, r2)  # 1.85 μs ± 3.69 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)

Not a high priority issue

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 at the pt.repeat entry point and compare the homogeneous repetition case with the scalar repeat path shown in the issue. Confirm the optimization preserves np.repeat equivalence for scalar and length-600 repetition inputs, and verify that the non-C Op is skipped as intended.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
performance
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.