<commit_before>import numpy as _np


def render_to_bool_array(obj, ranges, nums):
    linspaces = []
    for (a, b), n in zip(ranges, nums):
        linspaces.append(_np.linspace(a, b, num=n))

    [xs, ys, zs] = _np.meshgrid(*linspaces)

    vpf = _np.vectorize(obj.pf)
    return vpf(xs, ys, zs)


# TODO: Find proper way to do it
def tpl(*xs):
    return tuple(xs)


def head(xs):
    return xs[0]


def tail(xs):
    return xs[1:]


def iterate_range(rng, num):
    """

    :param start:
    :param stop:
    :param num:
    :return:

        >>> list(iterate_range((0, 1), num=5))
        [0.0, 0.25, 0.5, 0.75, 1.0]
        >>> list(iterate_range((1, 0), num=5))
        [1.0, 0.75, 0.5, 0.25, 0.0]
        >>> list(iterate_range((0, 0), num=5))
        [0.0, 0.0, 0.0, 0.0, 0.0]
    """
    a, b = rng
    delta = (b - a) / (num - 1)
    for i in range(num):
        yield a + delta*i


def iterate_ranges(ranges, nums):
    """

    :param ranges:
    :param nums:
    :return:

        >>> from pprint import pprint
        >>> pprint(list(iterate_ranges([(0, 1), (0, 1)], [2, 5])))
        [(0.0, 0.0),
         (0.0, 0.25),
         (0.0, 0.5),
         (0.0, 0.75),
         (0.0, 1.0),
         (1.0, 0.0),
         (1.0, 0.25),
         (1.0, 0.5),
         (1.0, 0.75),
         (1.0, 1.0)]


    """
    if len(ranges) <= 0:
        return None
    elif len(ranges) == 1:
        yield from iterate_range(ranges[0], nums[0])
    else:
        (a, b), *tail_ranges = ranges
        num,    *tail_nums   = nums

        for x in iterate_range((a, b), num):
            for rest in iterate_ranges(tail_ranges, tail_nums):
                yield (x,) + (rest,)


# TODO: Ad-hoc
def iterate_ranges3(ranges, nums):
    for x in iterate_range(ranges[0], nums[0]):
        for y in iterate_range(ranges[1], nums[1]):
            for z in iterate_range(ranges[2], nums[2]):
                yield (x, y, z)


def render_to_points_array(obj, ranges, nums):
    """

    :param obj:
    :param ranges:
    :param nums:
    :return:

    """

    pf = obj.pf
    for coords in iterate_ranges3(ranges, nums):
        if pf(*coords):
            yield coords<commit_msg>render.py: remove functions moved to 'rvlm-labhelpers'<commit_after>import numpy as _np


def render_to_bool_array(obj, ranges, nums):
    linspaces = []
    for (a, b), n in zip(ranges, nums):
        linspaces.append(_np.linspace(a, b, num=n))

    [xs, ys, zs] = _np.meshgrid(*linspaces)

    vpf = _np.vectorize(obj.pf)
    return vpf(xs, ys, zs)





def iterate_range(rng, num):
    """

    :param start:
    :param stop:
    :param num:
    :return:

        >>> list(iterate_range((0, 1), num=5))
        [0.0, 0.25, 0.5, 0.75, 1.0]
        >>> list(iterate_range((1, 0), num=5))
        [1.0, 0.75, 0.5, 0.25, 0.0]
        >>> list(iterate_range((0, 0), num=5))
        [0.0, 0.0, 0.0, 0.0, 0.0]
    """
    a, b = rng
    delta = (b - a) / (num - 1)
    for i in range(num):
        yield a + delta*i


# TODO: Ad-hoc
def iterate_ranges3(ranges, nums):
    for x in iterate_range(ranges[0], nums[0]):
        for y in iterate_range(ranges[1], nums[1]):
            for z in iterate_range(ranges[2], nums[2]):
                yield (x, y, z)


def render_to_points_array(obj, ranges, nums):
    """

    :param obj:
    :param ranges:
    :param nums:
    :return:

    """

    pf = obj.pf
    for coords in iterate_ranges3(ranges, nums):
        if pf(*coords):
            yield coords
{'fraction_non_alphanumeric': 0.17151916978956472, 'fraction_numerical': 0.04612280196021908, 'mean_word_length': 2.0043290043290045, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 27, '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': '1048075', 'n_tokens_mistral': 1521, 'n_tokens_neox': 1387, 'n_words': 343}