<commit_before>import pyviennacl as p
from . import _viennacl
from numpy import (ndarray, array,
                   result_type as np_result_type)
import logging

default_log_handler = logging.StreamHandler()
default_log_handler.setFormatter(logging.Formatter(
    "%(levelname)s %(asctime)s %(name)s %(lineno)d %(funcName)s\n  %(message)s"
))
logging.getLogger('pyviennacl').addHandler(default_log_handler)

def fix_operand(opand):
    """
    TODO docstring
    """
    if isinstance(opand, list):
        opand = from_ndarray(array(opand))
    if isinstance(opand, ndarray):
        return from_ndarray(opand)
    if (np_result_type(opand).name in p.HostScalarTypes
        and not isinstance(opand, p.MagicMethods)):
        return p.HostScalar(opand)
    else: return opand

def backend_finish():
    """
    Block until any computation active on the compute backend is finished.
    """
    return _viennacl.backend_finish()

def from_ndarray(obj):
    """
    Convert a NumPy ``ndarray`` into a PyViennaCL object of appropriate
    dimensionality.

    Parameters
    ----------
    obj : array-like

    Returns
    -------
    new : {Vector, Matrix}
        ``Vector`` if ``obj`` has 1 dimension; ``Matrix`` if 2.

    Raises
    ------
    AttributeError
        If ``obj`` has less than 1 or more than 2 dimensions.
    """
    if obj.ndim == 1:
        new = p.Vector(obj)
    elif obj.ndim == 2:
        new = p.Matrix(obj)
    else:
        raise AttributeError("Cannot cope with %d dimensions!" % self.operands[0].ndim)
    return new

<commit_msg>Remove duplicate function<commit_after>import pyviennacl as p
from . import _viennacl
from numpy import (ndarray, array,
                   result_type as np_result_type)
import logging

default_log_handler = logging.StreamHandler()
default_log_handler.setFormatter(logging.Formatter(
    "%(levelname)s %(asctime)s %(name)s %(lineno)d %(funcName)s\n  %(message)s"
))
logging.getLogger('pyviennacl').addHandler(default_log_handler)

def fix_operand(opand):
    """
    TODO docstring
    """
    if isinstance(opand, list):
        opand = from_ndarray(array(opand))
    if isinstance(opand, ndarray):
        return from_ndarray(opand)
    if (np_result_type(opand).name in p.HostScalarTypes
        and not isinstance(opand, p.MagicMethods)):
        return p.HostScalar(opand)
    else: return opand

def from_ndarray(obj):
    """
    Convert a NumPy ``ndarray`` into a PyViennaCL object of appropriate
    dimensionality.

    Parameters
    ----------
    obj : array-like

    Returns
    -------
    new : {Vector, Matrix}
        ``Vector`` if ``obj`` has 1 dimension; ``Matrix`` if 2.

    Raises
    ------
    AttributeError
        If ``obj`` has less than 1 or more than 2 dimensions.
    """
    if obj.ndim == 1:
        new = p.Vector(obj)
    elif obj.ndim == 2:
        new = p.Matrix(obj)
    else:
        raise AttributeError("Cannot cope with %d dimensions!" % self.operands[0].ndim)
    return new


{'fraction_non_alphanumeric': 0.12223710649698594, 'fraction_numerical': 0.004688546550569324, 'mean_word_length': 2.7667087011349305, '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': '5479771', 'n_tokens_mistral': 967, 'n_tokens_neox': 934, 'n_words': 249}