pymc-devs / pymc-devs/pytensor
ENH: allow val argument in fill_diagonal to be array-valued
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 644
- Forks
- 208
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 16
Description
Before
Currently the val argument in fill_diagonal only accepts scalar values:
fill_diagonal(a, val)
For example,
fill_diagonal(pt.ones(5), 3)
will fill the diagonal element with 3.
After
This function should be allowed to set different values for each diagonal element, for example:
fill_diagonal(pt.ones(5), np.arange(5))
Context for the issue:
In the context of covariance matrices, one may want to set diagonal elements to different values for each component of a multivariate normal, for example.
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 in pytensor/tensor/extra_ops.py at fill_diagonal, specifically the linked lines 952-982, and inspect its current scalar-value handling. Confirm the change with the shown np.arange(5) example; done means distinct array values populate the diagonal while scalar behavior remains supported.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, python
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100