<commit_before>import numpy as np
from MNNparcellation.inc.util import mat2cond_index, cond2mat_index
from MNNparcellation.inc.util import vec2symmetric_mat
from termcolor import colored


def test_mat2cond_index():
    " Test sym matrix to vector indexing "

    n = 10
    X = []
    Z = range(n*(n-1)/2)
    for i in range(n):
        for j in range(i):
            nv = mat2cond_index(n, i, j)
            X.extend([nv])
    return X.sort() == Z.sort()


def test_cond2mat_index():
    " Test vector 2 sym matrix indexing "

    n = 10
    X = []
    Y = []
    Z = range(n*(n-1)/2)
    for i in range(n):
        for j in range(i):
            X.append([j, i])
    for i in range(n*(n-1)/2):
        nv = cond2mat_index(n, i)
        Y.append(list(nv))
        if X[i].sort() == Y[i].sort():
            Z[i] = 1
    return np.sum(Z) == len(Z)


def test_vec2symmetric_mat():
    " Test vector 2 sym matrix writing "

    n = 3
    X = []
    Y = []
    a = np.random.rand(n, n)
    m = np.tril(a) + np.tril(a, -1).T
    Z = range(n*(n-1)/2)
    for i in range(n):
        m[i, i] = 1
        for j in range(i):
            nv = mat2cond_index(n, i, j)
            Z[nv] = m[i, j]
    SM = vec2symmetric_mat(Z, n)
    X = np.linalg.norm(m-SM)
    if X == 0.0:
        return True
    return False


if __name__ == "__main__":
    print "Test Util file........................",<commit_msg>remove unes var<commit_after>import numpy as np
from MNNparcellation.inc.util import mat2cond_index, cond2mat_index
from MNNparcellation.inc.util import vec2symmetric_mat
from termcolor import colored


def test_mat2cond_index():
    " Test sym matrix to vector indexing "

    n = 10
    X = []
    Z = range(n*(n-1)/2)
    for i in range(n):
        for j in range(i):
            nv = mat2cond_index(n, i, j)
            X.extend([nv])
    return X.sort() == Z.sort()


def test_cond2mat_index():
    " Test vector 2 sym matrix indexing "

    n = 10
    X = []
    Y = []
    Z = range(n*(n-1)/2)
    for i in range(n):
        for j in range(i):
            X.append([j, i])
    for i in range(n*(n-1)/2):
        nv = cond2mat_index(n, i)
        Y.append(list(nv))
        if X[i].sort() == Y[i].sort():
            Z[i] = 1
    return np.sum(Z) == len(Z)


def test_vec2symmetric_mat():
    " Test vector 2 sym matrix writing "

    n = 3
    X = []
    a = np.random.rand(n, n)
    m = np.tril(a) + np.tril(a, -1).T
    Z = range(n*(n-1)/2)
    for i in range(n):
        m[i, i] = 1
        for j in range(i):
            nv = mat2cond_index(n, i, j)
            Z[nv] = m[i, j]
    SM = vec2symmetric_mat(Z, n)
    X = np.linalg.norm(m-SM)
    if X == 0.0:
        return True
    return False


if __name__ == "__main__":
    print "Test Util file........................",
{'fraction_non_alphanumeric': 0.1608492263404102, 'fraction_numerical': 0.021590500179920834, 'mean_word_length': 1.848360655737705, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, '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': '6391914', 'n_tokens_mistral': 1087, 'n_tokens_neox': 1044, 'n_words': 288}