forked from inaos/iron-array-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_transpose.py
More file actions
90 lines (80 loc) · 2.41 KB
/
Copy pathtest_transpose.py
File metadata and controls
90 lines (80 loc) · 2.41 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
import pytest
import iarray as ia
import numpy as np
@pytest.mark.parametrize(
"shape, chunks, blocks, dtype, np_dtype, contiguous, urlpath, mode",
[
([100, 100], [50, 50], [20, 20], np.float32, None, False, None, "r"),
(
[100, 100],
[20, 20],
[10, 10],
np.float64,
">f4",
True,
"test_transpose_contiguous.iarr",
"r+",
),
(
[100, 500],
[50, 70],
[20, 20],
np.float32,
">f2",
False,
"test_transpose_sparse.iarr",
"w",
),
([50, 26], [20, 10], [15, 5], np.float64, "i4", True, None, "w-"),
pytest.param(
[1453, 266],
[100, 200],
[30, 20],
np.float64,
None,
True,
None,
"w-",
marks=pytest.mark.heavy,
),
],
)
def test_transpose(shape, chunks, blocks, dtype, np_dtype, contiguous, urlpath, mode):
ia.remove_urlpath(urlpath)
cfg = ia.Config(chunks=chunks, blocks=blocks, contiguous=contiguous, urlpath=urlpath)
a = ia.linspace(
-10, 10, int(np.prod(shape)), shape=shape, cfg=cfg, dtype=dtype, np_dtype=np_dtype
)
b = ia.iarray2numpy(a)
bn = b.T
npdtype = dtype if np_dtype is None else np.dtype(np_dtype)
rtol = 1e-6 if npdtype == np.float32 else 1e-14
at = a.T
an = ia.iarray2numpy(at)
if npdtype in [np.float16, np.float32, np.float64]:
np.testing.assert_allclose(an, bn, rtol=rtol)
else:
np.testing.assert_equal(an, bn)
if mode in ["r", "r+"]:
with pytest.raises(IOError):
at = a.transpose(mode=mode)
at = a.transpose()
else:
at = a.transpose(mode=mode)
an = ia.iarray2numpy(at)
if npdtype in [np.float16, np.float32, np.float64]:
np.testing.assert_allclose(an, bn, rtol=rtol)
else:
np.testing.assert_equal(an, bn)
if mode in ["r", "r+"]:
with pytest.raises(IOError):
at = ia.matrix_transpose(a, mode=mode)
at = ia.matrix_transpose(a)
else:
at = ia.matrix_transpose(a, mode=mode)
an = ia.iarray2numpy(at)
if npdtype in [np.float16, np.float32, np.float64]:
np.testing.assert_allclose(an, bn, rtol=rtol)
else:
np.testing.assert_equal(an, bn)
ia.remove_urlpath(urlpath)