Recursively flatten vectorized var => {0, 1} mappings.
553556
def _flatten(v, val):
    """"""
    if isinstance(v, Variable):
        yield v, int(val)
    else:
        if len(v) != len(val):
            raise ValueError("expected 1:1 mapping from Variable => {0, 1}")
        for _var, _val in zip(v, val):
            yield from _flatten(_var, _val)
1116256
def vectorize(fn):
    

    @functools.wraps(fn)
    def vectorized_method(self, values, *vargs, **kwargs):
        wrap = not isinstance(values, (list, tuple))
        should_unwrap = not kwargs.setdefault('wrap', False)
        unwrap = wrap and should_unwrap
        del kwargs['wrap']
        
        if wrap:
            values = [values]

        results = [fn(self, value, *vargs, **kwargs) for value in values]

        if unwrap:
            results = results[0]

        return results

    return vectorized_method
496693
def _nest_vars_in_rec(var_items, rec_items, input_order, items_by_key, parallel):
    
    num_items = var_items
    var_items = list(var_items)[0]
    if rec_items:
        rec_items = list(rec_items)[0]
        if ((rec_items == 1 and var_items > 1) or parallel.startswith("batch")):
            num_items = set([rec_items])
            for var_key in (k for (k, t) in input_order.items() if t != "record"):
                var_key = tuple(var_key.split("__"))
                items_by_key[var_key] = [items_by_key[var_key]] * rec_items
        else:
            assert var_items == rec_items, (var_items, rec_items)
    return items_by_key, num_items
339943
def _flatten(n):
    """"""
    if isinstance(n, collections.Sequence):
        for x in n:
            for y in _flatten(x):
                yield y
    else:
        yield n
329155
def array_map(f, ar):
    ""
    flat_ar = ravel(ar)
    out = zeros(len(flat_ar), flat_ar.typecode())
    for i in range(len(flat_ar)):
        out[i] = f(flat_ar[i])
    out.shape = ar.shape
    return out
852401
function transformVariables(source, dest) {
        var xformed, arrayVals;

        if (dest === undefined) {
            xformed = {};
        }
        else {
            xformed = dest;
        }

        $.each(source, function(prop, val) {
            if (val instanceof $) {
                xformed[prop] = val[0];
            }
            else if ($.isPlainObject(val)) {
                xformed[prop] = {};
                transformVariables(val, xformed[prop]);
            }
            else if ($.isArray(val)) {
                arrayVals = [];
                $.each(val, function(idx, arrayVal) {
                    if (arrayVal instanceof $) {
                        $.merge(arrayVals, arrayVal);
                    }
                    else {
                        arrayVals.push(arrayVal);
                    }
                });
                xformed[prop] = arrayVals;
            }
            else {
                xformed[prop] = val;
            }
        });

        if (dest === undefined) {
            return xformed;
        }
    }
1121931
function flatten(array) {
    var result = [], i, n;

    for (i = 0, n = array.length; i < n; i++) {
      if (isArray(array[i])) {
        result = result.concat(flatten(array[i]));
      }
      else {
        result.push(array[i]);
      }
    }

    return result;
  }
795146
def flatten(list_to_flatten):
    """"""

    def genflatten(lst):
        for elem in lst:
            if isinstance(elem, (list, tuple)):
                for x in flatten(elem):
                    yield x
            else:
                yield elem

    return list(genflatten(list_to_flatten))
576669
function flatten(matrix) {
    const res = [];

    // If the given matrix is not a matrix but a scalar.
    if (!Array.isArray(matrix)) {
        matrix = [
            [matrix]
        ];
    }

    matrix.forEach((row) => {
        // If the given matrix is a vector.
        if (!Array.isArray(row)) {
            row = [row];
        }

        row.forEach((elem) => {
            res.push(elem.real);
            res.push(elem.imag);
        });
    });
    return res;
}
216295
function flatten(array, i) {
  i = i || 0;

  if(i >= array.length)
    return array;

  if(isArray(array[i])) {
    return flatten(array.slice(0,i)
      .concat(array[i], array.slice(i+1)), i);
  }
  return flatten(array, i+1);
}
747241
def flatMap(f: Callable, xs: Iterable) -> List:
    
    return flatten(lmap(f, xs))
417545
def flatten(l, types=(list, float)):
    
    l = [item if isinstance(item, types) else [item] for item in l]
    return [item for sublist in l for item in sublist]
308683
def recursive_apply(inval, func):
    '''
    '''
    if isinstance(inval, dict):
        return {k: recursive_apply(v, func) for k, v in inval.items()}
    elif isinstance(inval, list):
        return [recursive_apply(v, func) for v in inval]
    else:
        return func(inval)
936123
def _vars(ftype, name, *dims):
    """"""
    shape = _dims2shape(*dims)
    objs = list()
    for indices in itertools.product(*[range(i, j) for i, j in shape]):
        objs.append(_VAR[ftype](name, indices))
    return farray(objs, shape, ftype)
220869
function flatten$1(list) {
    var result = [];
    var i = 0;
    while (i < list.length) {
        var item = list[i];
        if (Array.isArray(item)) {
            if (item.length > 0) {
                list = item.concat(list.slice(i + 1));
                i = 0;
            }
            else {
                i++;
            }
        }
        else {
            result.push(item);
            i++;
        }
    }
    return result;
}
1189084
def flatten(self):
        
        # go right to base alloc
        [c.allocate(-c.value) for c in self._childrenv if c.value != 0]
1359762
def flatten(iterable):
    """"""
    # likely not used
    iterable = iter(iterable)
    while True:
        try:
            item = next(iterable)
        except StopIteration:
            break

        if isinstance(item, six.string_types):
            yield item
            continue

        try:
            data = iter(item)
            iterable = itertools.chain(data, iterable)
        except:
            yield item