@@ -512,3 +512,51 @@ def arange(
512
512
hev , _ = ti ._linspace_step (start , _step , res , sycl_queue )
513
513
hev .wait ()
514
514
return res
515
+
516
+
517
+ def zeros (
518
+ sh , dtype = "f8" , order = "C" , device = None , usm_type = "device" , sycl_queue = None
519
+ ):
520
+ """
521
+ Creates `usm_ndarray` with zero elements.
522
+
523
+ Args:
524
+ shape (tuple): Dimensions of the array to be created.
525
+ dtype (optional): data type of the array. Can be typestring,
526
+ a `numpy.dtype` object, `numpy` char string, or a numpy
527
+ scalar type. Default: "f8"
528
+ order ("C", or F"): memory layout for the array. Default: "C"
529
+ device (optional): array API concept of device where the output array
530
+ is created. `device` can be `None`, a oneAPI filter selector string,
531
+ an instance of :class:`dpctl.SyclDevice` corresponding to a
532
+ non-partitioned SYCL device, an instance of
533
+ :class:`dpctl.SyclQueue`, or a `Device` object returnedby
534
+ `dpctl.tensor.usm_array.device`. Default: `None`.
535
+ usm_type ("device"|"shared"|"host", optional): The type of SYCL USM
536
+ allocation for the output array. Default: `"device"`.
537
+ sycl_queue (:class:`dpctl.SyclQueue`, optional): The SYCL queue to use
538
+ for output array allocation and copying. `sycl_queue` and `device`
539
+ are exclusive keywords, i.e. use one or another. If both are
540
+ specified, a `TypeError` is raised unless both imply the same
541
+ underlying SYCL queue to be used. If both a `None`, the
542
+ `dpctl.SyclQueue()` is used for allocation and copying.
543
+ Default: `None`.
544
+ """
545
+ dtype = np .dtype (dtype )
546
+ if not isinstance (order , str ) or len (order ) == 0 or order [0 ] not in "CcFf" :
547
+ raise ValueError (
548
+ "Unrecognized order keyword value, expecting 'F' or 'C'."
549
+ )
550
+ else :
551
+ order = order [0 ].upper ()
552
+ dpctl .utils .validate_usm_type (usm_type , allow_none = False )
553
+ sycl_queue = normalize_queue_device (sycl_queue = sycl_queue , device = device )
554
+ res = dpt .usm_ndarray (
555
+ sh ,
556
+ dtype = dtype ,
557
+ buffer = usm_type ,
558
+ order = order ,
559
+ buffer_ctor_kwargs = {"queue" : sycl_queue },
560
+ )
561
+ res .usm_data .memset ()
562
+ return res
0 commit comments