def get_flattened_value(self, path): """Return the named value, which may include an array index, as a flattened array of floats. If the value is not flattenable into an array of floats, raise a TypeError. """ val, idx = get_val_and_index(self, path) return flattened_value(path, val)
def _initialize(self, system): scope = system.scope name2collapsed = scope.name2collapsed flat_vars = system.flat_vars vector_vars = system.vector_vars self.app_ordering = system.app_ordering rank = system.mpi.rank vec_srcs = set([n[0] for n in vector_vars]) # to detect overlapping index sets, we need all of the subvar bases # that are NOT included in the vectors. If a base IS included in the vectors, # then all of its subvars are just subviews of the base view, so no chance # of overlapping causing redundant data in the vectors bases = dict([(n.split('[',1)[0], []) for n in vec_srcs if n.split('[',1)[0] not in vec_srcs]) # first, add views for vars whose sizes are added to the total, # i.e., either they are basevars or their basevars are not included # in the vector. start, end = 0, 0 for ivar, (name, var) in enumerate(vector_vars.items()): sz = system.local_var_sizes[rank, ivar] if sz > 0: end += sz # store the view, local start idx, and distributed start idx self._info[name] = ViewInfo(self.array[start:end], start, slice(None), end-start, False) base = name[0].split('[',1)[0] if base in bases and base not in vec_srcs: bases[base].append(name[0]) if len(bases[base]) > 1: # check for overlaping subvars idxset = set() bval = scope.get(base) for subname in bases[base]: _, idx = get_val_and_index(scope, subname) idxs = get_flattened_index(idx, get_shape(bval), cvt_to_slice=False) if idxset.intersection(set(idxs)): raise RuntimeError("Subvars %s share overlapping indices. Try reformulating the problem to prevent this." % [n for n in bases[base]]) idxset.update(idxs) if end-start > self.array[start:end].size: raise RuntimeError("size mismatch: in system %s view for %s is %s, size=%d" % (system.name,name, [start,end],self[name].size)) start += sz # now add views for subvars that are subviews of their # basevars if vector_vars: for name, var in flat_vars.items(): if name not in vector_vars: self._add_subview(scope, name)