Hacktoberfest 2026 : les issues que les mainteneurs ont marquées pour octobre, ouvertes et accessibles aux débutants. Parcourir les issues Hacktoberfest

Standardize "pinned" dtype promotions

Ouverte
#927 3 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
5/5
Temps estimé
Plus d'une semaine
Accessibilité débutants
35/100
Type d'issue
Fonctionnalité
Clarté
Plutôt claire
Activité
À l'abandon
Stack technique
python
Domaine
documentation

Piste de recherche

Commencez par les spécifications liées de setitem, des opérateurs in-place, de clip, de nextafter et la page sur dtype promotion. Comparez leurs règles actuelles avec le comportement de promotion fixé ou borné proposé ; le travail est considéré comme terminé lorsque la règle générale et les références aux fonctions concernées définissent clairement les cas scalaires et les cas de dtypes mixtes.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

These functions:

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__, and clip, the first parameter must be an array. This is an obvious necessity for __setitem__ and __iadd__, because it's a method, but not for clip.
  • in nextafter, the first parameter can be a Python scalar int | 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 where minimum and maximum are 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 words nextafter(float64, float32) is unambiguous.

Proposed changes

  • Allow clip to have the first parameter as a Python scalar, like it already happens in nextafter
  • Allow min and max parameters in clip and the y parameter in nextafter to be arrays of a dtype promotable to x.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, and nextafter point to this general rule
Langage dominant
Python
Étoiles
282
Forks
52
Métriques de merge des PR
Aucune PR mergée en 30 j

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de data-apis/array-api

Toutes les issues de data-apis/array-api

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.