1
1
import pytest
2
2
3
3
import dpnp
4
-
5
4
import numpy
6
5
7
6
@@ -16,3 +15,78 @@ def test_asfarray(type, input):
16
15
dpnp_res = dpnp .asfarray (input , type )
17
16
18
17
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