6464finfo = get_xp (cp )(_aliases .finfo )
6565iinfo = get_xp (cp )(_aliases .iinfo )
6666
67- _copy_default = object ()
68-
6967
7068# asarray also adds the copy keyword, which is not present in numpy 1.0.
7169def asarray (
@@ -79,7 +77,7 @@ def asarray(
7977 * ,
8078 dtype : Optional [DType ] = None ,
8179 device : Optional [Device ] = None ,
82- copy : Optional [bool ] = _copy_default ,
80+ copy : Optional [bool ] = None ,
8381 ** kwargs ,
8482) -> Array :
8583 """
@@ -88,26 +86,14 @@ def asarray(
8886 See the corresponding documentation in the array library and/or the array API
8987 specification for more details.
9088 """
91- with cp .cuda .Device (device ):
92- # cupy is like NumPy 1.26 (except without _CopyMode). See the comments
93- # in asarray in numpy/_aliases.py.
94- if copy is not _copy_default :
95- # A future version of CuPy will change the meaning of copy=False
96- # to mean no-copy. We don't know for certain what version it will
97- # be yet, so to avoid breaking that version, we use a different
98- # default value for copy so asarray(obj) with no copy kwarg will
99- # always do the copy-if-needed behavior.
100-
101- # This will still need to be updated to remove the
102- # NotImplementedError for copy=False, but at least this won't
103- # break the default or existing behavior.
104- if copy is None :
105- copy = False
106- elif copy is False :
107- raise NotImplementedError ("asarray(copy=False) is not yet supported in cupy" )
108- kwargs ['copy' ] = copy
109-
110- return cp .array (obj , dtype = dtype , ** kwargs )
89+ if copy is False :
90+ raise NotImplementedError ("asarray(copy=False) is not yet supported in cupy" )
91+
92+ like = obj if isinstance (obj , cp .ndarray ) else None
93+ if copy is None :
94+ return cp .asarray (obj , dtype = dtype , ** kwargs )
95+ else :
96+ return cp .array (obj , dtype = dtype , copy = True , ** kwargs )
11197
11298
11399def astype (
0 commit comments