@@ -136,7 +136,17 @@ def test_simple(self):
136
136
result = dpnp .piecewise (ia , [dpnp .array ([1 , 0 ])], [1 ])
137
137
assert_array_equal (result , expected )
138
138
139
- def test_error (self ):
139
+ # List of conditions: single bool tuple
140
+ expected = numpy .piecewise (a , ([True , False ], [False , True ]), [1 , - 4 ])
141
+ result = dpnp .piecewise (ia , ([True , False ], [False , True ]), [1 , - 4 ])
142
+ assert_array_equal (result , expected )
143
+
144
+ # Condition is single bool tuple
145
+ expected = numpy .piecewise (a , (True , False ), [1 ])
146
+ result = dpnp .piecewise (ia , (True , False ), [1 ])
147
+ assert_array_equal (result , expected )
148
+
149
+ def test_error_dpnp (self ):
140
150
ia = dpnp .array ([0 , 0 ])
141
151
# values cannot be a callable function
142
152
assert_raises_regex (
@@ -158,23 +168,45 @@ def test_error(self):
158
168
[- 1 , lambda x : 1 ],
159
169
)
160
170
171
+ # funclist is not array-like
172
+ assert_raises_regex (
173
+ TypeError ,
174
+ "funclist must be a sequence of scalars" ,
175
+ dpnp .piecewise ,
176
+ ia ,
177
+ [dpnp .array ([True , False ])],
178
+ 1 ,
179
+ )
180
+
181
+ assert_raises_regex (
182
+ TypeError ,
183
+ "object of type" ,
184
+ numpy .piecewise ,
185
+ ia .asnumpy (),
186
+ [numpy .array ([True , False ])],
187
+ 1 ,
188
+ )
189
+
190
+ @pytest .mark .parametrize ("xp" , [dpnp , numpy ])
191
+ def test_error (self , xp ):
192
+ ia = xp .array ([0 , 0 ])
161
193
# not enough functions
162
194
assert_raises_regex (
163
195
ValueError ,
164
196
"1 or 2 functions are expected" ,
165
- dpnp .piecewise ,
197
+ xp .piecewise ,
166
198
ia ,
167
- [dpnp .array ([True , False ])],
199
+ [xp .array ([True , False ])],
168
200
[],
169
201
)
170
202
171
203
# extra function
172
204
assert_raises_regex (
173
205
ValueError ,
174
206
"1 or 2 functions are expected" ,
175
- dpnp .piecewise ,
207
+ xp .piecewise ,
176
208
ia ,
177
- [dpnp .array ([True , False ])],
209
+ [xp .array ([True , False ])],
178
210
[1 , 2 , 3 ],
179
211
)
180
212
0 commit comments