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

Function test

numpy/lib/tests/test_arrayterator.py:10–46  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

8
9
10def test():
11 np.random.seed(np.arange(10))
12
13 # Create a random array
14 ndims = randint(5)+1
15 shape = tuple(randint(10)+1 for dim in range(ndims))
16 els = reduce(mul, shape)
17 a = np.arange(els)
18 a.shape = shape
19
20 buf_size = randint(2*els)
21 b = Arrayterator(a, buf_size)
22
23 # Check that each block has at most ``buf_size`` elements
24 for block in b:
25 assert_(len(block.flat) <= (buf_size or els))
26
27 # Check that all elements are iterated correctly
28 assert_(list(b.flat) == list(a.flat))
29
30 # Slice arrayterator
31 start = [randint(dim) for dim in shape]
32 stop = [randint(dim)+1 for dim in shape]
33 step = [randint(dim)+1 for dim in shape]
34 slice_ = tuple(slice(*t) for t in zip(start, stop, step))
35 c = b[slice_]
36 d = a[slice_]
37
38 # Check that each block has at most ``buf_size`` elements
39 for block in c:
40 assert_(len(block.flat) <= (buf_size or els))
41
42 # Check that the arrayterator is sliced correctly
43 assert_(np.all(c.__array__() == d))
44
45 # Check that all elements are iterated correctly
46 assert_(list(c.flat) == list(d.flat))

Callers 1

mainFunction · 0.85

Calls 4

ArrayteratorClass · 0.90
assert_Function · 0.90
allMethod · 0.45
__array__Method · 0.45

Tested by

no test coverage detected