diff options
author | Matti Picus <matti.picus@gmail.com> | 2021-11-15 10:26:04 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-15 10:26:04 +0200 |
commit | 7125cdfa21081b91907a65b6c888791cf150a0b2 (patch) | |
tree | 657688524789231600c21a3ae86157628ce7ea26 /numpy/array_api/_creation_functions.py | |
parent | a1813504ad44b70fb139181a9df8465bcb22e24d (diff) | |
parent | f058aea694327b517eb5c3d786c7f6a3e9c9898d (diff) | |
download | numpy-7125cdfa21081b91907a65b6c888791cf150a0b2.tar.gz |
Merge pull request #19173 from czgdp1807/never_copy
ENH: Add support for copy modes to NumPy
Diffstat (limited to 'numpy/array_api/_creation_functions.py')
-rw-r--r-- | numpy/array_api/_creation_functions.py | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/numpy/array_api/_creation_functions.py b/numpy/array_api/_creation_functions.py index 23beec444..741498ff6 100644 --- a/numpy/array_api/_creation_functions.py +++ b/numpy/array_api/_creation_functions.py @@ -41,7 +41,7 @@ def asarray( *, dtype: Optional[Dtype] = None, device: Optional[Device] = None, - copy: Optional[bool] = None, + copy: Optional[Union[bool, np._CopyMode]] = None, ) -> Array: """ Array API compatible wrapper for :py:func:`np.asarray <numpy.asarray>`. @@ -55,13 +55,13 @@ def asarray( _check_valid_dtype(dtype) if device not in ["cpu", None]: raise ValueError(f"Unsupported device {device!r}") - if copy is False: + if copy in (False, np._CopyMode.IF_NEEDED): # Note: copy=False is not yet implemented in np.asarray raise NotImplementedError("copy=False is not yet implemented") if isinstance(obj, Array): if dtype is not None and obj.dtype != dtype: copy = True - if copy is True: + if copy in (True, np._CopyMode.ALWAYS): return Array._new(np.array(obj._array, copy=True, dtype=dtype)) return obj if dtype is None and isinstance(obj, int) and (obj > 2 ** 64 or obj < -(2 ** 63)): |