def _empty_inner(self, row, col, filename, row_property, col_property, order, dtype, val_shape): self._ran_once = True self._dtype = np.dtype(dtype) self._order = order row = PstData._fixup_input(row) col = PstData._fixup_input(col) row_property = PstData._fixup_input(row_property,count=len(row)) col_property = PstData._fixup_input(col_property,count=len(col)) with open(filename,'wb') as fp: np.save(fp, np.array([_magic_number])) np.save(fp, np.array(["pstmemmap"])) #name of file format np.save(fp, np.array([2])) #file format version np.save(fp, row) np.save(fp, col) np.save(fp, row_property) np.save(fp, col_property) np.save(fp, np.array([self._dtype])) np.save(fp, np.array([self._order])) np.save(fp, np.array([val_shape])) self._offset = fp.tell() logging.info("About to start allocating memmap '{0}'".format(filename)) shape = (len(row),len(col)) if val_shape is None else (len(row),len(col),val_shape) val = np.memmap(filename, offset=self._offset, dtype=dtype, mode="r+", order=order, shape=shape) logging.info("Finished allocating memmap '{0}'. Size is {1:,}".format(filename,os.path.getsize(filename))) PstData.__init__(self,row,col,val,row_property,col_property,name="np.memmap('{0}')".format(filename))
def _run_once(self): if (self._ran_once): return row, col, val, row_property, col_property = self._run_once_inner() PstData.__init__(self, row, col, val, row_property, col_property, name="np.memmap('{0}')".format(self._filename))