@@ -452,19 +452,29 @@ def concatenate(
452
452
453
453
For full documentation refer to :obj:`numpy.concatenate`.
454
454
455
+ Parameters
456
+ ----------
457
+ arrays : {dpnp.ndarray, usm_ndarray}
458
+ The arrays must have the same shape, except in the dimension corresponding
459
+ to axis (the first, by default).
460
+ axis : int, optional
461
+ The axis along which the arrays will be joined. If axis is None, arrays are
462
+ flattened before use. Default is 0.
463
+ out : dpnp.ndarray, optional
464
+ If provided, the destination to place the result. The shape must be correct,
465
+ matching that of what concatenate would have returned if no out argument were
466
+ specified.
467
+ dtype : str or dtype
468
+ If provided, the destination array will have this dtype. Cannot be provided
469
+ together with out.
470
+ casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional
471
+ Controls what kind of data casting may occur. Defaults to 'same_kind'.
472
+
455
473
Returns
456
474
-------
457
475
out : dpnp.ndarray
458
476
The concatenated array.
459
477
460
- Limitations
461
- -----------
462
- Each array in `arrays` is supported as either :class:`dpnp.ndarray`
463
- or :class:`dpctl.tensor.usm_ndarray`. Otherwise ``TypeError`` exception
464
- will be raised.
465
- Parameters `out` and `dtype` are supported with default value.
466
- Otherwise the function will be executed sequentially on CPU.
467
-
468
478
See Also
469
479
--------
470
480
:obj:`dpnp.array_split` : Split an array into multiple sub-arrays of equal or near-equal size.
@@ -496,25 +506,20 @@ def concatenate(
496
506
497
507
"""
498
508
499
- if out is not None :
500
- pass
501
- elif dtype is not None :
502
- pass
503
- elif casting != "same_kind" :
504
- pass
505
- else :
506
- usm_arrays = [dpnp .get_usm_ndarray (x ) for x in arrays ]
507
- usm_res = dpt .concat (usm_arrays , axis = axis )
508
- return dpnp_array ._create_from_usm_ndarray (usm_res )
509
-
510
- return call_origin (
511
- numpy .concatenate ,
512
- arrays ,
513
- axis = axis ,
514
- out = out ,
515
- dtype = dtype ,
516
- casting = casting ,
517
- )
509
+ if dtype is not None and out is not None :
510
+ raise TypeError (
511
+ "concatenate() only takes `out` or `dtype` as an argument, but both were provided."
512
+ )
513
+
514
+ usm_arrays = [dpnp .get_usm_ndarray (x ) for x in arrays ]
515
+ usm_res = dpt .concat (usm_arrays , axis = axis )
516
+ res = dpnp_array ._create_from_usm_ndarray (usm_res )
517
+ if dtype is not None :
518
+ res = res .astype (dtype , casting = casting , copy = False )
519
+ elif out is not None :
520
+ dpnp .copyto (out , res , casting = casting )
521
+ return out
522
+ return res
518
523
519
524
520
525
def copyto (dst , src , casting = "same_kind" , where = True ):
@@ -868,19 +873,21 @@ def hstack(tup, *, dtype=None, casting="same_kind"):
868
873
869
874
For full documentation refer to :obj:`numpy.hstack`.
870
875
876
+ Parameters
877
+ ----------
878
+ tup : {dpnp.ndarray, usm_ndarray}
879
+ The arrays must have the same shape along all but the second axis,
880
+ except 1-D arrays which can be any length.
881
+ dtype : str or dtype
882
+ If provided, the destination array will have this dtype.
883
+ casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional
884
+ Controls what kind of data casting may occur. Defaults to 'same_kind'.
885
+
871
886
Returns
872
887
-------
873
888
out : dpnp.ndarray
874
889
The stacked array which has one more dimension than the input arrays.
875
890
876
- Limitations
877
- -----------
878
- Each array in `tup` is supported as either :class:`dpnp.ndarray`
879
- or :class:`dpctl.tensor.usm_ndarray`. Otherwise ``TypeError`` exception
880
- will be raised.
881
- Parameters `dtype` and `casting` are supported with default value.
882
- Otherwise the function will be executed sequentially on CPU.
883
-
884
891
See Also
885
892
--------
886
893
:obj:`dpnp.concatenate` : Join a sequence of arrays along an existing axis.
@@ -1357,26 +1364,32 @@ def squeeze(a, /, axis=None):
1357
1364
)
1358
1365
1359
1366
1360
- def stack (arrays , / , * , axis = 0 , out = None , dtype = None , ** kwargs ):
1367
+ def stack (arrays , / , * , axis = 0 , out = None , dtype = None , casting = "same_kind" ):
1361
1368
"""
1362
1369
Join a sequence of arrays along a new axis.
1363
1370
1364
1371
For full documentation refer to :obj:`numpy.stack`.
1365
1372
1373
+ Parameters
1374
+ ----------
1375
+ arrays : {dpnp.ndarray, usm_ndarray}
1376
+ Each array must have the same shape.
1377
+ axis : int, optional
1378
+ The axis in the result array along which the input arrays are stacked.
1379
+ out : dpnp.ndarray, optional
1380
+ If provided, the destination to place the result. The shape must be correct,
1381
+ matching that of what stack would have returned if no out argument were specified.
1382
+ dtype : str or dtype
1383
+ If provided, the destination array will have this dtype. Cannot be provided
1384
+ together with out.
1385
+ casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional
1386
+ Controls what kind of data casting may occur. Defaults to 'same_kind'.
1387
+
1366
1388
Returns
1367
1389
-------
1368
1390
out : dpnp.ndarray
1369
1391
The stacked array which has one more dimension than the input arrays.
1370
1392
1371
- Limitations
1372
- -----------
1373
- Each array in `arrays` is supported as either :class:`dpnp.ndarray`
1374
- or :class:`dpctl.tensor.usm_ndarray`. Otherwise ``TypeError`` exception
1375
- will be raised.
1376
- Parameters `out` and `dtype` are supported with default value.
1377
- Keyword argument `kwargs` is currently unsupported.
1378
- Otherwise the function will be executed sequentially on CPU.
1379
-
1380
1393
See Also
1381
1394
--------
1382
1395
:obj:`dpnp.concatenate` : Join a sequence of arrays along an existing axis.
@@ -1409,25 +1422,20 @@ def stack(arrays, /, *, axis=0, out=None, dtype=None, **kwargs):
1409
1422
1410
1423
"""
1411
1424
1412
- if kwargs :
1413
- pass
1425
+ if dtype is not None and out is not None :
1426
+ raise TypeError (
1427
+ "stack() only takes `out` or `dtype` as an argument, but both were provided."
1428
+ )
1429
+
1430
+ usm_arrays = [dpnp .get_usm_ndarray (x ) for x in arrays ]
1431
+ usm_res = dpt .stack (usm_arrays , axis = axis )
1432
+ res = dpnp_array ._create_from_usm_ndarray (usm_res )
1433
+ if dtype is not None :
1434
+ res = res .astype (dtype , casting = casting , copy = False )
1414
1435
elif out is not None :
1415
- pass
1416
- elif dtype is not None :
1417
- pass
1418
- else :
1419
- usm_arrays = [dpnp .get_usm_ndarray (x ) for x in arrays ]
1420
- usm_res = dpt .stack (usm_arrays , axis = axis )
1421
- return dpnp_array ._create_from_usm_ndarray (usm_res )
1422
-
1423
- return call_origin (
1424
- numpy .stack ,
1425
- arrays ,
1426
- axis = axis ,
1427
- out = out ,
1428
- dtype = dtype ,
1429
- ** kwargs ,
1430
- )
1436
+ dpnp .copyto (out , res , casting = casting )
1437
+ return out
1438
+ return res
1431
1439
1432
1440
1433
1441
def swapaxes (a , axis1 , axis2 ):
@@ -1649,19 +1657,21 @@ def vstack(tup, *, dtype=None, casting="same_kind"):
1649
1657
1650
1658
For full documentation refer to :obj:`numpy.vstack`.
1651
1659
1660
+ Parameters
1661
+ ----------
1662
+ tup : {dpnp.ndarray, usm_ndarray}
1663
+ The arrays must have the same shape along all but the first axis.
1664
+ 1-D arrays must have the same length.
1665
+ dtype : str or dtype
1666
+ If provided, the destination array will have this dtype.
1667
+ casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional
1668
+ Controls what kind of data casting may occur. Defaults to 'same_kind'.
1669
+
1652
1670
Returns
1653
1671
-------
1654
1672
out : dpnp.ndarray
1655
1673
The array formed by stacking the given arrays, will be at least 2-D.
1656
1674
1657
- Limitations
1658
- -----------
1659
- Each array in `tup` is supported as either :class:`dpnp.ndarray`
1660
- or :class:`dpctl.tensor.usm_ndarray`. Otherwise ``TypeError`` exception
1661
- will be raised.
1662
- Parameters `dtype` and `casting` are supported with default value.
1663
- Otherwise the function will be executed sequentially on CPU.
1664
-
1665
1675
See Also
1666
1676
--------
1667
1677
:obj:`dpnp.concatenate` : Join a sequence of arrays along an existing axis.
0 commit comments