Picked from https://github.com/adamhaile/surplus/blob/master/src/runtime/content.ts#L368 return an array of the indices of ns that comprise the longest increasing subsequence within ns
970732
function longestPositiveIncreasingSubsequence(ns, newStart) {
  let seq = [],
    is = [],
    l = -1,
    pre = new Array(ns.length);

  for (let i = newStart, len = ns.length; i < len; i++) {
    let n = ns[i];
    if (n < 0) continue;
    let j = findGreatestIndexLEQ(seq, n);
    if (j !== -1) pre[i] = is[j];
    if (j === l) {
      l++;
      seq[l] = n;
      is[l]  = i;
    } else if (n < seq[j + 1]) {
      seq[j + 1] = n;
      is[j + 1] = i;
    }
  }

  for (let i = is[l]; l >= 0; i = pre[i], l--) {
    seq[l] = i;
  }

  return seq;
}
130876
public int[] bestSequence(SequenceModel ts) {
    
    int[] sample = new int[ts.length()+ts.leftWindow()];

    for (int pos = ts.leftWindow(); pos < sample.length; pos++) {
      double[] scores = ts.scoresOf(sample, pos);
      double total = 0.0;
      for (int i = 0; i < scores.length; i++) {
        scores[i] = Math.exp(scores[i]);
      }
      ArrayMath.normalize(scores);
      int l = ArrayMath.sampleFromDistribution(scores);
      sample[pos] = ts.getPossibleValues(pos)[l];
    }

    return sample;
  }
946293
def __get_ra_index_indices(self):
        
        fragment_indices = []
        for idx, cumlen in enumerate(self._cumulative_lengths):
            cumlen_prev = self._cumulative_lengths[idx - 1] if idx > 0 else 0
            fragment_indices.append([np.argwhere(
                np.logical_and(self.ra_indices >= cumlen_prev, self.ra_indices < cumlen)
            )])
        return fragment_indices
914010
def get_interested_subsequences(subsequences):#, subseqdim):
    
    keep_indices = []
    # if subseqdim == 'ALLD':
    #     filter_subseq_suffixes = filter_subseq_suffixes
    # elif subseqdim == '3D':
    #     filter_subseq_suffixes = filter_subseq_3D_suffixes
    # elif subseqdim == '2D':
    #     filter_subseq_suffixes = filter_subseq_2D_suffixes
    # else:
    #     raise ValueError('ALLD, 3D, or 2D only!')

    for subseq in subsequences:
        if subseq == 'all':
            keep_indices.extend([x for x in filter_subseq_suffixes[subseq]])
        else:
            keep_indices.extend([subseq + '_' + x for x in filter_subseq_suffixes[subseq]])
    return keep_indices
465851
public int[] extractLongArray() {
	int[] argout;
	argout = new int[values.length];
	for (int i = 0; i < values.length; i++) {
	    argout[i] = Integer.parseInt(values[i]);
	}
	return argout;
    }
331671
def next(self) -> "ArrayEntry":
        
        try:
            newval, naft = self.after.pop()
        except IndexError:
            raise NonexistentInstance(self.json_pointer(), "next of last") from None
        return ArrayEntry(
            self.index + 1, self.before.cons(self.value), naft, newval,
            self.parinst, self.schema_node, self.timestamp)
815356
def get_restricted_index(index, length, length_index_allowed=True):
    '''
    
    '''
    if index and index >= length:
        index = length if length_index_allowed else length-1
    return get_non_negative_index(index, length)
481806
def _make_indices(self, Ns):
        '''  '''
        N_new = int(Ns * self.n_splits)

        test = [np.full(N_new, False) for i in range(self.n_splits)]
        for i in range(self.n_splits):
            test[i][np.arange(Ns * i, Ns * (i + 1))] = True
        train = [np.logical_not(test[i]) for i in range(self.n_splits)]

        test = [np.arange(N_new)[test[i]] for i in range(self.n_splits)]
        train = [np.arange(N_new)[train[i]] for i in range(self.n_splits)]

        cv = list(zip(train, test))
        return cv
1137122
def get_longest_non_repeat_v2(string):
    
    if string is None:
        return 0, ''
    sub_string = ''
    start, max_len = 0, 0
    used_char = {}
    for index, char in enumerate(string):
        if char in used_char and start <= used_char[char]:
            start = used_char[char] + 1
        else:
            if index - start + 1 > max_len:
                max_len = index - start + 1
                sub_string = string[start: index + 1]
        used_char[char] = index
    return max_len, sub_string
538444
def tuple_index(self, n):
        ''''''
        return n.args and n.args[-1].type == 'index' and general_type(n.args[-1].sequence.pseudo_type) == 'Tuple' and\
               n.args[-1].index.type == 'int' and\
               (n.args[-1].index.value == -1 or n.args[-1].index.value == len(n.args[-1].sequence.pseudo_type) - 2)
1078992
def longest_run_1d(arr):
    
    v, rl = rle_1d(arr)[:2]
    return np.where(v, rl, 0).max()
217831
public int getLeftIndexFromSNode(SSpan s) 
  {
    
    RelannisNodeFeature feat = 
      (RelannisNodeFeature) s.getFeature(SaltUtil.createQName(ANNIS_NS, FEAT_RELANNIS_NODE)).getValue();
    return (int) feat.getLeftToken();
  }
1239652
def find_near_matches_substitutions(subsequence, sequence, max_substitutions):
    
    _check_arguments(subsequence, sequence, max_substitutions)

    if max_substitutions == 0:
        return [
            Match(start_index, start_index + len(subsequence), 0)
            for start_index in search_exact(subsequence, sequence)
        ]

    elif len(subsequence) // (max_substitutions + 1) >= 3:
        return find_near_matches_substitutions_ngrams(
            subsequence, sequence, max_substitutions,
        )

    else:
        return find_near_matches_substitutions_lp(
            subsequence, sequence, max_substitutions,
        )
744901
private int linearSearch(int position) {
		int[] minSeqIndex = getMinSequenceIndex();
		int[] maxSeqIndex = getMaxSequenceIndex();
		int length = minSeqIndex.length;
		for (int i = 0; i < length; i++) {
			if (position >= minSeqIndex[i] && position <= maxSeqIndex[i]) {
				return i;
			}
		}
		throw new IndexOutOfBoundsException("Given position " + position + " does not map into this Sequence");
	}
149379
def _split_indices(self, concat_inds):
        
        clengths = np.append([0], np.cumsum(self.__lengths))
        mapping = np.zeros((clengths[-1], 2), dtype=int)
        for traj_i, (start, end) in enumerate(zip(clengths[:-1], clengths[1:])):
            mapping[start:end, 0] = traj_i
            mapping[start:end, 1] = np.arange(end - start)
        return mapping[concat_inds]
1366553
def ind2sub(ind, dimensions):
    
    # check that the index is within range
    if ind >= np.prod(dimensions):
        raise RuntimeError("ind2sub: index exceeds array size")
    cum_dims = list(dimensions)
    cum_dims.reverse()
    m = 1
    mult = []
    for d in cum_dims:
        m = m*d
        mult.append(m)
    mult.pop()
    mult.reverse()
    mult.append(1)
    indices = []
    for d in mult:
        indices.append((ind/d)+1)
        ind = ind - (ind/d)*d
    return indices
262502
private void constructSuffixArray(int[] bucket_A, int[] bucket_B, int n, int m) {
        int i, j, k; // ptr
        int s, c0, c1, c2;
        // (_c1)])
        if (0 < m) {
            /*
             * Construct the sorted order of type B suffixes by using the sorted order of
             * type B suffixes.
             */
            for (c1 = ALPHABET_SIZE - 2; 0 <= c1; --c1) {
                /* Scan the suffix array from right to left. */
                for (i = bucket_B[(c1) * ALPHABET_SIZE + (c1 + 1)], j = bucket_A[c1 + 1] - 1, k = 0, c2 = -1; i <= j; --j) {
                    if (0 < (s = SA[j])) {
                        // Tools.assertAlways(T[s] == c1, "");
                        // Tools.assertAlways(((s + 1) < n) && (T[s] <= T[s +
                        // 1]),
                        // "");
                        // Tools.assertAlways(T[s - 1] <= T[s], "");
                        SA[j] = ~s;
                        c0 = T[start + --s];
                        if ((0 < s) && (T[start + s - 1] > c0)) {
                            s = ~s;
                        }
                        if (c0 != c2) {
                            if (0 <= c2) {
                                bucket_B[(c1) * ALPHABET_SIZE + (c2)] = k;
                            }
                            k = bucket_B[(c1) * ALPHABET_SIZE + (c2 = c0)];
                        }
                        // Tools.assertAlways(k < j, "");
                        SA[k--] = s;
                    } else {
                        // Tools.assertAlways(((s == 0) && (T[s] == c1))
                        // || (s < 0), "");
                        SA[j] = ~s;
                    }
                }
            }
        }

        /*
         * Construct the suffix array by using the sorted order of type B suffixes.
         */
        k = bucket_A[c2 = T[start + n - 1]];
        SA[k++] = (T[start + n - 2] < c2) ? ~(n - 1) : (n - 1);
        /* Scan the suffix array from left to right. */
        for (i = 0, j = n; i < j; ++i) {
            if (0 < (s = SA[i])) {
                // Tools.assertAlways(T[s - 1] >= T[s], "");
                c0 = T[start + --s];
                if ((s == 0) || (T[start + s - 1] < c0)) {
                    s = ~s;
                }
                if (c0 != c2) {
                    bucket_A[c2] = k;
                    k = bucket_A[c2 = c0];
                }
                // Tools.assertAlways(i < k, "");
                SA[k++] = s;
            } else {
                // Tools.assertAlways(s < 0, "");
                SA[i] = ~s;
            }
        }
    }