pytensor icon indicating copy to clipboard operation
pytensor copied to clipboard

Change behavior of helper set/inc to act on an indexed variable directly

Open ricardoV94 opened this issue 9 months ago • 1 comments

Description

Reverting back to the option first suggested in https://github.com/pymc-devs/pytensor/pull/493 and then overridden in https://github.com/pymc-devs/pytensor/pull/494

The [ ] is the only way that allows for the Python slice : syntax, and cannot be reproduced otherwise. The current helper methods of set/inc require indexes to be passed as a tuple, and so users would need to write x.set((..., slice(None), 0), y) if they wanted a shortcut to pt.set_subtensor(x[..., :, 0], y), at which point the helper ceases to help at all. The reverted API instead looks like x[..., :, 0].set(y)

I still think a helper is useful because it's more discoverable and considerably more succinct than the function alternatives. If people disagree I would instead remove the method helpers altogether.

Related Issue

  • [ ] Closes #
  • [ ] Related to #

Checklist

Type of change

  • [ ] New feature / enhancement
  • [ ] Bug fix
  • [ ] Documentation
  • [x] Maintenance
  • [ ] Other (please specify):

ricardoV94 avatar Apr 25 '24 17:04 ricardoV94

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 80.76%. Comparing base (98070db) to head (f5b76e4).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #730   +/-   ##
=======================================
  Coverage   80.76%   80.76%           
=======================================
  Files         162      162           
  Lines       46715    46715           
  Branches    11427    11427           
=======================================
  Hits        37729    37729           
+ Misses       6736     6733    -3     
- Partials     2250     2253    +3     
Files Coverage Δ
pytensor/tensor/variable.py 87.45% <100.00%> (ø)

... and 3 files with indirect coverage changes

codecov[bot] avatar Apr 25 '24 18:04 codecov[bot]

@lucianopaz gave a very lukewarm nod to this reversion. If people have strong feelings I'm happy to remove the helpers altogether later.

ricardoV94 avatar May 10 '24 10:05 ricardoV94