Skip to content

Commit 760c537

Browse files
FIX: vstack, hstack fallback and tests (#782)
* TEST: tests for vstack, hstack
1 parent 7e864ea commit 760c537

File tree

4 files changed

+97
-3
lines changed

4 files changed

+97
-3
lines changed

dpnp/dpnp_iface_manipulation.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,15 @@ def hstack(tup):
290290
291291
"""
292292

293-
return call_origin(numpy.hstack, tup)
293+
# TODO:
294+
# `call_origin` cannot convert sequence of dparray to sequence of
295+
# nparrays
296+
tup_new = []
297+
for tp in tup:
298+
tpx = dpnp.asnumpy(tp) if isinstance(tp, dparray) else tp
299+
tup_new.append(tpx)
300+
301+
return call_origin(numpy.hstack, tup_new)
294302

295303

296304
def moveaxis(x1, source, destination):
@@ -619,4 +627,12 @@ def vstack(tup):
619627
620628
"""
621629

622-
return call_origin(numpy.vstack, tup)
630+
# TODO:
631+
# `call_origin` cannot convert sequence of dparray to sequence of
632+
# nparray
633+
tup_new = []
634+
for tp in tup:
635+
tpx = dpnp.asnumpy(tp) if isinstance(tp, dparray) else tp
636+
tup_new.append(tpx)
637+
638+
return call_origin(numpy.vstack, tup_new)

tests/skipped_tests.tbl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
tests/test_arraymanipulation.py::TestVstack::test_generator
2+
tests/test_arraymanipulation.py::TestHstack::test_generator
13
tests/test_linalg.py::test_cond[-1-[[1, 2, 3], [4, 5, 6], [7, 8, 9]]]
24
tests/test_linalg.py::test_cond[1-[[1, 2, 3], [4, 5, 6], [7, 8, 9]]]
35
tests/test_linalg.py::test_cond[-2-[[1, 0, -1], [0, 1, 0], [1, 0, 1]]]

tests/skipped_tests_gpu.tbl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
tests/test_arraymanipulation.py::TestHstack::test_generator
2+
tests/test_arraymanipulation.py::TestVstack::test_generator
13
tests/test_linalg.py::test_cond[-1-[[1, 2, 3], [4, 5, 6], [7, 8, 9]]]
24
tests/test_linalg.py::test_cond[1-[[1, 2, 3], [4, 5, 6], [7, 8, 9]]]
35
tests/test_linalg.py::test_cond[-2-[[1, 0, -1], [0, 1, 0], [1, 0, 1]]]

tests/test_arraymanipulation.py

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import pytest
22

33
import dpnp
4-
54
import numpy
65

76

@@ -16,3 +15,78 @@ def test_asfarray(type, input):
1615
dpnp_res = dpnp.asfarray(input, type)
1716

1817
numpy.testing.assert_array_equal(dpnp_res, np_res)
18+
19+
20+
class TestHstack:
21+
def test_non_iterable(self):
22+
numpy.testing.assert_raises(TypeError, dpnp.hstack, 1)
23+
24+
def test_empty_input(self):
25+
numpy.testing.assert_raises(ValueError, dpnp.hstack, ())
26+
27+
def test_0D_array(self):
28+
b = dpnp.array(2)
29+
a = dpnp.array(1)
30+
res = dpnp.hstack([a, b])
31+
desired = dpnp.array([1, 2])
32+
numpy.testing.assert_array_equal(res, desired)
33+
34+
def test_1D_array(self):
35+
a = dpnp.array([1])
36+
b = dpnp.array([2])
37+
res = dpnp.hstack([a, b])
38+
desired = dpnp.array([1, 2])
39+
numpy.testing.assert_array_equal(res, desired)
40+
41+
def test_2D_array(self):
42+
a = dpnp.array([[1], [2]])
43+
b = dpnp.array([[1], [2]])
44+
res = dpnp.hstack([a, b])
45+
desired = dpnp.array([[1, 1], [2, 2]])
46+
numpy.testing.assert_array_equal(res, desired)
47+
48+
def test_generator(self):
49+
with numpy.testing.assert_warns(FutureWarning):
50+
dpnp.hstack((numpy.arange(3) for _ in range(2)))
51+
with numpy.testing.assert_warns(FutureWarning):
52+
dpnp.hstack(map(lambda x: x, numpy.ones((3, 2))))
53+
54+
55+
class TestVstack:
56+
def test_non_iterable(self):
57+
numpy.testing.assert_raises(TypeError, dpnp.vstack, 1)
58+
59+
def test_empty_input(self):
60+
numpy.testing.assert_raises(ValueError, dpnp.vstack, ())
61+
62+
def test_0D_array(self):
63+
a = dpnp.array(1)
64+
b = dpnp.array(2)
65+
res = dpnp.vstack([a, b])
66+
desired = dpnp.array([[1], [2]])
67+
numpy.testing.assert_array_equal(res, desired)
68+
69+
def test_1D_array(self):
70+
a = dpnp.array([1])
71+
b = dpnp.array([2])
72+
res = dpnp.vstack([a, b])
73+
desired = dpnp.array([[1], [2]])
74+
numpy.testing.assert_array_equal(res, desired)
75+
76+
def test_2D_array(self):
77+
a = dpnp.array([[1], [2]])
78+
b = dpnp.array([[1], [2]])
79+
res = dpnp.vstack([a, b])
80+
desired = dpnp.array([[1], [2], [1], [2]])
81+
numpy.testing.assert_array_equal(res, desired)
82+
83+
def test_2D_array2(self):
84+
a = dpnp.array([1, 2])
85+
b = dpnp.array([1, 2])
86+
res = dpnp.vstack([a, b])
87+
desired = dpnp.array([[1, 2], [1, 2]])
88+
numpy.testing.assert_array_equal(res, desired)
89+
90+
def test_generator(self):
91+
with numpy.testing.assert_warns(FutureWarning):
92+
dpnp.vstack((numpy.arange(3) for _ in range(2)))

0 commit comments

Comments
 (0)