Create new vector of type variables from list of variables
changing all recursive bounds from old to new list.
2356
public List<Type> newInstances(List<Type> tvars) {
        List<Type> tvars1 = tvars.map(newInstanceFun);
        for (List<Type> l = tvars1; l.nonEmpty(); l = l.tail) {
            TypeVar tv = (TypeVar) l.head;
            tv.bound = subst(tv.bound, tvars, tvars1);
        }
        return tvars1;
    }
425840
def _var_strings(self, v_name, v_values, v_idx=None, v_start=None):
        """"""
        if self.uppercase:
            v_name = v_name.upper()

        var_strs = []

        # Parse a multidimensional array
        if is_nullable_list(v_values, list):
            if not v_idx:
                v_idx = []

            i_s = v_start[::-1][len(v_idx)] if v_start else None

            # FIXME: We incorrectly assume 1-based indexing if it is
            # unspecified.  This is necessary because our output method always
            # separates the outer axes to one per line.  But we cannot do this
            # if we don't know the first index (which we are no longer assuming
            # to be 1-based elsewhere).  Unfortunately, the solution needs a
            # rethink of multidimensional output.

            # NOTE: Fixing this would also clean up the output of todict(),
            # which is now incorrectly documenting unspecified indices as 1.

            # For now, we will assume 1-based indexing here, just to keep
            # things working smoothly.
            if i_s is None:
                i_s = 1

            for idx, val in enumerate(v_values, start=i_s):
                v_idx_new = v_idx + [idx]
                v_strs = self._var_strings(v_name, val, v_idx=v_idx_new,
                                           v_start=v_start)
                var_strs.extend(v_strs)

        # Parse derived type contents
        elif isinstance(v_values, Namelist):
            for f_name, f_vals in v_values.items():
                v_title = '%'.join([v_name, f_name])

                v_start_new = v_values.start_index.get(f_name, None)

                v_strs = self._var_strings(v_title, f_vals,
                                           v_start=v_start_new)
                var_strs.extend(v_strs)

        # Parse an array of derived types
        elif is_nullable_list(v_values, Namelist):
            if not v_idx:
                v_idx = []

            i_s = v_start[::-1][len(v_idx)] if v_start else 1

            for idx, val in enumerate(v_values, start=i_s):

                # Skip any empty elements in a list of derived types
                if val is None:
                    continue

                v_title = v_name + '({0})'.format(idx)

                v_strs = self._var_strings(v_title, val)
                var_strs.extend(v_strs)

        else:
            use_default_start_index = False
            if not isinstance(v_values, list):
                v_values = [v_values]
                use_default_start_index = False
            else:
                use_default_start_index = self.default_start_index is not None

            # Print the index range

            # TODO: Include a check for len(v_values) to determine if vector
            if v_idx or v_start or use_default_start_index:
                v_idx_repr = '('

                if v_start or use_default_start_index:
                    if v_start:
                        i_s = v_start[0]
                    else:
                        i_s = self.default_start_index

                    if i_s is None:
                        v_idx_repr += ':'

                    else:
                        i_e = i_s + len(v_values) - 1

                        if i_s == i_e:
                            v_idx_repr += '{0}'.format(i_s)
                        else:
                            v_idx_repr += '{0}:{1}'.format(i_s, i_e)
                else:
                    v_idx_repr += ':'

                if v_idx:
                    idx_delim = ', ' if self._index_spacing else ','
                    v_idx_repr += idx_delim
                    v_idx_repr += idx_delim.join(str(i) for i in v_idx[::-1])

                v_idx_repr += ')'

            else:
                v_idx_repr = ''

            # Split output across multiple lines (if necessary)

            val_strs = []

            val_line = ''
            for v_val in v_values:

                v_header = v_name + v_idx_repr + ' = '
                # Increase column width if the header exceeds this value
                if len(self.indent + v_header) >= self.column_width:
                    column_width = len(self.indent + v_header) + 1
                else:
                    column_width = self.column_width

                v_width = column_width - len(self.indent + v_header)

                if len(val_line) < v_width:
                    val_line += self._f90repr(v_val) + ', '

                if len(val_line) >= v_width:
                    val_strs.append(val_line.rstrip())
                    val_line = ''

            # Append any remaining values
            if val_line:
                val_strs.append(val_line.rstrip())

            if val_strs:
                if self.end_comma or v_values[-1] is None:
                    pass
                else:
                    val_strs[-1] = val_strs[-1][:-1]

            # Complete the set of values
            if val_strs:
                var_strs.append('{0}{1} = {2}'
                                ''.format(v_name, v_idx_repr,
                                          val_strs[0]).strip())

                for v_str in val_strs[1:]:
                    var_strs.append(' ' * len(v_header) + v_str)

        return var_strs
1174810
private void moveVariableDeclarations(List<Statement> from, List<Statement> to) {
    for (Statement stat : from) {
      DeclarationExpression declExpr = AstUtil.getExpression(stat, DeclarationExpression.class);
      if (declExpr == null) continue;

      ((ExpressionStatement) stat).setExpression(
          new BinaryExpression(
              copyLhsVariableExpressions(declExpr),
              Token.newSymbol(Types.ASSIGN, -1, -1),
              declExpr.getRightExpression()));

      declExpr.setRightExpression(createDefaultValueInitializer(declExpr));
      to.add(new ExpressionStatement(declExpr));
    }
  }
748866
function newNestedIndex(vectors) {
  var arity = vectors.length;
  if (arity === 0) {
    throw new Error('cannot index an empty list of vectors');
  }
  var numRows = vectors[0].size();

  // Initialize properties
  var nestedIndex = Object.create(nestedIndexProto);
  nestedIndex.initVectors = vectors;
  nestedIndex.size = 0;
  nestedIndex.arity = arity;
  nestedIndex._dtypes = vectors.map(function(v) { return v.dtype; });
  nestedIndex._map = Object.create(null);

  // Build index
  var rootMap = nestedIndex._map;
  var lastColInd = arity - 1;
  for (var i = 0; i < numRows; i++) {
    var currMap = rootMap;
    var currVector, key;
    for (var j = 0; j < lastColInd; j++) {
      currVector = vectors[j];
      key = cleanKey(currVector.values[i], currVector.dtype);
      var innerMap = currMap[key];

      // Create innerMap if not present
      if (isUndefined(innerMap)) {
        currMap[key] = innerMap = Object.create(null);
      }
      currMap = innerMap;
    }

    // Add the row number to the entry
    currVector = vectors[lastColInd];
    key = cleanKey(currVector.values[i], currVector.dtype);
    var rowNums = currMap[key];
    if (isUndefined(rowNums)) {
      currMap[key] = i;
      nestedIndex.size++;
    } else if (typeof rowNums === 'number') {
      currMap[key] = [rowNums, i];
    } else {
      // rowNums must be an array
      rowNums.push(i);
    }
  }

  return nestedIndex;
}
697325
public Assignment mapVariables(Map<Integer, Integer> varMap) {
    int[] newVarNums = new int[vars.length];
    Object[] newValues = new Object[vars.length];

    int numFilled = 0;
    for (int i = 0; i < vars.length; i++) {
      if (varMap.containsKey(vars[i])) {
        newVarNums[numFilled] = varMap.get(vars[i]);
        newValues[numFilled] = values[i];
        numFilled++;
      }
    }
    
    if (numFilled < newVarNums.length) {
      newVarNums = Arrays.copyOf(newVarNums, numFilled);
      newValues = Arrays.copyOf(newValues, numFilled);
    }
    return Assignment.fromUnsortedArrays(newVarNums, newValues);
  }
87743
private Assignment createAssignment(final LNGBooleanVector vec, final Collection<Variable> variables) {
        final Assignment model = new Assignment();
        for (int i = 1; i < vec.size(); i++) {
            final Variable var = this.f.variable(this.idx2name.get(i));
            if (vec.get(i)) {
                if (variables == null || variables.contains(var)) { model.addLiteral(var); }
            } else if (variables == null || variables.contains(var)) { model.addLiteral(var.negate()); }
        }
        return model;
    }
1062377
def flatten(in_list):
    """"""
    out_list = []
    for val in in_list:
        if isinstance(val, list):
            out_list.extend(val)
        else:
            out_list.append(val)

    return out_list
132615
function _fromVector(vector) {
  return new _Vector4(vector.values[0], vector.values[1], vector.values[2], vector.values[3]);
}
654567
def concat(cls, variables, dim='concat_dim', positions=None,
               shortcut=False):
        
        if not isinstance(dim, str):
            dim, = dim.dims

        variables = list(variables)
        first_var = variables[0]

        if any(not isinstance(v, cls) for v in variables):
            raise TypeError('IndexVariable.concat requires that all input '
                            'variables be IndexVariable objects')

        indexes = [v._data.array for v in variables]

        if not indexes:
            data = []
        else:
            data = indexes[0].append(indexes[1:])

            if positions is not None:
                indices = nputils.inverse_permutation(
                    np.concatenate(positions))
                data = data.take(indices)

        attrs = OrderedDict(first_var.attrs)
        if not shortcut:
            for var in variables:
                if var.dims != first_var.dims:
                    raise ValueError('inconsistent dimensions')
                utils.remove_incompatible_items(attrs, var.attrs)

        return cls(first_var.dims, data, attrs)
1228688
def add_variables(
        self, variables: Union[List["Variable"], "Variable"], index: int = None
    ) -> None:
        
        if isinstance(variables, Variable):
            addvars = copy.deepcopy([variables])
        else:
            addvars = copy.deepcopy(variables)

        if index is None:
            self.variables.extend(addvars)
        else:
            self.variables[index:index] = addvars
367659
def fromlist(cls, rnglist, autostep=None):
        """"""
        inst = RangeSet(autostep=autostep)
        inst.updaten(rnglist)
        return inst
1056643
def fromarray(A):
    """"""
    subs = np.nonzero(A)
    vals = A[subs]
    return sptensor(subs, vals, shape=A.shape, dtype=A.dtype)
1039861
def from_values(cls, vals):
        ""
        if util.config.future_deprecations:
            param.main.param.warning("%s.from_values is deprecated, the %s "
                                     "constructor may now be used directly.")
        return cls(items=cls._process_items(vals))
1335547
def _create_slots(self, var_list):
    """"""
    super(MultistepAdamOptimizer, self)._create_slots(var_list)
    first_var = min(var_list, key=lambda x: x.name)
    self._create_non_slot_variable(initial_value=0 if self._n == 1 else 1,
                                   name="iter",
                                   colocate_with=first_var)
    for v in var_list:
      self._zeros_slot(v, "grad_acc", self._name)
27674
private Collection<Tuple> getCombinedTuples( List<VarDef> combinedVars, Collection<Tuple> tuples)
    {
    // Apply any once-only constraints.
    Set<Tuple> onceTuples = getOnceTupleDefs( combinedVars);
    if( !onceTuples.isEmpty())
      {
      for( Tuple tuple : tuples)
        {
        tuple.setOnce( onceTuples.contains( tuple));
        }
      }
    
    return tuples;
    }
714826
function create2x2(a, b, c, d){
    if (undef(a)) throw new Error("At least one argument must be provided.");

    if (undef(b)){
        // Everything = a
        b = a;
        c = a;
        d = a;
    }
    else{
        // we have a and b
        if(undef(c)){
            c = a;
            d = b;
        }
        else{
            if(undef(d)) throw new Error("Argument 'd' must be provided if 'c' is.");
        }
    }

    return new Vector([[a, b],[c, d]]);
}
443766
def vectorize(values):
    
    if isinstance(values, list):
        return ','.join(str(v) for v in values)
    return values