<commit_before>import numpy as np
import scipy.sparse

import matrix
import matrix.errors
import matrix.dense.util
import matrix.sparse.util


def as_matrix_or_array(A, check_ndim_values=None):
    if not scipy.sparse.issparse(A):
        A = np.asanyarray(A)
    if check_ndim_values is not None and A.ndim not in check_ndim_values:
        raise ValueError('The number of dimensions of the input should be in '
                         '{} but it is {}.'.format(check_ndim_values, A.ndim))
    return A


def as_matrix_or_vector(A):
    return as_matrix_or_array(A, check_ndim_values=(1, 2))


def as_matrix(A):
    return as_matrix_or_array(A, check_ndim_values=(2,))


def as_vector(A):
    A = np.asarray(A)
    if A.ndim != 1:
        raise ValueError('The number of dimensions of the input should be 1 '
                         'but it is {}.'.format(A.ndim))<commit_msg>BUG: matrix.util: as_matrix_or_array returns now always a numpy array if not a sparse matrix<commit_after>import numpy as np
import scipy.sparse

import matrix
import matrix.errors
import matrix.dense.util
import matrix.sparse.util


def as_matrix_or_array(A, check_ndim_values=None):
    if not scipy.sparse.issparse(A):
        A = np.asarray(A)
    if check_ndim_values is not None and A.ndim not in check_ndim_values:
        raise ValueError('The number of dimensions of the input should be in '
                         '{} but it is {}.'.format(check_ndim_values, A.ndim))
    return A


def as_matrix_or_vector(A):
    return as_matrix_or_array(A, check_ndim_values=(1, 2))


def as_matrix(A):
    return as_matrix_or_array(A, check_ndim_values=(2,))


def as_vector(A):
    A = np.asarray(A)
    if A.ndim != 1:
        raise ValueError('The number of dimensions of the input should be 1 '
                         'but it is {}.'.format(A.ndim))
{'fraction_non_alphanumeric': 0.09432933478735006, 'fraction_numerical': 0.0054525627044711015, 'mean_word_length': 3.086859688195991, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2918145', 'n_tokens_mistral': 634, 'n_tokens_neox': 616, 'n_words': 178}