@@ -298,7 +298,7 @@ def append(arr, values, axis=None):
298
298
out : dpnp.ndarray
299
299
A copy of `arr` with `values` appended to `axis`. Note that
300
300
`append` does not occur in-place: a new array is allocated and
301
- filled. If `axis` is None, `out` is a flattened array.
301
+ filled. If `axis` is `` None`` , `out` is a flattened array.
302
302
303
303
See Also
304
304
--------
@@ -343,6 +343,89 @@ def append(arr, values, axis=None):
343
343
return dpnp .concatenate ((arr , values ), axis = axis )
344
344
345
345
346
+ def array_split (ary , indices_or_sections , axis = 0 ):
347
+ """
348
+ Split an array into multiple sub-arrays.
349
+
350
+ Please refer to the :obj:`dpnp.split` documentation. The only difference
351
+ between these functions is that ``dpnp.array_split`` allows
352
+ `indices_or_sections` to be an integer that does *not* equally divide the
353
+ axis. For an array of length l that should be split into n sections, it
354
+ returns ``l % n`` sub-arrays of size ``l//n + 1`` and the rest of size
355
+ ``l//n``.
356
+
357
+ For full documentation refer to :obj:`numpy.array_split`.
358
+
359
+ Parameters
360
+ ----------
361
+ ary : {dpnp.ndarray, usm_ndarray}
362
+ Array to be divided into sub-arrays.
363
+ indices_or_sections : {int, sequence of ints}
364
+ If `indices_or_sections` is an integer, N, and array length is l, it
365
+ returns ``l % n`` sub-arrays of size ``l//n + 1`` and the rest of size
366
+ ``l//n``.
367
+
368
+ If `indices_or_sections` is a sequence of sorted integers, the entries
369
+ indicate where along `axis` the array is split.
370
+ axis : int, optional
371
+ The axis along which to split.
372
+ Default: ``0``.
373
+
374
+ Returns
375
+ -------
376
+ sub-arrays : list of dpnp.ndarray
377
+ A list of sub arrays. Each array is a view of the corresponding input
378
+ array.
379
+
380
+ See Also
381
+ --------
382
+ :obj:`dpnp.split` : Split array into multiple sub-arrays of equal size.
383
+
384
+ Examples
385
+ --------
386
+ >>> import dpnp as np
387
+ >>> x = np.arange(8.0)
388
+ >>> np.array_split(x, 3)
389
+ [array([0., 1., 2.]), array([3., 4., 5.]), array([6., 7.])]
390
+
391
+ >>> x = np.arange(9)
392
+ >>> np.array_split(x, 4)
393
+ [array([0, 1, 2]), array([3, 4]), array([5, 6]), array([7, 8])]
394
+
395
+ """
396
+
397
+ dpnp .check_supported_arrays_type (ary )
398
+ n_tot = ary .shape [axis ]
399
+ try :
400
+ # handle array case.
401
+ n_sec = len (indices_or_sections ) + 1
402
+ div_points = [0 ] + list (indices_or_sections ) + [n_tot ]
403
+ except TypeError :
404
+ # indices_or_sections is a scalar, not an array.
405
+ n_sec = int (indices_or_sections )
406
+ if n_sec <= 0 :
407
+ raise ValueError ("number sections must be larger than 0." ) from None
408
+ n_each_sec , extras = numpy .divmod (n_tot , n_sec )
409
+ section_sizes = (
410
+ [0 ] + extras * [n_each_sec + 1 ] + (n_sec - extras ) * [n_each_sec ]
411
+ )
412
+ div_points = dpnp .array (
413
+ section_sizes ,
414
+ dtype = dpnp .intp ,
415
+ usm_type = ary .usm_type ,
416
+ sycl_queue = ary .sycl_queue ,
417
+ ).cumsum ()
418
+
419
+ sub_arys = []
420
+ sary = dpnp .swapaxes (ary , axis , 0 )
421
+ for i in range (n_sec ):
422
+ st = div_points [i ]
423
+ end = div_points [i + 1 ]
424
+ sub_arys .append (dpnp .swapaxes (sary [st :end ], axis , 0 ))
425
+
426
+ return sub_arys
427
+
428
+
346
429
def asarray_chkfinite (
347
430
a , dtype = None , order = None , * , device = None , usm_type = None , sycl_queue = None
348
431
):
@@ -357,12 +440,12 @@ def asarray_chkfinite(
357
440
Input data, in any form that can be converted to an array. This
358
441
includes lists, lists of tuples, tuples, tuples of tuples, tuples
359
442
of lists and ndarrays. Success requires no NaNs or Infs.
360
- dtype : str or dtype object, optional
443
+ dtype : {None, str, dtype object} , optional
361
444
By default, the data-type is inferred from the input data.
362
- default : ``None``.
363
- order : {"C", "F", "A", "K"}, optional
445
+ Default : ``None``.
446
+ order : {None, "C", "F", "A", "K"}, optional
364
447
Memory layout of the newly output array.
365
- Default: "K".
448
+ Default: `` "K"`` .
366
449
device : {None, string, SyclDevice, SyclQueue}, optional
367
450
An array API concept of device where the output array is created.
368
451
The `device` can be ``None`` (the default), an OneAPI filter selector
@@ -453,89 +536,6 @@ def asarray_chkfinite(
453
536
return a
454
537
455
538
456
- def array_split (ary , indices_or_sections , axis = 0 ):
457
- """
458
- Split an array into multiple sub-arrays.
459
-
460
- Please refer to the :obj:`dpnp.split` documentation. The only difference
461
- between these functions is that ``dpnp.array_split`` allows
462
- `indices_or_sections` to be an integer that does *not* equally divide the
463
- axis. For an array of length l that should be split into n sections, it
464
- returns ``l % n`` sub-arrays of size ``l//n + 1`` and the rest of size
465
- ``l//n``.
466
-
467
- For full documentation refer to :obj:`numpy.array_split`.
468
-
469
- Parameters
470
- ----------
471
- ary : {dpnp.ndarray, usm_ndarray}
472
- Array to be divided into sub-arrays.
473
- indices_or_sections : {int, sequence of ints}
474
- If `indices_or_sections` is an integer, N, and array length is l, it
475
- returns ``l % n`` sub-arrays of size ``l//n + 1`` and the rest of size
476
- ``l//n``.
477
-
478
- If `indices_or_sections` is a sequence of sorted integers, the entries
479
- indicate where along `axis` the array is split.
480
- axis : int, optional
481
- The axis along which to split.
482
- Default: ``0``.
483
-
484
- Returns
485
- -------
486
- sub-arrays : list of dpnp.ndarray
487
- A list of sub arrays. Each array is a view of the corresponding input
488
- array.
489
-
490
- See Also
491
- --------
492
- :obj:`dpnp.split` : Split array into multiple sub-arrays of equal size.
493
-
494
- Examples
495
- --------
496
- >>> import dpnp as np
497
- >>> x = np.arange(8.0)
498
- >>> np.array_split(x, 3)
499
- [array([0., 1., 2.]), array([3., 4., 5.]), array([6., 7.])]
500
-
501
- >>> x = np.arange(9)
502
- >>> np.array_split(x, 4)
503
- [array([0, 1, 2]), array([3, 4]), array([5, 6]), array([7, 8])]
504
-
505
- """
506
-
507
- dpnp .check_supported_arrays_type (ary )
508
- n_tot = ary .shape [axis ]
509
- try :
510
- # handle array case.
511
- n_sec = len (indices_or_sections ) + 1
512
- div_points = [0 ] + list (indices_or_sections ) + [n_tot ]
513
- except TypeError :
514
- # indices_or_sections is a scalar, not an array.
515
- n_sec = int (indices_or_sections )
516
- if n_sec <= 0 :
517
- raise ValueError ("number sections must be larger than 0." ) from None
518
- n_each_sec , extras = numpy .divmod (n_tot , n_sec )
519
- section_sizes = (
520
- [0 ] + extras * [n_each_sec + 1 ] + (n_sec - extras ) * [n_each_sec ]
521
- )
522
- div_points = dpnp .array (
523
- section_sizes ,
524
- dtype = dpnp .intp ,
525
- usm_type = ary .usm_type ,
526
- sycl_queue = ary .sycl_queue ,
527
- ).cumsum ()
528
-
529
- sub_arys = []
530
- sary = dpnp .swapaxes (ary , axis , 0 )
531
- for i in range (n_sec ):
532
- st = div_points [i ]
533
- end = div_points [i + 1 ]
534
- sub_arys .append (dpnp .swapaxes (sary [st :end ], axis , 0 ))
535
-
536
- return sub_arys
537
-
538
-
539
539
def asfarray (a , dtype = None , * , device = None , usm_type = None , sycl_queue = None ):
540
540
"""
541
541
Return an array converted to a float type.
0 commit comments