85
85
]
86
86
87
87
88
+ def _check_stack_arrays (arrays ):
89
+ """Validate a sequence type of arrays to stack."""
90
+
91
+ if not hasattr (arrays , "__getitem__" ):
92
+ raise TypeError (
93
+ 'arrays to stack must be passed as a "sequence" type '
94
+ "such as list or tuple."
95
+ )
96
+
97
+
88
98
def asfarray (a , dtype = None , * , device = None , usm_type = None , sycl_queue = None ):
89
99
"""
90
100
Return an array converted to a float type.
@@ -551,6 +561,8 @@ def column_stack(tup):
551
561
552
562
"""
553
563
564
+ _check_stack_arrays (tup )
565
+
554
566
arrays = []
555
567
for v in tup :
556
568
dpnp .check_supported_arrays_type (v )
@@ -563,7 +575,7 @@ def column_stack(tup):
563
575
)
564
576
565
577
arrays .append (v )
566
- return dpnp .concatenate (arrays , 1 )
578
+ return dpnp .concatenate (arrays , axis = 1 )
567
579
568
580
569
581
def concatenate (
@@ -778,6 +790,8 @@ def dstack(tup):
778
790
779
791
"""
780
792
793
+ _check_stack_arrays (tup )
794
+
781
795
arrs = atleast_3d (* tup )
782
796
if not isinstance (arrs , list ):
783
797
arrs = [arrs ]
@@ -1078,27 +1092,26 @@ def hstack(tup, *, dtype=None, casting="same_kind"):
1078
1092
Examples
1079
1093
--------
1080
1094
>>> import dpnp as np
1081
- >>> a = np.array((1,2, 3))
1082
- >>> b = np.array((4,5, 6))
1083
- >>> np.hstack((a,b))
1095
+ >>> a = np.array((1, 2, 3))
1096
+ >>> b = np.array((4, 5, 6))
1097
+ >>> np.hstack((a, b))
1084
1098
array([1, 2, 3, 4, 5, 6])
1085
1099
1086
- >>> a = np.array([[1],[2],[3]])
1087
- >>> b = np.array([[4],[5],[6]])
1088
- >>> np.hstack((a,b))
1100
+ >>> a = np.array([[1], [2], [3]])
1101
+ >>> b = np.array([[4], [5], [6]])
1102
+ >>> np.hstack((a, b))
1089
1103
array([[1, 4],
1090
1104
[2, 5],
1091
1105
[3, 6]])
1092
1106
1093
1107
"""
1094
1108
1095
- if not hasattr (tup , "__getitem__" ):
1096
- raise TypeError (
1097
- "Arrays to stack must be passed as a sequence type such as list or tuple."
1098
- )
1109
+ _check_stack_arrays (tup )
1110
+
1099
1111
arrs = dpnp .atleast_1d (* tup )
1100
1112
if not isinstance (arrs , list ):
1101
1113
arrs = [arrs ]
1114
+
1102
1115
# As a special case, dimension 0 of 1-dimensional arrays is "horizontal"
1103
1116
if arrs and arrs [0 ].ndim == 1 :
1104
1117
return dpnp .concatenate (arrs , axis = 0 , dtype = dtype , casting = casting )
@@ -1646,6 +1659,8 @@ def stack(arrays, /, *, axis=0, out=None, dtype=None, casting="same_kind"):
1646
1659
1647
1660
"""
1648
1661
1662
+ _check_stack_arrays (arrays )
1663
+
1649
1664
if dtype is not None and out is not None :
1650
1665
raise TypeError (
1651
1666
"stack() only takes `out` or `dtype` as an argument, but both were provided."
@@ -1887,6 +1902,9 @@ def vstack(tup, *, dtype=None, casting="same_kind"):
1887
1902
"""
1888
1903
Stack arrays in sequence vertically (row wise).
1889
1904
1905
+ :obj:`dpnp.row_stack` is an alias for :obj:`dpnp.vstack`.
1906
+ They are the same function.
1907
+
1890
1908
For full documentation refer to :obj:`numpy.vstack`.
1891
1909
1892
1910
Parameters
@@ -1935,10 +1953,8 @@ def vstack(tup, *, dtype=None, casting="same_kind"):
1935
1953
1936
1954
"""
1937
1955
1938
- if not hasattr (tup , "__getitem__" ):
1939
- raise TypeError (
1940
- "Arrays to stack must be passed as a sequence type such as list or tuple."
1941
- )
1956
+ _check_stack_arrays (tup )
1957
+
1942
1958
arrs = dpnp .atleast_2d (* tup )
1943
1959
if not isinstance (arrs , list ):
1944
1960
arrs = [arrs ]
0 commit comments