Skip to content

Commit 09a1967

Browse files
committed
Added tests
1 parent 816da75 commit 09a1967

File tree

4 files changed

+417
-278
lines changed

4 files changed

+417
-278
lines changed

dpnp/dpnp_iface_manipulation.py

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@
8585
]
8686

8787

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+
8898
def asfarray(a, dtype=None, *, device=None, usm_type=None, sycl_queue=None):
8999
"""
90100
Return an array converted to a float type.
@@ -551,6 +561,8 @@ def column_stack(tup):
551561
552562
"""
553563

564+
_check_stack_arrays(tup)
565+
554566
arrays = []
555567
for v in tup:
556568
dpnp.check_supported_arrays_type(v)
@@ -563,7 +575,7 @@ def column_stack(tup):
563575
)
564576

565577
arrays.append(v)
566-
return dpnp.concatenate(arrays, 1)
578+
return dpnp.concatenate(arrays, axis=1)
567579

568580

569581
def concatenate(
@@ -778,6 +790,8 @@ def dstack(tup):
778790
779791
"""
780792

793+
_check_stack_arrays(tup)
794+
781795
arrs = atleast_3d(*tup)
782796
if not isinstance(arrs, list):
783797
arrs = [arrs]
@@ -1078,27 +1092,26 @@ def hstack(tup, *, dtype=None, casting="same_kind"):
10781092
Examples
10791093
--------
10801094
>>> 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))
10841098
array([1, 2, 3, 4, 5, 6])
10851099
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))
10891103
array([[1, 4],
10901104
[2, 5],
10911105
[3, 6]])
10921106
10931107
"""
10941108

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+
10991111
arrs = dpnp.atleast_1d(*tup)
11001112
if not isinstance(arrs, list):
11011113
arrs = [arrs]
1114+
11021115
# As a special case, dimension 0 of 1-dimensional arrays is "horizontal"
11031116
if arrs and arrs[0].ndim == 1:
11041117
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"):
16461659
16471660
"""
16481661

1662+
_check_stack_arrays(arrays)
1663+
16491664
if dtype is not None and out is not None:
16501665
raise TypeError(
16511666
"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"):
18871902
"""
18881903
Stack arrays in sequence vertically (row wise).
18891904
1905+
:obj:`dpnp.row_stack` is an alias for :obj:`dpnp.vstack`.
1906+
They are the same function.
1907+
18901908
For full documentation refer to :obj:`numpy.vstack`.
18911909
18921910
Parameters
@@ -1935,10 +1953,8 @@ def vstack(tup, *, dtype=None, casting="same_kind"):
19351953
19361954
"""
19371955

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+
19421958
arrs = dpnp.atleast_2d(*tup)
19431959
if not isinstance(arrs, list):
19441960
arrs = [arrs]

0 commit comments

Comments
 (0)