<commit_before>import logging

import cv2

import numpy as np
from raspicam.localtypes import Dimension, Point2D

LOG = logging.getLogger(__name__)


def blit(canvas, image, size: Dimension, offset: Point2D):
    """
    Resizes an image and copies the resized result onto a canvas at position *offset* with size *size*.

    NOTE: The image in *canvas* will be modified in-place!

    Example::

        >>> canvas = np.zeros((100, 100, 3), np.uint8)
        >>> block = np.ones((100, 100, 3), np.uint8)
        >>> blit(canvas, block, Dimension(20, 20), Point2D(10, 10))
    """
    LOG.debug('Blitting image of dimension %r to %r', size, offset)
    if len(image.shape) == 2 and len(canvas.shape) == 3:
        image = cv2.cvtColor(image, cv2.COLOR_GRAY2BGR)
    elif len(image.shape) == 3 and len(canvas.shape) == 2:
        image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    canvas[offset.y:size.height+offset.y,
           offset.x:size.width + offset.x] = cv2.resize(image, (size.width, size.height))


def tile(images, cols=3, rows=3, tilesize=Dimension(320, 240), gap=5):
<commit_msg>Automatically determine rows for tiling<commit_after>import logging

import cv2

import numpy as np
from raspicam.localtypes import Dimension, Point2D

LOG = logging.getLogger(__name__)


def blit(canvas, image, size: Dimension, offset: Point2D):
    """
    Resizes an image and copies the resized result onto a canvas at position *offset* with size *size*.

    NOTE: The image in *canvas* will be modified in-place!

    Example::

        >>> canvas = np.zeros((100, 100, 3), np.uint8)
        >>> block = np.ones((100, 100, 3), np.uint8)
        >>> blit(canvas, block, Dimension(20, 20), Point2D(10, 10))
    """
    LOG.debug('Blitting image of dimension %r to %r', size, offset)
    if len(image.shape) == 2 and len(canvas.shape) == 3:
        image = cv2.cvtColor(image, cv2.COLOR_GRAY2BGR)
    elif len(image.shape) == 3 and len(canvas.shape) == 2:
        image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    canvas[offset.y:size.height+offset.y,
           offset.x:size.width + offset.x] = cv2.resize(image, (size.width, size.height))


def tile(images, cols=3, tilesize=Dimension(320, 240), gap=5):

    rows = len(images) // cols
    if len(images) % cols != 0:
        rows += 1

{'fraction_non_alphanumeric': 0.14029720279720279, 'fraction_numerical': 0.042395104895104896, 'mean_word_length': 3.36, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '6777728', 'n_tokens_mistral': 847, 'n_tokens_neox': 783, 'n_words': 222}