@@ -68,3 +68,101 @@ def test_flags_strides(dtype, order, strides):
68
68
assert usm_array .flags == dpnp_array .flags
69
69
assert numpy_array .flags .c_contiguous == dpnp_array .flags .c_contiguous
70
70
assert numpy_array .flags .f_contiguous == dpnp_array .flags .f_contiguous
71
+
72
+ def test_print_dpnp_int ():
73
+ result = repr (dpnp .array ([1 , 0 , 2 , - 3 , - 1 , 2 , 21 , - 9 ]))
74
+ expected = "dpnp_array([ 1, 0, 2, -3, -1, 2, 21, -9])"
75
+ assert (result == expected )
76
+
77
+ result = str (dpnp .array ([1 , 0 , 2 , - 3 , - 1 , 2 , 21 , - 9 ]))
78
+ expected = "[ 1 0 2 -3 -1 2 21 -9]"
79
+ assert (result == expected )
80
+ # int32
81
+ result = repr (dpnp .array ([1 , - 1 , 21 ], dtype = dpnp .int32 ))
82
+ expected = "dpnp_array([ 1, -1, 21], dtype=int32)"
83
+ assert (result == expected )
84
+
85
+ result = str (dpnp .array ([1 , - 1 , 21 ], dtype = dpnp .int32 ))
86
+ expected = "[ 1 -1 21]"
87
+ assert (result == expected )
88
+ # uint8
89
+ result = repr (dpnp .array ([1 , 0 , 3 ], dtype = numpy .uint8 ))
90
+ expected = "dpnp_array([1, 0, 3], dtype=uint8)"
91
+ assert (result == expected )
92
+
93
+ result = str (dpnp .array ([1 , 0 , 3 ], dtype = numpy .uint8 ))
94
+ expected = "[1 0 3]"
95
+ assert (result == expected )
96
+
97
+
98
+ def test_print_dpnp_float ():
99
+ result = repr (dpnp .array ([1 , - 1 , 21 ], dtype = float ))
100
+ expected = "dpnp_array([ 1., -1., 21.])"
101
+ assert (result == expected )
102
+
103
+ result = str (dpnp .array ([1 , - 1 , 21 ], dtype = float ))
104
+ expected = "[ 1. -1. 21.]"
105
+ assert (result == expected )
106
+ # float32
107
+ result = repr (dpnp .array ([1 , - 1 , 21 ], dtype = dpnp .float32 ))
108
+ expected = "dpnp_array([ 1., -1., 21.], dtype=float32)"
109
+ assert (result == expected )
110
+
111
+ result = str (dpnp .array ([1 , - 1 , 21 ], dtype = dpnp .float32 ))
112
+ expected = "[ 1. -1. 21.]"
113
+ assert (result == expected )
114
+
115
+ def test_print_dpnp_complex ():
116
+ result = repr (dpnp .array ([1 , - 1 , 21 ], dtype = complex ))
117
+ expected = "dpnp_array([ 1.+0.j, -1.+0.j, 21.+0.j])"
118
+ assert (result == expected )
119
+
120
+ result = str (dpnp .array ([1 , - 1 , 21 ], dtype = complex ))
121
+ expected = "[ 1.+0.j -1.+0.j 21.+0.j]"
122
+ assert (result == expected )
123
+
124
+ def test_print_dpnp_boolean ():
125
+ result = repr (dpnp .array ([1 , 0 , 3 ], dtype = bool ))
126
+ expected = "dpnp_array([ True, False, True])"
127
+ assert (result == expected )
128
+
129
+ result = str (dpnp .array ([1 , 0 , 3 ], dtype = bool ))
130
+ expected = "[ True False True]"
131
+ assert (result == expected )
132
+
133
+ def test_print_dpnp_special_character ():
134
+ # NaN
135
+ result = repr (dpnp .array ([1. , 0. , dpnp .nan , 3. ]))
136
+ expected = "dpnp_array([ 1., 0., nan, 3.])"
137
+ assert (result == expected )
138
+
139
+ result = str (dpnp .array ([1. , 0. , dpnp .nan , 3. ]))
140
+ expected = "[ 1. 0. nan 3.]"
141
+ assert (result == expected )
142
+ # inf
143
+ result = repr (dpnp .array ([1. , 0. , numpy .inf , 3. ]))
144
+ expected = "dpnp_array([ 1., 0., inf, 3.])"
145
+ assert (result == expected )
146
+
147
+ result = str (dpnp .array ([1. , 0. , numpy .inf , 3. ]))
148
+ expected = "[ 1. 0. inf 3.]"
149
+ assert (result == expected )
150
+
151
+ def test_print_dpnp_nd ():
152
+ # 2D
153
+ result = repr (dpnp .array ([[1 , 2 ], [3 , 4 ]]))
154
+ expected = "dpnp_array([[1, 2],\n [3, 4]])"
155
+ assert (result == expected )
156
+
157
+ result = str (dpnp .array ([[1 , 2 ], [3 , 4 ]]))
158
+ expected = "[[1 2]\n [3 4]]"
159
+ assert (result == expected )
160
+
161
+ # 0 shape
162
+ result = repr (dpnp .empty ( shape = (0 , 0 ) ))
163
+ expected = "dpnp_array([])"
164
+ assert (result == expected )
165
+
166
+ result = str (dpnp .empty ( shape = (0 , 0 ) ))
167
+ expected = "[]"
168
+ assert (result == expected )
0 commit comments