def _expand_if_needed(self, dims, write_dims, start, offset):
from operator import mul<EOL>if numpy.isscalar(start):<EOL><INDENT>start_is_scalar = True<EOL><DEDENT>else:<EOL><INDENT>start_is_scalar = False<EOL><DEDENT>existing_size = reduce(mul, dims, <NUM_LIT:1>)<EOL>required_size = offset + reduce(mul, write_dims, <NUM_LIT:1>)<EOL>if required_size > existing_size:<EOL><INDENT>print(<EOL>"<STR_LIT>", required_size,<EOL>"<STR_LIT>", existing_size)<EOL>ndim = len(dims)<EOL>idim = len(write_dims)<EOL>if start_is_scalar:<EOL><INDENT>if start == <NUM_LIT:0>:<EOL><INDENT>start = [<NUM_LIT:0>]*ndim<EOL><DEDENT>else:<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" % start)<EOL><DEDENT><DEDENT>if idim != ndim:<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" % (idim, ndim))<EOL><DEDENT>new_dims = []<EOL>for i in xrange(ndim):<EOL><INDENT>required_dim = start[i] + write_dims[i]<EOL>if required_dim < dims[i]:<EOL><INDENT>dimsize = dims[i]<EOL><DEDENT>else:<EOL><INDENT>dimsize = required_dim<EOL><DEDENT>new_dims.append(dimsize)<EOL><DEDENT>print("<STR_LIT>", new_dims)<EOL>self.reshape(new_dims)<EOL><DEDENT>
expand the on-disk image if the indended write will extend
beyond the existing dimensions