Standardize "pinned" dtype promotions
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- python
- Domain
- documentation
Research direction
Start with the linked specifications for setitem, in-place operators, clip, nextafter, and the dtype promotion page. Compare their current rules with the proposed pinned or bound promotion behavior; done means the general rule and the affected function references clearly define the scalar and mixed-dtype cases.
Written by the indexing model from the issue text.
Description
These functions:
__setitem____iadd__and other in-place operatorsclipnextafter
Have in common that the output dtype must match the dtype of the first parameter. This is unlike most other binary or ternary functions, where all parameters are free to be be promoted against each other.
Q: Are there other such functions?
Beyond this, however, these functions differ substantially in the details:
First parameter is a Python scalar
- in
__setitem__,__iadd__, andclip, the first parameter must be an array. This is an obvious necessity for__setitem__and__iadd__, because it's a method, but not forclip. - in
nextafter, the first parameter can be a Python scalarint | float. The spec is not clear on what must happen in this case; I interpret it as "the output dtype must be the dtype of x if x is an array, otherwise follow the normal dtype promotion rules and return float32 or float64 depending on the dtype of y." It could use an explicit clarification.
Second parameter is an array of different dtype
- In
__setitem__and__iadd__, if the second parameter (value) is an array it can be automatically promoted to the dtype of the first parameter (self). - In
clip, behaviour is undefined. Which to me is weird, because the result would be unambiguous in all cases whereminimumandmaximumare defined and have an output dtype matching the first parameter - for example,clip(int16, min=int8, max=int8). - In
nextafter, behaviour is also undefined, which again to me is weird because it is unambiguous in all cases where__lt__,__gt__, and__eq__are defined; in other wordsnextafter(float64, float32)is unambiguous.
Proposed changes
- Allow
clipto have the first parameter as a Python scalar, like it already happens innextafter - Allow
minandmaxparameters inclipand theyparameter innextafterto be arrays of a dtype promotable tox.dtype, like it already happens in__setitem__ - Add a section to the dtype promotion page for "pinned" or "bound" dtype promotion, defining a general rule
- Have
__setitem__,clip, andnextafterpoint to this general rule
- Dominant language
- Python
- Stars
- 281
- Forks
- 52
- PR merge metrics
- No merged PRs in 30d
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.
More from data-apis/array-api
-
bug Maintenance Narrative Content
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
-
Maintenance
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
All issues in data-apis/array-api
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
anthropics/skills#1811 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
speaches-ai/speaches#678 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
datalayer/mcp-compose#42 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
conda-forge/spacy-feedstock#177 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
UKGovernmentBEIS/inspect_evals#2523 ·