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
162 lines (154 loc) · 4.13 KB
/
Copy pathtest_iterator.py
File metadata and controls
162 lines (154 loc) · 4.13 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
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, np_dtype, acontiguous, aurlpath, bcontiguous, burlpath, mode",
[
([100, 100], [20, 20], [10, 10], [20, 20], np.float64, "f4", True, None, True, None, "r"),
(
[100, 100],
[15, 15],
[7, 8],
[15, 15],
np.float32,
None,
True,
"test_iter_acontiguous.iarr",
True,
"test_iter_bcontiguous.iarr",
"w-",
),
(
[10, 10, 10],
[4, 5, 6],
[2, 3, 6],
[4, 5, 6],
np.float64,
">f8",
False,
"test_iter_asparse.iarr",
False,
"test_iter_bsparse.iarr",
"w",
),
pytest.param(
[10, 10, 10, 10],
[3, 4, 3, 4],
[2, 2, 2, 2],
[3, 4, 3, 4],
np.int32,
None,
False,
None,
False,
None,
"r",
marks=pytest.mark.heavy,
),
(
[100, 100],
[50, 50],
[20, 20],
[50, 50],
np.uint64,
"m8[ms]",
False,
"test_iter_asparse.iarr",
True,
None,
"r+",
),
(
[100, 100],
[23, 35],
[21, 33],
[23, 35],
np.uint16,
None,
False,
None,
True,
"test_iter_bcontiguous.iarr",
"a",
),
pytest.param(
[10, 10, 10],
[10, 10, 10],
[5, 5, 5],
[10, 10, 10],
np.int16,
None,
True,
"test_iter_asparse.iarr",
True,
"test_iter_bsparse.iarr",
"a",
marks=pytest.mark.heavy,
),
(
[10, 10, 10, 10],
[3, 4, 3, 4],
[3, 4, 3, 4],
[3, 4, 3, 4],
np.float32,
None,
True,
None,
False,
None,
"w",
),
],
)
def test_iterator(
shape,
chunks,
blocks,
itershape,
dtype,
np_dtype,
acontiguous,
aurlpath,
bcontiguous,
burlpath,
mode,
):
acfg = ia.Config(chunks=chunks, blocks=blocks, contiguous=acontiguous, urlpath=aurlpath)
bcfg = ia.Config(
chunks=chunks, blocks=blocks, contiguous=bcontiguous, urlpath=burlpath, mode="a"
)
ia.remove_urlpath(aurlpath)
ia.remove_urlpath(burlpath)
max = 1
out_dtype = dtype if np_dtype is None else np.dtype(np_dtype)
if out_dtype not in [np.float64, np.float32]:
for i in range(len(shape)):
max *= shape[i]
a = ia.linspace(0, max, int(np.prod(shape)), shape=shape, dtype=dtype, np_dtype=np_dtype, cfg=acfg)
an = ia.iarray2numpy(a)
b = ia.empty(shape, dtype=dtype, np_dtype=np_dtype, cfg=bcfg)
mode2 = b.cfg.mode
b.cfg.mode = mode
if mode in ["r"]:
with pytest.raises(IOError):
izip(a.iter_read_block(itershape), b.iter_write_block(itershape))
b.cfg.mode = mode2
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)))
if out_dtype in [np.float64, np.float32]:
np.testing.assert_almost_equal(aslice, an[slices])
else:
np.testing.assert_array_equal(aslice, an[slices])
bn = ia.iarray2numpy(b)
if out_dtype in [np.float64, np.float32]:
np.testing.assert_almost_equal(bn, an)
else:
np.testing.assert_array_equal(bn, an)
ia.remove_urlpath(aurlpath)
ia.remove_urlpath(burlpath)