@@ -68,3 +68,100 @@ 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 ], dtype = 'i4' ))
74
+ expected = "dpnp_array([ 1, 0, 2, -3, -1, 2, 21, -9], dtype=int32)"
75
+ assert (result == expected )
76
+
77
+ result = str (dpnp .array ([1 , 0 , 2 , - 3 , - 1 , 2 , 21 , - 9 ], dtype = 'i4' ))
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
+ def test_print_dpnp_float ():
98
+ result = repr (dpnp .array ([1 , - 1 , 21 ], dtype = float ))
99
+ expected = "dpnp_array([ 1., -1., 21.])"
100
+ assert (result == expected )
101
+
102
+ result = str (dpnp .array ([1 , - 1 , 21 ], dtype = float ))
103
+ expected = "[ 1. -1. 21.]"
104
+ assert (result == expected )
105
+ # float32
106
+ result = repr (dpnp .array ([1 , - 1 , 21 ], dtype = dpnp .float32 ))
107
+ expected = "dpnp_array([ 1., -1., 21.], dtype=float32)"
108
+ assert (result == expected )
109
+
110
+ result = str (dpnp .array ([1 , - 1 , 21 ], dtype = dpnp .float32 ))
111
+ expected = "[ 1. -1. 21.]"
112
+ assert (result == expected )
113
+
114
+ def test_print_dpnp_complex ():
115
+ result = repr (dpnp .array ([1 , - 1 , 21 ], dtype = complex ))
116
+ expected = "dpnp_array([ 1.+0.j, -1.+0.j, 21.+0.j])"
117
+ assert (result == expected )
118
+
119
+ result = str (dpnp .array ([1 , - 1 , 21 ], dtype = complex ))
120
+ expected = "[ 1.+0.j -1.+0.j 21.+0.j]"
121
+ assert (result == expected )
122
+
123
+ def test_print_dpnp_boolean ():
124
+ result = repr (dpnp .array ([1 , 0 , 3 ], dtype = bool ))
125
+ expected = "dpnp_array([ True, False, True])"
126
+ assert (result == expected )
127
+
128
+ result = str (dpnp .array ([1 , 0 , 3 ], dtype = bool ))
129
+ expected = "[ True False True]"
130
+ assert (result == expected )
131
+
132
+ def test_print_dpnp_special_character ():
133
+ # NaN
134
+ result = repr (dpnp .array ([1. , 0. , dpnp .nan , 3. ]))
135
+ expected = "dpnp_array([ 1., 0., nan, 3.])"
136
+ assert (result == expected )
137
+
138
+ result = str (dpnp .array ([1. , 0. , dpnp .nan , 3. ]))
139
+ expected = "[ 1. 0. nan 3.]"
140
+ assert (result == expected )
141
+ # inf
142
+ result = repr (dpnp .array ([1. , 0. , numpy .inf , 3. ]))
143
+ expected = "dpnp_array([ 1., 0., inf, 3.])"
144
+ assert (result == expected )
145
+
146
+ result = str (dpnp .array ([1. , 0. , numpy .inf , 3. ]))
147
+ expected = "[ 1. 0. inf 3.]"
148
+ assert (result == expected )
149
+
150
+ def test_print_dpnp_nd ():
151
+ # 2D
152
+ result = repr (dpnp .array ([[1 , 2 ], [3 , 4 ]], dtype = float ))
153
+ expected = "dpnp_array([[1., 2.],\n [3., 4.]])"
154
+ assert (result == expected )
155
+
156
+ result = str (dpnp .array ([[1 , 2 ], [3 , 4 ]]))
157
+ expected = "[[1 2]\n [3 4]]"
158
+ assert (result == expected )
159
+
160
+ # 0 shape
161
+ result = repr (dpnp .empty ( shape = (0 , 0 ) ))
162
+ expected = "dpnp_array([])"
163
+ assert (result == expected )
164
+
165
+ result = str (dpnp .empty ( shape = (0 , 0 ) ))
166
+ expected = "[]"
167
+ assert (result == expected )
0 commit comments