@@ -237,7 +237,7 @@ def broadcast_to(x, /, shape, subok=False):
237
237
return call_origin (numpy .broadcast_to , x , shape = shape , subok = subok )
238
238
239
239
240
- def concatenate (arrays , * , axis = 0 , out = None , dtype = None , ** kwargs ):
240
+ def concatenate (arrays , / , * , axis = 0 , out = None , dtype = None , ** kwargs ):
241
241
"""
242
242
Join a sequence of arrays along an existing axis.
243
243
@@ -253,8 +253,7 @@ def concatenate(arrays, *, axis=0, out=None, dtype=None, **kwargs):
253
253
Each array in `arrays` is supported as either :class:`dpnp.ndarray`
254
254
or :class:`dpctl.tensor.usm_ndarray`. Otherwise ``TypeError`` exeption
255
255
will be raised.
256
- Parameter `out` is supported with default value.
257
- Parameter `dtype` is supported with default value.
256
+ Parameters `out` and `dtype are supported with default value.
258
257
Keyword argument ``kwargs`` is currently unsupported.
259
258
Otherwise the function will be executed sequentially on CPU.
260
259
@@ -834,15 +833,77 @@ def squeeze(x, /, axis=None):
834
833
return call_origin (numpy .squeeze , x , axis )
835
834
836
835
837
- def stack (arrays , axis = 0 , out = None ):
836
+ def stack (arrays , / , * , axis = 0 , out = None , dtype = None , ** kwargs ):
838
837
"""
839
838
Join a sequence of arrays along a new axis.
840
839
841
840
For full documentation refer to :obj:`numpy.stack`.
842
841
842
+ Returns
843
+ -------
844
+ out : dpnp.ndarray
845
+ The stacked array which has one more dimension than the input arrays.
846
+
847
+ Limitations
848
+ -----------
849
+ Each array in `arrays` is supported as either :class:`dpnp.ndarray`
850
+ or :class:`dpctl.tensor.usm_ndarray`. Otherwise ``TypeError`` exeption
851
+ will be raised.
852
+ Parameters `out` and `dtype are supported with default value.
853
+ Keyword argument ``kwargs`` is currently unsupported.
854
+ Otherwise the function will be executed sequentially on CPU.
855
+
856
+ See Also
857
+ --------
858
+ :obj:`dpnp.concatenate` : Join a sequence of arrays along an existing axis.
859
+ :obj:`dpnp.block` : Assemble an nd-array from nested lists of blocks.
860
+ :obj:`dpnp.split` : Split array into a list of multiple sub-arrays of equal size.
861
+
862
+ Examples
863
+ --------
864
+ >>> import dpnp as np
865
+ >>> arrays = [np.random.randn(3, 4) for _ in range(10)]
866
+ >>> np.stack(arrays, axis=0).shape
867
+ (10, 3, 4)
868
+
869
+ >>> np.stack(arrays, axis=1).shape
870
+ (3, 10, 4)
871
+
872
+ >>> np.stack(arrays, axis=2).shape
873
+ (3, 4, 10)
874
+
875
+ >>> a = np.array([1, 2, 3])
876
+ >>> b = np.array([4, 5, 6])
877
+ >>> np.stack((a, b))
878
+ array([[1, 2, 3],
879
+ [4, 5, 6]])
880
+
881
+ >>> np.stack((a, b), axis=-1)
882
+ array([[1, 4],
883
+ [2, 5],
884
+ [3, 6]])
885
+
843
886
"""
844
887
845
- return call_origin (numpy .stack , arrays , axis , out )
888
+ if kwargs :
889
+ pass
890
+ elif out is not None :
891
+ pass
892
+ elif dtype is not None :
893
+ pass
894
+ else :
895
+ usm_arrays = [dpnp .get_usm_ndarray (x ) for x in arrays ]
896
+ usm_res = dpt .stack (usm_arrays , axis = axis )
897
+ return dpnp_array ._create_from_usm_ndarray (usm_res )
898
+
899
+ return call_origin (
900
+ numpy .stack ,
901
+ arrays ,
902
+ axis = axis ,
903
+ out = out ,
904
+ dtype = dtype ,
905
+ ** kwargs ,
906
+ )
846
907
847
908
848
909
def swapaxes (x1 , axis1 , axis2 ):
0 commit comments