# Path: drain/util.py
# def to_float(*args):
#     """
#     cast numpy arrays to float32
#     if there's more than one, return an array
#     """
#     floats = [np.array(a, dtype=np.float32) for a in args]
#     return floats[0] if len(floats) == 1 else floats


import numpy as np
import pandas as pd
import sklearn.metrics
from drain.util import to_float
    """
    y_true, y_score = to_float(y_true, y_score)
    top = _argsort(y_score, k)

    n = np.nan_to_num(y_true[top]).cumsum()  # fill missing labels with 0
    d = (~np.isnan(y_true[top])).cumsum()    # count number of labels
    return pd.Series(n/d, index=np.arange(1, len(n)+1))


def recall(y_true, y_score, k=None, value=True):
    """
    Returns recall (number of positive examples) in the top k
    If value is False then counts number of negative examples
    TODO: add prop argument to return recall proportion instead of count
    """
    y_true, y_score = to_float(y_true, y_score)
    top = _argtop(y_score, k)

    if not value:
        y_true = 1-y_true

    r = np.nan_to_num(y_true[top]).sum()

    return r


def recall_series(y_true, y_score, k=None, value=True):
    """
    Returns series of length k whose i-th entry is the recall in the top i
    """

# Path: drain/util.py
# def to_float(*args):
#     """
#     cast numpy arrays to float32
#     if there's more than one, return an array
#     """
#     floats = [np.array(a, dtype=np.float32) for a in args]
#     return floats[0] if len(floats) == 1 else floats


# Path: drain/metrics.py
import numpy as np
import pandas as pd
import sklearn.metrics
from drain.util import to_float

    """
    y_true, y_score = to_float(y_true, y_score)
    top = _argsort(y_score, k)

    n = np.nan_to_num(y_true[top]).cumsum()  # fill missing labels with 0
    d = (~np.isnan(y_true[top])).cumsum()    # count number of labels
    return pd.Series(n/d, index=np.arange(1, len(n)+1))


def recall(y_true, y_score, k=None, value=True):
    """
    Returns recall (number of positive examples) in the top k
    If value is False then counts number of negative examples
    TODO: add prop argument to return recall proportion instead of count
    """
    y_true, y_score = to_float(y_true, y_score)
    top = _argtop(y_score, k)

    if not value:
        y_true = 1-y_true

    r = np.nan_to_num(y_true[top]).sum()

    return r


def recall_series(y_true, y_score, k=None, value=True):
    """
    Returns series of length k whose i-th entry is the recall in the top i
    """

    y_true, y_score = to_float(y_true, y_score)