forked from inaos/iron-array-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_iterator.py
More file actions
117 lines (109 loc) · 2.98 KB
/
Copy pathtest_iterator.py
File metadata and controls
117 lines (109 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import pytest
import iarray as ia
import numpy as np
from itertools import zip_longest as izip
# Expression
@pytest.mark.parametrize(
"shape, chunks, blocks, itershape, dtype, acontiguous, aurlpath, bcontiguous, burlpath",
[
([100, 100], [20, 20], [10, 10], [20, 20], np.float64, True, None, True, None),
(
[100, 100],
[15, 15],
[7, 8],
[15, 15],
np.float32,
True,
"test_iter_acontiguous.iarr",
True,
"test_iter_bcontiguous.iarr",
),
(
[10, 10, 10],
[4, 5, 6],
[2, 3, 6],
[4, 5, 6],
np.float64,
False,
"test_iter_asparse.iarr",
False,
"test_iter_bsparse.iarr",
),
(
[10, 10, 10, 10],
[3, 4, 3, 4],
[2, 2, 2, 2],
[3, 4, 3, 4],
np.float32,
False,
None,
False,
None,
),
(
[100, 100],
[50, 50],
[20, 20],
[50, 50],
np.float64,
False,
"test_iter_asparse.iarr",
True,
None,
),
(
[100, 100],
[23, 35],
[21, 33],
[23, 35],
np.float32,
False,
None,
True,
"test_iter_bcontiguous.iarr",
),
(
[10, 10, 10],
[10, 10, 10],
[5, 5, 5],
[10, 10, 10],
np.float64,
True,
"test_iter_asparse.iarr",
True,
"test_iter_bsparse.iarr",
),
(
[10, 10, 10, 10],
[3, 4, 3, 4],
[3, 4, 3, 4],
[3, 4, 3, 4],
np.float32,
True,
None,
False,
None,
),
],
)
def test_iterator(
shape, chunks, blocks, itershape, dtype, acontiguous, aurlpath, bcontiguous, burlpath
):
astore = ia.Store(chunks, blocks, contiguous=acontiguous, urlpath=aurlpath)
bstore = ia.Store(chunks, blocks, contiguous=bcontiguous, urlpath=burlpath)
ia.remove_urlpath(aurlpath)
ia.remove_urlpath(burlpath)
a = ia.linspace(shape, -10, 10, dtype=dtype, store=astore)
an = ia.iarray2numpy(a)
b = ia.empty(shape, dtype=dtype, store=bstore)
zip = izip(a.iter_read_block(itershape), b.iter_write_block(itershape))
for i, ((ainfo, aslice), (_, bslice)) in enumerate(zip):
bslice[:] = aslice
start = ainfo.elemindex
stop = tuple(ainfo.elemindex[i] + ainfo.shape[i] for i in range(len(ainfo.elemindex)))
slices = tuple(slice(start[i], stop[i]) for i in range(len(start)))
np.testing.assert_almost_equal(aslice, an[slices])
bn = ia.iarray2numpy(b)
np.testing.assert_almost_equal(bn, an)
ia.remove_urlpath(aurlpath)
ia.remove_urlpath(burlpath)