<commit_before>import collections

import numpy

import chainer
from chainer import cuda
from chainer import function
from chainer import utils
from chainer.utils import type_check
from chainer import variable


class GetItem(function.Function):

    """Function that slices array and extract elements."""

    def __init__(self, slices):<commit_msg>Add a function that convert slices to flat indexes<commit_after>import collections

import numpy

import chainer
from chainer import cuda
from chainer import function
from chainer import utils
from chainer.utils import type_check
from chainer import variable


def slices_to_indexes(slices, shape):
    """Get a flat 1D-array of integer indexes which is specified by the given
    slices to the shape.
    """
    if not isinstance(slices, tuple):
        slices = (slices,)
    index_subtensor = numpy.arange(numpy.prod(shape)).reshape(shape)
    none_slice = slice(None, None, None)  # [:], slice of end-to-end
    for d, slice_ in enumerate(slices):
        dth_indexes = (none_slice,) * d + (slice_, )
        index_subtensor = index_subtensor[dth_indexes]
    return index_subtensor.ravel()


class GetItem(function.Function):

    """Function that slices array and extract elements."""

    def __init__(self, slices):
{'fraction_non_alphanumeric': 0.07770800627943485, 'fraction_numerical': 0.0007849293563579278, 'mean_word_length': 4.246913580246914, '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': '5582320', 'n_tokens_mistral': 379, 'n_tokens_neox': 362, 'n_words': 131}