forked from inaos/iron-array-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_load_save.py
More file actions
78 lines (67 loc) · 2.29 KB
/
Copy pathtest_load_save.py
File metadata and controls
78 lines (67 loc) · 2.29 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
import pytest
import iarray as ia
import numpy as np
# Test load, open and save
@pytest.mark.parametrize("contiguous", [True, False])
@pytest.mark.parametrize(
"dtype, np_dtype",
[
(np.float32, ">f4"),
(np.float64, "i4"),
(np.int32, "M8[fs]"),
(np.uint32, None),
],
)
@pytest.mark.parametrize(
"shape, chunks, blocks",
[
([123], [44], [20]),
([40, 50], [12, 21], [10, 10]),
pytest.param([100, 100], [5, 17], [5, 5], marks=pytest.mark.heavy),
([10, 12, 21], [5, 4, 10], [2, 1, 5]),
],
)
@pytest.mark.parametrize("func", [ia.load, ia.open])
def test_load_save(shape, chunks, blocks, dtype, np_dtype, func, contiguous):
urlpath = "test_load_save.iarr"
ia.remove_urlpath(urlpath)
cfg = ia.Config(chunks=chunks, blocks=blocks, contiguous=contiguous)
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.arange(0, max, shape=shape, dtype=dtype, np_dtype=np_dtype, cfg=cfg)
an = ia.iarray2numpy(a)
ia.save(urlpath, a, contiguous=contiguous)
b = func(urlpath)
bn = ia.iarray2numpy(b)
if out_dtype in [np.float64, np.float32]:
np.testing.assert_almost_equal(an, bn)
else:
np.testing.assert_array_equal(an, bn)
# Overwrite existing array
ia.save(urlpath, a, contiguous=contiguous)
b = ia.open(urlpath)
assert b.cfg.contiguous == contiguous
assert isinstance(b.cfg.urlpath, bytes)
assert b.cfg.urlpath == urlpath.encode("utf-8")
assert b.cfg.chunks == a.chunks
assert b.cfg.blocks == a.blocks
assert b.cfg.filters == a.cfg.filters
assert b.cfg.fp_mantissa_bits == a.cfg.fp_mantissa_bits
assert b.dtype == a.dtype
assert b.np_dtype == a.np_dtype
assert b.cfg.mode == "a"
c = ia.load(urlpath)
assert c.cfg.contiguous is False
assert c.cfg.urlpath is None
assert c.cfg.chunks == a.chunks
assert c.cfg.blocks == a.blocks
assert c.cfg.codec == a.cfg.codec
assert c.cfg.filters == a.cfg.filters
assert c.cfg.fp_mantissa_bits == a.cfg.fp_mantissa_bits
assert c.dtype == a.dtype
assert c.np_dtype == a.np_dtype
assert c.cfg.mode == "a"
ia.remove_urlpath(urlpath)