<commit_before><commit_msg>Added enum_matrix function to replace apply_along_axis calls in `topics` etc.<commit_after>import numpy as np
from vsm import enum_sort

def enum_matrix(arr, axis=0, indices=None, field_name='i'):

    if not indices:
        indices = np.arange(arr.shape[0])
    dt = [(field_name, indices.dtype), ('value', arr.dtype)]
    mt = np.empty(shape=arr.shape, dtype=dt)

    mt['value'][:, :] = arr[:, :]

    for i in xrange(arr.shape[1]):
        mt[field_name][:, i] = indices[:]

    for i in xrange(mt.shape[1]):
        mt[:, i].sort(order='value')
        mt[:, i] = mt[:, i][::-1]

    return mt


def test_enum_matrix():

    return enum_matrix(arr)


if __name__=='__main__':

    arr = np.random.random((200000, 60))
{'fraction_non_alphanumeric': 0.172, 'fraction_numerical': 0.017333333333333333, 'mean_word_length': 3.497005988023952, 'pattern_counts': {'":': 0, '<': 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': '5960258', 'n_tokens_mistral': 281, 'n_tokens_neox': 267, 'n_words': 65}