<commit_before>"""Utility sub-module for mir-eval"""

import numpy as np
import os


def index_labels(labels):
    '''Convert a list of string identifiers into numerical indices.

    :parameters:
        - labels : list, shape=(n,)
          A list of annotations, e.g., segment or chord labels from an annotation file.
          ``labels[i]`` can be any hashable type (such as `str` or `int`)

    :returns:
        - indices : list, shape=(n,)
          Numerical representation of `labels`

        - index_to_label : dict
          Mapping to convert numerical indices back to labels.
          `labels[i] == index_to_label[indices[i]]``
    '''

    label_to_index = {}
    index_to_label = {}

    # First, build the unique label mapping
    for index, s in enumerate(sorted(set(labels))):
        label_to_index[s]       = index
        index_to_label[index]   = s

    # Remap the labels to indices
    indices = [label_to_index[s] for s in labels]

    # Return the converted labels, and the inverse mapping
    return indices, index_to_label


def intervals_to_samples(intervals, labels, offset=0, sample_size=0.1,
                         fill_value=None):
    '''Convert an array of labeled time intervals to annotated samples.

    :parameters:
        - intervals : np.ndarray, shape=(n, d)
            An array of time intervals, as returned by
            ``mir_eval.io.load_annotation``.
            The `i`th interval spans time ``intervals[i, 0]`` to
            ``intervals[i, 1]``.

        - labels : list, shape=(n,)
            The annotation for each interval

        - sample_size : float > 0
            duration of each sample to be generated (in seconds)

    :returns:
        - sample_labels : list
            array of segment labels for each generated sample

    ..note::
        Segment intervals will be rounded down to the nearest multiple
        of ``frame_size``.
    '''

    # Round intervals to the sample size
    num_samples = np.floor(intervals.max() / sample_size)<commit_msg>Added correct docstring to intervals_to_samples<commit_after>"""Utility sub-module for mir-eval"""

import numpy as np
import os


def index_labels(labels):
    '''Convert a list of string identifiers into numerical indices.

    :parameters:
        - labels : list, shape=(n,)
          A list of annotations, e.g., segment or chord labels from an annotation file.
          ``labels[i]`` can be any hashable type (such as `str` or `int`)

    :returns:
        - indices : list, shape=(n,)
          Numerical representation of `labels`

        - index_to_label : dict
          Mapping to convert numerical indices back to labels.
          `labels[i] == index_to_label[indices[i]]``
    '''

    label_to_index = {}
    index_to_label = {}

    # First, build the unique label mapping
    for index, s in enumerate(sorted(set(labels))):
        label_to_index[s]       = index
        index_to_label[index]   = s

    # Remap the labels to indices
    indices = [label_to_index[s] for s in labels]

    # Return the converted labels, and the inverse mapping
    return indices, index_to_label


def intervals_to_samples(intervals, labels, offset=0, sample_size=0.1,
                         fill_value=None):
    '''Convert an array of labeled time intervals to annotated samples.

    :parameters:
        - intervals : np.ndarray, shape=(n, d)
            An array of time intervals, as returned by
            ``mir_eval.io.load_annotation``.
            The `i`th interval spans time ``intervals[i, 0]`` to
            ``intervals[i, 1]``.

        - labels : list, shape=(n,)
            The annotation for each interval

        - offset : float > 0
            Phase offset of the sampled time grid (in seconds)

        - sample_size : float > 0
            duration of each sample to be generated (in seconds)

        - fill_value : type(labels[0])
            Object to use for the label with out-of-range time points.

    :returns:
        - sample_labels : list
            array of segment labels for each generated sample

    ..note::
        Segment intervals will be rounded down to the nearest multiple
        of ``frame_size``.
    '''

    # Round intervals to the sample size
    num_samples = int(np.floor(intervals.max() / sample_size))
{'fraction_non_alphanumeric': 0.09224318658280922, 'fraction_numerical': 0.003261122757978104, 'mean_word_length': 2.3158301158301158, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '4178670', 'n_tokens_mistral': 1225, 'n_tokens_neox': 1153, 'n_words': 429}