5
5
import numpy as np
6
6
7
7
8
- import zarr . ext as _ext
8
+ from zarr import ext as _ext
9
9
10
10
11
11
def empty (shape , chunks , dtype = None , cname = None , clevel = None , shuffle = None ,
12
- synchronized = True ):
12
+ synchronized = True , lazy = False ):
13
13
"""Create an empty array.
14
14
15
15
Parameters
@@ -31,6 +31,10 @@ def empty(shape, chunks, dtype=None, cname=None, clevel=None, shuffle=None,
31
31
synchronized : bool, optional
32
32
If True, each chunk will be protected with a lock to prevent data
33
33
collision during concurrent write operations.
34
+ lazy : bool, optional
35
+ If True, an alternative array class is used which instantiates chunk
36
+ objects only on demand. This may reduce overhead when working with
37
+ small regions of very large arrays with a large number of chunks.
34
38
35
39
Returns
36
40
-------
@@ -39,15 +43,21 @@ def empty(shape, chunks, dtype=None, cname=None, clevel=None, shuffle=None,
39
43
"""
40
44
41
45
if synchronized :
42
- cls = _ext .SynchronizedArray
46
+ if lazy :
47
+ cls = _ext .SynchronizedLazyArray
48
+ else :
49
+ cls = _ext .SynchronizedArray
43
50
else :
44
- cls = _ext .Array
51
+ if lazy :
52
+ cls = _ext .LazyArray
53
+ else :
54
+ cls = _ext .Array
45
55
return cls (shape = shape , chunks = chunks , dtype = dtype , cname = cname ,
46
56
clevel = clevel , shuffle = shuffle )
47
57
48
58
49
59
def zeros (shape , chunks , dtype = None , cname = None , clevel = None , shuffle = None ,
50
- synchronized = True ):
60
+ synchronized = True , lazy = False ):
51
61
"""Create an array, with zero being used as the default value for
52
62
uninitialised portions of the array.
53
63
@@ -70,6 +80,10 @@ def zeros(shape, chunks, dtype=None, cname=None, clevel=None, shuffle=None,
70
80
synchronized : bool, optional
71
81
If True, each chunk will be protected with a lock to prevent data
72
82
collision during concurrent write operations.
83
+ lazy : bool, optional
84
+ If True, an alternative array class is used which instantiates chunk
85
+ objects only on demand. This may reduce overhead when working with
86
+ small regions of very large arrays with a large number of chunks.
73
87
74
88
Returns
75
89
-------
@@ -78,15 +92,21 @@ def zeros(shape, chunks, dtype=None, cname=None, clevel=None, shuffle=None,
78
92
"""
79
93
80
94
if synchronized :
81
- cls = _ext .SynchronizedArray
95
+ if lazy :
96
+ cls = _ext .SynchronizedLazyArray
97
+ else :
98
+ cls = _ext .SynchronizedArray
82
99
else :
83
- cls = _ext .Array
100
+ if lazy :
101
+ cls = _ext .LazyArray
102
+ else :
103
+ cls = _ext .Array
84
104
return cls (shape = shape , chunks = chunks , dtype = dtype , cname = cname ,
85
105
clevel = clevel , shuffle = shuffle , fill_value = 0 )
86
106
87
107
88
108
def ones (shape , chunks , dtype = None , cname = None , clevel = None , shuffle = None ,
89
- synchronized = True ):
109
+ synchronized = True , lazy = False ):
90
110
"""Create an array, with one being used as the default value for
91
111
uninitialised portions of the array.
92
112
@@ -109,6 +129,10 @@ def ones(shape, chunks, dtype=None, cname=None, clevel=None, shuffle=None,
109
129
synchronized : bool, optional
110
130
If True, each chunk will be protected with a lock to prevent data
111
131
collision during write operations.
132
+ lazy : bool, optional
133
+ If True, an alternative array class is used which instantiates chunk
134
+ objects only on demand. This may reduce overhead when working with
135
+ small regions of very large arrays with a large number of chunks.
112
136
113
137
Returns
114
138
-------
@@ -117,15 +141,21 @@ def ones(shape, chunks, dtype=None, cname=None, clevel=None, shuffle=None,
117
141
"""
118
142
119
143
if synchronized :
120
- cls = _ext .SynchronizedArray
144
+ if lazy :
145
+ cls = _ext .SynchronizedLazyArray
146
+ else :
147
+ cls = _ext .SynchronizedArray
121
148
else :
122
- cls = _ext .Array
149
+ if lazy :
150
+ cls = _ext .LazyArray
151
+ else :
152
+ cls = _ext .Array
123
153
return cls (shape = shape , chunks = chunks , dtype = dtype , cname = cname ,
124
154
clevel = clevel , shuffle = shuffle , fill_value = 1 )
125
155
126
156
127
157
def full (shape , chunks , fill_value , dtype = None , cname = None , clevel = None ,
128
- shuffle = None , synchronized = True ):
158
+ shuffle = None , synchronized = True , lazy = False ):
129
159
"""Create an array, with `fill_value` being used as the default value for
130
160
uninitialised portions of the array.
131
161
@@ -150,6 +180,10 @@ def full(shape, chunks, fill_value, dtype=None, cname=None, clevel=None,
150
180
synchronized : bool, optional
151
181
If True, each chunk will be protected with a lock to prevent data
152
182
collision during write operations.
183
+ lazy : bool, optional
184
+ If True, an alternative array class is used which instantiates chunk
185
+ objects only on demand. This may reduce overhead when working with
186
+ small regions of very large arrays with a large number of chunks.
153
187
154
188
Returns
155
189
-------
@@ -158,15 +192,21 @@ def full(shape, chunks, fill_value, dtype=None, cname=None, clevel=None,
158
192
"""
159
193
160
194
if synchronized :
161
- cls = _ext .SynchronizedArray
195
+ if lazy :
196
+ cls = _ext .SynchronizedLazyArray
197
+ else :
198
+ cls = _ext .SynchronizedArray
162
199
else :
163
- cls = _ext .Array
200
+ if lazy :
201
+ cls = _ext .LazyArray
202
+ else :
203
+ cls = _ext .Array
164
204
return cls (shape = shape , chunks = chunks , dtype = dtype , cname = cname ,
165
205
clevel = clevel , shuffle = shuffle , fill_value = fill_value )
166
206
167
207
168
208
def array (data , chunks = None , dtype = None , cname = None , clevel = None ,
169
- shuffle = None , fill_value = None , synchronized = True ):
209
+ shuffle = None , fill_value = None , synchronized = True , lazy = False ):
170
210
"""Create an array filled with `data`.
171
211
172
212
Parameters
@@ -190,13 +230,29 @@ def array(data, chunks=None, dtype=None, cname=None, clevel=None,
190
230
synchronized : bool, optional
191
231
If True, each chunk will be protected with a lock to prevent data
192
232
collision during write operations.
233
+ lazy : bool, optional
234
+ If True, an alternative array class is used which instantiates chunk
235
+ objects only on demand. This may reduce overhead when working with
236
+ small regions of very large arrays with a large number of chunks.
193
237
194
238
Returns
195
239
-------
196
240
z : zarr Array
197
241
198
242
"""
199
243
244
+ # determine array class to use
245
+ if synchronized :
246
+ if lazy :
247
+ cls = _ext .SynchronizedLazyArray
248
+ else :
249
+ cls = _ext .SynchronizedArray
250
+ else :
251
+ if lazy :
252
+ cls = _ext .LazyArray
253
+ else :
254
+ cls = _ext .Array
255
+
200
256
# ensure data is array-like
201
257
if not hasattr (data , 'shape' ) or not hasattr (data , 'dtype' ):
202
258
data = np .asanyarray (data )
@@ -219,11 +275,7 @@ def array(data, chunks=None, dtype=None, cname=None, clevel=None,
219
275
else :
220
276
raise ValueError ('chunks must be specified' )
221
277
222
- # create array
223
- if synchronized :
224
- cls = _ext .SynchronizedArray
225
- else :
226
- cls = _ext .Array
278
+ # instantiate array
227
279
z = cls (shape = shape , chunks = chunks , dtype = dtype , cname = cname ,
228
280
clevel = clevel , shuffle = shuffle , fill_value = fill_value )
229
281
@@ -273,6 +325,8 @@ def open(path, mode='a', shape=None, chunks=None, dtype=None, cname=None,
273
325
274
326
"""
275
327
328
+ # TODO lazy option
329
+
276
330
if synchronized :
277
331
cls = _ext .SynchronizedPersistentArray
278
332
else :
0 commit comments