Only return the same array in asarray if the dtype is the same
@@ -21,7 +21,7 @@ def asarray(obj: Union[float, NestedSequence[bool|int|float], SupportsDLPack, Su
if copy is not None:
# Note: copy is not yet implemented in np.asarray
raise NotImplementedError("The copy keyword argument to asarray is not yet implemented")
- if isinstance(obj, ndarray):
+ if isinstance(obj, ndarray) and (dtype is None or obj.dtype == dtype):
return obj
res = np.asarray(obj, dtype=dtype)
if res.dtype not in _all_dtypes:
