pymc-devs / pymc-devs/pytensor
Consider adding alternative axis argument to `unpack`
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 644
- Forks
- 208
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 16
Description
Description
unpack is "awkward" in that it design assumes it should come after pack, and tries to work so that the user can pass the same keep_axes argument:
p, shapes = pt.pack(x, y, z, keep_axes=0)
x, y, z = pt.unpack(p, shapes, keep_axes=0)
When pack is used in isolation it still makes sense for the user to specify keep_axes, as those are the ones that must match among different inputs being packed
But when unpack is used in isolation I think it makes less sense. You end up having to specify everything but the axis you want to operate on:
x = pt.tensor("x", shape=(8, 8, 10, 10))
pt.unpack(p, packed_shapes=[(2,), (2, 3)], keep_axes=[0, 2, 3])
If you never meant to pack these inputs (in which case it's nice that you can use the same keep_axes), it's not very ergonomic. It would be more intuitive to specify axis=1?
We don't even have a good default value if the input is >1D, as keep_axes=None could never produce such input. If you call the second example with the default keep_axes it raises.
But axis=0 if axis is None and keep_axes is None would be a reasonable default, and work with both workflows of unpack. I temporarily considered that default but decided to revert until we discuss having an explicit axis argument.
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 by reviewing the pack and unpack entry points and the documented examples showing keep_axes. Determine the intended behavior for standalone unpack and for the pack/unpack workflow, then confirm that the proposed axis behavior is agreed before defining what a completed change should cover.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100