File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22import numpy as np
33import blosc2
44import time
5-
5+ from memory_profiler import memory_usage
6+ import matplotlib .pyplot as plt
67
78file = "dset-ones.b2nd"
89# a = blosc2.open(file)
2526print (f"Time to create expression: { time .time () - t :.6f} seconds" )
2627
2728# dim0
28- t = time .time ()
29- res = expr [1 ]
30- t0 = time .time () - t
31- print (f"Time to access dim0: { t0 :.6f} seconds" )
29+ def slice_dim0 ():
30+ t = time .time ()
31+ res = expr [1 ]
32+ t0 = time .time () - t
33+ print (f"Time to access dim0: { t0 :.6f} seconds" )
3234
3335# dim1
34- t = time .time ()
35- res = expr [:,1 ]
36- t1 = time .time () - t
37- print (f"Time to access dim1: { t1 :.6f} seconds" )
36+ def slice_dim1 ():
37+ t = time .time ()
38+ res = expr [:,1 ]
39+ t1 = time .time () - t
40+ print (f"Time to access dim1: { t1 :.6f} seconds" )
3841
3942# dim2
40- t = time .time ()
41- res = expr [:,:,1 ]
42- t2 = time .time () - t
43- print (f"Time to access dim2: { t2 :.6f} seconds" )
43+ def slice_dim2 ():
44+ t = time .time ()
45+ res = expr [:,:,1 ]
46+ t2 = time .time () - t
47+ print (f"Time to access dim2: { t2 :.6f} seconds" )
4448
4549# dim3
46- t = time .time ()
47- res = expr [:,:,:,1 ]
48- #res = expr[1]
49- t3 = time .time () - t
50+ def slice_dim3 ():
51+ t = time .time ()
52+ res = expr [:,:,:,1 ]
53+ #res = expr[1]
54+ t3 = time .time () - t
55+
56+ print (f"Time to access dim3: { t3 :.6f} seconds" )
57+
58+ fig = plt .figure ()
59+ interval = 0.001
60+ offset = 0
61+ for f in [slice_dim0 , slice_dim1 , slice_dim2 , slice_dim3 ]:
62+ mem = memory_usage ((f ,), interval = interval )
63+ times = offset + interval * np .arange (len (mem ))
64+ offset = times [- 1 ]
65+ plt .plot (times , mem )
5066
51- print (f"Time to access dim3: { t3 :.6f} seconds" )
67+ plt .xlabel ('Time (s)' )
68+ plt .ylabel ('Memory usage (MiB)' )
69+ plt .title ('Memory usage over time for slicing operations, slice-expr.py' )
70+ plt .legend (['dim0' , 'dim1' , 'dim2' , 'dim3' ])
71+ plt .savefig ('plots/slice-expr.png' , format = "png" )
Original file line number Diff line number Diff line change @@ -1076,7 +1076,7 @@ def test_eval_getitem(array_fixture):
10761076 np .testing .assert_allclose (expr [:10 ], nres [:10 ])
10771077 np .testing .assert_allclose (expr [0 :10 :2 ], nres [0 :10 :2 ])
10781078
1079- # Small test
1079+ # Small test for non-isomorphic shape
10801080 shape = (2 , 10 , 5 )
10811081 test_arr = blosc2 .linspace (0 , 10 , np .prod (shape ), shape = shape )
10821082 expr = test_arr * 30
@@ -1085,6 +1085,15 @@ def test_eval_getitem(array_fixture):
10851085 np .testing .assert_allclose (expr [:10 ], nres [:10 ])
10861086 np .testing .assert_allclose (expr [0 :10 :2 ], nres [0 :10 :2 ])
10871087
1088+ # Small test for broadcasting
1089+ shape = (2 , 10 , 5 )
1090+ test_arr = blosc2 .linspace (0 , 10 , np .prod (shape ), shape = shape )
1091+ expr = test_arr + test_arr .slice (slice (1 , 2 ))
1092+ nres = test_arr [:] + test_arr [1 ]
1093+ np .testing .assert_allclose (expr [0 ], nres [0 ])
1094+ np .testing .assert_allclose (expr [:10 ], nres [:10 ])
1095+ np .testing .assert_allclose (expr [0 :10 :2 ], nres [0 :10 :2 ])
1096+
10881097
10891098# Test lazyexpr's slice method
10901099def test_eval_slice (array_fixture ):
You can’t perform that action at this time.
0 commit comments