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