def test_get(): pool = MemoryPool() pa = empty(9) pc = empty(11) pool.add(pa) pool.add(pc) def func(v, b, bs, ba, bc, s, a, c): assert_equal(v.shape, s) if a: assert_aligned(v) if c: assert_contiguous(v) if a > ba or c and not bc or not bc and s != bs: assert address(pool._buffers) == address([pa, b]) else: assert address(pool._buffers) == address([pa, pc]) for b, ba, bc in zip(buffers, aligned, contiguous): with pool.set(b): for (s, a, c) in itertools.product([(10,), (5, 2), (2, 5)], [False, True], [False, True]): with pool.get(s, float, a, c) as v: yield func, v, b, b.shape, ba, bc, s, a, c assert address(pool._buffers) == address([pa, b, pc]) assert address(pool._buffers) == address([pa, pc])
def test_set(): pool = MemoryPool() a = np.empty(9) c = np.empty(11) pool.add(a) pool.add(c) def func(b): assert address(pool._buffers) == address([a, b, c]) for b in buffers: with pool.set(b): yield func, b assert address(pool._buffers) == address([a, c])
def test_new_entry(): pool = MemoryPool() a = empty(12) b = empty(20) pool.add(a) pool.add(b) shapes = ((4,), (15,), (30,)) def func(i, s, d=-1): assert_equal(len(pool), 3 + i) for i, s in enumerate(shapes): with pool.get(s, float): pass yield func, i, s for s in [a.shape, b.shape]: for d in [0, 1, 2]: with pool.get(s[0] - d, float): pass yield func, i, s, d
def test_get(): pool = MemoryPool() pa = empty(9) pc = empty(11) pool.add(pa) pool.add(pc) def func(v, b, bs, ba, bc, s, a, c): assert_equal(v.shape, s) if a: assert_aligned(v) if c: assert_contiguous(v) if a > ba or c and not bc or not bc and s != bs: assert address(pool._buffers) == address([pa, b]) else: assert address(pool._buffers) == address([pa, pc]) for b, ba, bc in zip(buffers, aligned, contiguous): with pool.set(b): for (s, a, c) in itertools.product([(10, ), (5, 2), (2, 5)], [False, True], [False, True]): with pool.get(s, float, a, c) as v: yield func, v, b, b.shape, ba, bc, s, a, c assert address(pool._buffers) == address([pa, b, pc]) assert address(pool._buffers) == address([pa, pc])
def test_new_entry(): pool = MemoryPool() a = empty(12) b = empty(20) pool.add(a) pool.add(b) shapes = ((4, ), (15, ), (30, )) def func(i, s, d=-1): assert_equal(len(pool), 3 + i) for i, s in enumerate(shapes): with pool.get(s, float): pass yield func, i, s for s in [a.shape, b.shape]: for d in [0, 1, 2]: with pool.get(s[0] - d, float): pass yield func, i, s, d