@@ -815,6 +815,14 @@ cdef class BaseArray:
815
815
def __get__ (self ):
816
816
return self .size * self .itemsize
817
817
818
+ property chunk_size :
819
+ def __get__ (self ):
820
+ return reduce (operator.mul, self ._chunks)
821
+
822
+ property chunk_nbytes :
823
+ def __get__ (self ):
824
+ return self .chunk_size * self .itemsize
825
+
818
826
def __getitem__ (self , item ):
819
827
cdef ndarray dest
820
828
cdef BaseChunk chunk
@@ -928,6 +936,8 @@ cdef class BaseArray:
928
936
r += ' ; cbytes: %s ' % _util.human_readable_size(self .cbytes)
929
937
if self .cbytes > 0 :
930
938
r += ' ; ratio: %.1f ' % (self .nbytes / self .cbytes)
939
+ # r += '; chunk_nbytes: %s' % \
940
+ # _util.human_readable_size(self.chunk_nbytes)
931
941
n_chunks = reduce (operator.mul, self ._cdata_shape)
932
942
r += ' ; initialized: %s /%s ' % (np.count_nonzero(self .is_initialized),
933
943
n_chunks)
@@ -1140,7 +1150,7 @@ cdef class PersistentArray(BaseArray):
1140
1150
meta_path = os.path.join(path, defaults.metapath)
1141
1151
1142
1152
if mode in [' r' , ' r+' ]:
1143
- self ._open(path)
1153
+ self ._open(path, ** kwargs )
1144
1154
1145
1155
elif mode == ' w' :
1146
1156
if os.path.exists(path):
@@ -1154,7 +1164,7 @@ cdef class PersistentArray(BaseArray):
1154
1164
1155
1165
elif mode == ' a' :
1156
1166
if os.path.exists(meta_path):
1157
- self ._open(path)
1167
+ self ._open(path, ** kwargs )
1158
1168
else :
1159
1169
self ._create(path, ** kwargs)
1160
1170
@@ -1207,19 +1217,32 @@ cdef class PersistentArray(BaseArray):
1207
1217
' fill_value' : self ._fill_value}
1208
1218
_write_array_metadata(path, metadata)
1209
1219
1210
- def _open (self , path ):
1220
+ def _open (self , path , shape = None , chunks = None , dtype = None , cname = None ,
1221
+ clevel = None , shuffle = None , fill_value = None ):
1211
1222
1212
1223
# read metadata
1213
1224
metadata = _read_array_metadata(path)
1214
1225
1215
1226
# set attributes
1216
1227
self ._shape = metadata[' shape' ]
1217
- self ._dtype = metadata[' dtype' ]
1218
1228
self ._chunks = metadata[' chunks' ]
1229
+ self ._dtype = metadata[' dtype' ]
1219
1230
self ._cname = metadata[' cname' ]
1220
1231
self ._clevel = metadata[' clevel' ]
1221
1232
self ._shuffle = metadata[' shuffle' ]
1222
1233
self ._fill_value = metadata[' fill_value' ]
1234
+
1235
+ # check consistency with user arguments
1236
+ if shape is not None and _normalize_shape(shape) != self ._shape:
1237
+ raise ValueError (' shape %r not consistent with existing %r ' %
1238
+ (shape, self ._shape))
1239
+ if chunks is not None and \
1240
+ _normalize_chunks(chunks, self ._shape) != self ._chunks:
1241
+ raise ValueError (' chunks %r not consistent with existing %r ' %
1242
+ (chunks, self ._chunks))
1243
+ if dtype is not None and np.dtype(dtype) != self ._dtype:
1244
+ raise ValueError (' dtype %r not consistent with existing %r ' %
1245
+ (dtype, self ._dtype))
1223
1246
1224
1247
property cbytes :
1225
1248
def __get__ (self ):
@@ -1455,6 +1478,7 @@ cdef class LazyPersistentArray(PersistentArray):
1455
1478
bn = os.path.basename(fn)[:- len (defaults.datasuffix)]
1456
1479
cidx = tuple (map (int , bn.split(' .' )))
1457
1480
a[cidx] = True
1481
+ return a
1458
1482
1459
1483
cdef BaseChunk get_chunk(self , tuple cidx):
1460
1484
return _lazy_get_chunk(self , cidx)
@@ -1486,6 +1510,8 @@ cdef class LazyPersistentArray(PersistentArray):
1486
1510
yield cidx, chunk
1487
1511
1488
1512
def resize (self , *args ):
1513
+ if self ._mode == ' r' :
1514
+ raise ValueError (' array is read-only' )
1489
1515
1490
1516
# do resize
1491
1517
_lazy_resize(self , * args)
0 commit comments