Expand lists in multidimensional arrays to pad unset values.
481720
def pad_array(v, idx):
    """"""
    i_v, i_s = idx[0]

    if len(idx) > 1:
        # Append missing subarrays
        v.extend([[] for _ in range(len(v), i_v - i_s + 1)])

        # Pad elements
        for e in v:
            pad_array(e, idx[1:])
    else:
        v.extend([None for _ in range(len(v), i_v - i_s + 1)])
1268046
def ungroup_array2singles(input, **params):
    
    PARAM_FIELD_KEY = 'field.key'
    PARAM_FIELD_ARRAY = 'field.array'
    PARAM_FIELD_SINGLE = 'field.single'

    res = []
    field_key = params.get(PARAM_FIELD_KEY) if PARAM_FIELD_KEY in params else None
    field_array = params.get(PARAM_FIELD_ARRAY)
    field_single = params.get(PARAM_FIELD_SINGLE)
    for row in input:
        if row[field_array] and len(row[field_array]) > 0:
            for value in row[field_array]:
                res.append({field_single: value} if not field_key else {field_key: row[field_key], field_single: value})
    return res
450536
def _fill_array_from_list(the_list, the_array):
        """"""
        for i, val in enumerate(the_list):
            the_array[i] = val
        return the_array
1087122
private String[] mergeAndConvert(List<String> list, String[] array) {
        Set<String> set = new HashSet<String>(Arrays.asList(array));
        set.addAll(list);
        return set.toArray(new String[set.size()]);
    }
1352326
def unweave(iterable, n=2):
    
    """
    res = [[] for i in range(n)]
    i = 0
    for x in iterable:
        res[i % n].append(x)
        i += 1
    return res
398127
function unflatten(valuesInOneDimension, size) {
  const {height, width} = size;
  const valuesInTwoDimensions = [];
  for (let y = 0; y < height; y++) {
    const start = y * width;
    const end = start + width;
    valuesInTwoDimensions.push(valuesInOneDimension.slice(start, end));
  }
  return valuesInTwoDimensions;
}
19034
def pop(self,*args):
        '''
        
        '''
        nargs=len(args)
        dimlist=args[0] if isiterable(args[0]) else [args[0]]
        missing=args[1] if nargs > 1 else None 
        out=()
        for d in dimlist:
            out+=(super(dimStr, self).pop(d,missing),)
            if out[-1] == missing : self.set_ndims()
        
        return out if len(out) > 1 else out[0]
396612
public void trim() {
    keys = Arrays.copyOf(keys, size);
    values = Arrays.copyOf(values, size);
    for (Container c : values) {
      c.trim();
    }
  }
264924
def unlist(list_thing, complain=True):
    """"""
    if complain and len(list_thing) > 1:
        raise ValueError("More than one element in {}".format(list_thing))
    elif len(list_thing) == 1:
        return list_thing[0]

    if complain:
        raise ValueError("Nothing in {}".format(list_thing))
    return None
45083
def expand_array(data,
                 scans,
                 c_align,
                 c_exp,
                 scan_size=16,
                 tpz_size=16,
                 nties=200,
                 track_offset=0.5,
                 scan_offset=0.5):
    """"""
    nties = np.asscalar(nties)
    tpz_size = np.asscalar(tpz_size)
    s_scan, s_track = da.meshgrid(np.arange(nties * tpz_size),
                                  np.arange(scans * scan_size))
    s_track = (s_track.reshape(scans, scan_size, nties, tpz_size) % scan_size +
               track_offset) / scan_size
    s_scan = (s_scan.reshape(scans, scan_size, nties, tpz_size) % tpz_size +
              scan_offset) / tpz_size

    a_scan = s_scan + s_scan * (1 - s_scan) * c_exp + s_track * (
        1 - s_track) * c_align
    a_track = s_track

    data_a = data[:scans * 2:2, np.newaxis, :-1, np.newaxis]
    data_b = data[:scans * 2:2, np.newaxis, 1:, np.newaxis]
    data_c = data[1:scans * 2:2, np.newaxis, 1:, np.newaxis]
    data_d = data[1:scans * 2:2, np.newaxis, :-1, np.newaxis]

    fdata = ((1 - a_track) *
             ((1 - a_scan) * data_a + a_scan * data_b) + a_track * (
                 (1 - a_scan) * data_d + a_scan * data_c))
    return fdata.reshape(scans * scan_size, nties * tpz_size)
737272
function removeValueFromList(list, value) {
    for (var i = list.length - 1; i >= 0; i--) {
        if (list[i] == value) {
            return list.splice(i, 1); // remove from array
        }
    }
    return false;
}
510090
def __unroll(self, rolled):
        """"""
        return np.array(np.concatenate([matrix.flatten() for matrix in rolled], axis=1)).reshape(-1)
1233484
private static int[] pad(int[] list) {
        double m = list.length / (double)WORD_LENGTH;
        int size = (int)Math.ceil(m);
        int[] ret = new int[size * WORD_LENGTH];
        Arrays.fill(ret, 0);
        System.arraycopy(list,0,ret,0,list.length);
        return ret;
    }
890102
def _adjust_inserted_indices(inserted_indices_list, prune_indices_list):
        """"""
        # Created a copy, to preserve cached property
        updated_inserted = [[i for i in dim_inds] for dim_inds in inserted_indices_list]
        pruned_and_inserted = zip(prune_indices_list, updated_inserted)
        for prune_inds, inserted_inds in pruned_and_inserted:
            # Only prune indices if they're not H&S (inserted)
            prune_inds = prune_inds[~np.in1d(prune_inds, inserted_inds)]
            for i, ind in enumerate(inserted_inds):
                ind -= np.sum(prune_inds < ind)
                inserted_inds[i] = ind
        return updated_inserted
1284105
def flatten(list_of_lists):
    """"""
    flat_list = []
    for sublist in list_of_lists:
        if isinstance(sublist, string_types) or isinstance(sublist, int):
            flat_list.append(sublist)
        elif sublist is None:
            continue
        elif not isinstance(sublist, string_types) and len(sublist) == 1:
            flat_list.append(sublist[0])
        else:
            flat_list.append(tuple(sublist))
    return flat_list
159055
private final void expand_array()
  {
//    if (tc.isEntryEnabled())
//      SibTr.entry(tc, "expand_array");

    int length = m_array.length;
    Object[] m_new = new Object[length*2];
    System.arraycopy(m_array, m_head, m_new, m_head, length-m_head);
    System.arraycopy(m_array, 0, m_new, length, m_tail);
    m_tail += length;
    m_array = m_new;

//    if (tc.isEntryEnabled())
//      SibTr.exit(tc, "expand_array");
  }
820722
def _mk_uninit_array(self, bounds):
        
        if len(bounds) == 0:
            raise For2PyError("Zero-length arrays current not handled!.")

        this_dim = bounds[0]
        lo,hi = this_dim[0],this_dim[1]
        sz = hi-lo+1

        if len(bounds) == 1:
            return [None] * sz

        sub_array = self._mk_uninit_array(bounds[1:])
        this_array = [copy.deepcopy(sub_array) for i in range(sz)]

        return this_array