using a context amanger and using nditer.close are equivalent
()
| 3411 | assert_raises(RuntimeError, enter) |
| 3412 | |
| 3413 | def test_close_equivalent(): |
| 3414 | ''' using a context amanger and using nditer.close are equivalent |
| 3415 | ''' |
| 3416 | def add_close(x, y, out=None): |
| 3417 | addop = np.add |
| 3418 | it = np.nditer([x, y, out], [], |
| 3419 | [['readonly'], ['readonly'], ['writeonly', 'allocate']]) |
| 3420 | for (a, b, c) in it: |
| 3421 | addop(a, b, out=c) |
| 3422 | ret = it.operands[2] |
| 3423 | it.close() |
| 3424 | return ret |
| 3425 | |
| 3426 | def add_context(x, y, out=None): |
| 3427 | addop = np.add |
| 3428 | it = np.nditer([x, y, out], [], |
| 3429 | [['readonly'], ['readonly'], ['writeonly', 'allocate']]) |
| 3430 | with it: |
| 3431 | for (a, b, c) in it: |
| 3432 | addop(a, b, out=c) |
| 3433 | return it.operands[2] |
| 3434 | z = add_close(range(5), range(5)) |
| 3435 | assert_equal(z, range(0, 10, 2)) |
| 3436 | z = add_context(range(5), range(5)) |
| 3437 | assert_equal(z, range(0, 10, 2)) |
| 3438 | |
| 3439 | def test_close_raises(): |
| 3440 | it = np.nditer(np.arange(3)) |
nothing calls this directly
no test coverage detected
searching dependent graphs…