Associatively expand out nested arguments of the flat class.
    E.g.::

        >>> class Plus(Operation):
        ...     simplifications = [assoc, ]
        >>> Plus.create(1,Plus(2,3))
        Plus(1, 2, 3)
971866
def assoc(cls, ops, kwargs):
    
    expanded = [(o,) if not isinstance(o, cls) else o.operands for o in ops]
    return sum(expanded, ()), kwargs
837229
def extend(self, *args, **kwargs):
        
        if len(args) > 1:
            raise TypeError("extend() takes at most 1 positional "
                            "arguments ({0} given)".format(len(args)))
        other = args[0] if len(args) >= 1 else ()

        if isinstance(other, HTTPHeaderDict):
            for key, val in other.iteritems():
                self.add(key, val)
        elif isinstance(other, Mapping):
            for key in other:
                self.add(key, other[key])
        elif hasattr(other, "keys"):
            for key in other.keys():
                self.add(key, other[key])
        else:
            for key, value in other:
                self.add(key, value)

        for key, value in kwargs.items():
            self.add(key, value)
1248391
function expand(object, options) {
  var expanded = {};
  var options = options || {};
  var separator = options.separator || '.';
  var affix = options.affix ? separator + options.affix + separator : separator;

  for (var path in object) {
    var value = object[path];
    var pointer = expanded;

    if (path.indexOf('[') >= 0) {
      path = path.replace(/\[/g, '[.').replace(/]/g, '');
    }
    var parts = path.split(separator).join(affix).split('.');

    while (parts.length - 1) {
      var key = parts.shift();
      if (key.slice(-1) === '[') {
        key = key.slice(0, - 1);
        pointer[key] = Array.isArray(pointer[key]) ? pointer[key] : [];
      } else {
        pointer[key] = (pointer[key] !== null && typeof pointer[key] === 'object' && pointer[key].constructor === Object) ? pointer[key] : {};
      }
      pointer = pointer[key];
    }
    pointer[parts.shift()] = value;
  }
  return expanded;
}
1357427
def expand_parameters(self, para):
        '''
        
        '''
        if len(para) == 1:
            for key, values in para.items():
                return list(map(lambda v: {key: v}, values))

        key = list(para)[0]
        values = para.pop(key)
        rest_para = self.expand_parameters(para)
        ret_para = list()
        for val in values:
            for config in rest_para:
                config[key] = val
                ret_para.append(copy.deepcopy(config))
        return ret_para
913332
def flatten(self):
        
        if self._flat is None:
            flat = {}
            for arg in self.args:
                if isinstance(arg, Option):
                    flat[arg.name] = arg

                elif isinstance(arg, ListOption):
                    flat[arg.name] = arg

                elif isinstance(arg, DictOption):
                    flat[arg.name] = arg
                    if arg.scheme:
                        for k, v in arg.scheme.flatten().items():
                            flat[arg.name + '.' + k] = v

            self._flat = flat
        return self._flat
961281
def expand_dict(flat_dict, sep='_'):
    
    res = {}
    rdict = defaultdict(list)

    for flat_key, value in flat_dict.items():
        key = flat_key.split(sep, 1)
        if 1 == len(key):
            res[key[0]] = value
        else:
            rdict[key[0]].append((key[1:], value))

    for k, v in rdict.items():
        res[k] = expand_dict({ik: iv for (ik,), iv in v})

    return res
1304049
def multiply(**kwargs):
    
    result = 1
    for i in list(kwargs.values()):
        if not i:
            # If one value is null, we return null.
            return i
        result *= i
    return result
680673
def expand_args(cmd_args):
    
    if isinstance(cmd_args, (tuple, list)):
        args_list = list(cmd_args)
    else:
        args_list = shlex.split(cmd_args)
    return args_list
527485
def flatten(l: Iterable) -> List:
    
    rval = []
    for e in l:
        if not isinstance(e, str) and isinstance(e, Iterable):
            if len(list(e)):
                rval += flatten(e)
        else:
            rval.append(e)
    return rval
593105
def extend(self, *args):
        
        args = list(args)
        for i in args:
            self.obj.update(i)

        return self._wrap(self.obj)
815111
private void simpleIncrement(TensorBase other, double multiplier) {
    Preconditions.checkArgument(Arrays.equals(other.getDimensionNumbers(), getDimensionNumbers()));
    if (other instanceof DenseTensorBase) {
      double[] otherTensorValues = ((DenseTensorBase) other).values;
      Preconditions.checkArgument(otherTensorValues.length == values.length);
      int length = values.length;
      for (int i = 0; i < length; i++) {
        values[i] += otherTensorValues[i] * multiplier;
      }
    } else {
      int otherSize = other.size();
      for (int i = 0; i < otherSize; i++) {
        long keyNum = other.indexToKeyNum(i);
        double value = other.getByIndex(i);
        values[keyNumToIndex(keyNum)] += value * multiplier;
      }
    }
  }
50814
def createArgs(**kwargs):
  
  if len(kwargs) == 0: return [{}]
  kargs = deepcopy(kwargs)
  k1 = kargs.keys()[0]
  values = kargs.pop(k1)
  args = []

  # Get all other combinations
  otherArgs = createArgs(**kargs)

  # Create combinations for values associated with k1
  for v in values:
    newArgs = deepcopy(otherArgs)
    arg = {k1: v}
    for newArg in newArgs:
      newArg.update(arg)
      args.append(newArg)

  return args
556220
function augment(fn, keys) {
  keys = keys || fn.params || [];
  if (!Array.isArray(keys)) keys = Object.keys(keys);
  fn.params = keys;
  return fn;
}
999188
def _subs(self, substitutions, default, simplify):
        
        # track the new list of unchanged args or replaced args through
        # a substitution
        new_arguments = []
        changed_something = False

        # shortcut for basic logic True or False
        if self is self.TRUE or self is self.FALSE:
            return self

        # if the expression has no elements, e.g. is empty, do not apply
        # substitions
        if not self.args:
            return default

        # iterate the subexpressions: either plain symbols or a subexpressions
        for arg in self.args:
            # collect substitutions for exact matches
            # break as soon as we have a match
            for expr, substitution in substitutions.items():
                if arg == expr:
                    new_arguments.append(substitution)
                    changed_something = True
                    break

            # this will execute only if we did not break out of the
            # loop, e.g. if we did not change anything and did not
            # collect any substitutions
            else:
                # recursively call _subs on each arg to see if we get a
                # substituted arg
                new_arg = arg._subs(substitutions, default, simplify)
                if new_arg is None:
                    # if we did not collect a substitution for this arg,
                    # keep the arg as-is, it is not replaced by anything
                    new_arguments.append(arg)
                else:
                    # otherwise, we add the substitution for this arg instead
                    new_arguments.append(new_arg)
                    changed_something = True

        if not changed_something:
            return

        # here we did some substitution: we return a new expression
        # built from the new_arguments
        newexpr = self.__class__(*new_arguments)
        return newexpr.simplify() if simplify else newexpr
612886
def ExpandDims(a, dim):
    
    shape = list(a.shape)
    if dim >= 0:
        shape.insert(dim, 1)
    else:
        shape.insert(len(shape) + dim + 1, 1)
    return np.copy(a).reshape(*shape),
374190
def expand_value(self, **kwargs):
        
        selection = []
        for v in self.get_value(**kwargs):
            for choice in self.choices:
                if v==choice and choice not in selection:
                    selection.append(choice)
                elif fnmatch(choice, v) and choice not in selection:
                    selection.append(choice)

        return selection
189942
def _make_plus_helper(obj, fields):
    
    new_obj = {}

    for key, value in obj.items():
        if key in fields or key.startswith('_'):
            # if there's a subschema apply it to a list or subdict
            if fields.get(key):
                if isinstance(value, list):
                    value = [_make_plus_helper(item, fields[key])
                             for item in value]
            # assign the value (modified potentially) to the new_obj
            new_obj[key] = value
        else:
            # values not in the fields dict get a +
            new_obj['+%s' % key] = value

    return new_obj