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