@@ -132,7 +132,7 @@ def zeros_like(a, dtype=None, order='K', subok=True, shape=None):
132132
133133@set_array_function_like_doc
134134@set_module ('numpy' )
135- def ones (shape ,dtype = None ,order = 'C' ,* ,like = None ):
135+ def ones (shape ,dtype = None ,order = 'C' ,* ,device = None , like = None ):
136136"""
137137 Return a new array of given shape and type, filled with ones.
138138
@@ -147,6 +147,10 @@ def ones(shape, dtype=None, order='C', *, like=None):
147147 Whether to store multi-dimensional data in row-major
148148 (C-style) or column-major (Fortran-style) order in
149149 memory.
150+ device : str, optional
151+ The device on which to place the created array. Default: None.
152+
153+ .. versionadded:: 2.0.0
150154 ${ARRAY_FUNCTION_LIKE}
151155
152156 .. versionadded:: 1.20.0
@@ -163,7 +167,6 @@ def ones(shape, dtype=None, order='C', *, like=None):
163167 zeros : Return a new array setting values to zero.
164168 full : Return a new array of given shape filled with value.
165169
166-
167170 Examples
168171 --------
169172 >>> np.ones(5)
@@ -182,6 +185,11 @@ def ones(shape, dtype=None, order='C', *, like=None):
182185 [1., 1.]])
183186
184187 """
188+ if device not in ["cpu" ,None ]:
189+ raise ValueError (
190+ f"Unsupported device:{ device } . Only\" cpu\" is allowed."
191+ )
192+
185193if like is not None :
186194return _ones_with_like (like ,shape ,dtype = dtype ,order = order )
187195
@@ -264,13 +272,15 @@ def ones_like(a, dtype=None, order='K', subok=True, shape=None):
264272return res
265273
266274
267- def _full_dispatcher (shape ,fill_value ,dtype = None ,order = None ,* ,like = None ):
275+ def _full_dispatcher (
276+ shape ,fill_value ,dtype = None ,order = None ,* ,device = None ,like = None
277+ ):
268278return (like ,)
269279
270280
271281@set_array_function_like_doc
272282@set_module ('numpy' )
273- def full (shape ,fill_value ,dtype = None ,order = 'C' ,* ,like = None ):
283+ def full (shape ,fill_value ,dtype = None ,order = 'C' ,* ,device = None , like = None ):
274284"""
275285 Return a new array of given shape and type, filled with `fill_value`.
276286
@@ -286,6 +296,10 @@ def full(shape, fill_value, dtype=None, order='C', *, like=None):
286296 order : {'C', 'F'}, optional
287297 Whether to store multidimensional data in C- or Fortran-contiguous
288298 (row- or column-wise) order in memory.
299+ device : str, optional
300+ The device on which to place the created array. Default: None.
301+
302+ .. versionadded:: 2.0.0
289303 ${ARRAY_FUNCTION_LIKE}
290304
291305 .. versionadded:: 1.20.0
@@ -316,6 +330,11 @@ def full(shape, fill_value, dtype=None, order='C', *, like=None):
316330 [1, 2]])
317331
318332 """
333+ if device not in ["cpu" ,None ]:
334+ raise ValueError (
335+ f"Unsupported device:{ device } . Only\" cpu\" is allowed."
336+ )
337+
319338if like is not None :
320339return _full_with_like (
321340like ,shape ,fill_value ,dtype = dtype ,order = order )
@@ -332,13 +351,17 @@ def full(shape, fill_value, dtype=None, order='C', *, like=None):
332351
333352
334353def _full_like_dispatcher (
335- a ,fill_value ,dtype = None ,order = None ,subok = None ,shape = None
354+ a ,fill_value ,dtype = None ,order = None ,subok = None ,shape = None ,
355+ * ,device = None
336356):
337357return (a ,)
338358
339359
340360@array_function_dispatch (_full_like_dispatcher )
341- def full_like (a ,fill_value ,dtype = None ,order = 'K' ,subok = True ,shape = None ):
361+ def full_like (
362+ a ,fill_value ,dtype = None ,order = 'K' ,subok = True ,shape = None ,
363+ * ,device = None
364+ ):
342365"""
343366 Return a full array with the same shape and type as a given array.
344367
@@ -366,6 +389,10 @@ def full_like(a, fill_value, dtype=None, order='K', subok=True, shape=None):
366389 order='C' is implied.
367390
368391 .. versionadded:: 1.17.0
392+ device : str, optional
393+ The device on which to place the created array. Default: None.
394+
395+ .. versionadded:: 2.0.0
369396
370397 Returns
371398 -------
@@ -402,6 +429,11 @@ def full_like(a, fill_value, dtype=None, order='K', subok=True, shape=None):
402429 [[ 0, 0, 255],
403430 [ 0, 0, 255]]])
404431 """
432+ if device not in ["cpu" ,None ]:
433+ raise ValueError (
434+ f"Unsupported device:{ device } . Only\" cpu\" is allowed."
435+ )
436+
405437res = empty_like (a ,dtype = dtype ,order = order ,subok = subok ,shape = shape )
406438multiarray .copyto (res ,fill_value ,casting = 'unsafe' )
407439return res