MCPcopy Create free account
hub / github.com/numpy/numpy / test_close_equivalent

Function test_close_equivalent

numpy/core/tests/test_nditer.py:3154–3178  ·  view source on GitHub ↗

using a context amanger and using nditer.close are equivalent

()

Source from the content-addressed store, hash-verified

3152 assert_raises(RuntimeError, enter)
3153
3154def test_close_equivalent():
3155 ''' using a context amanger and using nditer.close are equivalent
3156 '''
3157 def add_close(x, y, out=None):
3158 addop = np.add
3159 it = np.nditer([x, y, out], [],
3160 [['readonly'], ['readonly'], ['writeonly','allocate']])
3161 for (a, b, c) in it:
3162 addop(a, b, out=c)
3163 ret = it.operands[2]
3164 it.close()
3165 return ret
3166
3167 def add_context(x, y, out=None):
3168 addop = np.add
3169 it = np.nditer([x, y, out], [],
3170 [['readonly'], ['readonly'], ['writeonly','allocate']])
3171 with it:
3172 for (a, b, c) in it:
3173 addop(a, b, out=c)
3174 return it.operands[2]
3175 z = add_close(range(5), range(5))
3176 assert_equal(z, range(0, 10, 2))
3177 z = add_context(range(5), range(5))
3178 assert_equal(z, range(0, 10, 2))
3179
3180def test_close_raises():
3181 it = np.nditer(np.arange(3))

Callers

nothing calls this directly

Calls 3

assert_equalFunction · 0.90
add_closeFunction · 0.85
add_contextFunction · 0.85

Tested by

no test coverage detected