(self)
| 3243 | assert_equal(res1[4], {'out': (a,)}) |
| 3244 | |
| 3245 | def test_ufunc_override_mro(self): |
| 3246 | |
| 3247 | # Some multi arg functions for testing. |
| 3248 | def tres_mul(a, b, c): |
| 3249 | return a * b * c |
| 3250 | |
| 3251 | def quatro_mul(a, b, c, d): |
| 3252 | return a * b * c * d |
| 3253 | |
| 3254 | # Make these into ufuncs. |
| 3255 | three_mul_ufunc = np.frompyfunc(tres_mul, 3, 1) |
| 3256 | four_mul_ufunc = np.frompyfunc(quatro_mul, 4, 1) |
| 3257 | |
| 3258 | class A: |
| 3259 | def __array_ufunc__(self, func, method, *inputs, **kwargs): |
| 3260 | return "A" |
| 3261 | |
| 3262 | class ASub(A): |
| 3263 | def __array_ufunc__(self, func, method, *inputs, **kwargs): |
| 3264 | return "ASub" |
| 3265 | |
| 3266 | class B: |
| 3267 | def __array_ufunc__(self, func, method, *inputs, **kwargs): |
| 3268 | return "B" |
| 3269 | |
| 3270 | class C: |
| 3271 | def __init__(self): |
| 3272 | self.count = 0 |
| 3273 | |
| 3274 | def __array_ufunc__(self, func, method, *inputs, **kwargs): |
| 3275 | self.count += 1 |
| 3276 | return NotImplemented |
| 3277 | |
| 3278 | class CSub(C): |
| 3279 | def __array_ufunc__(self, func, method, *inputs, **kwargs): |
| 3280 | self.count += 1 |
| 3281 | return NotImplemented |
| 3282 | |
| 3283 | a = A() |
| 3284 | a_sub = ASub() |
| 3285 | b = B() |
| 3286 | c = C() |
| 3287 | |
| 3288 | # Standard |
| 3289 | res = np.multiply(a, a_sub) |
| 3290 | assert_equal(res, "ASub") |
| 3291 | res = np.multiply(a_sub, b) |
| 3292 | assert_equal(res, "ASub") |
| 3293 | |
| 3294 | # With 1 NotImplemented |
| 3295 | res = np.multiply(c, a) |
| 3296 | assert_equal(res, "A") |
| 3297 | assert_equal(c.count, 1) |
| 3298 | # Check our counter works, so we can trust tests below. |
| 3299 | res = np.multiply(c, a) |
| 3300 | assert_equal(c.count, 2) |
| 3301 | |
| 3302 | # Both NotImplemented. |
nothing calls this directly
no test coverage detected