recursive function to resolve multiple assignments on loops
425777
def _resolve_looppart(parts, assign_path, context):
    """"""
    assign_path = assign_path[:]
    index = assign_path.pop(0)
    for part in parts:
        if part is util.Uninferable:
            continue
        if not hasattr(part, "itered"):
            continue
        try:
            itered = part.itered()
        except TypeError:
            continue
        for stmt in itered:
            index_node = nodes.Const(index)
            try:
                assigned = stmt.getitem(index_node, context)
            except (
                AttributeError,
                exceptions.AstroidTypeError,
                exceptions.AstroidIndexError,
            ):
                continue
            if not assign_path:
                # we achieved to resolved the assignment path,
                # don't infer the last part
                yield assigned
            elif assigned is util.Uninferable:
                break
            else:
                # we are not yet on the last part of the path
                # search on each possibly inferred value
                try:
                    yield from _resolve_looppart(
                        assigned.infer(context), assign_path, context
                    )
                except exceptions.InferenceError:
                    break
482288
function(buf, V) {
    var M = Array(8);
    var a = Array(8);
    var b = Array(8);
    M[0] = buf[0];
    M[1] = buf[1];
    M[2] = buf[2];
    M[3] = buf[3];
    M[4] = buf[4];
    M[5] = buf[5];
    M[6] = buf[6];
    M[7] = buf[7];
    o.xORTable(a, V[0], V[1], 8);
    o.xORTable(b, V[2], V[3], 8);
    o.xORTable(a, a, b, 8);
    o.xORTable(a, a, V[4], 8);
    M2(a, a);
    o.xORTable(V[0], a, V[0], 8);
    o.xORTable(V[1], a, V[1], 8);
    o.xORTable(V[2], a, V[2], 8);
    o.xORTable(V[3], a, V[3], 8);
    o.xORTable(V[4], a, V[4], 8);
    M2(b, V[0]);
    o.xORTable(b, b, V[1], 8);
    M2(V[1], V[1]);
    o.xORTable(V[1], V[1], V[2], 8);
    M2(V[2], V[2]);
    o.xORTable(V[2], V[2], V[3], 8);
    M2(V[3], V[3]);
    o.xORTable(V[3], V[3], V[4], 8);
    M2(V[4], V[4]);
    o.xORTable(V[4], V[4], V[0], 8);
    M2(V[0], b);
    o.xORTable(V[0], V[0], V[4], 8);
    M2(V[4], V[4]);
    o.xORTable(V[4], V[4], V[3], 8);
    M2(V[3], V[3]);
    o.xORTable(V[3], V[3], V[2], 8);
    M2(V[2], V[2]);
    o.xORTable(V[2], V[2], V[1], 8);
    M2(V[1], V[1]);
    o.xORTable(V[1], V[1], b, 8);
    o.xORTable(V[0], V[0], M, 8);
    M2(M, M);
    o.xORTable(V[1], V[1], M, 8);
    M2(M, M);
    o.xORTable(V[2], V[2], M, 8);
    M2(M, M);
    o.xORTable(V[3], V[3], M, 8);
    M2(M, M);
    o.xORTable(V[4], V[4], M, 8);
}
498240
def _resolve_duplicates(self):
        '''
        
        '''
        self._initialize_graph_status_for_traversing()

        # Traverse the graph from roots to leaves
        for operator in self.topological_operator_iterator():
            if operator.type != 'identity':
                continue

            if any(variable.is_root for variable in operator.inputs) and \
                    any(variable.is_leaf for variable in operator.outputs):
                continue

            # Replace the output variable with the input variable everywhere
            original = operator.inputs[0]
            duplicate = operator.outputs[0]
            for another_scope in self.scopes:
                for another_operator in another_scope.operators.values():
                    for i in range(len(another_operator.inputs)):
                        if another_operator.inputs[i].onnx_name != duplicate.onnx_name:
                            continue
                        another_operator.inputs[i] = original

            # When original variable's documentation string or denotation is empty but duplicate's is not, we
            # copy that field to the original variable to avoid information loss.
            if not original.type.doc_string and duplicate.type.doc_string:
                original.type.doc_string = duplicate.type.doc_string

            if isinstance(original.type, TensorType) and isinstance(duplicate.type, TensorType):
                if not original.type.denotation and duplicate.type.denotation:
                    original.type.denotation = duplicate.type.denotation
                if not original.type.channel_denotations:
                    original.type.channel_denotations = duplicate.type.channel_denotations
                elif duplicate.type.channel_denotations:
                    # Merge the channel denotations if available in both the original and the duplicate
                    for i in range(len(original.type.channel_denotations)):
                        if original.type.channel_denotations[i]:
                            continue
                        original.type.channel_denotations[i] = duplicate.type.channel_denotations[i]
                # Sometime, shapes of duplicates are different. We try to replace the original variable's unknown dimensions
                # as many as possible because we will get rid of the duplicate.
                if len(original.type.shape) == len(duplicate.type.shape):
                    for i in range(len(original.type.shape)):
                        if original.type.shape[i] != 'None':
                            continue
                        original.type.shape[i] = duplicate.type.shape[i]

            # Because we're iterating through the topology, we cannot delete any operator or variable. Otherwise,
            # the traversing function may be broken. We will delete those abandoned ones later.
            duplicate.is_abandoned = True
            operator.is_abandoned = True

        for scope in self.scopes:
            # Find out who is going to be abandoned
            abandoned_operator_names = set(onnx_name for onnx_name, operator in scope.operators.items()
                                           if operator.is_abandoned)
            abandoned_variable_names = set(onnx_name for onnx_name, variable in scope.variables.items()
                                           if variable.is_abandoned)

            # Remove abandoned operators
            for name in abandoned_operator_names:
                scope.delete_local_operator(name)

            # Remove abandoned variables
            for name in abandoned_variable_names:
                scope.delete_local_variable(name)
1365468
function(d_o, c_o, b_o, a_o) { 
        //convert everything to text
        var a = a_o.text(), b = b_o.text(), c = c_o.text(), d = d_o.text(); 
        var d0s = '({1})^2-3*({0})*({2})',
            d0 = _.parse(format(d0s, a, b, c)),
            Q = _.parse(format('((2*({1})^3-9*({0})*({1})*({2})+27*({0})^2*({3}))^2-4*(({1})^2-3*({0})*({2}))^3)^(1/2)', a, b, c, d)),
            C = _.parse(format('((1/2)*(({4})+2*({1})^3-9*({0})*({1})*({2})+27*({0})^2*({3})))^(1/3)', a, b, c, d, Q));
        //check if C equals 0
        var scope = {};
        //populate the scope object
        variables(C).map(function(x) {
            scope[x] = 1;
        });
        
        var Ct = core.Utils.block('PARSE2NUMBER', function() {
            return _.parse(C, scope);
        });
        
        if(Number(d0) === 0 && Number(Ct) === 0) //negate Q such that C != 0
            C = _.parse(format('((1/2)*(-({4})+2*({1})^3-9*({0})*({1})*({2})+27*({0})^2*({3})))^(1/3)', a, b, c, d, Q));

        var xs = [
            '-(b/(3*a))-C/(3*a)-(((b^2-3*a*c))/(3*a*C))',
            '-(b/(3*a))+(C*(1+i*sqrt(3)))/(6*a)+((1-i*sqrt(3))*(b^2-3*a*c))/(6*a*C)'.replace(/i/g, core.Settings.IMAGINARY),
            '-(b/(3*a))+(C*(1-i*sqrt(3)))/(6*a)+((1+i*sqrt(3))*(b^2-3*a*c))/(6*a*C)'.replace(/i/g, core.Settings.IMAGINARY)
        ];
        
        

        return xs.map(function(e, i) { 
            var o = { a: a_o.clone(), b: b_o.clone(), c: c_o.clone(), d: d_o.clone(), C: C.clone()};
            return _.parse(e, o);
        });
    }
267218
function(eq) {
            var lhs = new Symbol(0),
                rhs = new Symbol(0);
            eq.each(function(x) {
                if(x.contains(solve_for, true))
                    lhs = _.add(lhs, x.clone());
                else
                    rhs = _.subtract(rhs, x.clone());
            });
            return [lhs, rhs];
        }
878855
def rewrite_return_as_assignments(func_node, interface):
    """"""
    func_node = _RewriteReturn(interface).visit(func_node)
    ast.fix_missing_locations(func_node)
    return func_node
1145050
function redo_if(statements) {
                statements = MAP(statements, walk);

                for (var i = 0; i < statements.length; ++i) {
                        var fi = statements[i];
                        if (fi[0] != "if") continue;

                        if (fi[3] && walk(fi[3])) continue;

                        var t = walk(fi[2]);
                        if (!aborts(t)) continue;

                        var conditional = walk(fi[1]);

                        var e_body = statements.slice(i + 1);
                        var e = e_body.length == 1 ? e_body[0] : [ "block", e_body ];

                        var ret = statements.slice(0, i).concat([ [
                                fi[0],          // "if"
                                conditional,    // conditional
                                t,              // then
                                e               // else
                        ] ]);

                        return redo_if(ret);
                }

                return statements;
        }
1180127
function(eqns, var_array) {
        //check if a var_array was specified
        //nerdamer.clearVars();// this deleted ALL variables: not what we want
        //parse all the equations to LHS. Remember that they come in as strings
        for(var i=0; i<eqns.length; i++) 
            eqns[i] = toLHS(eqns[i]);
        
        var l = eqns.length,
            m = new core.Matrix(),
            c = new core.Matrix(),
            expand_result = false,
            vars;
        
        if(typeof var_array === 'undefined') {
            //check to make sure that all the equations are linear
            if(!_A.allLinear(eqns)) 
                core.err('System must contain all linear equations!');
            vars = variables(eqns[0]);

            //get all variables
            for(var i=1; i<l; i++) 
                vars = vars.concat(variables(eqns[i])); 
            //remove duplicates
            vars = core.Utils.arrayUnique(vars).sort();
            
            // deletes only the variables of the linear equations in the nerdamer namespace
            for (var i=0;i<vars.length;i++){
                nerdamer.setVar(vars[i],"delete");
            }
            // populate the matrix
            for(var i=0; i<l; i++) {
                var e = eqns[i]; //store the expression
                for(var j=0; j<l; j++) {     
                    var variable = e.symbols[vars[j]];
                    m.set(i, j, variable ? variable.multiplier : 0);
                }
                var num = e.symbols['#']; 
                c.set(i, 0, new Symbol(num ? -num.multiplier : 0));
            }
        }
        else {
            /**
             * The idea is that we loop through each equation and then expand it. Afterwards we loop
             * through each term and see if and check to see if it matches one of the variables.
             * When a match is found we mark it. No other match should be found for that term. If it
             * is we stop since it's not linear.
             */               
            vars = var_array;
            expand_result = true;
            for(i=0; i<l; i++) {
                //prefill
                c.set(i, 0, new Symbol(0));
                var e = _.expand(eqns[i]).collectSymbols(); //expand and store
                //go trough each of the variables
                for(var j=0; j<var_array.length; j++) {
                    m.set(i, j, new Symbol(0));
                    var v = var_array[j];
                    //go through the terms and sort the variables
                    for(var k=0; k<e.length; k++) {
                        var term = e[k],
                            check = false;
                        for(var z=0; z<var_array.length; z++) {
                            //check to see if terms contain multiple variables
                            if(term.contains(var_array[z])) {
                                if(check)
                                    core.err('Multiple variables found for term '+term);
                                check = true;
                            }   
                        }
                        //we made sure that every term contains one variable so it's safe to assume that if the
                        //variable is found then the remainder is the coefficient.
                        if(term.contains(v)) {
                            var tparts = explode(remove(e, k), v);
                            m.set(i, j, _.add(m.get(i, j), tparts[0]));
                        }
                    }
                }
                //all the remaining terms go to the c matrix
                for(k=0; k<e.length; k++) {
                    c.set(i, 0, _.add(c.get(i, 0), e[k]));
                }
            }
            //consider case (a+b)*I+u
        }
            
        // Use M^-1*c to solve system
        m = m.invert();
        var result = m.multiply(c);
        //correct the sign as per issue #410
        if(core.Utils.isArray(var_array))
            result.each(function(x) {
                return x.negate();
            });
        var solutions = core.Settings.SOLUTIONS_AS_OBJECT ? {} : [];
        result.each(function(e, idx) { 
            var solution = (expand_result ? _.expand(e) : e).valueOf();
            var variable = vars[idx];
            if(core.Settings.SOLUTIONS_AS_OBJECT) {
                solutions[variable] = solution;
            }
            else
                solutions.push([variable, solution]); 
        });
        //done
        return solutions;
    }
909080
def _recurse_replace(obj, key, new_key, sub, remove):
    """"""
    if isinstance(obj, list):
        return [_recurse_replace(x, key, new_key, sub, remove) for x in obj]
    if isinstance(obj, dict):
        for k, v in list(obj.items()):
            if k == key and v in sub:
                obj[new_key] = sub[v]
                if remove:
                    del obj[key]
            else:
                obj[k] = _recurse_replace(v, key, new_key, sub, remove)
    return obj
694612
function _resolvePromises (opts, val) {
  opts = opts || {}
  var duplicate = opts.duplicate
  if (is(Array, val)) {
    return Promise.all(duplicate ? concat([], val) : val)
  } else if (duplicate && is(Object, val) && !is(Function, val.then)) {
    return Object.assign({}, val)
  }
  return val
}
207753
def recursive_map(func, data):
    
    def recurse(item):
        return recursive_map(func, item)
    items_mapped = map_collection(recurse, data)
    return func(items_mapped)
211631
def pairwise(values):
    
    i = iter(values)
    a = next(i)

    for b in i:
        yield (a, b)
        a = b
606064
function swap(a, i1, i2) {
      var t = a[i1];
      a[i1] = a[i2];
      a[i2] = t;
    }
140588
def make_assignment(instr, queue, stack):
    
    value = make_expr(stack)

    # Make assignment targets.
    # If there are multiple assignments (e.g. 'a = b = c'),
    # each LHS expression except the last is preceded by a DUP_TOP instruction.
    # Thus, we make targets until we don't see a DUP_TOP, and then make one
    # more.
    targets = []
    while isinstance(instr, instrs.DUP_TOP):
        targets.append(make_assign_target(queue.popleft(), queue, stack))
        instr = queue.popleft()

    targets.append(make_assign_target(instr, queue, stack))

    return ast.Assign(targets=targets, value=value)
545087
function ( n, k ) {
            if ( ! n || ( n < k ) )
                throw new RangeError( 'check input values' )
                ;
            // buffer for generating combinations
            const buff = balloc( n, 0 )
                // colex recursive generator
                , colex_gen = function *( n, k ) {
                    if ( n === 0 ) yield buff;
                    else {
                        if ( k < n ) {
                            buff[ n - 1 ] = 0;
                            yield* colex_gen( n - 1, k );
                        }
                        if ( k > 0 ) {
                            buff[ n - 1 ] = 1;
                            yield* colex_gen( n - 1, k - 1 );
                        }
                    }
                }
                // generating colex order for k <= n/2.
                , colex_gen_2 = function *( n, k ) {
                    if ( k === 0 ) yield buff;
                    else {
                        if ( k < n ) {
                            buff[ n - 1 ] = 0;
                            yield* colex_gen_2( n - 1, k );
                        }
                        buff[ n - 1 ] = 1;
                        yield* colex_gen_2( n - 1, k - 1);
                        buff[ n - 1 ] = 0;
                    }
                }
                ;
            return ( k > n / 2 ) ?
                colex_gen( n , k ) :
                colex_gen_2( n, k )
                ;
        }
516862
function(x0, y0, x1, y1, x2, y2, x3, y3) {
  var tvalues = [],
      bounds = [[], []],
      a, b, c, t, t1, t2, b2ac, sqrtb2ac;
  for (var i = 0; i < 2; ++i) {
    if (i == 0) {
      b = 6 * x0 - 12 * x1 + 6 * x2;
      a = -3 * x0 + 9 * x1 - 9 * x2 + 3 * x3;
      c = 3 * x1 - 3 * x0;
    } else {
      b = 6 * y0 - 12 * y1 + 6 * y2;
      a = -3 * y0 + 9 * y1 - 9 * y2 + 3 * y3;
      c = 3 * y1 - 3 * y0;
    }
    if (Math.abs(a) < 1e-12) {
      if (Math.abs(b) < 1e-12) {
        continue;
      }
      t = -c / b;
      if (0 < t && t < 1) {
        tvalues.push(t);
      }
      continue;
    }
    b2ac = b * b - 4 * c * a;
    sqrtb2ac = Math.sqrt(b2ac);
    if (b2ac < 0) {
      continue;
    }
    t1 = (-b + sqrtb2ac) / (2 * a);
    if (0 < t1 && t1 < 1) {
      tvalues.push(t1);
    }
    t2 = (-b - sqrtb2ac) / (2 * a);
    if (0 < t2 && t2 < 1) {
      tvalues.push(t2);
    }
  }

  var x, y, j = tvalues.length,
      jlen = j,
      mt;
  while (j--) {
    t = tvalues[j];
    mt = 1 - t;
    bounds[0][j] = (mt * mt * mt * x0) + (3 * mt * mt * t * x1) + (3 * mt * t * t * x2) + (t * t * t * x3);
    bounds[1][j] = (mt * mt * mt * y0) + (3 * mt * mt * t * y1) + (3 * mt * t * t * y2) + (t * t * t * y3);
  }

  bounds[0][jlen] = x0;
  bounds[1][jlen] = y0;
  bounds[0][jlen + 1] = x3;
  bounds[1][jlen + 1] = y3;
  bounds[0].length = bounds[1].length = jlen + 2;

  return {
    min: {x: Math.min.apply(0, bounds[0]), y: Math.min.apply(0, bounds[1])},
    max: {x: Math.max.apply(0, bounds[0]), y: Math.max.apply(0, bounds[1])}
  };
}
555590
function dfl(a, b, c) {
        switch (arguments.length) {
            case 2: return a != null ? a : b;
            case 3: return a != null ? a : b != null ? b : c;
            default: throw new Error("Implement me");
        }
    }