Python six.itervalues() Examples
The following are 30
code examples of six.itervalues().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
six
, or try the search function
.
Example #1
Source File: node.py From tributary with Apache License 2.0 | 6 votes |
def set(self, *args, **kwargs): for k, v in six.iteritems(kwargs): _set = False for deps in six.itervalues(self._dependencies): # try to set args for arg in deps[0]: if arg._name_no_id() == k: arg._dirty = (arg._value != v) arg._value = v _set = True break if _set: continue # try to set kwargs for kwarg in six.itervalues(deps[1]): if kwarg._name_no_id() == k: kwarg._dirty = (kwarg._value != v) kwarg._value = v _set = True break
Example #2
Source File: scheduler.py From pyspider with Apache License 2.0 | 6 votes |
def _check_delete(self): '''Check project delete''' now = time.time() for project in list(itervalues(self.projects)): if project.db_status != 'STOP': continue if now - project.updatetime < self.DELETE_TIME: continue if 'delete' not in self.projectdb.split_group(project.group): continue logger.warning("deleting project: %s!", project.name) del self.projects[project.name] self.taskdb.drop(project.name) self.projectdb.drop(project.name) if self.resultdb: self.resultdb.drop(project.name) for each in self._cnt.values(): del each[project.name]
Example #3
Source File: sgmcmc.py From zhusuan with MIT License | 6 votes |
def _apply_updates(self, grad_func): qs = self._var_list self._define_variables(qs) update_ops, infos = self._update(qs, grad_func) with tf.control_dependencies([self.t.assign_add(1)]): sample_op = tf.group(*update_ops) list_attrib = zip(*map(lambda d: six.itervalues(d), infos)) list_attrib_with_k = map(lambda l: dict(zip(self._latent_k, l)), list_attrib) attrib_names = list(six.iterkeys(infos[0])) dict_info = dict(zip(attrib_names, list_attrib_with_k)) SGMCMCInfo = namedtuple("SGMCMCInfo", attrib_names) sgmcmc_info = SGMCMCInfo(**dict_info) return sample_op, sgmcmc_info
Example #4
Source File: collection.py From rekall with GNU General Public License v2.0 | 6 votes |
def collect(self): which = self.session.plugins.which_plugin( type_name=self.plugin_args.type_name, producers_only=True) results = {} for producer in which.collect(): # We know the producer plugin implements 'produce' because # 'which_plugin' guarantees it. self.session.logging.debug("Producing %s from producer %r", self.type_name, producer) for result in producer.produce(): previous = results.get(result.indices) if previous: previous.obj_producers.add(producer.name) else: result.obj_producers = set([producer.name]) results[result.indices] = result return six.itervalues(results)
Example #5
Source File: async_task.py From asynq with Apache License 2.0 | 6 votes |
def extract_futures(value, result): """Enumerates all the futures inside a particular value.""" if value is None: pass elif isinstance(value, futures.FutureBase): result.append(value) elif type(value) is tuple or type(value) is list: # backwards because tasks are added to a stack, so the last one executes first i = len(value) - 1 while i >= 0: extract_futures(value[i], result) i -= 1 elif type(value) is dict: for item in six.itervalues(value): extract_futures(item, result) return result
Example #6
Source File: contquery.py From python-esppy with Apache License 2.0 | 6 votes |
def delete_templates(self, *templates): ''' Delete templates and related windows Parameters ---------- templates : one-or-more strings or Template objects The template to delete ''' for item in templates: template_key = getattr(item, 'name', item) template = self.templates[template_key] self.delete_windows(*six.itervalues(template.windows)) del self.templates[template_key] return self.templates
Example #7
Source File: updater.py From chainer-stylegan with MIT License | 6 votes |
def __init__(self, models, optimizer, stage_manager, device=None, **kwargs): if len(models) == 3: models = models + [None, None] self.map, self.gen, self.dis, self.smoothed_gen, self.smoothed_map = models assert isinstance(optimizer, dict) self._optimizers = optimizer if device is not None and device >= 0: for _optimizer in six.itervalues(self._optimizers): _optimizer.target.to_gpu(device) self.device = device # Stage manager self.stage_manager = stage_manager # Parse kwargs for updater self.use_cleargrads = kwargs.pop('use_cleargrads') self.smoothing = kwargs.pop('smoothing') self.lambda_gp = kwargs.pop('lambda_gp') self.total_gpu = kwargs.pop('total_gpu') self.style_mixing_rate = kwargs.pop('style_mixing_rate')
Example #8
Source File: IdCommand.py From aetros-cli with MIT License | 6 votes |
def main(self, args): import aetros.const parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter, prog=aetros.const.__prog__ + ' id') parsed_args = parser.parse_args(args) config = read_home_config() try: user = api.user() except KeyNotConfiguredException as e: self.logger.error(str(e)) sys.exit(1) print("Logged in as %s (%s) on %s" % (user['username'], user['name'], config['host'])) if len(user['accounts']) > 0: for orga in six.itervalues(user['accounts']): print(" %s of organisation %s (%s)." % ("Owner" if orga['memberType'] == 1 else "Member", orga['username'], orga['name'])) else: print(" Without membership to an organisation.")
Example #9
Source File: route_table.py From ec2-api with Apache License 2.0 | 6 votes |
def _get_active_route_destinations(context, route_table): vpn_connections = {vpn['vpn_gateway_id']: vpn for vpn in db_api.get_items(context, 'vpn')} dst_ids = [route[id_key] for route in route_table['routes'] for id_key in ('gateway_id', 'network_interface_id') if route.get(id_key) is not None] dst_ids.extend(route_table.get('propagating_gateways', [])) destinations = {item['id']: item for item in db_api.get_items_by_ids(context, dst_ids) if (item['vpc_id'] == route_table['vpc_id'] and (ec2utils.get_ec2_id_kind(item['id']) != 'vgw' or item['id'] in vpn_connections))} for vpn in six.itervalues(vpn_connections): if vpn['vpn_gateway_id'] in destinations: destinations[vpn['vpn_gateway_id']]['vpn_connection'] = vpn return destinations
Example #10
Source File: scorers.py From lingvo with Apache License 2.0 | 6 votes |
def AddSentence(self, ref_str, hyp_str): """Accumulates ngram statistics for the given ref and hyp string pair.""" ref_tokens = tuple(_Tokenize(self._unsegmenter(ref_str))) self._num_ref_tokens += len(ref_tokens) hyp_tokens = tuple(_Tokenize(self._unsegmenter(hyp_str))) self._num_hyp_tokens += len(hyp_tokens) for order_idx in range(self._max_ngram): ref_counts = collections.Counter(NGrams(ref_tokens, order_idx + 1)) hyp_matches = collections.Counter() hyp_count = 0 for x in NGrams(hyp_tokens, order_idx + 1): hyp_count += 1 count = ref_counts[x] if count: # Clip hyp_matches so ngrams that are repeated more frequently in hyp # than ref are not double counted. hyp_matches[x] = min(hyp_matches[x] + 1, count) self._hyp_ngram_matches[order_idx] += sum(six.itervalues(hyp_matches)) self._hyp_ngram_counts[order_idx] += hyp_count
Example #11
Source File: images.py From neuropythy with GNU Affero General Public License v3.0 | 6 votes |
def imspec_lookup(imspec, k, default=None): ''' imspec_lookup(imspec, k) yields the value associated with the key k in the mapping imspec; if k is not in imspec, then imspec alises are checked and the appropriate value is returned; otherwise None is returned. imspec_lookup(imspec, k, default) yields default if neither k not an alias cannot be found. ''' k = k.lower() if k in imspec: return imspec[k] aliases = imspec_aliases.get(k, None) if aliases is None: for q in six.itervalues(imspec_aliases): if k in q: aliases = q break if aliases is None: return default for kk in aliases: if kk in imspec: return imspec[kk] return default
Example #12
Source File: base.py From linter-pylama with MIT License | 6 votes |
def leave_module(self, node): # pylint: disable=unused-argument for all_groups in six.itervalues(self._bad_names): if len(all_groups) < 2: continue groups = collections.defaultdict(list) min_warnings = sys.maxsize for group in six.itervalues(all_groups): groups[len(group)].append(group) min_warnings = min(len(group), min_warnings) if len(groups[min_warnings]) > 1: by_line = sorted(groups[min_warnings], key=lambda group: min(warning[0].lineno for warning in group)) warnings = itertools.chain(*by_line[1:]) else: warnings = groups[min_warnings][0] for args in warnings: self._raise_name_warning(*args)
Example #13
Source File: head.py From lambda-packs with MIT License | 5 votes |
def create_model_fn_ops(self, features, mode, labels=None, train_op_fn=None, logits=None, logits_input=None, scope=None): """See `Head`.""" with variable_scope.variable_scope( scope, default_name=self.head_name or "binary_logistic_head", values=(tuple(six.itervalues(features)) + (labels, logits, logits_input))): labels = self._transform_labels(mode=mode, labels=labels) logits = _logits(logits_input, logits, self.logits_dimension) return _create_model_fn_ops( features=features, mode=mode, loss_fn=self._loss_fn, logits_to_predictions_fn=self._logits_to_predictions, metrics_fn=self._metrics, create_output_alternatives_fn=_classification_output_alternatives( self.head_name, self._problem_type), labels=labels, train_op_fn=train_op_fn, logits=logits, logits_dimension=self.logits_dimension, head_name=self.head_name, weight_column_name=self.weight_column_name, enable_centered_bias=self._enable_centered_bias)
Example #14
Source File: kernel_estimators.py From lambda-packs with MIT License | 5 votes |
def _check_valid_kernel_mappers(kernel_mappers): """Checks that the input kernel_mappers are valid.""" if kernel_mappers is None: return True for kernel_mappers_list in six.itervalues(kernel_mappers): for kernel_mapper in kernel_mappers_list: if not isinstance(kernel_mapper, dkm.DenseKernelMapper): return False return True
Example #15
Source File: core_encoder.py From model-optimization with Apache License 2.0 | 5 votes |
def fully_commutes_with_sum(self): """`True/False` based on whether the `Encoder` commutes with sum. This property will return `True` iff the entire composition of encoding stages controlled by this object commutes with sum. That is, the stage wrapped by this object commutes with sum, and each of its children also `fully_commutes_with_sum`. Returns: A boolean, `True` iff the `Encoder` commutes with sum. """ result = True for encoder in six.itervalues(self.children): result &= encoder.fully_commutes_with_sum return result & self.stage.commutes_with_sum
Example #16
Source File: collections.py From unifi-video-api with MIT License | 5 votes |
def __iter__(self, *args, **kwargs): return itervalues(self, **kwargs)
Example #17
Source File: bn.py From zhusuan with MIT License | 5 votes |
def _log_joint(self): if (self._meta_bn is None) or (self._meta_bn.log_joint is None): ret = sum(node.cond_log_p for node in six.itervalues(self._nodes) if isinstance(node, StochasticTensor)) elif callable(self._meta_bn.log_joint): ret = self._meta_bn.log_joint(self) else: raise TypeError( "{}.log_joint is set to a non-callable instance: {}" .format(self._meta_bn.__class__.__name__, repr(self._meta_bn.log_joint))) return ret
Example #18
Source File: machines.py From automaton with Apache License 2.0 | 5 votes |
def initialize(self, start_state=None, nested_start_state_fetcher=None): """Sets up the state machine (sets current state to start state...). :param start_state: explicit start state to use to initialize the state machine to. If ``None`` is provided then the machine's default start state will be used instead. :param nested_start_state_fetcher: A callback that can return start states for any nested machines **only**. If not ``None`` then it will be provided a single argument, the machine to provide a starting state for and it is expected to return a starting state (or ``None``) for each machine called with. Do note that this callback will also be passed to other nested state machines as well, so it will also be used to initialize any state machines they contain (recursively). """ super(HierarchicalFiniteMachine, self).initialize( start_state=start_state) for data in six.itervalues(self._states): if 'machine' in data: nested_machine = data['machine'] nested_start_state = None if nested_start_state_fetcher is not None: nested_start_state = nested_start_state_fetcher( nested_machine) if isinstance(nested_machine, HierarchicalFiniteMachine): nested_machine.initialize( start_state=nested_start_state, nested_start_state_fetcher=nested_start_state_fetcher) else: nested_machine.initialize(start_state=nested_start_state)
Example #19
Source File: model_fn.py From lambda-packs with MIT License | 5 votes |
def _prediction_values(predictions): """Returns the values of the given predictions dict or `Tensor`.""" if predictions is None: return [] if isinstance(predictions, dict): return list(six.itervalues(predictions)) return [predictions]
Example #20
Source File: base.py From zhusuan with MIT License | 5 votes |
def _entropy_term(self): if not hasattr(self, '_entropy_cache'): if len(self._v_log_probs) > 0: self._entropy_cache = -sum(six.itervalues(self._v_log_probs)) else: self._entropy_cache = None return self._entropy_cache
Example #21
Source File: process_lattice.py From knmt with GNU General Public License v3.0 | 5 votes |
def pos_iter(self): return (x for x in itertools.chain( iter(self.leaf_lst), itertools.chain(six.itervalues(*self.inner_lst))) if x is not None) # def replace(self, elem, new_elems): # assert elem.is_leaf() # assert isinstance(new_elems, Node) # self.remove(elem) # for new_e in new_elems.pos_iter(): # self.add_elem(new_e)
Example #22
Source File: s3server.py From ec2-api with Apache License 2.0 | 5 votes |
def render_xml(self, value): assert isinstance(value, dict) and len(value) == 1 self.set_header("Content-Type", "application/xml; charset=UTF-8") name = next(six.iterkeys(value)) parts = [] parts.append('<' + name + ' xmlns="http://s3.amazonaws.com/doc/2006-03-01/">') self._render_parts(next(six.itervalues(value)), parts) parts.append('</' + name + '>') self.finish('<?xml version="1.0" encoding="UTF-8"?>\n' + ''.join(parts))
Example #23
Source File: vpn_connection.py From ec2-api with Apache License 2.0 | 5 votes |
def _stop_vpn_connection(neutron, vpn_connection): connection_ids = vpn_connection['os_ipsec_site_connections'] for os_connection_id in six.itervalues(connection_ids): try: neutron.delete_ipsec_site_connection(os_connection_id) except neutron_exception.NotFound: pass
Example #24
Source File: instance.py From ec2-api with Apache License 2.0 | 5 votes |
def _get_ip_info_for_instance(os_instance): addresses = list(itertools.chain(*six.itervalues(os_instance.addresses))) fixed_ip = next((addr['addr'] for addr in addresses if (addr['version'] == 4 and addr['OS-EXT-IPS:type'] == 'fixed')), None) fixed_ip6 = next((addr['addr'] for addr in addresses if (addr['version'] == 6 and addr['OS-EXT-IPS:type'] == 'fixed')), None) floating_ip = next((addr['addr'] for addr in addresses if addr['OS-EXT-IPS:type'] == 'floating'), None) return fixed_ip, fixed_ip6, floating_ip
Example #25
Source File: node.py From tributary with Apache License 2.0 | 5 votes |
def _subtree_dirty(self): for call, deps in six.iteritems(self._dependencies): # callable node if hasattr(call, '_node_wrapper') and \ call._node_wrapper is not None: if call._node_wrapper.isDirty(): # CRITICAL # always set self to be dirty if subtree is dirty self._dirty = True return True # check args for arg in deps[0]: if arg.isDirty(): # CRITICAL # always set self to be dirty if subtree is dirty self._dirty = True return True # check kwargs for kwarg in six.itervalues(deps[1]): if kwarg.isDirty(): # CRITICAL # always set self to be dirty if subtree is dirty self._dirty = True return True return False
Example #26
Source File: node.py From tributary with Apache License 2.0 | 5 votes |
def _compute_from_dependencies(self): if self._dependencies: self._greendd3g() for deps in six.itervalues(self._dependencies): # recompute args for arg in deps[0]: arg._recompute() # Set yourself as parent if self not in arg._parents: arg._parents.append(self) # recompute kwargs for kwarg in six.itervalues(deps[1]): kwarg._recompute() # Set yourself as parent if self not in kwarg._parents: kwarg._parents.append(self) k = list(self._dependencies.keys())[0] if self._callable_is_method: new_value = k(self._self_reference, *self._dependencies[k][0], **self._dependencies[k][1]) else: new_value = k(*self._dependencies[k][0], **self._dependencies[k][1]) if isinstance(new_value, Node): k._node_wrapper = new_value new_value = new_value() # get value if isinstance(new_value, Node): raise Exception('Value should not itself be a node!') self._value = new_value self._whited3g() return self._value
Example #27
Source File: probability.py From mathematics_dataset with Apache License 2.0 | 5 votes |
def probability(self, event): # Specializations for optimization. if isinstance(event, FiniteProductEvent): assert len(self._spaces) == len(event.events) return sympy.prod([ space.probability(event_slice) for space, event_slice in zip(self._spaces, event.events)]) if isinstance(event, CountLevelSetEvent) and self.all_spaces_equal(): space = self._spaces[0] counts = event.counts probabilities = { value: space.probability(DiscreteEvent({value})) for value in six.iterkeys(counts) } num_events = sum(six.itervalues(counts)) assert num_events == len(self._spaces) # Multinomial coefficient: coeff = ( sympy.factorial(num_events) / sympy.prod( [sympy.factorial(i) for i in six.itervalues(counts)])) return coeff * sympy.prod([ pow(probabilities[value], counts[value]) for value in six.iterkeys(counts) ]) raise ValueError('Unhandled event type {}'.format(type(event)))
Example #28
Source File: probability.py From mathematics_dataset with Apache License 2.0 | 5 votes |
def normalize_weights(weights): """Normalizes the weights (as sympy.Rational) in dictionary of weights.""" weight_sum = sum(six.itervalues(weights)) return { i: sympy.Rational(weight, weight_sum) for i, weight in six.iteritems(weights) }
Example #29
Source File: generate_test.py From mathematics_dataset with Apache License 2.0 | 5 votes |
def testGenerate(self, regime): generate.init_modules() for module in six.itervalues(generate.filtered_modules[regime]): for _ in range(3): question = module() str(question)
Example #30
Source File: arithmetic.py From mathematics_dataset with Apache License 2.0 | 5 votes |
def _entropy_of_factor_split(integer): """Returns entropy (log base 10) of decomposing: integer = a * b.""" assert integer.is_Integer if integer == 0: return 0 # Gives dict of form {factor: multiplicity} factors = sympy.factorint(integer) return sum(math.log10(mult + 1) for mult in six.itervalues(factors))