()
| 8 | |
| 9 | |
| 10 | def 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)) |
no test coverage detected