forked from inaos/iron-array-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopy_array.py
More file actions
47 lines (37 loc) · 1002 Bytes
/
Copy pathcopy_array.py
File metadata and controls
47 lines (37 loc) · 1002 Bytes
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
# Exercises the copy() with actual arrays and views of them too.
from time import time
import iarray as ia
import numpy as np
from dataclasses import asdict
# Create an ironArray array
a = ia.linspace(
-10,
10,
num=10000**2,
shape=[10000, 10000],
chunks=[2000, 2000],
blocks=[256, 256],
dtype=np.float64,
)
print(f"src chunks: {a.chunks}")
# Do a regular copy changing the parameters
params = {"chunks": [2048, 2048], "blocks": [256, 256], "codec": ia.Codec.LZ4, "clevel": 5}
t0 = time()
b = a.copy(**params)
t1 = time()
print(f"Time to make a copy with with (cont -> cont): {t1 - t0:.5f}")
print(f"- Chunks: {b.chunks}")
# Do a regular copy
t0 = time()
c = a.copy()
t1 = time()
print(f"Time to make a copy (cont -> cont): {t1 - t0:.5f}")
print(f"- Chunks: {c.chunks}")
# Get a slice (view)
v = a[0]
t0 = time()
d = v.copy()
t1 = time()
print(f"Time to make a copy (view -> cont): {t1 - t0:.5f}")
print(f"- View chunks: {v.chunks}")
print(f"- Chunks: {d.chunks}")