<commit_before><commit_msg>Added utility function for converting various inputs into lists of discrete trajectories: see pyemma.util.types<commit_after>__author__ = 'noe'

import numpy as np

def is_list_of_int(l):
    if isinstance(l, list):
        if (len(l) > 0):
            if isinstance(l[0], int):
                return True
        else:
            return False
    else:
        return False

def is_int_array(l):
    if isinstance(l, np.ndarray):
        if l.ndim == 1 and (l.dtype.kind == 'i' or l.dtype == l.dtype.kind == 'u'):
            return True
    return False

def ensure_dtraj(dtraj):
    if is_int_array(dtraj):
        return dtraj
    elif is_list_of_int(dtraj):
        return np.array(dtraj, dtype=int)
    else:
        raise TypeError('Argument dtraj is not a discrete trajectory - only list of integers or int-ndarrays are allowed. Check type.')

def ensure_dtraj_list(dtrajs):
    # is this a list?
    if isinstance(dtrajs, list):
        # elements are ints? then wrap into a list
        if is_list_of_int(dtrajs):
            return [np.array(dtrajs, dtype=int)]
        else:
            for i in range(len(dtrajs)):
                dtrajs[i] = ensure_dtraj(dtrajs[i])
            return dtrajs
    else:
        return [ensure_dtraj(dtrajs)]

{'fraction_non_alphanumeric': 0.09664848012470771, 'fraction_numerical': 0.002338269680436477, 'mean_word_length': 2.34375, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1508364', 'n_tokens_mistral': 436, 'n_tokens_neox': 412, 'n_words': 121}