def dst_group_struct(self, dst_group_struct): if dst_group_struct is None: self._dst_group_struct = None self._dst_ngroups = 0 self._src_to_dst_matrix = None elif same_arr_or_none(dst_group_struct, self._dst_group_struct): return else: self._dst_group_struct = np.asarray(dst_group_struct) self._dst_ngroups = len(dst_group_struct) - 1 self._src_to_dst_matrix = partial_energy_matrix( dst_group_struct, self._src_group_struct)
def __setitem__(self, key, value): """Key setting via custom cache functionality.""" # Set the E_g if (key == 'E_g'): value = _valid_group_struct(value) cache_value = self._cache['E_g'] self.clear() self._cache['phi_g'] = None for ds in self.data_sources: ds.dst_group_struct = value elif (key == 'phi_g'): value = value if value is None else np.asarray(value, dtype='f8') cache_value = self._cache['phi_g'] if same_arr_or_none(value, cache_value): return E_g = self._cache['E_g'] if len(value) + 1 == len(E_g): self.clear() else: raise ValueError("phi_g does not match existing group structure E_g!") # Set the value normally self._cache[key] = value