an alternative method for assigning values to nested DotDict
        instances.  It accepts keys in the form of X.Y.Z.  If any nested
        DotDict instances don't yet exist, they will be created.
421569
def assign(self, key, value):
        """"""
        key_split = key.split('.')
        cur_dict = self
        for k in key_split[:-1]:
            try:
                cur_dict = cur_dict[k]
            except KeyError:
                cur_dict[k] = self.__class__()  # so that derived classes
                                                # remain true to type
                cur_dict = cur_dict[k]
        cur_dict[key_split[-1]] = value
262646
def keys_with_value(dictionary, value):
        ""

        subset = [key for key in dictionary if dictionary[key] == value]

        return subset
670146
def set(self, x):
        
        for name, value in iter(x.items()):
            if hasattr(value, "ndim"):
                if self[name].value.ndim < value.ndim:
                    self[name].value.itemset(value.squeeze())
                else:
                    self[name].value = value
            else:
                self[name].value.itemset(value)
614807
def _assign(self, values):
        
        LOGGER.debug('Assigning values: %r', values)
        if not values:
            return
        keys = self.keys()
        if not self._ref:
            keys.append('_ref')
        if isinstance(values, dict):
            for key in keys:
                if values.get(key):
                    if isinstance(values.get(key), list):
                        items = list()
                        for item in values[key]:
                            if isinstance(item, dict):
                                if '_ref' in item:
                                    obj_class = get_class(item['_ref'])
                                    if obj_class:
                                        items.append(obj_class(self._session,
                                                               **item))
                            else:
                                items.append(item)
                        setattr(self, key, items)
                    else:
                        setattr(self, key, values[key])
        elif isinstance(values, list):
            self._assign(values[0])
        else:
            LOGGER.critical('Unhandled return type: %r', values)
525217
def values(self, key_type=None):
        
        if(key_type is not None):
            all_items = {} # in order to preserve keys() type (dict_values for python3) 
            keys_used = set()
            direct_key = str(key_type)
            if direct_key in self.__dict__:
                for intermediate_key in self.__dict__[direct_key].values():
                    if not intermediate_key in keys_used:
                        all_items[intermediate_key] = self.items_dict[intermediate_key]
                        keys_used.add(intermediate_key)
            return all_items.values()
        else:
            return self.items_dict.values()
1132516
def read_keys(self, keys, dict_cls=AttrDict, path="/"):
        
        od = dict_cls()
        for k in keys:
            try:
                # Try to read a variable.
                od[k] = self.read_value(k, path=path)
            except self.Error:
                try:
                    # Try to read a dimension.
                    od[k] = self.read_dimvalue(k, path=path)
                except self.Error:
                    od[k] = None

        return od
495792
def dict_assign(dict_, keys, vals):
    
    for key, val in zip(keys, vals):
        dict_[key] = val
788049
public SDVariable dot(String name, SDVariable x, SDVariable y, int... dimensions) {
        SDValidation.validateNumerical("dot", x, y);
        SDVariable ret = f().dot(x, y, dimensions);
        return updateVariableNameAndReference(ret, name);
    }
857116
def FromDict(self, dictionary):
    """"""
    dynamic_fields = []

    for key, value in iteritems(dictionary):
      field_type_info = self.type_infos.get(key)
      if isinstance(field_type_info, ProtoEmbedded):
        nested_value = field_type_info.GetDefault(container=self)
        nested_value.FromDict(value)
        self.Set(key, nested_value)
      elif isinstance(field_type_info, ProtoList):
        if isinstance(field_type_info.delegate, ProtoEmbedded):
          nested_values = []
          for v in value:
            nested_value = field_type_info.delegate.GetDefault(container=self)
            nested_value.FromDict(v)
            nested_values.append(nested_value)

          self.Set(key, nested_values)
        else:
          self.Set(key, value)
      elif isinstance(field_type_info, ProtoDynamicEmbedded):
        dynamic_fields.append(field_type_info)
      elif field_type_info.proto_type_name == "bytes":
        self.Set(key, base64.decodestring(value or ""))
      else:
        self.Set(key, value)

    # Process dynamic fields after all other fields, because most probably
    # their class is determined by one of the previously set fields.
    for dynamic_field in dynamic_fields:
      nested_value = dynamic_field.GetDefault(container=self)
      if nested_value is None:
        raise RuntimeError("Can't initialize dynamic field %s, probably some "
                           "necessary fields weren't supplied." %
                           dynamic_field.name)
      nested_value.FromDict(dictionary[dynamic_field.name])
      self.Set(dynamic_field.name, nested_value)
286430
def _set_nd_basic_indexing(self, key, value):
        """"""
        shape = self.shape
        if isinstance(key, integer_types):
            if key < 0:
                key += shape[0]
            if key < 0 or key >= shape[0]:
                if key < 0:
                    key -= shape[0]
                raise IndexError('index %d is out of bounds for axis 0 with size %d'
                                 % (key, shape[0]))
            key = py_slice(key, key+1)  # key must be >= 0 here

        if isinstance(key, py_slice):
            assign_to_self = key.step is None or key.step == 1
            assign_to_self &= key.start is None or key.start == 0
            assign_to_self &= key.stop is None or key.stop == shape[0]
            if assign_to_self:  # trivial case, assign value to self
                if isinstance(value, NDArray):
                    if value.handle is not self.handle:
                        if value.shape != shape:
                            value = value.broadcast_to(shape)
                        value.copyto(self)
                elif isinstance(value, numeric_types):
                    _internal._full(shape=shape, ctx=self.context,
                                    dtype=self.dtype, value=float(value), out=self)
                elif isinstance(value, (np.ndarray, np.generic)):
                    if isinstance(value, np.generic) or value.shape != shape:
                        value = np.broadcast_to(value, shape)
                    self._sync_copyfrom(value)
                else:  # value might be a list or a tuple
                    value_nd = self._prepare_value_nd(value, shape)
                    value_nd.copyto(self)
                return
            else:  # non-trivial case, use _slice_assign or _slice_assign_scalar
                key = (key,)

        assert isinstance(key, tuple), "key=%s must be a tuple of slices and integers" % str(key)

        assert len(key) <= len(shape), "Indexing dimensions exceed array dimensions, %d vs %d"\
                                       % (len(key), len(shape))
        begin = []
        end = []
        steps = []
        oshape = []  # output shape of slice using key
        vshape = []  # value shape of data[key]
        for i, slice_i in enumerate(key):
            dim_size = 1
            if isinstance(slice_i, py_slice):
                begin.append(slice_i.start)
                end.append(slice_i.stop)
                steps.append(slice_i.step)
                start, stop, step = _get_index_range(slice_i.start, slice_i.stop,
                                                     shape[i], slice_i.step)
                dim_size = _get_dim_size(start, stop, step)
                vshape.append(dim_size)
            elif isinstance(slice_i, integer_types):
                begin.append(slice_i)
                end.append(slice_i+1 if slice_i != -1 else self.shape[i])
                steps.append(1)
            else:
                raise ValueError("basic indexing does not support index=%s of type=%s"
                                 % (str(slice_i), str(type(slice_i))))
            oshape.append(dim_size)

        oshape.extend(shape[len(key):])
        vshape.extend(shape[len(key):])
        # if key contains all integers, vshape should be (1,)
        if len(vshape) == 0:
            vshape.append(1)
        oshape = tuple(oshape)
        vshape = tuple(vshape)

        if isinstance(value, numeric_types):
            _internal._slice_assign_scalar(self, out=self, begin=begin, end=end,
                                           step=steps, scalar=float(value))
        else:
            value_nd = self._prepare_value_nd(value, vshape)
            if vshape != oshape:
                value_nd = value_nd.reshape(oshape)
            _internal._slice_assign(self, value_nd, begin, end, steps, out=self)
88926
def nest_values(self, levels, level=0, metric=None, dims=()):
        
        if not level:
            return [{
                'name': m,
                'val': levels[0][m],
                'children': self.nest_values(levels, 1, m),
            } for m in levels[0].index]
        if level == 1:
            return [{
                'name': i,
                'val': levels[1][metric][i],
                'children': self.nest_values(levels, 2, metric, (i,)),
            } for i in levels[1][metric].index]
        if level >= len(levels):
            return []
        return [{
            'name': i,
            'val': levels[level][metric][dims][i],
            'children': self.nest_values(
                levels, level + 1, metric, dims + (i,),
            ),
        } for i in levels[level][metric][dims].index]
1311609
private void repmatIncrement(TensorBase other, double multiplier) {
    // Maps a key of other into a partial key of this.
    int[] dimensionMapping = getDimensionMapping(other.getDimensionNumbers());
    int[] partialKey = ArrayUtils.copyOf(getDimensionSizes(), getDimensionSizes().length);
    for (int i = 0; i < dimensionMapping.length; i++) {
      partialKey[dimensionMapping[i]] = 1;
    }

    int numValues = 1;
    for (int i = 0; i < partialKey.length; i++) {
      numValues *= partialKey[i];
    }
    int[] keyOffsets = new int[numValues];
    Iterator<int[]> myKeyIterator = new IntegerArrayIterator(partialKey, new int[0]);
    int ind = 0;
    while (myKeyIterator.hasNext()) {
      keyOffsets[ind] = dimKeyToIndex(myKeyIterator.next());
      ind++;
    }
    Preconditions.checkState(ind == keyOffsets.length);

    Iterator<KeyValue> otherKeyValues = other.keyValueIterator();
    while (otherKeyValues.hasNext()) {
      KeyValue otherKeyValue = otherKeyValues.next();
      int baseOffset = 0;
      for (int i = 0; i < otherKeyValue.getKey().length; i++) {
        baseOffset += otherKeyValue.getKey()[i] * indexOffsets[dimensionMapping[i]];
      }

      for (int i = 0; i < keyOffsets.length; i++) {
        values[baseOffset + keyOffsets[i]] += otherKeyValue.getValue() * multiplier;
      }
    }
  }
249075
def _dict_value_to_pairs(d):
    
    d = d[tz.first(d)]

    for k, v in d.items():
        yield {k: v}
892165
def convert_values(self, matchdict: Dict[str, str]) -> Dict[str, Any]:
        

        converted = {}
        for varname, value in matchdict.items():
            converter = self.converters[varname]
            converted[varname] = converter(value)
        return converted
1183481
def iflatten_dict_values(node, depth=0):
    
    if isinstance(node, dict):
        _iter = (iflatten_dict_values(value) for value in six.itervalues(node))
        return util_iter.iflatten(_iter)
    else:
        return node
479690
def nested_key_indices(nested_dict):
    
    outer_keys, inner_keys = collect_nested_keys(nested_dict)
    outer_key_indices = {k: i for (i, k) in enumerate(outer_keys)}
    inner_key_indices = {k: i for (i, k) in enumerate(inner_keys)}
    return outer_key_indices, inner_key_indices
1303869
def dict2obj(d):
    
    if isinstance(d, (list, tuple)):
        d = [dict2obj(x) for x in d]
    if not isinstance(d, dict):
        return d
    class ObjectFromDict(object):
        pass
    o = ObjectFromDict() #an object created from a dict
    for k in d:
        o.__dict__[k] = dict2obj(d[k])
    return o