Calculate the line numbers where the swath will be split in smaller
    granules for parallel processing
762035
def get_scene_splits(nlines_swath, nlines_scan, n_cpus):
    """"""

    nscans = nlines_swath // nlines_scan
    if nscans < n_cpus:
        nscans_subscene = 1
    else:
        nscans_subscene = nscans // n_cpus
    nlines_subscene = nscans_subscene * nlines_scan

    return range(nlines_subscene, nlines_swath, nlines_subscene)
168190
def parse_cell(line, world_size):
    
    # Remove "CELL "
    line = line[4:]

    # Extract information
    sline = [i.strip() for i in line.split(":")]
    name = sline[0]
    name = reduce_resource_name_to_task(name)
    cell_components = sline[1].split(",")
    cells = []

    # List all cells
    for i in range(len(cell_components)):
        if ".." in cell_components[i]:
            cell_range = [int(j) for j in cell_components[i].split("..")]
            for j in range(int(cell_range[0]), int(cell_range[1]+1)):
                cells.append(j)
        else:
            cells.append(int(cell_components[i]))

    if cells == [""]:
        return (name, [])

    xy_pairs = [(int(c) % world_size[0], int(c)//world_size[0]) for c in cells]

    return (name, xy_pairs)
180881
def num_coll_reqd(DIM_FRACTAL, material, DiamTarget):
    
    return DIM_FRACTAL * np.log2(DiamTarget/material.Diameter)
153722
def _scatter(sequence, n):
  """"""
  chunklen = int(math.ceil(float(len(sequence)) / float(n)))

  return [
    sequence[ i*chunklen : (i+1)*chunklen ] for i in range(n)
  ]
825297
def thread_partition_array(x):
    ""
    n_threads = get_threadpool_size()
    if len(x.shape) > 1:
        maxind = x.shape[1]
    else:
        maxind = x.shape[0]
    bounds = np.array(np.linspace(0, maxind, n_threads + 1), dtype='int')
    cmin = bounds[:-1]
    cmax = bounds[1:]
    return cmin, cmax
910331
def to_ary
      lines.take(1000).map { |l| { :number => l.filtered_number, :file => l.filtered_file, :method => l.filtered_method, :source => l.source } }
    end
388464
def pad(lines, delim):
	
	"""
	Populates text into chunks. If the delim was & then
	['12 & 344', '344 & 8', '8 & 88'] would be stored in chunks as
	[['12', '344', '8'], ['344', '8', '88']]
	"""
	chunks = []
	for i in range(len(lines)):
		line = lines[i]
		sections = line.split(delim)
		for j in range(len(sections)):
			if len(chunks) <= j:
				chunks.append([])
			chunks[j].append(sections[j])

	"""
	Calculates & Stores the max length of chunks
	"""
	max_lengths = []
	for i in range(len(chunks)):
		_max = max([len(j) for j in chunks[i]])
		max_lengths.append(_max)

	"""
	Pads the children of chunks according to the chunk's max length" \
	"""
	for i in range(len(chunks)):
		for j in range(len(chunks[i])):
			chunks[i][j] += (max_lengths[i] - len(chunks[i][j])) * ' '
	new_lines = ['' for i in range(len(lines))]

	for i in range(len(chunks)):
		for j in range(len(chunks[i])):
			new_lines[j] += chunks[i][j]
	return new_lines
608698
def split_task_parameters(line):
    
    if line is None:
        result = []
    else:
        result = [parameter.strip() for parameter in line.split(",")]
    return result
1306473
def get_curr_lines(self):
        
        start = max(0, self._coord.line - 5)
        end = min(len(self._template_lines), self._coord.line + 4)

        lines = [(x, self._template_lines[x]) for x in six.moves.range(start, end, 1)]
        return self._coord.line, lines
46547
def branchScale(self):
        """"""
        bs = -(self.prx * scipy.diagonal(self.Prxy, axis1=1, axis2=2)
                ).sum() * self.mu / float(self.nsites)
        assert bs > 0
        return bs
1047699
def _multiline_width(multiline_s, line_width_fn=len):
    """"""
    return max(map(line_width_fn, re.split("[\r\n]", multiline_s)))
103302
function(T, SA, fs, n, k, isbwt) {
        var C, B, RA;
        var i, j, b, c, m, p, q, name, pidx = 0, newfs;
        var c0, c1;
        var flags = 0;

        // allocate temporary storage [CSA]
        if (k <= 256) {
            C = Util.makeS32Buffer(k);
            if (k <= fs) { B = SA.subarray(n + fs - k); flags = 1; }
            else { B = Util.makeS32Buffer(k); flags = 3; }
        } else if (k <= fs) {
            C = SA.subarray(n + fs - k);
            if (k <= (fs - k)) { B = SA.subarray(n + fs - k * 2); flags = 0; }
            else if (k <= 1024) { B = Util.makeS32Buffer(k); flags = 2; }
            else { B = C; flags = 8; }
        } else {
            C = B = Util.makeS32Buffer(k);
            flags = 4 | 8;
        }

        /* stage 1: reduce the problem by at least 1/2
           sort all the LMS-substrings */
        getCounts(T, C, n, k);
        getBuckets(C, B, k, true); /* find ends of buckets */
        for (i = 0; i < n; i++) { SA[i] = 0; }
        b = -1; i = n - 1; j = n; m = 0; c0 = T[n - 1];
        do { c1 = c0; } while ((--i >= 0) && ((c0 = T[i]) >= c1));
        for (; i >= 0 ;) {
            do { c1 = c0; } while ((--i >= 0) && ((c0 = T[i]) <= c1));
            if ( i >= 0 ) {
                if ( b >= 0 ) { SA[b] = j; }
                b = --B[c1];
                j = i;
                ++m;
                do { c1 = c0; } while ((--i >= 0) && ((c0 = T[i]) >= c1));
            }
        }

        if (m > 1) {
            LMSsort(T, SA, C, B, n, k);
            name = LMSpostproc(T, SA, n, m);
        } else if (m === 1) {
            SA[b] = j + 1;
            name = 1;
        } else {
            name = 0;
        }

        /* stage 2: solve the reduced problem
           recurse if names are not yet unique */
        if(name < m) {
            if((flags & 4) !== 0) { C = null; B = null; }
            if((flags & 2) !== 0) { B = null; }
            newfs = (n + fs) - (m * 2);
            if((flags & (1 | 4 | 8)) === 0) {
                if((k + name) <= newfs) { newfs -= k; }
                else { flags |= 8; }
            }
            ASSERT( (n >>> 1) <= (newfs + m) );
            for (i = m + (n >>> 1) - 1, j = m * 2 + newfs - 1; m <= i; i--) {
                if(SA[i] !== 0) { SA[j--] = SA[i] - 1; }
            }
            RA = SA.subarray(m + newfs);
            SA_IS(RA, SA, newfs, m, name, false);
            RA = null;

            i = n - 1; j = m * 2 - 1; c0 = T[n - 1];
            do { c1 = c0; } while ((--i >= 0) && ((c0 = T[i]) >= c1));
            for (; i >= 0 ;) {
                do { c1 = c0; } while ((--i >= 0) && ((c0 = T[i]) <= c1));
                if ( i >= 0 ) {
                    SA[j--] = i + 1;
                    do { c1 = c0; } while ((--i >= 0) && ((c0 = T[i]) >= c1));
                }
            }

            for (i = 0; i < m; i++) { SA[i] = SA[m + SA[i]]; }
            if((flags & 4) !== 0) { C = B = Util.makeS32Buffer(k); }
            if((flags & 2) !== 0) { B = Util.makeS32Buffer(k); }
        }

        /* stage 3: induce the result for the original problem */
        if((flags & 8) !== 0) { getCounts(T, C, n, k); }
        /* put all left-most S characters into their buckets */
        if (m > 1) {
            getBuckets(C, B, k, true); /* find ends of buckets */
            i = m - 1; j = n; p = SA[m - 1]; c1 = T[p];
            do {
                q = B[c0 = c1];
                while (q < j) { SA[--j] = 0; }
                do {
                    SA[--j] = p;
                    if(--i < 0) { break; }
                    p = SA[i];
                } while((c1 = T[p]) === c0);
            } while (i >= 0 );
            while ( j > 0 ) { SA[--j] = 0; }
        }
        if (!isbwt) { induceSA(T, SA, C, B, n, k); }
        else { pidx = computeBWT(T, SA, C, B, n, k); }
        C = null; B = null;
        return pidx;
    }
586757
function splitInLines() {
            let legendEntries = svg.selectAll('.legend-entry');
            let numberOfEntries = legendEntries.size();
            let lineHeight = (chartHeight / 2) * 1.7;
            let newLine = svg.select('.legend-group')
              .append('g')
                .classed('legend-line', true)
                .attr('transform', `translate(0, ${lineHeight})`);
            let lastEntry = legendEntries.filter(`:nth-child(${numberOfEntries})`);

            lastEntry.attr('transform', `translate(${markerSize},0)`);
            newLine.append(() => lastEntry.node());
        }
1332799
def _get_split_tasks(args, split_fn, file_key, outfile_i=-1):
    
    split_args = []
    combine_map = {}
    finished_map = collections.OrderedDict()
    extras = []
    for data in args:
        out_final, out_parts = split_fn(data)
        for parts in out_parts:
            split_args.append([utils.deepish_copy(data)] + list(parts))
        for part_file in [x[outfile_i] for x in out_parts]:
            combine_map[part_file] = out_final
        if len(out_parts) == 0:
            if out_final is not None:
                if out_final not in finished_map:
                    data[file_key] = out_final
                    finished_map[out_final] = [data]
                else:
                    extras.append([data])
            else:
                extras.append([data])
    return split_args, combine_map, list(finished_map.values()), extras
477503
def parallelize_func(iterable, func, chunksz=1, n_jobs=16, *args, **kwargs):
    
    chunker = func
    chunks = more_itertools.chunked(iterable, chunksz)
    chunks_results = Parallel(n_jobs=n_jobs, verbose=50)(
        delayed(chunker)(chunk, *args, **kwargs) for chunk in chunks)
    results = more_itertools.flatten(chunks_results)
    return list(results)
950799
def square_off(samples, run_parallel):
    
    to_process = []
    extras = []
    for data in [utils.to_single_data(x) for x in samples]:
        added = False
        if tz.get_in(("metadata", "batch"), data):
            for add in genotype.handle_multiple_callers(data, "jointcaller", require_bam=False):
                if _is_jointcaller_compatible(add):
                    added = True
                    to_process.append([add])
        if not added:
            extras.append([data])
    processed = grouped_parallel_split_combine(to_process, _split_by_callable_region,
                                               multi.group_batches_joint, run_parallel,
                                               "square_batch_region", "concat_variant_files",
                                               "vrn_file", ["region", "sam_ref", "config"])
    return _combine_to_jointcaller(processed) + extras
539380
def parallel(func, arr:Collection, max_workers:int=None):
    ""
    max_workers = ifnone(max_workers, defaults.cpus)
    if max_workers<2: results = [func(o,i) for i,o in progress_bar(enumerate(arr), total=len(arr))]
    else:
        with ProcessPoolExecutor(max_workers=max_workers) as ex:
            futures = [ex.submit(func,o,i) for i,o in enumerate(arr)]
            results = []
            for f in progress_bar(concurrent.futures.as_completed(futures), total=len(arr)): results.append(f.result())
    if any([o is not None for o in results]): return results