@@ -289,7 +289,7 @@ cdef class SynchronizedChunk(Chunk):
289
289
super (SynchronizedChunk, self ).__setitem__(key, value)
290
290
291
291
292
- cdef normalise_array_selection(item, shape):
292
+ def normalise_array_selection (item , shape ):
293
293
""" Convenience function to normalise a selection within an array with
294
294
the given `shape`."""
295
295
@@ -318,7 +318,7 @@ cdef normalise_array_selection(item, shape):
318
318
raise ValueError (' expected indices or slice, found: %r ' % item)
319
319
320
320
321
- cdef normalise_axis_selection(item, l):
321
+ def normalise_axis_selection (item , l ):
322
322
""" Convenience function to normalise a selection within a single axis
323
323
of size `l`."""
324
324
@@ -349,30 +349,30 @@ cdef normalise_axis_selection(item, l):
349
349
raise ValueError (' expected integer or slice, found: %r ' % item)
350
350
351
351
352
- cdef get_chunk_range(tuple selection, tuple chunks):
352
+ def get_chunk_range (tuple selection , tuple chunks ):
353
353
""" Convenience function to get a range over all chunk indices,
354
354
for iterating over chunks."""
355
355
chunk_range = [range (start// l, int (np.ceil(stop/ l)))
356
356
for (start, stop), l in zip (selection, chunks)]
357
357
return chunk_range
358
358
359
359
360
- cdef normalise_shape(shape):
360
+ def normalise_shape (shape ):
361
361
""" Convenience function to normalise the `shape` argument."""
362
- if isinstance (shape, int ) :
363
- shape = ( shape, )
364
- else :
365
- shape = tuple ( shape)
362
+ try :
363
+ shape = tuple ( int (s) for s in shape)
364
+ except TypeError :
365
+ shape = ( int ( shape), )
366
366
return shape
367
367
368
368
369
- cdef normalise_chunks(chunks, tuple shape):
369
+ def normalise_chunks (chunks , tuple shape ):
370
370
""" Convenience function to normalise the `chunks` argument for an array
371
371
with the given `shape`."""
372
- if isinstance (chunks, int ) :
373
- chunks = ( chunks, )
374
- else :
375
- chunks = tuple ( chunks)
372
+ try :
373
+ chunks = tuple ( int (c) for c in chunks)
374
+ except TypeError :
375
+ chunks = ( int ( chunks), )
376
376
if len (chunks) < len (shape):
377
377
# assume chunks across remaining dimensions
378
378
chunks += shape[len (chunks):]
0 commit comments