Skip to content

Commit 04e0cb9

Browse files
committed
Update some Note comments in numpy.array_api
Original NumPy Commit: 7ed0189477ed4a7d2907d0728b3b8121722d8a2f
1 parent 45c0c17 commit 04e0cb9

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

array_api_strict/_array_object.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ def _promote_scalar(self, scalar):
177177
integer that is too large to fit in a NumPy integer dtype, or
178178
TypeError when the scalar type is incompatible with the dtype of self.
179179
"""
180+
# Note: Only Python scalar types that match the array dtype are
181+
# allowed.
180182
if isinstance(scalar, bool):
181183
if self.dtype not in _boolean_dtypes:
182184
raise TypeError(
@@ -195,6 +197,9 @@ def _promote_scalar(self, scalar):
195197
else:
196198
raise TypeError("'scalar' must be a Python scalar")
197199

200+
# Note: scalars are unconditionally cast to the same dtype as the
201+
# array.
202+
198203
# Note: the spec only specifies integer-dtype/int promotion
199204
# behavior for integers within the bounds of the integer dtype.
200205
# Outside of those bounds we use the default NumPy behavior (either

array_api_strict/_data_type_functions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ def can_cast(from_: Union[Dtype, Array], to: Dtype, /) -> bool:
5656
raise TypeError(f"{from_=}, but should be an array_api array or dtype")
5757
if to not in _all_dtypes:
5858
raise TypeError(f"{to=}, but should be a dtype")
59-
# Note: We avoid np.can_cast() as it has discrepancies with the array API.
59+
# Note: We avoid np.can_cast() as it has discrepancies with the array API,
60+
# since NumPy allows cross-kind casting (e.g., NumPy allows bool -> int8).
6061
# See https://github.com/numpy/numpy/issues/20870
6162
try:
6263
# We promote `from_` and `to` together. We then check if the promoted

0 commit comments

Comments
 (0)