@@ -417,34 +417,81 @@ def place(x, mask, vals, /):
417
417
return call_origin (numpy .place , x , mask , vals , dpnp_inplace = True )
418
418
419
419
420
- def put (x1 , ind , v , mode = "raise " ):
420
+ def put (a , indices , vals , / , * , axis = None , mode = "wrap " ):
421
421
"""
422
- Replaces specified elements of an array with given values .
422
+ Puts values of an array into another array along a given axis .
423
423
424
424
For full documentation refer to :obj:`numpy.put`.
425
425
426
426
Limitations
427
427
-----------
428
- Input array is supported as :obj:`dpnp.ndarray`.
429
- Not supported parameter mode.
428
+ Parameters `a` and `indices` are supported either as :class:`dpnp.ndarray`
429
+ or :class:`dpctl.tensor.usm_ndarray`.
430
+ Parameter `indices` is supported as 1-D array of integer data type.
431
+ Parameter `vals` must be broadcastable to the shape of `indices`
432
+ and has the same data type as `a` if it is as :class:`dpnp.ndarray`
433
+ or :class:`dpctl.tensor.usm_ndarray`.
434
+ Parameter `mode` is supported with ``wrap``, the default, and ``clip`` values.
435
+ Parameter `axis` is supported as integer only.
436
+ Otherwise the function will be executed sequentially on CPU.
437
+
438
+ See Also
439
+ --------
440
+ :obj:`dpnp.putmask` : Changes elements of an array based on conditional and input values.
441
+ :obj:`dpnp.place` : Change elements of an array based on conditional and input values.
442
+ :obj:`dpnp.put_along_axis` : Put values into the destination array by matching 1d index and data slices.
443
+
444
+ Notes
445
+ -----
446
+ In contrast to :obj:`numpy.put` `wrap` mode which wraps indices around the array for cyclic operations,
447
+ :obj:`dpnp.put` `wrap` mode clamps indices to a fixed range within the array boundaries (-n <= i < n).
448
+
449
+ Examples
450
+ --------
451
+ >>> import dpnp as np
452
+ >>> x = np.arange(5)
453
+ >>> indices = np.array([0, 1])
454
+ >>> np.put(x, indices, [-44, -55])
455
+ >>> x
456
+ array([-44, -55, 2, 3, 4])
457
+
458
+ >>> x = np.arange(5)
459
+ >>> indices = np.array([22])
460
+ >>> np.put(x, indices, -5, mode='clip')
461
+ >>> x
462
+ array([ 0, 1, 2, 3, -5])
463
+
430
464
"""
431
465
432
- x1_desc = dpnp .get_dpnp_descriptor (
433
- x1 , copy_when_strides = False , copy_when_nondefault_queue = False
434
- )
435
- if x1_desc :
436
- if mode != "raise" :
466
+ if dpnp .is_supported_array_type (a ) and dpnp .is_supported_array_type (
467
+ indices
468
+ ):
469
+ if indices .ndim != 1 or not dpnp .issubdtype (
470
+ indices .dtype , dpnp .integer
471
+ ):
437
472
pass
438
- elif type ( ind ) is not type ( v ):
473
+ elif mode not in ( "clip" , "wrap" ):
439
474
pass
440
- elif (
441
- numpy .max (ind ) >= x1_desc .size or numpy .min (ind ) + x1_desc .size < 0
442
- ):
475
+ elif axis is not None and not isinstance (axis , int ):
476
+ raise TypeError (f"`axis` must be of integer type, got { type (axis )} " )
477
+ # TODO: remove when #1382(dpctl) is solved
478
+ elif dpnp .is_supported_array_type (vals ) and a .dtype != vals .dtype :
443
479
pass
444
480
else :
445
- return dpnp_put (x1_desc , ind , v )
481
+ if axis is None and a .ndim > 1 :
482
+ a = dpnp .reshape (a , - 1 )
483
+ dpt_array = dpnp .get_usm_ndarray (a )
484
+ dpt_indices = dpnp .get_usm_ndarray (indices )
485
+ dpt_vals = (
486
+ dpnp .get_usm_ndarray (vals )
487
+ if isinstance (vals , dpnp_array )
488
+ else vals
489
+ )
490
+ return dpt .put (
491
+ dpt_array , dpt_indices , dpt_vals , axis = axis , mode = mode
492
+ )
446
493
447
- return call_origin (numpy .put , x1 , ind , v , mode , dpnp_inplace = True )
494
+ return call_origin (numpy .put , a , indices , vals , mode , dpnp_inplace = True )
448
495
449
496
450
497
def put_along_axis (x1 , indices , values , axis ):
@@ -557,7 +604,7 @@ def take(x, indices, /, *, axis=None, out=None, mode="wrap"):
557
604
or :class:`dpctl.tensor.usm_ndarray`.
558
605
Parameter `indices` is supported as 1-D array of integer data type.
559
606
Parameter `out` is supported only with default value.
560
- Parameter `mode` is supported with ``wrap``( default) and ``clip`` mode .
607
+ Parameter `mode` is supported with ``wrap``, the default, and ``clip`` values .
561
608
Providing parameter `axis` is optional when `x` is a 1-D array.
562
609
Otherwise the function will be executed sequentially on CPU.
563
610
0 commit comments