def __repr__(self): s = "" for k in self.__odict__: #_odict.__iter__(self): s += "('" + k + "', " + str(self[k]) + "), " if len(s) > 0: s = s[:-2] return _odict.__class__(_odict(self)).__name__ + "([" + s + "])"
def _group_structs(self, lst, make_variable, make_struct, coerce_array): array_of_structs_re = _re.compile("^([a-zA-Z_][a-zA-Z_0-9]*)\[([0-9]+)\]\.([a-zA-Z_][a-zA-Z_0-9]*)$") struct_re = _re.compile("^([a-zA-Z_][a-zA-Z_0-9]*)\.([a-zA-Z_][a-zA-Z_0-9]*)$") array_re = _re.compile("^([a-zA-Z_][a-zA-Z_0-9]*)\[([0-9]+)\]$") basic_re = _re.compile("^([a-zA-Z_][a-zA-Z_0-9]*)$") names = _odict() for location, size, dtype, name in lst: m = array_of_structs_re.match(name) if m is not None: name, index, field = m.groups() index = int(index) array = names.setdefault(name, coerce_array(name, parent=self)) array[index, field] = make_variable(field, location, dtype, size, parent=self) continue m = struct_re.match(name) if m is not None: name, field = m.groups() struct = names.setdefault(name, make_struct(name, parent=self)) struct[field] = make_variable(field, location, dtype, size, parent=self) continue m = array_re.match(name) if m is not None: name, index = m.groups() index = int(index) names[name] = make_variable(name, location, dtype, size, parent=self) # TODO how should this depend on index? continue m = basic_re.match(name) if m is not None: name, = m.groups() names[name] = make_variable(name, location, dtype, size, parent=self) continue raise NameError("shader variable '%s' could not be parsed" % name) return names
def _group_structs(self, lst, make_variable, make_struct, coerce_array): array_of_structs_re = _re.compile( "^([a-zA-Z_][a-zA-Z_0-9]*)\[([0-9]+)\]\.([a-zA-Z_][a-zA-Z_0-9]*)$") struct_re = _re.compile( "^([a-zA-Z_][a-zA-Z_0-9]*)\.([a-zA-Z_][a-zA-Z_0-9]*)$") array_re = _re.compile("^([a-zA-Z_][a-zA-Z_0-9]*)\[([0-9]+)\]$") basic_re = _re.compile("^([a-zA-Z_][a-zA-Z_0-9]*)$") names = _odict() for location, size, dtype, name in lst: m = array_of_structs_re.match(name) if m is not None: name, index, field = m.groups() index = int(index) array = names.setdefault(name, coerce_array(name, parent=self)) array[index, field] = make_variable(field, location, dtype, size, parent=self) continue m = struct_re.match(name) if m is not None: name, field = m.groups() struct = names.setdefault(name, make_struct(name, parent=self)) struct[field] = make_variable(field, location, dtype, size, parent=self) continue m = array_re.match(name) if m is not None: name, index = m.groups() index = int(index) names[name] = make_variable( name, location, dtype, size, parent=self) # TODO how should this depend on index? continue m = basic_re.match(name) if m is not None: name, = m.groups() names[name] = make_variable(name, location, dtype, size, parent=self) continue raise NameError("shader variable '%s' could not be parsed" % name) return names
def __init__(self, data=[], warn=True, lock=False, interactive=True): ''' A dictionary or list of tuples of key/value pairs. If lock=True, keys cannot be reassigned without first deleting the item. If interactive=True, then expose keys as attributes. ''' super(ListDict, self).__setattr__('__lock__', lock) super(ListDict, self).__setattr__('__warn__', warn) super(ListDict, self).__setattr__('__inter__', interactive) if isinstance(data, dict): data = [ i for i in data.items() ] if interactive: data = make_safe(data, warn) super(ListDict, self).__setattr__('__odict__', _odict(data)) if interactive and data: self.__dict__.update(data)
def __init__(self, data=[], warn=True, lock=False, interactive=True): ''' A dictionary or list of tuples of key/value pairs. If lock=True, keys cannot be reassigned without first deleting the item. If interactive=True, then expose keys as attributes. ''' super(ListDict, self).__setattr__('__lock__', lock) super(ListDict, self).__setattr__('__warn__', warn) super(ListDict, self).__setattr__('__inter__', interactive) if isinstance(data, dict): data = [i for i in data.items()] if interactive: data = make_safe(data, warn) super(ListDict, self).__setattr__('__odict__', _odict(data)) if interactive and data: self.__dict__.update(data)
def set_explicit_water_wires(self, max_water=5, allow_direct_bonds=True, water_in_convex_hull=False): self.set_water_wires(max_water, allow_direct_bonds, water_in_convex_hull) filtered_results = {} for wire_key in self.hashs: hashs, hash_index, hash_count = _np.unique(self.hashs[wire_key], return_index=True, return_counts=True) filter_occupancy = _np.in1d(hashs, _np.arange(-1, self.nb_frames, dtype=int), invert=True) occupancy = (hash_count / self.nb_frames)[filter_occupancy] for i,h in enumerate(hashs[filter_occupancy]): try: w_string = ':'.join([self._all_ids[w_id] for w_id in self.hash_table[h]]) except KeyError: if allow_direct_bonds: w_string = wire_key else: break try: filtered_results[occupancy[i]].append((w_string, hash_index[filter_occupancy][i], self.hashs[wire_key] == h)) except: filtered_results[occupancy[i]] = [] filtered_results[occupancy[i]].append((w_string, hash_index[filter_occupancy][i], self.hashs[wire_key] == h)) occupancy_dict = _odict(sorted(filtered_results.items())) edges = [] first_frame_dict = {} temp_occupancy_dict = {} for occupancy in occupancy_dict: for wire, first_appearance_frame, occupancy_series in occupancy_dict[occupancy]: nodes_in_wire = wire.split(':') for node in nodes_in_wire: first_frame_dict[node] = first_appearance_frame for nodea, nodeb in _hf.pairwise(nodes_in_wire): edges.append(':'.join((nodea,nodeb))) temp_occupancy_dict[':'.join((nodea,nodeb))] = occupancy_series self.current_results = temp_occupancy_dict self.filtered_results = temp_occupancy_dict self._generate_graph_from_current_results() self._generate_filtered_graph_from_filtered_results() self.occupancy_dict = occupancy_dict self.first_frame_dict = first_frame_dict
def __repr__(self): unique_values = _odict( (field, value) for ((index, field), value) in list(self.items())) return "struct { %s } %s[%d];" % (" ".join( repr(value) for value in list(unique_values.values())), self.name, self.size)
def __str__(self): unique_values = _odict((field, value) for ((index, field), value) in list(self.items())) return "uniform struct { %s } %s[%d];" % (" ".join(str(value) for value in list(unique_values.values())), self.name, self.size)