diff options
| author | Aaron Meurer <asmeurer@gmail.com> | 2022-03-28 16:12:47 -0600 |
|---|---|---|
| committer | Aaron Meurer <asmeurer@gmail.com> | 2022-03-28 16:12:47 -0600 |
| commit | 7ed0189477ed4a7d2907d0728b3b8121722d8a2f (patch) | |
| tree | e70095408b371e7a81ffe0eced36fffd59aaa778 /numpy/array_api | |
| parent | 71e7620711d6ff8cb838bdffb5e91cdd25497dba (diff) | |
| download | numpy-7ed0189477ed4a7d2907d0728b3b8121722d8a2f.tar.gz | |
Update some Note comments in numpy.array_api
Diffstat (limited to 'numpy/array_api')
| -rw-r--r-- | numpy/array_api/_array_object.py | 5 | ||||
| -rw-r--r-- | numpy/array_api/_data_type_functions.py | 3 |
2 files changed, 7 insertions, 1 deletions
diff --git a/numpy/array_api/_array_object.py b/numpy/array_api/_array_object.py index c86cfb3a6..6cf9ec6f3 100644 --- a/numpy/array_api/_array_object.py +++ b/numpy/array_api/_array_object.py @@ -177,6 +177,8 @@ class Array: integer that is too large to fit in a NumPy integer dtype, or TypeError when the scalar type is incompatible with the dtype of self. """ + # Note: Only Python scalar types that match the array dtype are + # allowed. if isinstance(scalar, bool): if self.dtype not in _boolean_dtypes: raise TypeError( @@ -195,6 +197,9 @@ class Array: else: raise TypeError("'scalar' must be a Python scalar") + # Note: scalars are unconditionally cast to the same dtype as the + # array. + # Note: the spec only specifies integer-dtype/int promotion # behavior for integers within the bounds of the integer dtype. # Outside of those bounds we use the default NumPy behavior (either diff --git a/numpy/array_api/_data_type_functions.py b/numpy/array_api/_data_type_functions.py index 1fb6062f6..7026bd489 100644 --- a/numpy/array_api/_data_type_functions.py +++ b/numpy/array_api/_data_type_functions.py @@ -56,7 +56,8 @@ def can_cast(from_: Union[Dtype, Array], to: Dtype, /) -> bool: raise TypeError(f"{from_=}, but should be an array_api array or dtype") if to not in _all_dtypes: raise TypeError(f"{to=}, but should be a dtype") - # Note: We avoid np.can_cast() as it has discrepancies with the array API. + # Note: We avoid np.can_cast() as it has discrepancies with the array API, + # since NumPy allows cross-kind casting (e.g., NumPy allows bool -> int8). # See https://github.com/numpy/numpy/issues/20870 try: # We promote `from_` and `to` together. We then check if the promoted |
