@@ -54,6 +54,7 @@ def __init__(self, size_ckp, n_ckp, dtype, profiler, wd=0, rd=0, name="storage")
5454 self .name = name
5555 self .__maxsize = self .size_ckp * n_ckp
5656 self .__current_size = 0
57+ self .__itemsize = np .dtype (self .dtype ).itemsize
5758
5859 # stack interface controls
5960 self .__stack_ptr = - 1
@@ -97,12 +98,17 @@ def isEmpty(self):
9798
9899 @property
99100 def maxsize (self ):
100- """Returns the maximum storage size in bytes """
101+ """Returns the maximum storage size in words of 'dtype' """
101102 return self .__maxsize
102103
104+ @property
105+ def maxsize_in_bytes (self ):
106+ """Returns the maximum storage size in bytes"""
107+ return self .__maxsize * self .__itemsize
108+
103109 @property
104110 def size (self ):
105- """Returns the current storage size in bytes """
111+ """Returns the current storage size in words of 'dtype' """
106112 return self .__current_size
107113
108114 @property
@@ -216,12 +222,13 @@ def save(self, key, data_pointers):
216222 else :
217223 ckpfile = self .datFileName + (".k%d" % (key ))
218224 self .checkFilesDir ()
219- slot = open (ckpfile , "bw+ " )
225+ slot = open (ckpfile , "bw" )
220226
221227 for ptr in data_pointers :
222228 assert ptr .strides [- 1 ] == ptr .itemsize
223229 with self .profiler .get_timer ("storage" , "flatten" ):
224230 data = ptr .ravel ()
231+ data = data .astype (self .dtype )
225232 data .tofile (slot )
226233 slot .flush ()
227234 self .__current_size += self .size_ckp
@@ -238,7 +245,7 @@ def load(self, key, locations):
238245 else :
239246 ckpfile = self .datFileName + (".k%d" % (key ))
240247 self .checkFilesDir ()
241- slot = open (ckpfile , "br+ " )
248+ slot = open (ckpfile , "br" )
242249
243250 offset = 0
244251 for shape , ptr in zip (self .shapes [key ], locations ):
@@ -283,6 +290,7 @@ def save(self, key, data_pointers):
283290 data = ptr .ravel ()
284291 with self .profiler .get_timer ("storage" , "copy_save" ):
285292 np .copyto (slot [offset :(len (data ) + offset )], data )
293+
286294 offset += len (data )
287295 shapes .append (ptr .shape )
288296 self .shapes [key ] = shapes
0 commit comments